comparison tcp-accept.c @ 297:79bf1023cf11 agent-client

propagate from branch 'au.asn.ucc.matt.dropbear' (head 0501e6f661b5415eb76f3b312d183c3adfbfb712) to branch 'au.asn.ucc.matt.dropbear.cli-agent' (head 01038174ec27245b51bd43a66c01ad930880f67b)
author Matt Johnston <matt@ucc.asn.au>
date Tue, 21 Mar 2006 16:20:59 +0000
parents 3cea9d789cca
children 454a34b2dfd1 6aea2cfc113e
comparison
equal deleted inserted replaced
225:ca7e76d981d9 297:79bf1023cf11
37 static void cleanup_tcp(struct Listener *listener) { 37 static void cleanup_tcp(struct Listener *listener) {
38 38
39 struct TCPListener *tcpinfo = (struct TCPListener*)(listener->typedata); 39 struct TCPListener *tcpinfo = (struct TCPListener*)(listener->typedata);
40 40
41 m_free(tcpinfo->sendaddr); 41 m_free(tcpinfo->sendaddr);
42 m_free(tcpinfo->listenaddr);
42 m_free(tcpinfo); 43 m_free(tcpinfo);
43 } 44 }
44 45
45 static void tcp_acceptor(struct Listener *listener, int sock) { 46 static void tcp_acceptor(struct Listener *listener, int sock) {
46 47
47 int fd; 48 int fd;
48 struct sockaddr_storage addr; 49 struct sockaddr_storage addr;
49 int len; 50 socklen_t len;
50 char ipstring[NI_MAXHOST], portstring[NI_MAXSERV]; 51 char ipstring[NI_MAXHOST], portstring[NI_MAXSERV];
51 struct TCPListener *tcpinfo = (struct TCPListener*)(listener->typedata); 52 struct TCPListener *tcpinfo = (struct TCPListener*)(listener->typedata);
52 53
53 len = sizeof(addr); 54 len = sizeof(addr);
54 55
62 NI_NUMERICHOST | NI_NUMERICSERV) != 0) { 63 NI_NUMERICHOST | NI_NUMERICSERV) != 0) {
63 return; 64 return;
64 } 65 }
65 66
66 if (send_msg_channel_open_init(fd, tcpinfo->chantype) == DROPBEAR_SUCCESS) { 67 if (send_msg_channel_open_init(fd, tcpinfo->chantype) == DROPBEAR_SUCCESS) {
68 unsigned char* addr = NULL;
69 unsigned int port = 0;
67 70
68 buf_putstring(ses.writepayload, tcpinfo->sendaddr, 71 if (tcpinfo->tcp_type == direct) {
69 strlen(tcpinfo->sendaddr)); 72 /* "direct-tcpip" */
70 buf_putint(ses.writepayload, tcpinfo->sendport); 73 /* host to connect, port to connect */
74 addr = tcpinfo->sendaddr;
75 port = tcpinfo->sendport;
76 } else {
77 dropbear_assert(tcpinfo->tcp_type == forwarded);
78 /* "forwarded-tcpip" */
79 /* address that was connected, port that was connected */
80 addr = tcpinfo->listenaddr;
81 port = tcpinfo->listenport;
82 }
83
84 buf_putstring(ses.writepayload, addr, strlen(addr));
85 buf_putint(ses.writepayload, port);
86
87 /* originator ip */
71 buf_putstring(ses.writepayload, ipstring, strlen(ipstring)); 88 buf_putstring(ses.writepayload, ipstring, strlen(ipstring));
89 /* originator port */
72 buf_putint(ses.writepayload, atol(portstring)); 90 buf_putint(ses.writepayload, atol(portstring));
73 91
74 encrypt_packet(); 92 encrypt_packet();
75 93
76 } else { 94 } else {
84 char portstring[NI_MAXSERV]; 102 char portstring[NI_MAXSERV];
85 int socks[DROPBEAR_MAX_SOCKS]; 103 int socks[DROPBEAR_MAX_SOCKS];
86 struct Listener *listener = NULL; 104 struct Listener *listener = NULL;
87 int nsocks; 105 int nsocks;
88 char* errstring = NULL; 106 char* errstring = NULL;
107 // listen_spec = NULL indicates localhost
108 const char* listen_spec = NULL;
89 109
90 TRACE(("enter listen_tcpfwd")) 110 TRACE(("enter listen_tcpfwd"))
91 111
92 /* first we try to bind, so don't need to do so much cleanup on failure */ 112 /* first we try to bind, so don't need to do so much cleanup on failure */
93 snprintf(portstring, sizeof(portstring), "%d", tcpinfo->listenport); 113 snprintf(portstring, sizeof(portstring), "%d", tcpinfo->listenport);
94 114
95 /* XXX Note: we're just listening on localhost, no matter what they tell 115 /* a listenaddr of "" will indicate all interfaces */
96 * us. If someone wants to make it listen otherways, then change 116 if (opts.listen_fwd_all
97 * the "" argument. but that requires UI changes too */ 117 && (strcmp(tcpinfo->listenaddr, "localhost") != 0) ) {
98 nsocks = dropbear_listen("", portstring, socks, 118 listen_spec = tcpinfo->listenaddr;
119 }
120
121 nsocks = dropbear_listen(listen_spec, portstring, socks,
99 DROPBEAR_MAX_SOCKS, &errstring, &ses.maxfd); 122 DROPBEAR_MAX_SOCKS, &errstring, &ses.maxfd);
100 if (nsocks < 0) { 123 if (nsocks < 0) {
101 dropbear_log(LOG_INFO, "TCP forward failed: %s", errstring); 124 dropbear_log(LOG_INFO, "TCP forward failed: %s", errstring);
102 m_free(errstring); 125 m_free(errstring);
103 TRACE(("leave listen_tcpfwd: dropbear_listen failed")) 126 TRACE(("leave listen_tcpfwd: dropbear_listen failed"))