summaryrefslogtreecommitdiff
path: root/channels.c
diff options
context:
space:
mode:
Diffstat (limited to 'channels.c')
-rw-r--r--channels.c74
1 files changed, 36 insertions, 38 deletions
diff --git a/channels.c b/channels.c
index d9513fada..ce4c5952d 100644
--- a/channels.c
+++ b/channels.c
@@ -40,7 +40,7 @@
40 */ 40 */
41 41
42#include "includes.h" 42#include "includes.h"
43RCSID("$OpenBSD: channels.c,v 1.126 2001/06/20 13:56:39 markus Exp $"); 43RCSID("$OpenBSD: channels.c,v 1.127 2001/06/23 15:12:17 itojun Exp $");
44 44
45#include "ssh.h" 45#include "ssh.h"
46#include "ssh1.h" 46#include "ssh1.h"
@@ -133,12 +133,11 @@ static u_int x11_fake_data_len;
133static char *auth_sock_name = NULL; 133static char *auth_sock_name = NULL;
134static char *auth_sock_dir = NULL; 134static char *auth_sock_dir = NULL;
135 135
136
137/* AF_UNSPEC or AF_INET or AF_INET6 */ 136/* AF_UNSPEC or AF_INET or AF_INET6 */
138extern int IPv4or6; 137extern int IPv4or6;
139 138
140/* helper */ 139/* helper */
141void port_open_helper(Channel *c, char *rtype); 140static void port_open_helper(Channel *c, char *rtype);
142 141
143/* -- channel core */ 142/* -- channel core */
144 143
@@ -164,7 +163,7 @@ channel_lookup(int id)
164 * when the channel consumer/producer is ready, e.g. shell exec'd 163 * when the channel consumer/producer is ready, e.g. shell exec'd
165 */ 164 */
166 165
167void 166static void
168channel_register_fds(Channel *c, int rfd, int wfd, int efd, 167channel_register_fds(Channel *c, int rfd, int wfd, int efd,
169 int extusage, int nonblock) 168 int extusage, int nonblock)
170{ 169{
@@ -270,7 +269,7 @@ channel_new(char *ctype, int type, int rfd, int wfd, int efd,
270 269
271/* Close all channel fd/socket. */ 270/* Close all channel fd/socket. */
272 271
273void 272static void
274channel_close_fds(Channel *c) 273channel_close_fds(Channel *c)
275{ 274{
276 debug3("channel_close_fds: channel %d: r %d w %d e %d", 275 debug3("channel_close_fds: channel %d: r %d w %d e %d",
@@ -633,20 +632,20 @@ typedef void chan_fn(Channel *c, fd_set * readset, fd_set * writeset);
633chan_fn *channel_pre[SSH_CHANNEL_MAX_TYPE]; 632chan_fn *channel_pre[SSH_CHANNEL_MAX_TYPE];
634chan_fn *channel_post[SSH_CHANNEL_MAX_TYPE]; 633chan_fn *channel_post[SSH_CHANNEL_MAX_TYPE];
635 634
636void 635static void
637channel_pre_listener(Channel *c, fd_set * readset, fd_set * writeset) 636channel_pre_listener(Channel *c, fd_set * readset, fd_set * writeset)
638{ 637{
639 FD_SET(c->sock, readset); 638 FD_SET(c->sock, readset);
640} 639}
641 640
642void 641static void
643channel_pre_connecting(Channel *c, fd_set * readset, fd_set * writeset) 642channel_pre_connecting(Channel *c, fd_set * readset, fd_set * writeset)
644{ 643{
645 debug3("channel %d: waiting for connection", c->self); 644 debug3("channel %d: waiting for connection", c->self);
646 FD_SET(c->sock, writeset); 645 FD_SET(c->sock, writeset);
647} 646}
648 647
649void 648static void
650channel_pre_open_13(Channel *c, fd_set * readset, fd_set * writeset) 649channel_pre_open_13(Channel *c, fd_set * readset, fd_set * writeset)
651{ 650{
652 if (buffer_len(&c->input) < packet_get_maxsize()) 651 if (buffer_len(&c->input) < packet_get_maxsize())
@@ -655,7 +654,7 @@ channel_pre_open_13(Channel *c, fd_set * readset, fd_set * writeset)
655 FD_SET(c->sock, writeset); 654 FD_SET(c->sock, writeset);
656} 655}
657 656
658void 657static void
659channel_pre_open_15(Channel *c, fd_set * readset, fd_set * writeset) 658channel_pre_open_15(Channel *c, fd_set * readset, fd_set * writeset)
660{ 659{
661 /* test whether sockets are 'alive' for read/write */ 660 /* test whether sockets are 'alive' for read/write */
@@ -672,7 +671,7 @@ channel_pre_open_15(Channel *c, fd_set * readset, fd_set * writeset)
672 } 671 }
673} 672}
674 673
675void 674static void
676channel_pre_open_20(Channel *c, fd_set * readset, fd_set * writeset) 675channel_pre_open_20(Channel *c, fd_set * readset, fd_set * writeset)
677{ 676{
678 if (c->istate == CHAN_INPUT_OPEN && 677 if (c->istate == CHAN_INPUT_OPEN &&
@@ -698,7 +697,7 @@ channel_pre_open_20(Channel *c, fd_set * readset, fd_set * writeset)
698 } 697 }
699} 698}
700 699
701void 700static void
702channel_pre_input_draining(Channel *c, fd_set * readset, fd_set * writeset) 701channel_pre_input_draining(Channel *c, fd_set * readset, fd_set * writeset)
703{ 702{
704 if (buffer_len(&c->input) == 0) { 703 if (buffer_len(&c->input) == 0) {
@@ -710,7 +709,7 @@ channel_pre_input_draining(Channel *c, fd_set * readset, fd_set * writeset)
710 } 709 }
711} 710}
712 711
713void 712static void
714channel_pre_output_draining(Channel *c, fd_set * readset, fd_set * writeset) 713channel_pre_output_draining(Channel *c, fd_set * readset, fd_set * writeset)
715{ 714{
716 if (buffer_len(&c->output) == 0) 715 if (buffer_len(&c->output) == 0)
@@ -728,7 +727,7 @@ channel_pre_output_draining(Channel *c, fd_set * readset, fd_set * writeset)
728 * XXX All this happens at the client side. 727 * XXX All this happens at the client side.
729 * Returns: 0 = need more data, -1 = wrong cookie, 1 = ok 728 * Returns: 0 = need more data, -1 = wrong cookie, 1 = ok
730 */ 729 */
731int 730static int
732x11_open_helper(Buffer *b) 731x11_open_helper(Buffer *b)
733{ 732{
734 u_char *ucp; 733 u_char *ucp;
@@ -786,7 +785,7 @@ x11_open_helper(Buffer *b)
786 return 1; 785 return 1;
787} 786}
788 787
789void 788static void
790channel_pre_x11_open_13(Channel *c, fd_set * readset, fd_set * writeset) 789channel_pre_x11_open_13(Channel *c, fd_set * readset, fd_set * writeset)
791{ 790{
792 int ret = x11_open_helper(&c->output); 791 int ret = x11_open_helper(&c->output);
@@ -811,7 +810,7 @@ channel_pre_x11_open_13(Channel *c, fd_set * readset, fd_set * writeset)
811 } 810 }
812} 811}
813 812
814void 813static void
815channel_pre_x11_open(Channel *c, fd_set * readset, fd_set * writeset) 814channel_pre_x11_open(Channel *c, fd_set * readset, fd_set * writeset)
816{ 815{
817 int ret = x11_open_helper(&c->output); 816 int ret = x11_open_helper(&c->output);
@@ -830,7 +829,7 @@ channel_pre_x11_open(Channel *c, fd_set * readset, fd_set * writeset)
830} 829}
831 830
832/* try to decode a socks4 header */ 831/* try to decode a socks4 header */
833int 832static int
834channel_decode_socks4(Channel *c, fd_set * readset, fd_set * writeset) 833channel_decode_socks4(Channel *c, fd_set * readset, fd_set * writeset)
835{ 834{
836 u_char *p, *host; 835 u_char *p, *host;
@@ -900,7 +899,7 @@ channel_decode_socks4(Channel *c, fd_set * readset, fd_set * writeset)
900} 899}
901 900
902/* dynamic port forwarding */ 901/* dynamic port forwarding */
903void 902static void
904channel_pre_dynamic(Channel *c, fd_set * readset, fd_set * writeset) 903channel_pre_dynamic(Channel *c, fd_set * readset, fd_set * writeset)
905{ 904{
906 u_char *p; 905 u_char *p;
@@ -940,7 +939,7 @@ channel_pre_dynamic(Channel *c, fd_set * readset, fd_set * writeset)
940} 939}
941 940
942/* This is our fake X11 server socket. */ 941/* This is our fake X11 server socket. */
943void 942static void
944channel_post_x11_listener(Channel *c, fd_set * readset, fd_set * writeset) 943channel_post_x11_listener(Channel *c, fd_set * readset, fd_set * writeset)
945{ 944{
946 Channel *nc; 945 Channel *nc;
@@ -998,7 +997,7 @@ channel_post_x11_listener(Channel *c, fd_set * readset, fd_set * writeset)
998 } 997 }
999} 998}
1000 999
1001void 1000static void
1002port_open_helper(Channel *c, char *rtype) 1001port_open_helper(Channel *c, char *rtype)
1003{ 1002{
1004 int direct; 1003 int direct;
@@ -1052,7 +1051,7 @@ port_open_helper(Channel *c, char *rtype)
1052/* 1051/*
1053 * This socket is listening for connections to a forwarded TCP/IP port. 1052 * This socket is listening for connections to a forwarded TCP/IP port.
1054 */ 1053 */
1055void 1054static void
1056channel_post_port_listener(Channel *c, fd_set * readset, fd_set * writeset) 1055channel_post_port_listener(Channel *c, fd_set * readset, fd_set * writeset)
1057{ 1056{
1058 Channel *nc; 1057 Channel *nc;
@@ -1100,7 +1099,7 @@ channel_post_port_listener(Channel *c, fd_set * readset, fd_set * writeset)
1100 * This is the authentication agent socket listening for connections from 1099 * This is the authentication agent socket listening for connections from
1101 * clients. 1100 * clients.
1102 */ 1101 */
1103void 1102static void
1104channel_post_auth_listener(Channel *c, fd_set * readset, fd_set * writeset) 1103channel_post_auth_listener(Channel *c, fd_set * readset, fd_set * writeset)
1105{ 1104{
1106 Channel *nc; 1105 Channel *nc;
@@ -1140,7 +1139,7 @@ channel_post_auth_listener(Channel *c, fd_set * readset, fd_set * writeset)
1140 } 1139 }
1141} 1140}
1142 1141
1143void 1142static void
1144channel_post_connecting(Channel *c, fd_set * readset, fd_set * writeset) 1143channel_post_connecting(Channel *c, fd_set * readset, fd_set * writeset)
1145{ 1144{
1146 int err = 0; 1145 int err = 0;
@@ -1187,7 +1186,7 @@ channel_post_connecting(Channel *c, fd_set * readset, fd_set * writeset)
1187 } 1186 }
1188} 1187}
1189 1188
1190int 1189static int
1191channel_handle_rfd(Channel *c, fd_set * readset, fd_set * writeset) 1190channel_handle_rfd(Channel *c, fd_set * readset, fd_set * writeset)
1192{ 1191{
1193 char buf[16*1024]; 1192 char buf[16*1024];
@@ -1225,7 +1224,7 @@ channel_handle_rfd(Channel *c, fd_set * readset, fd_set * writeset)
1225 } 1224 }
1226 return 1; 1225 return 1;
1227} 1226}
1228int 1227static int
1229channel_handle_wfd(Channel *c, fd_set * readset, fd_set * writeset) 1228channel_handle_wfd(Channel *c, fd_set * readset, fd_set * writeset)
1230{ 1229{
1231 struct termios tio; 1230 struct termios tio;
@@ -1273,7 +1272,7 @@ channel_handle_wfd(Channel *c, fd_set * readset, fd_set * writeset)
1273 } 1272 }
1274 return 1; 1273 return 1;
1275} 1274}
1276int 1275static int
1277channel_handle_efd(Channel *c, fd_set * readset, fd_set * writeset) 1276channel_handle_efd(Channel *c, fd_set * readset, fd_set * writeset)
1278{ 1277{
1279 char buf[16*1024]; 1278 char buf[16*1024];
@@ -1318,7 +1317,7 @@ channel_handle_efd(Channel *c, fd_set * readset, fd_set * writeset)
1318 } 1317 }
1319 return 1; 1318 return 1;
1320} 1319}
1321int 1320static int
1322channel_check_window(Channel *c) 1321channel_check_window(Channel *c)
1323{ 1322{
1324 if (c->type == SSH_CHANNEL_OPEN && 1323 if (c->type == SSH_CHANNEL_OPEN &&
@@ -1338,14 +1337,14 @@ channel_check_window(Channel *c)
1338 return 1; 1337 return 1;
1339} 1338}
1340 1339
1341void 1340static void
1342channel_post_open_1(Channel *c, fd_set * readset, fd_set * writeset) 1341channel_post_open_1(Channel *c, fd_set * readset, fd_set * writeset)
1343{ 1342{
1344 channel_handle_rfd(c, readset, writeset); 1343 channel_handle_rfd(c, readset, writeset);
1345 channel_handle_wfd(c, readset, writeset); 1344 channel_handle_wfd(c, readset, writeset);
1346} 1345}
1347 1346
1348void 1347static void
1349channel_post_open_2(Channel *c, fd_set * readset, fd_set * writeset) 1348channel_post_open_2(Channel *c, fd_set * readset, fd_set * writeset)
1350{ 1349{
1351 channel_handle_rfd(c, readset, writeset); 1350 channel_handle_rfd(c, readset, writeset);
@@ -1355,7 +1354,7 @@ channel_post_open_2(Channel *c, fd_set * readset, fd_set * writeset)
1355 channel_check_window(c); 1354 channel_check_window(c);
1356} 1355}
1357 1356
1358void 1357static void
1359channel_post_output_drain_13(Channel *c, fd_set * readset, fd_set * writeset) 1358channel_post_output_drain_13(Channel *c, fd_set * readset, fd_set * writeset)
1360{ 1359{
1361 int len; 1360 int len;
@@ -1370,7 +1369,7 @@ channel_post_output_drain_13(Channel *c, fd_set * readset, fd_set * writeset)
1370 } 1369 }
1371} 1370}
1372 1371
1373void 1372static void
1374channel_handler_init_20(void) 1373channel_handler_init_20(void)
1375{ 1374{
1376 channel_pre[SSH_CHANNEL_OPEN] = &channel_pre_open_20; 1375 channel_pre[SSH_CHANNEL_OPEN] = &channel_pre_open_20;
@@ -1391,7 +1390,7 @@ channel_handler_init_20(void)
1391 channel_post[SSH_CHANNEL_DYNAMIC] = &channel_post_open_2; 1390 channel_post[SSH_CHANNEL_DYNAMIC] = &channel_post_open_2;
1392} 1391}
1393 1392
1394void 1393static void
1395channel_handler_init_13(void) 1394channel_handler_init_13(void)
1396{ 1395{
1397 channel_pre[SSH_CHANNEL_OPEN] = &channel_pre_open_13; 1396 channel_pre[SSH_CHANNEL_OPEN] = &channel_pre_open_13;
@@ -1413,7 +1412,7 @@ channel_handler_init_13(void)
1413 channel_post[SSH_CHANNEL_DYNAMIC] = &channel_post_open_1; 1412 channel_post[SSH_CHANNEL_DYNAMIC] = &channel_post_open_1;
1414} 1413}
1415 1414
1416void 1415static void
1417channel_handler_init_15(void) 1416channel_handler_init_15(void)
1418{ 1417{
1419 channel_pre[SSH_CHANNEL_OPEN] = &channel_pre_open_15; 1418 channel_pre[SSH_CHANNEL_OPEN] = &channel_pre_open_15;
@@ -1432,7 +1431,7 @@ channel_handler_init_15(void)
1432 channel_post[SSH_CHANNEL_DYNAMIC] = &channel_post_open_1; 1431 channel_post[SSH_CHANNEL_DYNAMIC] = &channel_post_open_1;
1433} 1432}
1434 1433
1435void 1434static void
1436channel_handler_init(void) 1435channel_handler_init(void)
1437{ 1436{
1438 int i; 1437 int i;
@@ -1448,7 +1447,7 @@ channel_handler_init(void)
1448 channel_handler_init_15(); 1447 channel_handler_init_15();
1449} 1448}
1450 1449
1451void 1450static void
1452channel_handler(chan_fn *ftab[], fd_set * readset, fd_set * writeset) 1451channel_handler(chan_fn *ftab[], fd_set * readset, fd_set * writeset)
1453{ 1452{
1454 static int did_init = 0; 1453 static int did_init = 0;
@@ -1828,7 +1827,7 @@ channel_input_open_confirmation(int type, int plen, void *ctxt)
1828 } 1827 }
1829} 1828}
1830 1829
1831char * 1830static char *
1832reason2txt(int reason) 1831reason2txt(int reason)
1833{ 1832{
1834 switch(reason) { 1833 switch(reason) {
@@ -2220,7 +2219,7 @@ channel_clear_permitted_opens(void)
2220 2219
2221 2220
2222/* return socket to remote host, port */ 2221/* return socket to remote host, port */
2223int 2222static int
2224connect_to(const char *host, u_short port) 2223connect_to(const char *host, u_short port)
2225{ 2224{
2226 struct addrinfo hints, *ai, *aitop; 2225 struct addrinfo hints, *ai, *aitop;
@@ -2455,8 +2454,7 @@ x11_create_display_inet(int screen_number, int x11_display_offset)
2455#define X_UNIX_PATH "/tmp/.X11-unix/X" 2454#define X_UNIX_PATH "/tmp/.X11-unix/X"
2456#endif 2455#endif
2457 2456
2458static 2457static int
2459int
2460connect_local_xsocket(u_int dnr) 2458connect_local_xsocket(u_int dnr)
2461{ 2459{
2462 static const char *const x_sockets[] = { 2460 static const char *const x_sockets[] = {