2 * Dropbear - a SSH2 server
4 * Copyright (c) 2002,2003 Matt Johnston
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 #ifndef DROPBEAR_CHANNEL_H_
26 #define DROPBEAR_CHANNEL_H_
30 #include "circbuffer.h"
32 #define SSH_OPEN_ADMINISTRATIVELY_PROHIBITED 1
33 #define SSH_OPEN_CONNECT_FAILED 2
34 #define SSH_OPEN_UNKNOWN_CHANNEL_TYPE 3
35 #define SSH_OPEN_RESOURCE_SHORTAGE 4
38 #define SSH_OPEN_IN_PROGRESS 99
40 #define CHAN_EXTEND_SIZE 3 /* how many extra slots to add when we need more */
44 enum dropbear_channel_prio
{
45 DROPBEAR_CHANNEL_PRIO_INTERACTIVE
, /* pty shell, x11 */
46 DROPBEAR_CHANNEL_PRIO_UNKNOWABLE
, /* tcp - can't know what's being forwarded */
47 DROPBEAR_CHANNEL_PRIO_BULK
, /* the rest - probably scp or something */
48 DROPBEAR_CHANNEL_PRIO_EARLY
, /* channel is still being set up */
53 unsigned int index
; /* the local channel index */
54 unsigned int remotechan
;
55 unsigned int recvwindow
, transwindow
;
56 unsigned int recvdonelen
;
57 unsigned int recvmaxpacket
, transmaxpacket
;
58 void* typedata
; /* a pointer to type specific data */
59 int writefd
; /* read from wire, written to insecure side */
60 int readfd
; /* read from insecure side, written to wire */
61 int errfd
; /* used like writefd or readfd, depending if it's client or server.
62 Doesn't exactly belong here, but is cleaner here */
63 circbuffer
*writebuf
; /* data from the wire, for local consumption. Can be
65 circbuffer
*extrabuf
; /* extended-data for the program - used like writebuf
68 /* whether close/eof messages have been exchanged */
69 int sent_close
, recv_close
;
70 int recv_eof
, sent_eof
;
72 /* Set after running the ChanType-specific close hander
73 * to ensure we don't run it twice (nor type->checkclose()). */
74 int close_handler_done
;
76 struct dropbear_progress_connection
*conn_pending
;
77 int initconn
; /* used for TCP forwarding, whether the channel has been
80 int await_open
; /* flag indicating whether we've sent an open request
81 for this channel (and are awaiting a confirmation
86 /* Used by client chansession to handle ~ escaping, NULL ignored otherwise */
87 void (*read_mangler
)(struct Channel
*, unsigned char* bytes
, int *len
);
89 const struct ChanType
* type
;
91 enum dropbear_channel_prio prio
;
96 int sepfds
; /* Whether this channel has separate pipes for in/out or not */
98 int (*inithandler
)(struct Channel
*);
99 int (*check_close
)(struct Channel
*);
100 void (*reqhandler
)(struct Channel
*);
101 void (*closehandler
)(struct Channel
*);
104 /* Callback for connect_remote */
105 void channel_connect_done(int result
, int sock
, void* user_data
, const char* errstring
);
107 void chaninitialise(const struct ChanType
*chantypes
[]);
109 void setchannelfds(fd_set
*readfds
, fd_set
*writefds
, int allow_reads
);
110 void channelio(fd_set
*readfd
, fd_set
*writefd
);
111 struct Channel
* getchannel();
112 /* Returns an arbitrary channel that is in a ready state - not
113 being initialised and no EOF in either direction. NULL if none. */
114 struct Channel
* get_any_ready_channel();
116 void recv_msg_channel_open();
117 void recv_msg_channel_request();
118 void send_msg_channel_failure(struct Channel
*channel
);
119 void send_msg_channel_success(struct Channel
*channel
);
120 void recv_msg_channel_data();
121 void recv_msg_channel_extended_data();
122 void recv_msg_channel_window_adjust();
123 void recv_msg_channel_close();
124 void recv_msg_channel_eof();
126 void common_recv_msg_channel_data(struct Channel
*channel
, int fd
,
129 #ifdef DROPBEAR_CLIENT
130 extern const struct ChanType clichansess
;
133 #if defined(USING_LISTENERS) || defined(DROPBEAR_CLIENT)
134 int send_msg_channel_open_init(int fd
, const struct ChanType
*type
);
135 void recv_msg_channel_open_confirmation();
136 void recv_msg_channel_open_failure();
138 void start_send_channel_request(struct Channel
*channel
, char *type
);
140 void send_msg_request_success();
141 void send_msg_request_failure();
144 #endif /* DROPBEAR_CHANNEL_H_ */