Mercurial > dropbear
annotate cli-tcpfwd.c @ 577:69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 24 Feb 2010 16:13:15 +0000 |
parents | 805e557fdff7 |
children | 8c737cd7c1af |
rev | line source |
---|---|
74
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
1 /* |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
2 * Dropbear SSH |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
3 * |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
4 * Copyright (c) 2002,2003 Matt Johnston |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
5 * All rights reserved. |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
6 * |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
7 * Permission is hereby granted, free of charge, to any person obtaining a copy |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
8 * of this software and associated documentation files (the "Software"), to deal |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
9 * in the Software without restriction, including without limitation the rights |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
11 * copies of the Software, and to permit persons to whom the Software is |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
12 * furnished to do so, subject to the following conditions: |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
13 * |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
14 * The above copyright notice and this permission notice shall be included in |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
15 * all copies or substantial portions of the Software. |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
16 * |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
23 * SOFTWARE. */ |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
70
diff
changeset
|
24 |
62 | 25 #include "includes.h" |
26 #include "options.h" | |
64 | 27 #include "dbutil.h" |
28 #include "tcpfwd.h" | |
62 | 29 #include "channel.h" |
64 | 30 #include "runopts.h" |
31 #include "session.h" | |
32 #include "ssh.h" | |
62 | 33 |
156
8c2b3506f112
Rearrange preprocessor parts so that compilation with various options
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
34 #ifdef ENABLE_CLI_REMOTETCPFWD |
64 | 35 static int newtcpforwarded(struct Channel * channel); |
36 | |
37 const struct ChanType cli_chan_tcpremote = { | |
38 1, /* sepfds */ | |
39 "forwarded-tcpip", | |
40 newtcpforwarded, | |
41 NULL, | |
42 NULL, | |
43 NULL | |
44 }; | |
156
8c2b3506f112
Rearrange preprocessor parts so that compilation with various options
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
45 #endif |
8c2b3506f112
Rearrange preprocessor parts so that compilation with various options
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
46 |
8c2b3506f112
Rearrange preprocessor parts so that compilation with various options
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
47 #ifdef ENABLE_CLI_LOCALTCPFWD |
577
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
48 static int cli_localtcp(const char* listenaddr, |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
49 unsigned int listenport, |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
50 const char* remoteaddr, |
156
8c2b3506f112
Rearrange preprocessor parts so that compilation with various options
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
51 unsigned int remoteport); |
62 | 52 static const struct ChanType cli_chan_tcplocal = { |
53 1, /* sepfds */ | |
54 "direct-tcpip", | |
55 NULL, | |
56 NULL, | |
64 | 57 NULL, |
62 | 58 NULL |
59 }; | |
156
8c2b3506f112
Rearrange preprocessor parts so that compilation with various options
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
60 #endif |
62 | 61 |
156
8c2b3506f112
Rearrange preprocessor parts so that compilation with various options
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
62 #ifdef ENABLE_CLI_LOCALTCPFWD |
63
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
63 void setup_localtcp() { |
62 | 64 |
64 | 65 int ret; |
66 | |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
67 TRACE(("enter setup_localtcp")) |
66
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
68 |
64 | 69 if (cli_opts.localfwds == NULL) { |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
70 TRACE(("cli_opts.localfwds == NULL")) |
64 | 71 } |
72 | |
73 while (cli_opts.localfwds != NULL) { | |
577
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
74 ret = cli_localtcp( |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
75 cli_opts.localfwds->listenaddr, |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
76 cli_opts.localfwds->listenport, |
64 | 77 cli_opts.localfwds->connectaddr, |
78 cli_opts.localfwds->connectport); | |
79 if (ret == DROPBEAR_FAILURE) { | |
80 dropbear_log(LOG_WARNING, "Failed local port forward %d:%s:%d", | |
577
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
81 cli_opts.localfwds->listenaddr, |
64 | 82 cli_opts.localfwds->listenport, |
83 cli_opts.localfwds->connectaddr, | |
84 cli_opts.localfwds->connectport); | |
85 } | |
86 | |
87 cli_opts.localfwds = cli_opts.localfwds->next; | |
88 } | |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
89 TRACE(("leave setup_localtcp")) |
62 | 90 |
63
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
91 } |
62 | 92 |
577
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
93 static int cli_localtcp(const char* listenaddr, |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
94 unsigned int listenport, |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
95 const char* remoteaddr, |
63
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
96 unsigned int remoteport) { |
62 | 97 |
98 struct TCPListener* tcpinfo = NULL; | |
64 | 99 int ret; |
100 | |
101 TRACE(("enter cli_localtcp: %d %s %d", listenport, remoteaddr, | |
102 remoteport)); | |
62 | 103 |
184
ca55377e4f7e
- allocate correct buffer size for channel info, rather than sizeof(pointer).
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
104 tcpinfo = (struct TCPListener*)m_malloc(sizeof(struct TCPListener)); |
258
306499676384
* add -g (dbclient) and -a (dropbear) options for allowing non-local
Matt Johnston <matt@ucc.asn.au>
parents:
253
diff
changeset
|
105 |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
74
diff
changeset
|
106 tcpinfo->sendaddr = m_strdup(remoteaddr); |
63
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
107 tcpinfo->sendport = remoteport; |
258
306499676384
* add -g (dbclient) and -a (dropbear) options for allowing non-local
Matt Johnston <matt@ucc.asn.au>
parents:
253
diff
changeset
|
108 |
577
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
109 if (listenaddr) |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
110 { |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
111 tcpinfo->listenaddr = m_strdup(listenaddr); |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
112 } |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
113 else |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
114 { |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
115 if (opts.listen_fwd_all) { |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
116 tcpinfo->listenaddr = m_strdup(""); |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
117 } else { |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
118 tcpinfo->listenaddr = m_strdup("localhost"); |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
119 } |
258
306499676384
* add -g (dbclient) and -a (dropbear) options for allowing non-local
Matt Johnston <matt@ucc.asn.au>
parents:
253
diff
changeset
|
120 } |
63
dcc43965928f
- A nice cleaner structure for tcp (acceptor) forwarding.
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
121 tcpinfo->listenport = listenport; |
258
306499676384
* add -g (dbclient) and -a (dropbear) options for allowing non-local
Matt Johnston <matt@ucc.asn.au>
parents:
253
diff
changeset
|
122 |
62 | 123 tcpinfo->chantype = &cli_chan_tcplocal; |
259
c049490e43fe
* fix -L forwarding on the client, broke last rev
Matt Johnston <matt@ucc.asn.au>
parents:
258
diff
changeset
|
124 tcpinfo->tcp_type = direct; |
62 | 125 |
126 ret = listen_tcpfwd(tcpinfo); | |
127 | |
128 if (ret == DROPBEAR_FAILURE) { | |
129 m_free(tcpinfo); | |
130 } | |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
131 TRACE(("leave cli_localtcp: %d", ret)) |
62 | 132 return ret; |
133 } | |
156
8c2b3506f112
Rearrange preprocessor parts so that compilation with various options
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
134 #endif /* ENABLE_CLI_LOCALTCPFWD */ |
64 | 135 |
156
8c2b3506f112
Rearrange preprocessor parts so that compilation with various options
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
136 #ifdef ENABLE_CLI_REMOTETCPFWD |
577
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
137 static void send_msg_global_request_remotetcp(const char *addr, int port) { |
64 | 138 |
258
306499676384
* add -g (dbclient) and -a (dropbear) options for allowing non-local
Matt Johnston <matt@ucc.asn.au>
parents:
253
diff
changeset
|
139 char* listenspec = NULL; |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
140 TRACE(("enter send_msg_global_request_remotetcp")) |
64 | 141 |
142 CHECKCLEARTOWRITE(); | |
143 buf_putbyte(ses.writepayload, SSH_MSG_GLOBAL_REQUEST); | |
144 buf_putstring(ses.writepayload, "tcpip-forward", 13); | |
505
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
145 buf_putbyte(ses.writepayload, 1); /* want_reply */ |
577
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
146 buf_putstring(ses.writepayload, addr, strlen(addr)); |
64 | 147 buf_putint(ses.writepayload, port); |
148 | |
149 encrypt_packet(); | |
150 | |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
151 TRACE(("leave send_msg_global_request_remotetcp")) |
64 | 152 } |
153 | |
505
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
154 /* The only global success/failure messages are for remotetcp. |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
155 * Since there isn't any identifier in these messages, we have to rely on them |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
156 * being in the same order as we sent the requests. This is the ordering |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
157 * of the cli_opts.remotefwds list */ |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
158 void cli_recv_msg_request_success() { |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
159 |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
160 /* Nothing in the packet. We just mark off that we have received the reply, |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
161 * so that we can report failure for later ones. */ |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
162 struct TCPFwdList * iter = NULL; |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
163 |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
164 iter = cli_opts.remotefwds; |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
165 while (iter != NULL) { |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
166 if (!iter->have_reply) |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
167 { |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
168 iter->have_reply = 1; |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
169 return; |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
170 } |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
171 iter = iter->next; |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
172 } |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
173 } |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
174 |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
175 void cli_recv_msg_request_failure() { |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
176 struct TCPFwdList * iter = NULL; |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
177 |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
178 iter = cli_opts.remotefwds; |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
179 while (iter != NULL) { |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
180 if (!iter->have_reply) |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
181 { |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
182 iter->have_reply = 1; |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
183 dropbear_log(LOG_WARNING, "Remote TCP forward request failed (port %d -> %s:%d)", iter->listenport, iter->connectaddr, iter->connectport); |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
184 return; |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
185 } |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
186 iter = iter->next; |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
187 } |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
188 } |
805e557fdff7
Report errors if a remote request fails
Matt Johnston <matt@ucc.asn.au>
parents:
259
diff
changeset
|
189 |
64 | 190 void setup_remotetcp() { |
191 | |
192 struct TCPFwdList * iter = NULL; | |
193 | |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
194 TRACE(("enter setup_remotetcp")) |
66
38c3146aa23d
Some more sanity-checking of args, and just warn and ignore OpenSSH args
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
195 |
64 | 196 if (cli_opts.remotefwds == NULL) { |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
197 TRACE(("cli_opts.remotefwds == NULL")) |
64 | 198 } |
199 | |
200 iter = cli_opts.remotefwds; | |
201 | |
202 while (iter != NULL) { | |
577
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
203 if (!iter->listenaddr) |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
204 { |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
205 // we store the addresses so that we can compare them |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
206 // when the server sends them back |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
207 if (opts.listen_fwd_all) { |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
208 iter->listenaddr = m_strdup(""); |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
209 } else { |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
210 iter->listenaddr = m_strdup("localhost"); |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
211 } |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
212 } |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
213 send_msg_global_request_remotetcp(iter->listenaddr, iter->listenport); |
64 | 214 iter = iter->next; |
215 } | |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
216 TRACE(("leave setup_remotetcp")) |
64 | 217 } |
218 | |
219 static int newtcpforwarded(struct Channel * channel) { | |
220 | |
577
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
221 char *origaddr = NULL; |
64 | 222 unsigned int origport; |
223 struct TCPFwdList * iter = NULL; | |
224 char portstring[NI_MAXSERV]; | |
225 int sock; | |
70
b0316ce64e4b
Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents:
66
diff
changeset
|
226 int err = SSH_OPEN_ADMINISTRATIVELY_PROHIBITED; |
64 | 227 |
577
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
228 origaddr = buf_getstring(ses.payload, NULL); |
64 | 229 origport = buf_getint(ses.payload); |
230 | |
231 /* Find which port corresponds */ | |
232 iter = cli_opts.remotefwds; | |
233 | |
234 while (iter != NULL) { | |
577
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
235 if (origport == iter->listenport |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
236 && (strcmp(origaddr, iter->listenaddr) == 0)) { |
64 | 237 break; |
238 } | |
239 iter = iter->next; | |
240 } | |
241 | |
242 if (iter == NULL) { | |
243 /* We didn't request forwarding on that port */ | |
577
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
244 cleantext(origaddr); |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
245 dropbear_log(LOG_INFO, "Server sent unrequested forward from \"%s:%d\"", |
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
246 origaddr, origport); |
64 | 247 goto out; |
248 } | |
249 | |
250 snprintf(portstring, sizeof(portstring), "%d", iter->connectport); | |
251 sock = connect_remote(iter->connectaddr, portstring, 1, NULL); | |
252 if (sock < 0) { | |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
253 TRACE(("leave newtcpdirect: sock failed")) |
70
b0316ce64e4b
Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents:
66
diff
changeset
|
254 err = SSH_OPEN_CONNECT_FAILED; |
64 | 255 goto out; |
256 } | |
257 | |
258 ses.maxfd = MAX(ses.maxfd, sock); | |
259 | |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
184
diff
changeset
|
260 /* We don't set readfd, that will get set after the connection's |
64 | 261 * progress succeeds */ |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
184
diff
changeset
|
262 channel->writefd = sock; |
64 | 263 channel->initconn = 1; |
264 | |
70
b0316ce64e4b
Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents:
66
diff
changeset
|
265 err = SSH_OPEN_IN_PROGRESS; |
64 | 266 |
267 out: | |
577
69e98c45db7c
- Progress for allowing specifying a listenaddr for tcp forwards
Matt Johnston <matt@ucc.asn.au>
parents:
505
diff
changeset
|
268 m_free(origaddr); |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
269 TRACE(("leave newtcpdirect: err %d", err)) |
70
b0316ce64e4b
Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents:
66
diff
changeset
|
270 return err; |
64 | 271 } |
156
8c2b3506f112
Rearrange preprocessor parts so that compilation with various options
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
272 #endif /* ENABLE_CLI_REMOTETCPFWD */ |