comparison svr-tcpfwd.c @ 165:0cfba3034be5

Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
author Matt Johnston <matt@ucc.asn.au>
date Sun, 02 Jan 2005 20:25:56 +0000
parents 8c2b3506f112
children 161557a9dde8
comparison
equal deleted inserted replaced
161:b9d3f725e00b 165:0cfba3034be5
68 unsigned char* reqname = NULL; 68 unsigned char* reqname = NULL;
69 unsigned int namelen; 69 unsigned int namelen;
70 unsigned int wantreply = 0; 70 unsigned int wantreply = 0;
71 int ret = DROPBEAR_FAILURE; 71 int ret = DROPBEAR_FAILURE;
72 72
73 TRACE(("enter recv_msg_global_request_remotetcp")); 73 TRACE(("enter recv_msg_global_request_remotetcp"))
74 74
75 if (opts.noremotetcp) { 75 if (opts.noremotetcp) {
76 TRACE(("leave recv_msg_global_request_remotetcp: remote tcp forwarding disabled")); 76 TRACE(("leave recv_msg_global_request_remotetcp: remote tcp forwarding disabled"))
77 goto out; 77 goto out;
78 } 78 }
79 79
80 reqname = buf_getstring(ses.payload, &namelen); 80 reqname = buf_getstring(ses.payload, &namelen);
81 wantreply = buf_getbyte(ses.payload); 81 wantreply = buf_getbyte(ses.payload);
82 82
83 if (namelen > MAXNAMLEN) { 83 if (namelen > MAXNAMLEN) {
84 TRACE(("name len is wrong: %d", namelen)); 84 TRACE(("name len is wrong: %d", namelen))
85 goto out; 85 goto out;
86 } 86 }
87 87
88 if (strcmp("tcpip-forward", reqname) == 0) { 88 if (strcmp("tcpip-forward", reqname) == 0) {
89 ret = svr_remotetcpreq(); 89 ret = svr_remotetcpreq();
90 } else if (strcmp("cancel-tcpip-forward", reqname) == 0) { 90 } else if (strcmp("cancel-tcpip-forward", reqname) == 0) {
91 ret = svr_cancelremotetcp(); 91 ret = svr_cancelremotetcp();
92 } else { 92 } else {
93 TRACE(("reqname isn't tcpip-forward: '%s'", reqname)); 93 TRACE(("reqname isn't tcpip-forward: '%s'", reqname))
94 } 94 }
95 95
96 out: 96 out:
97 if (wantreply) { 97 if (wantreply) {
98 if (ret == DROPBEAR_SUCCESS) { 98 if (ret == DROPBEAR_SUCCESS) {
102 } 102 }
103 } 103 }
104 104
105 m_free(reqname); 105 m_free(reqname);
106 106
107 TRACE(("leave recv_msg_global_request")); 107 TRACE(("leave recv_msg_global_request"))
108 } 108 }
109 109
110 110
111 static void send_msg_request_success() { 111 static void send_msg_request_success() {
112 112
141 unsigned int addrlen; 141 unsigned int addrlen;
142 unsigned int port; 142 unsigned int port;
143 struct Listener * listener = NULL; 143 struct Listener * listener = NULL;
144 struct TCPListener tcpinfo; 144 struct TCPListener tcpinfo;
145 145
146 TRACE(("enter cancelremotetcp")); 146 TRACE(("enter cancelremotetcp"))
147 147
148 bindaddr = buf_getstring(ses.payload, &addrlen); 148 bindaddr = buf_getstring(ses.payload, &addrlen);
149 if (addrlen > MAX_IP_LEN) { 149 if (addrlen > MAX_IP_LEN) {
150 TRACE(("addr len too long: %d", addrlen)); 150 TRACE(("addr len too long: %d", addrlen))
151 goto out; 151 goto out;
152 } 152 }
153 153
154 port = buf_getint(ses.payload); 154 port = buf_getint(ses.payload);
155 155
161 ret = DROPBEAR_SUCCESS; 161 ret = DROPBEAR_SUCCESS;
162 } 162 }
163 163
164 out: 164 out:
165 m_free(bindaddr); 165 m_free(bindaddr);
166 TRACE(("leave cancelremotetcp")); 166 TRACE(("leave cancelremotetcp"))
167 return ret; 167 return ret;
168 } 168 }
169 169
170 static int svr_remotetcpreq() { 170 static int svr_remotetcpreq() {
171 171
173 unsigned char * bindaddr = NULL; 173 unsigned char * bindaddr = NULL;
174 unsigned int addrlen; 174 unsigned int addrlen;
175 struct TCPListener *tcpinfo = NULL; 175 struct TCPListener *tcpinfo = NULL;
176 unsigned int port; 176 unsigned int port;
177 177
178 TRACE(("enter remotetcpreq")); 178 TRACE(("enter remotetcpreq"))
179 179
180 /* NOTE: at this stage, we ignore bindaddr. see below and listen_tcpfwd */ 180 /* NOTE: at this stage, we ignore bindaddr. see below and listen_tcpfwd */
181 bindaddr = buf_getstring(ses.payload, &addrlen); 181 bindaddr = buf_getstring(ses.payload, &addrlen);
182 if (addrlen > MAX_IP_LEN) { 182 if (addrlen > MAX_IP_LEN) {
183 TRACE(("addr len too long: %d", addrlen)); 183 TRACE(("addr len too long: %d", addrlen))
184 goto out; 184 goto out;
185 } 185 }
186 186
187 port = buf_getint(ses.payload); 187 port = buf_getint(ses.payload);
188 188
190 dropbear_log(LOG_INFO, "Server chosen tcpfwd ports are unsupported"); 190 dropbear_log(LOG_INFO, "Server chosen tcpfwd ports are unsupported");
191 goto out; 191 goto out;
192 } 192 }
193 193
194 if (port < 1 || port > 65535) { 194 if (port < 1 || port > 65535) {
195 TRACE(("invalid port: %d", port)); 195 TRACE(("invalid port: %d", port))
196 goto out; 196 goto out;
197 } 197 }
198 198
199 if (!ses.allowprivport && port < IPPORT_RESERVED) { 199 if (!ses.allowprivport && port < IPPORT_RESERVED) {
200 TRACE(("can't assign port < 1024 for non-root")); 200 TRACE(("can't assign port < 1024 for non-root"))
201 goto out; 201 goto out;
202 } 202 }
203 203
204 tcpinfo = (struct TCPListener*)m_malloc(sizeof(struct TCPListener)); 204 tcpinfo = (struct TCPListener*)m_malloc(sizeof(struct TCPListener));
205 tcpinfo->sendaddr = bindaddr; 205 tcpinfo->sendaddr = bindaddr;
216 /* we only free it if a listener wasn't created, since the listener 216 /* we only free it if a listener wasn't created, since the listener
217 * has to remember it if it's to be cancelled */ 217 * has to remember it if it's to be cancelled */
218 m_free(tcpinfo->sendaddr); 218 m_free(tcpinfo->sendaddr);
219 m_free(tcpinfo); 219 m_free(tcpinfo);
220 } 220 }
221 TRACE(("leave remotetcpreq")); 221 TRACE(("leave remotetcpreq"))
222 return ret; 222 return ret;
223 } 223 }
224 224
225 /* Called upon creating a new direct tcp channel (ie we connect out to an 225 /* Called upon creating a new direct tcp channel (ie we connect out to an
226 * address */ 226 * address */
234 int sock; 234 int sock;
235 int len; 235 int len;
236 int err = SSH_OPEN_ADMINISTRATIVELY_PROHIBITED; 236 int err = SSH_OPEN_ADMINISTRATIVELY_PROHIBITED;
237 237
238 if (opts.nolocaltcp) { 238 if (opts.nolocaltcp) {
239 TRACE(("leave newtcpdirect: local tcp forwarding disabled")); 239 TRACE(("leave newtcpdirect: local tcp forwarding disabled"))
240 goto out; 240 goto out;
241 } 241 }
242 242
243 desthost = buf_getstring(ses.payload, &len); 243 desthost = buf_getstring(ses.payload, &len);
244 if (len > MAX_HOST_LEN) { 244 if (len > MAX_HOST_LEN) {
245 TRACE(("leave newtcpdirect: desthost too long")); 245 TRACE(("leave newtcpdirect: desthost too long"))
246 goto out; 246 goto out;
247 } 247 }
248 248
249 destport = buf_getint(ses.payload); 249 destport = buf_getint(ses.payload);
250 250
251 orighost = buf_getstring(ses.payload, &len); 251 orighost = buf_getstring(ses.payload, &len);
252 if (len > MAX_HOST_LEN) { 252 if (len > MAX_HOST_LEN) {
253 TRACE(("leave newtcpdirect: orighost too long")); 253 TRACE(("leave newtcpdirect: orighost too long"))
254 goto out; 254 goto out;
255 } 255 }
256 256
257 origport = buf_getint(ses.payload); 257 origport = buf_getint(ses.payload);
258 258
259 /* best be sure */ 259 /* best be sure */
260 if (origport > 65535 || destport > 65535) { 260 if (origport > 65535 || destport > 65535) {
261 TRACE(("leave newtcpdirect: port > 65535")); 261 TRACE(("leave newtcpdirect: port > 65535"))
262 goto out; 262 goto out;
263 } 263 }
264 264
265 snprintf(portstring, sizeof(portstring), "%d", destport); 265 snprintf(portstring, sizeof(portstring), "%d", destport);
266 sock = connect_remote(desthost, portstring, 1, NULL); 266 sock = connect_remote(desthost, portstring, 1, NULL);
267 if (sock < 0) { 267 if (sock < 0) {
268 err = SSH_OPEN_CONNECT_FAILED; 268 err = SSH_OPEN_CONNECT_FAILED;
269 TRACE(("leave newtcpdirect: sock failed")); 269 TRACE(("leave newtcpdirect: sock failed"))
270 goto out; 270 goto out;
271 } 271 }
272 272
273 ses.maxfd = MAX(ses.maxfd, sock); 273 ses.maxfd = MAX(ses.maxfd, sock);
274 274
282 err = SSH_OPEN_IN_PROGRESS; 282 err = SSH_OPEN_IN_PROGRESS;
283 283
284 out: 284 out:
285 m_free(desthost); 285 m_free(desthost);
286 m_free(orighost); 286 m_free(orighost);
287 TRACE(("leave newtcpdirect: err %d", err)); 287 TRACE(("leave newtcpdirect: err %d", err))
288 return err; 288 return err;
289 } 289 }
290 290
291 #endif 291 #endif