summaryrefslogtreecommitdiff
path: root/channels.h
diff options
context:
space:
mode:
Diffstat (limited to 'channels.h')
-rw-r--r--channels.h185
1 files changed, 60 insertions, 125 deletions
diff --git a/channels.h b/channels.h
index 55d31854e..e9d583656 100644
--- a/channels.h
+++ b/channels.h
@@ -32,10 +32,10 @@
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */ 34 */
35/* RCSID("$OpenBSD: channels.h,v 1.33 2001/05/28 23:14:49 markus Exp $"); */ 35/* RCSID("$OpenBSD: channels.h,v 1.35 2001/05/31 10:30:15 markus Exp $"); */
36 36
37#ifndef CHANNELS_H 37#ifndef CHANNEL_H
38#define CHANNELS_H 38#define CHANNEL_H
39 39
40#include "buffer.h" 40#include "buffer.h"
41 41
@@ -124,21 +124,42 @@ struct Channel {
124#define CHAN_X11_WINDOW_DEFAULT (4*1024) 124#define CHAN_X11_WINDOW_DEFAULT (4*1024)
125#define CHAN_X11_PACKET_DEFAULT (CHAN_X11_WINDOW_DEFAULT/2) 125#define CHAN_X11_PACKET_DEFAULT (CHAN_X11_WINDOW_DEFAULT/2)
126 126
127/* possible input states */
128#define CHAN_INPUT_OPEN 0x01
129#define CHAN_INPUT_WAIT_DRAIN 0x02
130#define CHAN_INPUT_WAIT_OCLOSE 0x04
131#define CHAN_INPUT_CLOSED 0x08
127 132
128void channel_open(int id); 133/* possible output states */
134#define CHAN_OUTPUT_OPEN 0x10
135#define CHAN_OUTPUT_WAIT_DRAIN 0x20
136#define CHAN_OUTPUT_WAIT_IEOF 0x40
137#define CHAN_OUTPUT_CLOSED 0x80
138
139#define CHAN_CLOSE_SENT 0x01
140#define CHAN_CLOSE_RCVD 0x02
141
142
143/* channel management */
144
145Channel *channel_lookup(int id);
146Channel *
147channel_new(char *ctype, int type, int rfd, int wfd, int efd,
148 int window, int maxpack, int extusage, char *remote_name, int nonblock);
149void
150channel_set_fds(int id, int rfd, int wfd, int efd,
151 int extusage, int nonblock);
152void channel_free(Channel *c);
153
154void channel_send_open(int id);
129void channel_request(int id, char *service, int wantconfirm); 155void channel_request(int id, char *service, int wantconfirm);
130void channel_request_start(int id, char *service, int wantconfirm); 156void channel_request_start(int id, char *service, int wantconfirm);
131void channel_register_callback(int id, int mtype, channel_callback_fn *fn, void *arg); 157void channel_register_callback(int id, int mtype, channel_callback_fn *fn, void *arg);
132void channel_register_cleanup(int id, channel_callback_fn *fn); 158void channel_register_cleanup(int id, channel_callback_fn *fn);
133void channel_register_filter(int id, channel_filter_fn *fn); 159void channel_register_filter(int id, channel_filter_fn *fn);
134void channel_cancel_cleanup(int id); 160void channel_cancel_cleanup(int id);
135Channel *channel_lookup(int id);
136 161
137void 162/* protocol handler */
138channel_set_fds(int id, int rfd, int wfd, int efd,
139 int extusage, int nonblock);
140
141void deny_input_open(int type, int plen, void *ctxt);
142 163
143void channel_input_channel_request(int type, int plen, void *ctxt); 164void channel_input_channel_request(int type, int plen, void *ctxt);
144void channel_input_close(int type, int plen, void *ctxt); 165void channel_input_close(int type, int plen, void *ctxt);
@@ -152,66 +173,22 @@ void channel_input_open_failure(int type, int plen, void *ctxt);
152void channel_input_port_open(int type, int plen, void *ctxt); 173void channel_input_port_open(int type, int plen, void *ctxt);
153void channel_input_window_adjust(int type, int plen, void *ctxt); 174void channel_input_window_adjust(int type, int plen, void *ctxt);
154 175
155/* Sets specific protocol options. */ 176/* file descriptor handling (read/write) */
156void channel_set_options(int hostname_in_open);
157
158/*
159 * Allocate a new channel object and set its type and socket. Remote_name
160 * must have been allocated with xmalloc; this will free it when the channel
161 * is freed.
162 */
163Channel *
164channel_new(char *ctype, int type, int rfd, int wfd, int efd,
165 int window, int maxpack, int extended_usage, char *remote_name,
166 int nonblock);
167
168/* Free the channel and close its socket. */
169void channel_free(Channel *c);
170 177
171/*
172 * Allocate/update select bitmasks and add any bits relevant to channels in
173 * select bitmasks.
174 */
175void 178void
176channel_prepare_select(fd_set **readsetp, fd_set **writesetp, int *maxfdp, 179channel_prepare_select(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
177 int rekeying); 180 int rekeying);
178
179/*
180 * After select, perform any appropriate operations for channels which have
181 * events pending.
182 */
183void channel_after_select(fd_set * readset, fd_set * writeset); 181void channel_after_select(fd_set * readset, fd_set * writeset);
184
185/* If there is data to send to the connection, send some of it now. */
186void channel_output_poll(void); 182void channel_output_poll(void);
187 183
188/* Returns true if no channel has too much buffered data. */
189int channel_not_very_much_buffered_data(void); 184int channel_not_very_much_buffered_data(void);
190
191/* This closes any sockets that are listening for connections; this removes
192 any unix domain sockets. */
193void channel_stop_listening(void); 185void channel_stop_listening(void);
194
195/*
196 * Closes the sockets of all channels. This is used to close extra file
197 * descriptors after a fork.
198 */
199void channel_close_all(void); 186void channel_close_all(void);
200
201/* Returns true if there is still an open channel over the connection. */
202int channel_still_open(void); 187int channel_still_open(void);
203
204/*
205 * Returns a string containing a list of all open channels. The list is
206 * suitable for displaying to the user. It uses crlf instead of newlines.
207 * The caller should free the string with xfree.
208 */
209char *channel_open_message(void); 188char *channel_open_message(void);
189int channel_find_open(void);
210 190
211/* 191/* channel_tcpfwd.c */
212 * Initiate forwarding of connections to local port "port" through the secure
213 * channel to host:port from remote side.
214 */
215int 192int
216channel_request_local_forwarding(u_short listen_port, 193channel_request_local_forwarding(u_short listen_port,
217 const char *host_to_connect, u_short port_to_connect, int gateway_ports); 194 const char *host_to_connect, u_short port_to_connect, int gateway_ports);
@@ -219,95 +196,53 @@ int
219channel_request_forwarding(const char *listen_address, u_short listen_port, 196channel_request_forwarding(const char *listen_address, u_short listen_port,
220 const char *host_to_connect, u_short port_to_connect, int gateway_ports, 197 const char *host_to_connect, u_short port_to_connect, int gateway_ports,
221 int remote_fwd); 198 int remote_fwd);
222
223/*
224 * Initiate forwarding of connections to port "port" on remote host through
225 * the secure channel to host:port from local side. This never returns if
226 * there was an error. This registers that open requests for that port are
227 * permitted.
228 */
229void 199void
230channel_request_remote_forwarding(u_short port, const char *host, 200channel_request_remote_forwarding(u_short port, const char *host,
231 u_short remote_port); 201 u_short remote_port);
232
233/*
234 * Permits opening to any host/port if permitted_opens[] is empty. This is
235 * usually called by the server, because the user could connect to any port
236 * anyway, and the server has no way to know but to trust the client anyway.
237 */
238void channel_permit_all_opens(void); 202void channel_permit_all_opens(void);
239
240/* Add host/port to list of allowed targets for port forwarding */
241void channel_add_permitted_opens(char *host, int port); 203void channel_add_permitted_opens(char *host, int port);
242
243/* Flush list */
244void channel_clear_permitted_opens(void); 204void channel_clear_permitted_opens(void);
245
246/*
247 * This is called after receiving CHANNEL_FORWARDING_REQUEST. This initates
248 * listening for the port, and sends back a success reply (or disconnect
249 * message if there was an error). This never returns if there was an error.
250 */
251void channel_input_port_forward_request(int is_root, int gateway_ports); 205void channel_input_port_forward_request(int is_root, int gateway_ports);
206int channel_connect_to(const char *host, u_short host_port);
207int channel_connect_by_listen_adress(u_short listen_port);
252 208
253/* 209/* x11 forwarding */
254 * Creates a port for X11 connections, and starts listening for it. Returns
255 * the display name, or NULL if an error was encountered.
256 */
257char *x11_create_display(int screen);
258 210
259/* 211int x11_connect_display(void);
260 * Creates an internet domain socket for listening for X11 connections. 212//int x11_check_cookie(Buffer *b);
261 * Returns a suitable value for the DISPLAY variable, or NULL if an error 213char *x11_create_display(int screen);
262 * occurs.
263 */
264char *x11_create_display_inet(int screen, int x11_display_offset); 214char *x11_create_display_inet(int screen, int x11_display_offset);
265
266/*
267 * This is called when SSH_SMSG_X11_OPEN is received. The packet contains
268 * the remote channel number. We should do whatever we want, and respond
269 * with either SSH_MSG_OPEN_CONFIRMATION or SSH_MSG_OPEN_FAILURE.
270 */
271void x11_input_open(int type, int plen, void *ctxt); 215void x11_input_open(int type, int plen, void *ctxt);
272
273/*
274 * Requests forwarding of X11 connections. This should be called on the
275 * client only.
276 */
277void x11_request_forwarding(void); 216void x11_request_forwarding(void);
278
279/*
280 * Requests forwarding for X11 connections, with authentication spoofing.
281 * This should be called in the client only.
282 */
283void 217void
284x11_request_forwarding_with_spoofing(int client_session_id, 218x11_request_forwarding_with_spoofing(int client_session_id,
285 const char *proto, const char *data); 219 const char *proto, const char *data);
220void deny_input_open(int type, int plen, void *ctxt);
286 221
287/* Sends a message to the server to request authentication fd forwarding. */ 222/* agent forwarding */
288void auth_request_forwarding(void);
289 223
290/* 224void auth_request_forwarding(void);
291 * Returns the name of the forwarded authentication socket. Returns NULL if
292 * there is no forwarded authentication socket. The returned value points to
293 * a static buffer.
294 */
295char *auth_get_socket_name(void); 225char *auth_get_socket_name(void);
296
297/*
298 * This is called to process SSH_CMSG_AGENT_REQUEST_FORWARDING on the server.
299 * This starts forwarding authentication requests.
300 */
301int auth_input_request_forwarding(struct passwd * pw); 226int auth_input_request_forwarding(struct passwd * pw);
302
303/* This is called to process an SSH_SMSG_AGENT_OPEN message. */
304void auth_input_open_request(int type, int plen, void *ctxt); 227void auth_input_open_request(int type, int plen, void *ctxt);
305 228
306/* XXX */ 229/* channel close */
307int channel_connect_to(const char *host, u_short host_port);
308int channel_connect_by_listen_adress(u_short listen_port);
309int x11_connect_display(void);
310 230
311int channel_find_open(void); 231typedef void chan_event_fn(Channel * c);
232
233/* for the input state */
234extern chan_event_fn *chan_rcvd_oclose;
235extern chan_event_fn *chan_read_failed;
236extern chan_event_fn *chan_ibuf_empty;
237
238/* for the output state */
239extern chan_event_fn *chan_rcvd_ieof;
240extern chan_event_fn *chan_write_failed;
241extern chan_event_fn *chan_obuf_empty;
242
243int chan_is_dead(Channel * c);
244void chan_mark_dead(Channel * c);
245void chan_init_iostates(Channel * c);
246void chan_init(void);
312 247
313#endif 248#endif