diff options
Diffstat (limited to 'channels.h')
-rw-r--r-- | channels.h | 185 |
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 | ||
128 | void 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 | |||
145 | Channel *channel_lookup(int id); | ||
146 | Channel * | ||
147 | channel_new(char *ctype, int type, int rfd, int wfd, int efd, | ||
148 | int window, int maxpack, int extusage, char *remote_name, int nonblock); | ||
149 | void | ||
150 | channel_set_fds(int id, int rfd, int wfd, int efd, | ||
151 | int extusage, int nonblock); | ||
152 | void channel_free(Channel *c); | ||
153 | |||
154 | void channel_send_open(int id); | ||
129 | void channel_request(int id, char *service, int wantconfirm); | 155 | void channel_request(int id, char *service, int wantconfirm); |
130 | void channel_request_start(int id, char *service, int wantconfirm); | 156 | void channel_request_start(int id, char *service, int wantconfirm); |
131 | void channel_register_callback(int id, int mtype, channel_callback_fn *fn, void *arg); | 157 | void channel_register_callback(int id, int mtype, channel_callback_fn *fn, void *arg); |
132 | void channel_register_cleanup(int id, channel_callback_fn *fn); | 158 | void channel_register_cleanup(int id, channel_callback_fn *fn); |
133 | void channel_register_filter(int id, channel_filter_fn *fn); | 159 | void channel_register_filter(int id, channel_filter_fn *fn); |
134 | void channel_cancel_cleanup(int id); | 160 | void channel_cancel_cleanup(int id); |
135 | Channel *channel_lookup(int id); | ||
136 | 161 | ||
137 | void | 162 | /* protocol handler */ |
138 | channel_set_fds(int id, int rfd, int wfd, int efd, | ||
139 | int extusage, int nonblock); | ||
140 | |||
141 | void deny_input_open(int type, int plen, void *ctxt); | ||
142 | 163 | ||
143 | void channel_input_channel_request(int type, int plen, void *ctxt); | 164 | void channel_input_channel_request(int type, int plen, void *ctxt); |
144 | void channel_input_close(int type, int plen, void *ctxt); | 165 | void channel_input_close(int type, int plen, void *ctxt); |
@@ -152,66 +173,22 @@ void channel_input_open_failure(int type, int plen, void *ctxt); | |||
152 | void channel_input_port_open(int type, int plen, void *ctxt); | 173 | void channel_input_port_open(int type, int plen, void *ctxt); |
153 | void channel_input_window_adjust(int type, int plen, void *ctxt); | 174 | void channel_input_window_adjust(int type, int plen, void *ctxt); |
154 | 175 | ||
155 | /* Sets specific protocol options. */ | 176 | /* file descriptor handling (read/write) */ |
156 | void 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 | */ | ||
163 | Channel * | ||
164 | channel_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. */ | ||
169 | void channel_free(Channel *c); | ||
170 | 177 | ||
171 | /* | ||
172 | * Allocate/update select bitmasks and add any bits relevant to channels in | ||
173 | * select bitmasks. | ||
174 | */ | ||
175 | void | 178 | void |
176 | channel_prepare_select(fd_set **readsetp, fd_set **writesetp, int *maxfdp, | 179 | channel_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 | */ | ||
183 | void channel_after_select(fd_set * readset, fd_set * writeset); | 181 | void 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. */ | ||
186 | void channel_output_poll(void); | 182 | void channel_output_poll(void); |
187 | 183 | ||
188 | /* Returns true if no channel has too much buffered data. */ | ||
189 | int channel_not_very_much_buffered_data(void); | 184 | int 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. */ | ||
193 | void channel_stop_listening(void); | 185 | void 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 | */ | ||
199 | void channel_close_all(void); | 186 | void channel_close_all(void); |
200 | |||
201 | /* Returns true if there is still an open channel over the connection. */ | ||
202 | int channel_still_open(void); | 187 | int 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 | */ | ||
209 | char *channel_open_message(void); | 188 | char *channel_open_message(void); |
189 | int 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 | */ | ||
215 | int | 192 | int |
216 | channel_request_local_forwarding(u_short listen_port, | 193 | channel_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 | |||
219 | channel_request_forwarding(const char *listen_address, u_short listen_port, | 196 | channel_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 | */ | ||
229 | void | 199 | void |
230 | channel_request_remote_forwarding(u_short port, const char *host, | 200 | channel_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 | */ | ||
238 | void channel_permit_all_opens(void); | 202 | void channel_permit_all_opens(void); |
239 | |||
240 | /* Add host/port to list of allowed targets for port forwarding */ | ||
241 | void channel_add_permitted_opens(char *host, int port); | 203 | void channel_add_permitted_opens(char *host, int port); |
242 | |||
243 | /* Flush list */ | ||
244 | void channel_clear_permitted_opens(void); | 204 | void 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 | */ | ||
251 | void channel_input_port_forward_request(int is_root, int gateway_ports); | 205 | void channel_input_port_forward_request(int is_root, int gateway_ports); |
206 | int channel_connect_to(const char *host, u_short host_port); | ||
207 | int 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 | */ | ||
257 | char *x11_create_display(int screen); | ||
258 | 210 | ||
259 | /* | 211 | int 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 | 213 | char *x11_create_display(int screen); |
262 | * occurs. | ||
263 | */ | ||
264 | char *x11_create_display_inet(int screen, int x11_display_offset); | 214 | char *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 | */ | ||
271 | void x11_input_open(int type, int plen, void *ctxt); | 215 | void 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 | */ | ||
277 | void x11_request_forwarding(void); | 216 | void 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 | */ | ||
283 | void | 217 | void |
284 | x11_request_forwarding_with_spoofing(int client_session_id, | 218 | x11_request_forwarding_with_spoofing(int client_session_id, |
285 | const char *proto, const char *data); | 219 | const char *proto, const char *data); |
220 | void 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 */ |
288 | void auth_request_forwarding(void); | ||
289 | 223 | ||
290 | /* | 224 | void 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 | */ | ||
295 | char *auth_get_socket_name(void); | 225 | char *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 | */ | ||
301 | int auth_input_request_forwarding(struct passwd * pw); | 226 | int auth_input_request_forwarding(struct passwd * pw); |
302 | |||
303 | /* This is called to process an SSH_SMSG_AGENT_OPEN message. */ | ||
304 | void auth_input_open_request(int type, int plen, void *ctxt); | 227 | void auth_input_open_request(int type, int plen, void *ctxt); |
305 | 228 | ||
306 | /* XXX */ | 229 | /* channel close */ |
307 | int channel_connect_to(const char *host, u_short host_port); | ||
308 | int channel_connect_by_listen_adress(u_short listen_port); | ||
309 | int x11_connect_display(void); | ||
310 | 230 | ||
311 | int channel_find_open(void); | 231 | typedef void chan_event_fn(Channel * c); |
232 | |||
233 | /* for the input state */ | ||
234 | extern chan_event_fn *chan_rcvd_oclose; | ||
235 | extern chan_event_fn *chan_read_failed; | ||
236 | extern chan_event_fn *chan_ibuf_empty; | ||
237 | |||
238 | /* for the output state */ | ||
239 | extern chan_event_fn *chan_rcvd_ieof; | ||
240 | extern chan_event_fn *chan_write_failed; | ||
241 | extern chan_event_fn *chan_obuf_empty; | ||
242 | |||
243 | int chan_is_dead(Channel * c); | ||
244 | void chan_mark_dead(Channel * c); | ||
245 | void chan_init_iostates(Channel * c); | ||
246 | void chan_init(void); | ||
312 | 247 | ||
313 | #endif | 248 | #endif |