comparison cli-runopts.c @ 995:6fb4c010c448

Default client key path ~/.ssh/id_dropbear
author Matt Johnston <matt@ucc.asn.au>
date Sat, 24 Jan 2015 00:05:26 +0800
parents a4032b946355
children 47643024fc90
comparison
equal deleted inserted replaced
994:5c5ade336926 995:6fb4c010c448
36 static void printhelp(); 36 static void printhelp();
37 static void parse_hostname(const char* orighostarg); 37 static void parse_hostname(const char* orighostarg);
38 static void parse_multihop_hostname(const char* orighostarg, const char* argv0); 38 static void parse_multihop_hostname(const char* orighostarg, const char* argv0);
39 static void fill_own_user(); 39 static void fill_own_user();
40 #ifdef ENABLE_CLI_PUBKEY_AUTH 40 #ifdef ENABLE_CLI_PUBKEY_AUTH
41 static void loadidentityfile(const char* filename); 41 static void loadidentityfile(const char* filename, int warnfail);
42 #endif 42 #endif
43 #ifdef ENABLE_CLI_ANYTCPFWD 43 #ifdef ENABLE_CLI_ANYTCPFWD
44 static void addforward(const char* str, m_list *fwdlist); 44 static void addforward(const char* str, m_list *fwdlist);
45 #endif 45 #endif
46 #ifdef ENABLE_CLI_NETCAT 46 #ifdef ENABLE_CLI_NETCAT
63 "-f Run in background after auth\n" 63 "-f Run in background after auth\n"
64 "-y Always accept remote host key if unknown\n" 64 "-y Always accept remote host key if unknown\n"
65 "-y -y Don't perform any remote host key checking (caution)\n" 65 "-y -y Don't perform any remote host key checking (caution)\n"
66 "-s Request a subsystem (use by external sftp)\n" 66 "-s Request a subsystem (use by external sftp)\n"
67 #ifdef ENABLE_CLI_PUBKEY_AUTH 67 #ifdef ENABLE_CLI_PUBKEY_AUTH
68 "-i <identityfile> (multiple allowed)\n" 68 "-i <identityfile> (multiple allowed, default %s)\n"
69 #endif 69 #endif
70 #ifdef ENABLE_CLI_AGENTFWD 70 #ifdef ENABLE_CLI_AGENTFWD
71 "-A Enable agent auth forwarding\n" 71 "-A Enable agent auth forwarding\n"
72 #endif 72 #endif
73 #ifdef ENABLE_CLI_LOCALTCPFWD 73 #ifdef ENABLE_CLI_LOCALTCPFWD
93 "-V Version\n" 93 "-V Version\n"
94 #ifdef DEBUG_TRACE 94 #ifdef DEBUG_TRACE
95 "-v verbose (compiled with DEBUG_TRACE)\n" 95 "-v verbose (compiled with DEBUG_TRACE)\n"
96 #endif 96 #endif
97 ,DROPBEAR_VERSION, cli_opts.progname, 97 ,DROPBEAR_VERSION, cli_opts.progname,
98 #ifdef ENABLE_CLI_PUBKEY_AUTH
99 DROPBEAR_DEFAULT_CLI_AUTHKEY,
100 #endif
98 DEFAULT_RECV_WINDOW, DEFAULT_KEEPALIVE, DEFAULT_IDLE_TIMEOUT); 101 DEFAULT_RECV_WINDOW, DEFAULT_KEEPALIVE, DEFAULT_IDLE_TIMEOUT);
99 102
100 } 103 }
101 104
102 void cli_getopts(int argc, char ** argv) { 105 void cli_getopts(int argc, char ** argv) {
172 /* Iterate all the arguments */ 175 /* Iterate all the arguments */
173 for (i = 1; i < (unsigned int)argc; i++) { 176 for (i = 1; i < (unsigned int)argc; i++) {
174 #ifdef ENABLE_CLI_PUBKEY_AUTH 177 #ifdef ENABLE_CLI_PUBKEY_AUTH
175 if (nextiskey) { 178 if (nextiskey) {
176 /* Load a hostkey since the previous argument was "-i" */ 179 /* Load a hostkey since the previous argument was "-i" */
177 loadidentityfile(argv[i]); 180 loadidentityfile(argv[i], 1);
178 nextiskey = 0; 181 nextiskey = 0;
179 continue; 182 continue;
180 } 183 }
181 #endif 184 #endif
182 #ifdef ENABLE_CLI_REMOTETCPFWD 185 #ifdef ENABLE_CLI_REMOTETCPFWD
229 break; 232 break;
230 #ifdef ENABLE_CLI_PUBKEY_AUTH 233 #ifdef ENABLE_CLI_PUBKEY_AUTH
231 case 'i': /* an identityfile */ 234 case 'i': /* an identityfile */
232 /* Keep scp happy when it changes "-i file" to "-ifile" */ 235 /* Keep scp happy when it changes "-i file" to "-ifile" */
233 if (strlen(argv[i]) > 2) { 236 if (strlen(argv[i]) > 2) {
234 loadidentityfile(&argv[i][2]); 237 loadidentityfile(&argv[i][2], 1);
235 } else { 238 } else {
236 nextiskey = 1; 239 nextiskey = 1;
237 } 240 }
238 break; 241 break;
239 #endif 242 #endif
442 if (cli_opts.cmd && cli_opts.netcat_host) { 445 if (cli_opts.cmd && cli_opts.netcat_host) {
443 dropbear_log(LOG_INFO, "Ignoring command '%s' in netcat mode", cli_opts.cmd); 446 dropbear_log(LOG_INFO, "Ignoring command '%s' in netcat mode", cli_opts.cmd);
444 } 447 }
445 #endif 448 #endif
446 449
450 #ifdef DROPBEAR_DEFAULT_CLI_AUTHKEY
451 {
452 char *expand_path = expand_tilde(DROPBEAR_DEFAULT_CLI_AUTHKEY);
453 loadidentityfile(expand_path, 0);
454 m_free(expand_path);
455 }
456 #endif
457
447 /* The hostname gets set up last, since 458 /* The hostname gets set up last, since
448 * in multi-hop mode it will require knowledge 459 * in multi-hop mode it will require knowledge
449 * of other flags such as -i */ 460 * of other flags such as -i */
450 #ifdef ENABLE_CLI_MULTIHOP 461 #ifdef ENABLE_CLI_MULTIHOP
451 parse_multihop_hostname(host_arg, argv[0]); 462 parse_multihop_hostname(host_arg, argv[0]);
453 parse_hostname(host_arg); 464 parse_hostname(host_arg);
454 #endif 465 #endif
455 } 466 }
456 467
457 #ifdef ENABLE_CLI_PUBKEY_AUTH 468 #ifdef ENABLE_CLI_PUBKEY_AUTH
458 static void loadidentityfile(const char* filename) { 469 static void loadidentityfile(const char* filename, int warnfail) {
459 sign_key *key; 470 sign_key *key;
460 enum signkey_type keytype; 471 enum signkey_type keytype;
472
473 TRACE(("loadidentityfile %s", filename))
461 474
462 key = new_sign_key(); 475 key = new_sign_key();
463 keytype = DROPBEAR_SIGNKEY_ANY; 476 keytype = DROPBEAR_SIGNKEY_ANY;
464 if ( readhostkey(filename, key, &keytype) != DROPBEAR_SUCCESS ) { 477 if ( readhostkey(filename, key, &keytype) != DROPBEAR_SUCCESS ) {
465 fprintf(stderr, "Failed loading keyfile '%s'\n", filename); 478 if (warnfail) {
479 fprintf(stderr, "Failed loading keyfile '%s'\n", filename);
480 }
466 sign_key_free(key); 481 sign_key_free(key);
467 } else { 482 } else {
468 key->type = keytype; 483 key->type = keytype;
469 key->source = SIGNKEY_SOURCE_RAW_FILE; 484 key->source = SIGNKEY_SOURCE_RAW_FILE;
470 key->filename = m_strdup(filename); 485 key->filename = m_strdup(filename);