Mercurial > dropbear
annotate tcp-accept.c @ 67:86725004a0ea
fake-rfc stuff
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 12 Aug 2004 14:39:17 +0000 |
parents | 02e4a7f614f8 |
children | e3adf4cf5465 |
rev | line source |
---|---|
62 | 1 #include "includes.h" |
2 #include "ssh.h" | |
64 | 3 #include "tcpfwd.h" |
62 | 4 #include "dbutil.h" |
5 #include "session.h" | |
6 #include "buffer.h" | |
7 #include "packet.h" | |
8 #include "listener.h" | |
9 #include "runopts.h" | |
10 | |
65
02e4a7f614f8
Oops, forgot to call the actual code.
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
11 #ifdef DROPBEAR_TCP_ACCEPT |
63
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
12 |
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
13 static void cleanup_tcp(struct Listener *listener) { |
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
14 |
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
15 struct TCPListener *tcpinfo = (struct TCPListener*)(listener->typedata); |
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
16 |
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
17 m_free(tcpinfo->sendaddr); |
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
18 m_free(tcpinfo); |
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
19 } |
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
20 |
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
21 static void tcp_acceptor(struct Listener *listener, int sock) { |
62 | 22 |
23 int fd; | |
24 struct sockaddr_storage addr; | |
25 int len; | |
26 char ipstring[NI_MAXHOST], portstring[NI_MAXSERV]; | |
27 struct TCPListener *tcpinfo = (struct TCPListener*)(listener->typedata); | |
28 | |
29 len = sizeof(addr); | |
30 | |
31 fd = accept(sock, (struct sockaddr*)&addr, &len); | |
32 if (fd < 0) { | |
33 return; | |
34 } | |
35 | |
36 if (getnameinfo((struct sockaddr*)&addr, len, ipstring, sizeof(ipstring), | |
37 portstring, sizeof(portstring), | |
38 NI_NUMERICHOST | NI_NUMERICSERV) != 0) { | |
39 return; | |
40 } | |
41 | |
42 if (send_msg_channel_open_init(fd, tcpinfo->chantype) == DROPBEAR_SUCCESS) { | |
43 | |
63
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
44 buf_putstring(ses.writepayload, tcpinfo->sendaddr, |
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
45 strlen(tcpinfo->sendaddr)); |
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
46 buf_putint(ses.writepayload, tcpinfo->sendport); |
62 | 47 buf_putstring(ses.writepayload, ipstring, strlen(ipstring)); |
48 buf_putint(ses.writepayload, atol(portstring)); | |
63
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
49 |
62 | 50 encrypt_packet(); |
51 | |
52 } else { | |
53 /* XXX debug? */ | |
54 close(fd); | |
55 } | |
56 } | |
57 | |
58 int listen_tcpfwd(struct TCPListener* tcpinfo) { | |
59 | |
63
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
60 char portstring[NI_MAXSERV]; |
62 | 61 int socks[DROPBEAR_MAX_SOCKS]; |
62 struct Listener *listener = NULL; | |
63 int nsocks; | |
63
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
64 char* errstring = NULL; |
62 | 65 |
66 TRACE(("enter listen_tcpfwd")); | |
67 | |
68 /* first we try to bind, so don't need to do so much cleanup on failure */ | |
64 | 69 snprintf(portstring, sizeof(portstring), "%d", tcpinfo->listenport); |
63
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
70 |
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
71 /* XXX Note: we're just listening on localhost, no matter what they tell |
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
72 * us. If someone wants to make it listen otherways, then change |
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
73 * the "" argument. but that requires UI changes too */ |
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
74 nsocks = dropbear_listen("", portstring, socks, |
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
75 DROPBEAR_MAX_SOCKS, &errstring, &ses.maxfd); |
62 | 76 if (nsocks < 0) { |
63
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
77 dropbear_log(LOG_INFO, "TCP forward failed: %s", errstring); |
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
78 m_free(errstring); |
62 | 79 TRACE(("leave listen_tcpfwd: dropbear_listen failed")); |
80 return DROPBEAR_FAILURE; | |
81 } | |
82 | |
83 listener = new_listener(socks, nsocks, CHANNEL_ID_TCPFORWARDED, tcpinfo, | |
63
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
84 tcp_acceptor, cleanup_tcp); |
62 | 85 |
86 if (listener == NULL) { | |
87 m_free(tcpinfo); | |
88 TRACE(("leave listen_tcpfwd: listener failed")); | |
89 return DROPBEAR_FAILURE; | |
90 } | |
91 | |
92 TRACE(("leave listen_tcpfwd: success")); | |
93 return DROPBEAR_SUCCESS; | |
94 } | |
95 | |
65
02e4a7f614f8
Oops, forgot to call the actual code.
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
96 #endif /* DROPBEAR_TCP_ACCEPT */ |