annotate tcpfwd-remote.c @ 38:5c6f9d27ea1c

get rid of the substitution... We want a fixed identifier
author Matt Johnston <matt@ucc.asn.au>
date Fri, 30 Jul 2004 11:27:52 +0000
parents 469950e86d0f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 #include "includes.h"
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 #include "ssh.h"
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 #include "tcpfwd-remote.h"
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 #include "dbutil.h"
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 #include "session.h"
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 #include "buffer.h"
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 #include "packet.h"
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 #include "listener.h"
24
469950e86d0f switching to global vars
Matt Johnston <matt@ucc.asn.au>
parents: 21
diff changeset
9 #include "runopts.h"
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 #ifndef DISABLE_REMOTETCPFWD
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 struct RemoteTCP {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 unsigned char* addr;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 unsigned int port;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 };
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 static void send_msg_request_success();
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 static void send_msg_request_failure();
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 static int cancelremotetcp();
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 static int remotetcpreq();
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 static int listen_tcpfwd(unsigned char* bindaddr, unsigned int port);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 static void acceptremote(struct Listener *listener);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 /* At the moment this is completely used for tcp code (with the name reflecting
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 * that). If new request types are added, this should be replaced with code
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 * similar to the request-switching in chansession.c */
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 void recv_msg_global_request_remotetcp() {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 unsigned char* reqname = NULL;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 unsigned int namelen;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 unsigned int wantreply = 0;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 int ret = DROPBEAR_FAILURE;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 TRACE(("enter recv_msg_global_request_remotetcp"));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38
24
469950e86d0f switching to global vars
Matt Johnston <matt@ucc.asn.au>
parents: 21
diff changeset
39 if (opts.noremotetcp) {
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 TRACE(("leave recv_msg_global_request_remotetcp: remote tcp forwarding disabled"));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 goto out;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 reqname = buf_getstring(ses.payload, &namelen);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 wantreply = buf_getbyte(ses.payload);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 if (namelen > MAXNAMLEN) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48 TRACE(("name len is wrong: %d", namelen));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49 goto out;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 if (strcmp("tcpip-forward", reqname) == 0) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53 ret = remotetcpreq();
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54 } else if (strcmp("cancel-tcpip-forward", reqname) == 0) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 ret = cancelremotetcp();
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 } else {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 TRACE(("reqname isn't tcpip-forward: '%s'", reqname));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 out:
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 if (wantreply) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 if (ret == DROPBEAR_SUCCESS) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 send_msg_request_success();
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 } else {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 send_msg_request_failure();
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 m_free(reqname);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 TRACE(("leave recv_msg_global_request"));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74 static const struct ChanType chan_tcpremote = {
11
f76c9389e9e0 Mostly done with the listener changeover
Matt Johnston <matt@ucc.asn.au>
parents: 9
diff changeset
75 1, /* sepfds */
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76 "forwarded-tcpip",
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77 NULL,
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78 NULL,
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 NULL,
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 NULL
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81 };
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84 static void acceptremote(struct Listener *listener) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86 int fd;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 struct sockaddr addr;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 int len;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 char ipstring[NI_MAXHOST], portstring[NI_MAXSERV];
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 struct RemoteTCP *tcpinfo = (struct RemoteTCP*)(listener->typedata);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92 len = sizeof(addr);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
94 fd = accept(listener->sock, &addr, &len);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95 if (fd < 0) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96 return;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
97 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
99 if (getnameinfo(&addr, len, ipstring, sizeof(ipstring), portstring,
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
100 sizeof(portstring), NI_NUMERICHOST | NI_NUMERICSERV) != 0) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
101 return;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
102 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
103
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104 if (send_msg_channel_open_init(fd, &chan_tcpremote) == DROPBEAR_SUCCESS) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
105
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
106 buf_putstring(ses.writepayload, tcpinfo->addr,
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
107 strlen(tcpinfo->addr));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
108 buf_putint(ses.writepayload, tcpinfo->port);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109 buf_putstring(ses.writepayload, ipstring, strlen(ipstring));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110 buf_putint(ses.writepayload, atol(portstring));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
111 encrypt_packet();
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
112
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
113 } else {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
114 /* XXX debug? */
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
115 close(fd);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
116 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
117 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
118
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
119 static void cleanupremote(struct Listener *listener) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
120
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
121 struct RemoteTCP *tcpinfo = (struct RemoteTCP*)(listener->typedata);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
122
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123 m_free(tcpinfo->addr);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
124 m_free(tcpinfo);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
125 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
126
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
127 static void send_msg_request_success() {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
128
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
129 CHECKCLEARTOWRITE();
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
130 buf_putbyte(ses.writepayload, SSH_MSG_REQUEST_SUCCESS);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
131 encrypt_packet();
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
132
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
133 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
134
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
135 static void send_msg_request_failure() {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
137 CHECKCLEARTOWRITE();
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
138 buf_putbyte(ses.writepayload, SSH_MSG_REQUEST_FAILURE);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
139 encrypt_packet();
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
140
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
141 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
142
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
143 static int matchtcp(void* typedata1, void* typedata2) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
144
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
145 const struct RemoteTCP *info1 = (struct RemoteTCP*)typedata1;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
146 const struct RemoteTCP *info2 = (struct RemoteTCP*)typedata2;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
147
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
148 return info1->port == info2->port
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
149 && (strcmp(info1->addr, info2->addr) == 0);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
150 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
151
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
152 static int cancelremotetcp() {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
153
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
154 int ret = DROPBEAR_FAILURE;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
155 unsigned char * bindaddr = NULL;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
156 unsigned int addrlen;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
157 unsigned int port;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
158 struct Listener * listener = NULL;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
159 struct RemoteTCP tcpinfo;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
160
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
161 TRACE(("enter cancelremotetcp"));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
162
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
163 bindaddr = buf_getstring(ses.payload, &addrlen);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
164 if (addrlen > MAX_IP_LEN) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
165 TRACE(("addr len too long: %d", addrlen));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
166 goto out;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
167 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
168
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
169 port = buf_getint(ses.payload);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
170
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
171 tcpinfo.addr = bindaddr;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
172 tcpinfo.port = port;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
173 listener = get_listener(CHANNEL_ID_TCPFORWARDED, &tcpinfo, matchtcp);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
174 if (listener) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
175 remove_listener( listener );
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
176 ret = DROPBEAR_SUCCESS;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
177 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
178
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
179 out:
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
180 m_free(bindaddr);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
181 TRACE(("leave cancelremotetcp"));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
182 return ret;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
183 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
184
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
185 static int remotetcpreq() {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
186
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
187 int ret = DROPBEAR_FAILURE;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
188 unsigned char * bindaddr = NULL;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
189 unsigned int addrlen;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
190 unsigned int port;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
191
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
192 TRACE(("enter remotetcpreq"));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
193
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
194 bindaddr = buf_getstring(ses.payload, &addrlen);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
195 if (addrlen > MAX_IP_LEN) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
196 TRACE(("addr len too long: %d", addrlen));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
197 goto out;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
198 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
199
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
200 port = buf_getint(ses.payload);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
201
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
202 if (port == 0) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
203 dropbear_log(LOG_INFO, "Server chosen tcpfwd ports are unsupported");
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
204 goto out;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
205 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
206
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
207 if (port < 1 || port > 65535) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
208 TRACE(("invalid port: %d", port));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
209 goto out;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
210 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
211
21
d7cc5b484a2e - Port restriction code back in
Matt Johnston <matt@ucc.asn.au>
parents: 11
diff changeset
212 if (!ses.allowprivport && port < IPPORT_RESERVED) {
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
213 TRACE(("can't assign port < 1024 for non-root"));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
214 goto out;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
215 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
216
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
217 ret = listen_tcpfwd(bindaddr, port);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
218
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
219 out:
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
220 if (ret == DROPBEAR_FAILURE) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
221 /* we only free it if a listener wasn't created, since the listener
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
222 * has to remember it if it's to be cancelled */
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
223 m_free(bindaddr);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
224 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
225 TRACE(("leave remotetcpreq"));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
226 return ret;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
227 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
228
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
229 static int listen_tcpfwd(unsigned char* bindaddr, unsigned int port) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
230
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
231 struct RemoteTCP * tcpinfo = NULL;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
232 char portstring[6]; /* "65535\0" */
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
233 struct addrinfo *res = NULL, *ai = NULL;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
234 struct addrinfo hints;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
235 int sock = -1;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
236 struct Listener *listener = NULL;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
237
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
238 TRACE(("enter listen_tcpfwd"));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
239
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
240 /* first we try to bind, so don't need to do so much cleanup on failure */
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
241 snprintf(portstring, sizeof(portstring), "%d", port);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
242 memset(&hints, 0x0, sizeof(hints));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
243 hints.ai_socktype = SOCK_STREAM;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
244 hints.ai_family = PF_INET;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
245 hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
246
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
247 if (getaddrinfo(bindaddr, portstring, &hints, &res) < 0) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
248 TRACE(("leave listen_tcpfwd: getaddrinfo failed: %s",
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
249 strerror(errno)));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
250 goto done;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
251 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
252
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
253 /* find the first one which works */
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
254 for (ai = res; ai != NULL; ai = ai->ai_next) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
255 if (ai->ai_family != PF_INET && ai->ai_family != PF_INET6) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
256 continue;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
257 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
258
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
259 sock = socket(ai->ai_family, SOCK_STREAM, 0);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
260 if (sock < 0) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
261 TRACE(("socket failed: %s", strerror(errno)));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
262 goto fail;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
263 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
264
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
265 if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
266 TRACE(("bind failed: %s", strerror(errno)));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
267 goto fail;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
268 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
269
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
270 if (listen(sock, 20) < 0) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
271 TRACE(("listen failed: %s", strerror(errno)));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
272 goto fail;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
273 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
274
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
275 if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
276 TRACE(("fcntl nonblocking failed: %s", strerror(errno)));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
277 goto fail;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
278 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
279
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
280 /* success */
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
281 break;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
282
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
283 fail:
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
284 close(sock);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
285 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
286
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
287
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
288 if (ai == NULL) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
289 TRACE(("no successful sockets"));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
290 goto done;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
291 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
292
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
293 tcpinfo = (struct RemoteTCP*)m_malloc(sizeof(struct RemoteTCP));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
294 tcpinfo->addr = bindaddr;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
295 tcpinfo->port = port;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
296
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
297 listener = new_listener(sock, CHANNEL_ID_TCPFORWARDED, tcpinfo,
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
298 acceptremote, cleanupremote);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
299
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
300 if (listener == NULL) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
301 m_free(tcpinfo);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
302 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
303
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
304 done:
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
305 if (res) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
306 freeaddrinfo(res);
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
307 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
308
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
309 TRACE(("leave listen_tcpfwd"));
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
310 if (listener == NULL) {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
311 return DROPBEAR_FAILURE;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
312 } else {
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
313 return DROPBEAR_SUCCESS;
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
314 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
315 }
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
316
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
317 #endif /* DISABLE_REMOTETCPFWD */