comparison cli-tcpfwd.c @ 551:c3f2ec71e3d4 agent-client

New standard linked list to use, rather than adhoc SignKeyList or TCPFwdList
author Matt Johnston <matt@ucc.asn.au>
date Mon, 06 Jul 2009 12:59:13 +0000
parents 805e557fdff7
children 44f486b72427
comparison
equal deleted inserted replaced
550:61c3513825b0 551:c3f2ec71e3d4
57 }; 57 };
58 #endif 58 #endif
59 59
60 #ifdef ENABLE_CLI_LOCALTCPFWD 60 #ifdef ENABLE_CLI_LOCALTCPFWD
61 void setup_localtcp() { 61 void setup_localtcp() {
62 62 m_list_elem *iter;
63 int ret; 63 int ret;
64 64
65 TRACE(("enter setup_localtcp")) 65 TRACE(("enter setup_localtcp"))
66 66
67 if (cli_opts.localfwds == NULL) { 67 for (iter = cli_opts.localfwds->first; iter; iter = iter->next) {
68 TRACE(("cli_opts.localfwds == NULL")) 68 struct TCPFwdEntry * fwd = (struct TCPFwdEntry*)iter->item;
69 } 69 ret = cli_localtcp(fwd->listenport,
70 70 fwd->connectaddr,
71 while (cli_opts.localfwds != NULL) { 71 fwd->connectport);
72 ret = cli_localtcp(cli_opts.localfwds->listenport,
73 cli_opts.localfwds->connectaddr,
74 cli_opts.localfwds->connectport);
75 if (ret == DROPBEAR_FAILURE) { 72 if (ret == DROPBEAR_FAILURE) {
76 dropbear_log(LOG_WARNING, "Failed local port forward %d:%s:%d", 73 dropbear_log(LOG_WARNING, "Failed local port forward %d:%s:%d",
77 cli_opts.localfwds->listenport, 74 fwd->listenport,
78 cli_opts.localfwds->connectaddr, 75 fwd->connectaddr,
79 cli_opts.localfwds->connectport); 76 fwd->connectport);
80 } 77 }
81
82 cli_opts.localfwds = cli_opts.localfwds->next;
83 } 78 }
84 TRACE(("leave setup_localtcp")) 79 TRACE(("leave setup_localtcp"))
85 80
86 } 81 }
87 82
146 /* The only global success/failure messages are for remotetcp. 141 /* The only global success/failure messages are for remotetcp.
147 * Since there isn't any identifier in these messages, we have to rely on them 142 * Since there isn't any identifier in these messages, we have to rely on them
148 * being in the same order as we sent the requests. This is the ordering 143 * being in the same order as we sent the requests. This is the ordering
149 * of the cli_opts.remotefwds list */ 144 * of the cli_opts.remotefwds list */
150 void cli_recv_msg_request_success() { 145 void cli_recv_msg_request_success() {
151
152 /* Nothing in the packet. We just mark off that we have received the reply, 146 /* Nothing in the packet. We just mark off that we have received the reply,
153 * so that we can report failure for later ones. */ 147 * so that we can report failure for later ones. */
154 struct TCPFwdList * iter = NULL; 148 m_list_elem * iter = NULL;
155 149 for (iter = cli_opts.remotefwds->first; iter; iter = iter->next) {
156 iter = cli_opts.remotefwds; 150 struct TCPFwdEntry *fwd = (struct TCPFwdEntry*)iter->item;
157 while (iter != NULL) { 151 if (!fwd->have_reply) {
158 if (!iter->have_reply) 152 fwd->have_reply = 1;
159 {
160 iter->have_reply = 1;
161 return; 153 return;
162 } 154 }
163 iter = iter->next;
164 } 155 }
165 } 156 }
166 157
167 void cli_recv_msg_request_failure() { 158 void cli_recv_msg_request_failure() {
168 struct TCPFwdList * iter = NULL; 159 m_list_elem *iter;
169 160 for (iter = cli_opts.remotefwds->first; iter; iter = iter->next) {
170 iter = cli_opts.remotefwds; 161 struct TCPFwdEntry *fwd = (struct TCPFwdEntry*)iter->item;
171 while (iter != NULL) { 162 if (!fwd->have_reply) {
172 if (!iter->have_reply) 163 fwd->have_reply = 1;
173 { 164 dropbear_log(LOG_WARNING, "Remote TCP forward request failed (port %d -> %s:%d)", fwd->listenport, fwd->connectaddr, fwd->connectport);
174 iter->have_reply = 1;
175 dropbear_log(LOG_WARNING, "Remote TCP forward request failed (port %d -> %s:%d)", iter->listenport, iter->connectaddr, iter->connectport);
176 return; 165 return;
177 } 166 }
178 iter = iter->next;
179 } 167 }
180 } 168 }
181 169
182 void setup_remotetcp() { 170 void setup_remotetcp() {
183 171 m_list_elem *iter;
184 struct TCPFwdList * iter = NULL;
185
186 TRACE(("enter setup_remotetcp")) 172 TRACE(("enter setup_remotetcp"))
187 173
188 if (cli_opts.remotefwds == NULL) { 174 for (iter = cli_opts.remotefwds->first; iter; iter = iter->next) {
189 TRACE(("cli_opts.remotefwds == NULL")) 175 struct TCPFwdEntry *fwd = (struct TCPFwdEntry*)iter->item;
190 } 176 send_msg_global_request_remotetcp(fwd->listenport);
191 177 }
192 iter = cli_opts.remotefwds; 178
193
194 while (iter != NULL) {
195 send_msg_global_request_remotetcp(iter->listenport);
196 iter = iter->next;
197 }
198 TRACE(("leave setup_remotetcp")) 179 TRACE(("leave setup_remotetcp"))
199 } 180 }
200 181
201 static int newtcpforwarded(struct Channel * channel) { 182 static int newtcpforwarded(struct Channel * channel) {
202 183
203 unsigned int origport; 184 unsigned int origport;
204 struct TCPFwdList * iter = NULL; 185 m_list_elem * iter = NULL;
186 struct TCPFwdEntry *fwd;
205 char portstring[NI_MAXSERV]; 187 char portstring[NI_MAXSERV];
206 int sock; 188 int sock;
207 int err = SSH_OPEN_ADMINISTRATIVELY_PROHIBITED; 189 int err = SSH_OPEN_ADMINISTRATIVELY_PROHIBITED;
208 190
209 /* We don't care what address they connected to */ 191 /* We don't care what address they connected to */
210 buf_eatstring(ses.payload); 192 buf_eatstring(ses.payload);
211 193
212 origport = buf_getint(ses.payload); 194 origport = buf_getint(ses.payload);
213 195
214 /* Find which port corresponds */ 196 /* Find which port corresponds */
215 iter = cli_opts.remotefwds; 197 for (iter = cli_opts.remotefwds->first; iter; iter = iter->next) {
216 198 fwd = (struct TCPFwdEntry*)iter->item;
217 while (iter != NULL) { 199 if (origport == fwd->listenport) {
218 if (origport == iter->listenport) {
219 break; 200 break;
220 } 201 }
221 iter = iter->next;
222 } 202 }
223 203
224 if (iter == NULL) { 204 if (iter == NULL) {
225 /* We didn't request forwarding on that port */ 205 /* We didn't request forwarding on that port */
226 dropbear_log(LOG_INFO, "Server send unrequested port, from port %d", 206 dropbear_log(LOG_INFO, "Server send unrequested port, from port %d",
227 origport); 207 origport);
228 goto out; 208 goto out;
229 } 209 }
230 210
231 snprintf(portstring, sizeof(portstring), "%d", iter->connectport); 211 snprintf(portstring, sizeof(portstring), "%d", fwd->connectport);
232 sock = connect_remote(iter->connectaddr, portstring, 1, NULL); 212 sock = connect_remote(fwd->connectaddr, portstring, 1, NULL);
233 if (sock < 0) { 213 if (sock < 0) {
234 TRACE(("leave newtcpdirect: sock failed")) 214 TRACE(("leave newtcpdirect: sock failed"))
235 err = SSH_OPEN_CONNECT_FAILED; 215 err = SSH_OPEN_CONNECT_FAILED;
236 goto out; 216 goto out;
237 } 217 }