1 /* 2 * ProFTPD - mod_sftp channels 3 * Copyright (c) 2008-2016 TJ Saunders 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. 18 * 19 * As a special exemption, TJ Saunders and other respective copyright holders 20 * give permission to link this program with OpenSSL, and distribute the 21 * resulting executable, without including the source code for OpenSSL in the 22 * source distribution. 23 */ 24 25 #ifndef MOD_SFTP_CHANNEL_H 26 #define MOD_SFTP_CHANNEL_H 27 28 #include "mod_sftp.h" 29 #include "packet.h" 30 31 #define SFTP_SSH2_CHANNEL_OPEN_ADMINISTRATIVELY_PROHIBITED 1 32 #define SFTP_SSH2_CHANNEL_OPEN_CONNECT_FAILED 2 33 #define SFTP_SSH2_CHANNEL_OPEN_UNKNOWN_CHANNEL_TYPE 3 34 #define SFTP_SSH2_CHANNEL_OPEN_RESOURCE_SHORTAGE 4 35 36 #define SFTP_SSH2_CHANNEL_MAX_COUNT 10 37 #define SFTP_SSH2_CHANNEL_MAX_PACKET_SIZE 32768UL 38 39 /* Max channel window size, per RFC4254 Section 5.2 is 2^32-1 bytes. */ 40 #define SFTP_SSH2_CHANNEL_WINDOW_SIZE 4294967295UL 41 42 struct ssh2_channel_databuf; 43 44 struct ssh2_channel { 45 pool *pool; 46 const char *type; 47 48 uint32_t local_channel_id; 49 uint32_t local_windowsz; 50 uint32_t local_max_packetsz; 51 52 uint32_t remote_channel_id; 53 uint32_t remote_windowsz; 54 uint32_t remote_max_packetsz; 55 56 struct ssh2_channel_databuf *outgoing; 57 58 int recvd_eof, sent_eof; 59 int recvd_close, sent_close; 60 61 /* For channel handling systems (e.g. fxp, scp) */ 62 int (*prepare)(uint32_t); 63 int (*postopen)(uint32_t); 64 int (*handle_packet)(pool *, void *, uint32_t, unsigned char *, uint32_t); 65 int (*finish)(uint32_t); 66 }; 67 68 uint32_t sftp_channel_get_max_packetsz(void); 69 uint32_t sftp_channel_get_windowsz(uint32_t); 70 unsigned int sftp_channel_set_max_count(unsigned int); 71 uint32_t sftp_channel_set_max_packetsz(uint32_t); 72 uint32_t sftp_channel_set_max_windowsz(uint32_t); 73 74 int sftp_channel_drain_data(void); 75 int sftp_channel_free(void); 76 int sftp_channel_handle(struct ssh2_packet *, char); 77 int sftp_channel_init(void); 78 int sftp_channel_write_data(pool *, uint32_t, unsigned char *, uint32_t); 79 80 /* Like sftp_channel_write_data(), but sends EXTENDED_DATA messages. */ 81 int sftp_channel_write_ext_data_stderr(pool *, uint32_t, unsigned char *, 82 uint32_t); 83 84 /* Return the number of open channels, if any. If a pointer to a uint32_t 85 * is provided, AND the returned count is greater than zero, then the 86 * pointer will point to a randomly selected remote channel ID for an open 87 * channel. 88 */ 89 unsigned int sftp_channel_opened(uint32_t *); 90 91 #endif /* MOD_SFTP_CHANNEL_H */ 92