Mercurial > dropbear
comparison cli-runopts.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 | 568638be7203 |
children | 005530560594 |
comparison
equal
deleted
inserted
replaced
550:61c3513825b0 | 551:c3f2ec71e3d4 |
---|---|
27 #include "signkey.h" | 27 #include "signkey.h" |
28 #include "buffer.h" | 28 #include "buffer.h" |
29 #include "dbutil.h" | 29 #include "dbutil.h" |
30 #include "algo.h" | 30 #include "algo.h" |
31 #include "tcpfwd.h" | 31 #include "tcpfwd.h" |
32 #include "list.h" | |
32 | 33 |
33 cli_runopts cli_opts; /* GLOBAL */ | 34 cli_runopts cli_opts; /* GLOBAL */ |
34 | 35 |
35 static void printhelp(); | 36 static void printhelp(); |
36 static void parse_hostname(const char* orighostarg); | 37 static void parse_hostname(const char* orighostarg); |
38 static void fill_own_user(); | 39 static void fill_own_user(); |
39 #ifdef ENABLE_CLI_PUBKEY_AUTH | 40 #ifdef ENABLE_CLI_PUBKEY_AUTH |
40 static void loadidentityfile(const char* filename); | 41 static void loadidentityfile(const char* filename); |
41 #endif | 42 #endif |
42 #ifdef ENABLE_CLI_ANYTCPFWD | 43 #ifdef ENABLE_CLI_ANYTCPFWD |
43 static void addforward(const char* str, struct TCPFwdList** fwdlist); | 44 static void addforward(const char* str, m_list *fwdlist); |
44 #endif | 45 #endif |
45 #ifdef ENABLE_CLI_NETCAT | 46 #ifdef ENABLE_CLI_NETCAT |
46 static void add_netcat(const char *str); | 47 static void add_netcat(const char *str); |
47 #endif | 48 #endif |
48 | 49 |
126 cli_opts.backgrounded = 0; | 127 cli_opts.backgrounded = 0; |
127 cli_opts.wantpty = 9; /* 9 means "it hasn't been touched", gets set later */ | 128 cli_opts.wantpty = 9; /* 9 means "it hasn't been touched", gets set later */ |
128 cli_opts.always_accept_key = 0; | 129 cli_opts.always_accept_key = 0; |
129 cli_opts.is_subsystem = 0; | 130 cli_opts.is_subsystem = 0; |
130 #ifdef ENABLE_CLI_PUBKEY_AUTH | 131 #ifdef ENABLE_CLI_PUBKEY_AUTH |
131 cli_opts.privkeys = NULL; | 132 cli_opts.privkeys = list_new(); |
132 #endif | 133 #endif |
133 #ifdef ENABLE_CLI_LOCALTCPFWD | 134 #ifdef ENABLE_CLI_LOCALTCPFWD |
134 cli_opts.localfwds = NULL; | 135 cli_opts.localfwds = list_new(); |
135 opts.listen_fwd_all = 0; | 136 opts.listen_fwd_all = 0; |
136 #endif | 137 #endif |
137 #ifdef ENABLE_CLI_REMOTETCPFWD | 138 #ifdef ENABLE_CLI_REMOTETCPFWD |
138 cli_opts.remotefwds = NULL; | 139 cli_opts.remotefwds = list_new(); |
139 #endif | 140 #endif |
140 #ifdef ENABLE_CLI_AGENTFWD | 141 #ifdef ENABLE_CLI_AGENTFWD |
141 cli_opts.agent_fwd = 0; | 142 cli_opts.agent_fwd = 0; |
142 cli_opts.agent_keys_loaded = 0; | 143 cli_opts.agent_keys_loaded = 0; |
143 #endif | 144 #endif |
163 } | 164 } |
164 #endif | 165 #endif |
165 #ifdef ENABLE_CLI_REMOTETCPFWD | 166 #ifdef ENABLE_CLI_REMOTETCPFWD |
166 if (nextisremote) { | 167 if (nextisremote) { |
167 TRACE(("nextisremote true")) | 168 TRACE(("nextisremote true")) |
168 addforward(argv[i], &cli_opts.remotefwds); | 169 addforward(argv[i], cli_opts.remotefwds); |
169 nextisremote = 0; | 170 nextisremote = 0; |
170 continue; | 171 continue; |
171 } | 172 } |
172 #endif | 173 #endif |
173 #ifdef ENABLE_CLI_LOCALTCPFWD | 174 #ifdef ENABLE_CLI_LOCALTCPFWD |
174 if (nextislocal) { | 175 if (nextislocal) { |
175 TRACE(("nextislocal true")) | 176 TRACE(("nextislocal true")) |
176 addforward(argv[i], &cli_opts.localfwds); | 177 addforward(argv[i], cli_opts.localfwds); |
177 nextislocal = 0; | 178 nextislocal = 0; |
178 continue; | 179 continue; |
179 } | 180 } |
180 #endif | 181 #endif |
181 #ifdef ENABLE_CLI_NETCAT | 182 #ifdef ENABLE_CLI_NETCAT |
404 #endif | 405 #endif |
405 } | 406 } |
406 | 407 |
407 #ifdef ENABLE_CLI_PUBKEY_AUTH | 408 #ifdef ENABLE_CLI_PUBKEY_AUTH |
408 static void loadidentityfile(const char* filename) { | 409 static void loadidentityfile(const char* filename) { |
409 | |
410 struct SignKeyList * nextkey; | |
411 sign_key *key; | 410 sign_key *key; |
412 int keytype; | 411 int keytype; |
413 | 412 |
414 key = new_sign_key(); | 413 key = new_sign_key(); |
415 keytype = DROPBEAR_SIGNKEY_ANY; | 414 keytype = DROPBEAR_SIGNKEY_ANY; |
416 if ( readhostkey(filename, key, &keytype) != DROPBEAR_SUCCESS ) { | 415 if ( readhostkey(filename, key, &keytype) != DROPBEAR_SUCCESS ) { |
417 fprintf(stderr, "Failed loading keyfile '%s'\n", filename); | 416 fprintf(stderr, "Failed loading keyfile '%s'\n", filename); |
418 sign_key_free(key); | 417 sign_key_free(key); |
419 } else { | 418 } else { |
420 nextkey = (struct SignKeyList*)m_malloc(sizeof(struct SignKeyList)); | 419 key->type = keytype; |
421 nextkey->key = key; | 420 key->source = SIGNKEY_SOURCE_RAW_FILE; |
422 nextkey->filename = m_strdup(filename); | 421 key->filename = m_strdup(filename); |
423 nextkey->next = cli_opts.privkeys; | 422 list_append(cli_opts.privkeys, key); |
424 nextkey->type = keytype; | |
425 nextkey->source = SIGNKEY_SOURCE_RAW_FILE; | |
426 cli_opts.privkeys = nextkey; | |
427 } | 423 } |
428 } | 424 } |
429 #endif | 425 #endif |
430 | 426 |
431 #ifdef ENABLE_CLI_MULTIHOP | 427 #ifdef ENABLE_CLI_MULTIHOP |
433 static char* | 429 static char* |
434 multihop_passthrough_args() { | 430 multihop_passthrough_args() { |
435 char *ret; | 431 char *ret; |
436 int total; | 432 int total; |
437 unsigned int len = 0; | 433 unsigned int len = 0; |
438 struct SignKeyList *nextkey; | 434 m_list_elem *iter; |
439 /* Fill out -i and -W options that make sense for all | 435 /* Fill out -i and -W options that make sense for all |
440 * the intermediate processes */ | 436 * the intermediate processes */ |
441 for (nextkey = cli_opts.privkeys; nextkey; nextkey = nextkey->next) | 437 for (iter = cli_opts.privkeys->first; iter; iter = iter->next) |
442 { | 438 { |
443 len += 3 + strlen(nextkey->filename); | 439 sign_key * key = (sign_key*)iter->item; |
440 len += 3 + strlen(key->filename); | |
444 } | 441 } |
445 len += 20; // space for -W <size>, terminator. | 442 len += 20; // space for -W <size>, terminator. |
446 ret = m_malloc(len); | 443 ret = m_malloc(len); |
447 total = 0; | 444 total = 0; |
448 | 445 |
450 { | 447 { |
451 int written = snprintf(ret+total, len-total, "-W %d", opts.recv_window); | 448 int written = snprintf(ret+total, len-total, "-W %d", opts.recv_window); |
452 total += written; | 449 total += written; |
453 } | 450 } |
454 | 451 |
455 for (nextkey = cli_opts.privkeys; nextkey; nextkey = nextkey->next) | 452 for (iter = cli_opts.privkeys->first; iter; iter = iter->next) |
456 { | 453 { |
454 sign_key * key = (sign_key*)iter->item; | |
457 const size_t size = len - total; | 455 const size_t size = len - total; |
458 int written = snprintf(ret+total, size, "-i %s", nextkey->filename); | 456 int written = snprintf(ret+total, size, "-i %s", key->filename); |
459 dropbear_assert(written < size); | 457 dropbear_assert(written < size); |
460 total += written; | 458 total += written; |
461 } | 459 } |
462 | 460 |
463 return ret; | 461 return ret; |
619 } | 617 } |
620 | 618 |
621 #ifdef ENABLE_CLI_ANYTCPFWD | 619 #ifdef ENABLE_CLI_ANYTCPFWD |
622 /* Turn a "listenport:remoteaddr:remoteport" string into into a forwarding | 620 /* Turn a "listenport:remoteaddr:remoteport" string into into a forwarding |
623 * set, and add it to the forwarding list */ | 621 * set, and add it to the forwarding list */ |
624 static void addforward(const char* origstr, struct TCPFwdList** fwdlist) { | 622 static void addforward(const char* origstr, m_list *fwdlist) { |
625 | 623 |
626 char * listenport = NULL; | 624 char * listenport = NULL; |
627 char * connectport = NULL; | 625 char * connectport = NULL; |
628 char * connectaddr = NULL; | 626 char * connectaddr = NULL; |
629 struct TCPFwdList* newfwd = NULL; | 627 struct TCPFwdEntry* newfwd = NULL; |
630 char * str = NULL; | 628 char * str = NULL; |
631 | 629 |
632 TRACE(("enter addforward")) | 630 TRACE(("enter addforward")) |
633 | 631 |
634 /* We need to split the original argument up. This var | 632 /* We need to split the original argument up. This var |
651 goto fail; | 649 goto fail; |
652 } | 650 } |
653 *connectport = '\0'; | 651 *connectport = '\0'; |
654 connectport++; | 652 connectport++; |
655 | 653 |
656 newfwd = (struct TCPFwdList*)m_malloc(sizeof(struct TCPFwdList)); | 654 newfwd = m_malloc(sizeof(struct TCPFwdEntry)); |
657 | 655 |
658 /* Now we check the ports - note that the port ints are unsigned, | 656 /* Now we check the ports - note that the port ints are unsigned, |
659 * the check later only checks for >= MAX_PORT */ | 657 * the check later only checks for >= MAX_PORT */ |
660 if (m_str_to_uint(listenport, &newfwd->listenport) == DROPBEAR_FAILURE) { | 658 if (m_str_to_uint(listenport, &newfwd->listenport) == DROPBEAR_FAILURE) { |
661 TRACE(("bad listenport strtoul")) | 659 TRACE(("bad listenport strtoul")) |
678 TRACE(("connectport > 65535")) | 676 TRACE(("connectport > 65535")) |
679 goto badport; | 677 goto badport; |
680 } | 678 } |
681 | 679 |
682 newfwd->have_reply = 0; | 680 newfwd->have_reply = 0; |
683 newfwd->next = *fwdlist; | 681 list_append(fwdlist, newfwd); |
684 *fwdlist = newfwd; | |
685 | 682 |
686 TRACE(("leave addforward: done")) | 683 TRACE(("leave addforward: done")) |
687 return; | 684 return; |
688 | 685 |
689 fail: | 686 fail: |