Debian Codegraph @

contrib/mod_sftp/channel.h

raw symbols SCIP
1 /*
2 * ProFTPD - mod_sftp channels
3 * Copyright (c) 2008-2023 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 *incoming_head, *incoming_tail;
57 struct ssh2_channel_databuf *outgoing_head, *outgoing_tail;
58 unsigned long incoming_len, outgoing_len;
59
60 int recvd_eof, sent_eof;
61 int recvd_close, sent_close;
62
63 /* For channel handling systems (e.g. fxp, scp) */
64 int (*prepare)(uint32_t);
65 int (*postopen)(uint32_t);
66 int (*handle_packet)(pool *, void *, uint32_t, unsigned char *, uint32_t);
67 int (*finish)(uint32_t);
68 };
69
70 uint32_t sftp_channel_get_max_packetsz(void);
71 uint32_t sftp_channel_get_windowsz(uint32_t);
72 unsigned int sftp_channel_set_max_count(unsigned int);
73 uint32_t sftp_channel_set_max_packetsz(uint32_t);
74 uint32_t sftp_channel_set_max_windowsz(uint32_t);
75
76 int sftp_channel_drain_data(void);
77 int sftp_channel_free(void);
78 int sftp_channel_handle(struct ssh2_packet *, char);
79 int sftp_channel_init(void);
80 int sftp_channel_write_data(pool *, uint32_t, unsigned char *, uint32_t);
81
82 /* Like sftp_channel_write_data(), but sends EXTENDED_DATA messages. */
83 int sftp_channel_write_ext_data_stderr(pool *, uint32_t, unsigned char *,
84 uint32_t);
85
86 /* Return the number of open channels, if any. If a pointer to a uint32_t
87 * is provided, AND the returned count is greater than zero, then the
88 * pointer will point to a randomly selected remote channel ID for an open
89 * channel.
90 */
91 unsigned int sftp_channel_opened(uint32_t *);
92
93 #endif /* MOD_SFTP_CHANNEL_H */