comparison cli-runopts.c @ 483:738313e73b1c

- "-J 'nc localhost 22'" kind of works, needs fixing hostkeys, ptys etc.
author Matt Johnston <matt@ucc.asn.au>
date Mon, 15 Sep 2008 14:40:30 +0000
parents e3db1f7a2e43
children effb4a25b1ae
comparison
equal deleted inserted replaced
482:7ad49f34a122 483:738313e73b1c
32 32
33 cli_runopts cli_opts; /* GLOBAL */ 33 cli_runopts cli_opts; /* GLOBAL */
34 34
35 static void printhelp(); 35 static void printhelp();
36 static void parsehostname(char* userhostarg); 36 static void parsehostname(char* userhostarg);
37 static void fill_own_user();
37 #ifdef ENABLE_CLI_PUBKEY_AUTH 38 #ifdef ENABLE_CLI_PUBKEY_AUTH
38 static void loadidentityfile(const char* filename); 39 static void loadidentityfile(const char* filename);
39 #endif 40 #endif
40 #ifdef ENABLE_CLI_ANYTCPFWD 41 #ifdef ENABLE_CLI_ANYTCPFWD
41 static void addforward(char* str, struct TCPFwdList** fwdlist); 42 static void addforward(char* str, struct TCPFwdList** fwdlist);
88 int nextislocal = 0; 89 int nextislocal = 0;
89 #endif 90 #endif
90 #ifdef ENABLE_CLI_REMOTETCPFWD 91 #ifdef ENABLE_CLI_REMOTETCPFWD
91 int nextisremote = 0; 92 int nextisremote = 0;
92 #endif 93 #endif
93 #ifdef ENABLE_CLI_PROXYCMD
94 int nextisproxycmd = 0;
95 #endif
96 char* dummy = NULL; /* Not used for anything real */ 94 char* dummy = NULL; /* Not used for anything real */
97 95
98 char* recv_window_arg = NULL; 96 char* recv_window_arg = NULL;
99 char* keepalive_arg = NULL; 97 char* keepalive_arg = NULL;
100 98
116 opts.listen_fwd_all = 0; 114 opts.listen_fwd_all = 0;
117 #endif 115 #endif
118 #ifdef ENABLE_CLI_REMOTETCPFWD 116 #ifdef ENABLE_CLI_REMOTETCPFWD
119 cli_opts.remotefwds = NULL; 117 cli_opts.remotefwds = NULL;
120 #endif 118 #endif
119 #ifdef ENABLE_CLI_PROXYCMD
120 cli_opts.proxycmd = NULL;
121 #endif
121 /* not yet 122 /* not yet
122 opts.ipv4 = 1; 123 opts.ipv4 = 1;
123 opts.ipv6 = 1; 124 opts.ipv6 = 1;
124 */ 125 */
125 opts.recv_window = DEFAULT_RECV_WINDOW; 126 opts.recv_window = DEFAULT_RECV_WINDOW;
127
128 fill_own_user();
126 129
127 /* Iterate all the arguments */ 130 /* Iterate all the arguments */
128 for (i = 1; i < (unsigned int)argc; i++) { 131 for (i = 1; i < (unsigned int)argc; i++) {
129 #ifdef ENABLE_CLI_PUBKEY_AUTH 132 #ifdef ENABLE_CLI_PUBKEY_AUTH
130 if (nextiskey) { 133 if (nextiskey) {
292 break; 295 break;
293 } 296 }
294 } 297 }
295 } 298 }
296 299
300 #ifdef ENABLE_CLI_PROXYCMD
301 if (cli_opts.proxycmd != NULL) {
302 /* XXX something more useful */
303 cli_opts.remotehost = cli_opts.proxycmd;
304 cli_opts.remoteport = "";
305 }
306 #endif
307
297 if (cli_opts.remotehost == NULL) { 308 if (cli_opts.remotehost == NULL) {
298 printhelp(); 309 printhelp();
299 exit(EXIT_FAILURE); 310 exit(EXIT_FAILURE);
300 } 311 }
301 312
316 if (cli_opts.backgrounded && cli_opts.cmd == NULL 327 if (cli_opts.backgrounded && cli_opts.cmd == NULL
317 && cli_opts.no_cmd == 0) { 328 && cli_opts.no_cmd == 0) {
318 dropbear_exit("command required for -f"); 329 dropbear_exit("command required for -f");
319 } 330 }
320 331
321 if (recv_window_arg) 332 if (recv_window_arg) {
322 {
323 opts.recv_window = atol(recv_window_arg); 333 opts.recv_window = atol(recv_window_arg);
324 if (opts.recv_window == 0 || opts.recv_window > MAX_RECV_WINDOW) 334 if (opts.recv_window == 0 || opts.recv_window > MAX_RECV_WINDOW) {
325 {
326 dropbear_exit("Bad recv window '%s'", recv_window_arg); 335 dropbear_exit("Bad recv window '%s'", recv_window_arg);
327 } 336 }
328 } 337 }
329 if (keepalive_arg) { 338 if (keepalive_arg) {
330 opts.keepalive_secs = strtoul(keepalive_arg, NULL, 10); 339 opts.keepalive_secs = strtoul(keepalive_arg, NULL, 10);
331 if (opts.keepalive_secs == 0 && errno == EINVAL) 340 if (opts.keepalive_secs == 0 && errno == EINVAL) {
332 {
333 dropbear_exit("Bad keepalive '%s'", keepalive_arg); 341 dropbear_exit("Bad keepalive '%s'", keepalive_arg);
334 } 342 }
335 } 343 }
336 344
337 } 345 }
363 371
364 372
365 /* Parses a [user@]hostname argument. userhostarg is the argv[i] corresponding 373 /* Parses a [user@]hostname argument. userhostarg is the argv[i] corresponding
366 * - note that it will be modified */ 374 * - note that it will be modified */
367 static void parsehostname(char* orighostarg) { 375 static void parsehostname(char* orighostarg) {
368
369 uid_t uid;
370 struct passwd *pw = NULL;
371 char *userhostarg = NULL; 376 char *userhostarg = NULL;
372 377
373 /* We probably don't want to be editing argvs */ 378 /* We probably don't want to be editing argvs */
374 userhostarg = m_strdup(orighostarg); 379 userhostarg = m_strdup(orighostarg);
375 380
383 cli_opts.remotehost++; 388 cli_opts.remotehost++;
384 cli_opts.username = userhostarg; 389 cli_opts.username = userhostarg;
385 } 390 }
386 391
387 if (cli_opts.username == NULL) { 392 if (cli_opts.username == NULL) {
388 uid = getuid(); 393 cli_opts.username = m_strdup(cli_opts.own_user);
389
390 pw = getpwuid(uid);
391 if (pw == NULL || pw->pw_name == NULL) {
392 dropbear_exit("Unknown own user");
393 }
394
395 cli_opts.username = m_strdup(pw->pw_name);
396 } 394 }
397 395
398 if (cli_opts.remotehost[0] == '\0') { 396 if (cli_opts.remotehost[0] == '\0') {
399 dropbear_exit("Bad hostname"); 397 dropbear_exit("Bad hostname");
400 } 398 }
399 }
400
401 static void fill_own_user() {
402 uid_t uid;
403 struct passwd *pw = NULL;
404
405 uid = getuid();
406
407 pw = getpwuid(uid);
408 if (pw == NULL || pw->pw_name == NULL) {
409 dropbear_exit("Unknown own user");
410 }
411
412 cli_opts.own_user = m_strdup(pw->pw_name);
401 } 413 }
402 414
403 #ifdef ENABLE_CLI_ANYTCPFWD 415 #ifdef ENABLE_CLI_ANYTCPFWD
404 /* Turn a "listenport:remoteaddr:remoteport" string into into a forwarding 416 /* Turn a "listenport:remoteaddr:remoteport" string into into a forwarding
405 * set, and add it to the forwarding list */ 417 * set, and add it to the forwarding list */