Mercurial > dropbear
comparison tcp-accept.c @ 258:306499676384
* add -g (dbclient) and -a (dropbear) options for allowing non-local
hosts to connect to forwarded ports. Rearranged various some of the
tcp listening code.
* changed to /* */ style brackets in svr-authpam.c
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 04 Dec 2005 16:13:11 +0000 |
parents | 0cfba3034be5 |
children | c049490e43fe |
comparison
equal
deleted
inserted
replaced
257:63601217f5ab | 258:306499676384 |
---|---|
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 |
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) { |
67 | 68 |
68 buf_putstring(ses.writepayload, tcpinfo->sendaddr, | 69 // address that was connected |
69 strlen(tcpinfo->sendaddr)); | 70 buf_putstring(ses.writepayload, tcpinfo->listenaddr, |
70 buf_putint(ses.writepayload, tcpinfo->sendport); | 71 strlen(tcpinfo->listenaddr)); |
72 // port that was connected | |
73 buf_putint(ses.writepayload, tcpinfo->listenport); | |
74 // originator ip | |
71 buf_putstring(ses.writepayload, ipstring, strlen(ipstring)); | 75 buf_putstring(ses.writepayload, ipstring, strlen(ipstring)); |
76 // originator port | |
72 buf_putint(ses.writepayload, atol(portstring)); | 77 buf_putint(ses.writepayload, atol(portstring)); |
73 | 78 |
74 encrypt_packet(); | 79 encrypt_packet(); |
75 | 80 |
76 } else { | 81 } else { |
84 char portstring[NI_MAXSERV]; | 89 char portstring[NI_MAXSERV]; |
85 int socks[DROPBEAR_MAX_SOCKS]; | 90 int socks[DROPBEAR_MAX_SOCKS]; |
86 struct Listener *listener = NULL; | 91 struct Listener *listener = NULL; |
87 int nsocks; | 92 int nsocks; |
88 char* errstring = NULL; | 93 char* errstring = NULL; |
94 // listen_spec = NULL indicates localhost | |
95 const char* listen_spec = NULL; | |
89 | 96 |
90 TRACE(("enter listen_tcpfwd")) | 97 TRACE(("enter listen_tcpfwd")) |
91 | 98 |
92 /* first we try to bind, so don't need to do so much cleanup on failure */ | 99 /* first we try to bind, so don't need to do so much cleanup on failure */ |
93 snprintf(portstring, sizeof(portstring), "%d", tcpinfo->listenport); | 100 snprintf(portstring, sizeof(portstring), "%d", tcpinfo->listenport); |
94 | 101 |
95 /* XXX Note: we're just listening on localhost, no matter what they tell | 102 /* a listenaddr of "" will indicate all interfaces */ |
96 * us. If someone wants to make it listen otherways, then change | 103 if (opts.listen_fwd_all |
97 * the "" argument. but that requires UI changes too */ | 104 && (strcmp(tcpinfo->listenaddr, "localhost") != 0) ) { |
98 nsocks = dropbear_listen("", portstring, socks, | 105 listen_spec = tcpinfo->listenaddr; |
106 } | |
107 | |
108 nsocks = dropbear_listen(listen_spec, portstring, socks, | |
99 DROPBEAR_MAX_SOCKS, &errstring, &ses.maxfd); | 109 DROPBEAR_MAX_SOCKS, &errstring, &ses.maxfd); |
100 if (nsocks < 0) { | 110 if (nsocks < 0) { |
101 dropbear_log(LOG_INFO, "TCP forward failed: %s", errstring); | 111 dropbear_log(LOG_INFO, "TCP forward failed: %s", errstring); |
102 m_free(errstring); | 112 m_free(errstring); |
103 TRACE(("leave listen_tcpfwd: dropbear_listen failed")) | 113 TRACE(("leave listen_tcpfwd: dropbear_listen failed")) |