diff options
Diffstat (limited to 'ssh.c')
-rw-r--r-- | ssh.c | 41 |
1 files changed, 22 insertions, 19 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssh.c,v 1.358 2011/05/06 21:18:02 djm Exp $ */ | 1 | /* $OpenBSD: ssh.c,v 1.359 2011/05/06 21:34:32 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -114,10 +114,8 @@ extern char *__progname; | |||
114 | /* Flag indicating whether debug mode is on. May be set on the command line. */ | 114 | /* Flag indicating whether debug mode is on. May be set on the command line. */ |
115 | int debug_flag = 0; | 115 | int debug_flag = 0; |
116 | 116 | ||
117 | /* Flag indicating whether a tty should be allocated */ | 117 | /* Flag indicating whether a tty should be requested */ |
118 | int tty_flag = 0; | 118 | int tty_flag = 0; |
119 | int no_tty_flag = 0; | ||
120 | int force_tty_flag = 0; | ||
121 | 119 | ||
122 | /* don't exec a shell */ | 120 | /* don't exec a shell */ |
123 | int no_shell_flag = 0; | 121 | int no_shell_flag = 0; |
@@ -135,7 +133,7 @@ int stdin_null_flag = 0; | |||
135 | int need_controlpersist_detach = 0; | 133 | int need_controlpersist_detach = 0; |
136 | 134 | ||
137 | /* Copies of flags for ControlPersist foreground slave */ | 135 | /* Copies of flags for ControlPersist foreground slave */ |
138 | int ostdin_null_flag, ono_shell_flag, ono_tty_flag, otty_flag; | 136 | int ostdin_null_flag, ono_shell_flag, otty_flag, orequest_tty; |
139 | 137 | ||
140 | /* | 138 | /* |
141 | * Flag indicating that ssh should fork after authentication. This is useful | 139 | * Flag indicating that ssh should fork after authentication. This is useful |
@@ -389,9 +387,10 @@ main(int ac, char **av) | |||
389 | #endif | 387 | #endif |
390 | break; | 388 | break; |
391 | case 't': | 389 | case 't': |
392 | if (tty_flag) | 390 | if (options.request_tty == REQUEST_TTY_YES) |
393 | force_tty_flag = 1; | 391 | options.request_tty = REQUEST_TTY_FORCE; |
394 | tty_flag = 1; | 392 | else |
393 | options.request_tty = REQUEST_TTY_YES; | ||
395 | break; | 394 | break; |
396 | case 'v': | 395 | case 'v': |
397 | if (debug_flag == 0) { | 396 | if (debug_flag == 0) { |
@@ -434,7 +433,7 @@ main(int ac, char **av) | |||
434 | optarg); | 433 | optarg); |
435 | exit(255); | 434 | exit(255); |
436 | } | 435 | } |
437 | no_tty_flag = 1; | 436 | options.request_tty = REQUEST_TTY_NO; |
438 | no_shell_flag = 1; | 437 | no_shell_flag = 1; |
439 | options.clear_forwardings = 1; | 438 | options.clear_forwardings = 1; |
440 | options.exit_on_forward_failure = 1; | 439 | options.exit_on_forward_failure = 1; |
@@ -543,10 +542,10 @@ main(int ac, char **av) | |||
543 | break; | 542 | break; |
544 | case 'N': | 543 | case 'N': |
545 | no_shell_flag = 1; | 544 | no_shell_flag = 1; |
546 | no_tty_flag = 1; | 545 | options.request_tty = REQUEST_TTY_NO; |
547 | break; | 546 | break; |
548 | case 'T': | 547 | case 'T': |
549 | no_tty_flag = 1; | 548 | options.request_tty = REQUEST_TTY_NO; |
550 | break; | 549 | break; |
551 | case 'o': | 550 | case 'o': |
552 | dummy = 1; | 551 | dummy = 1; |
@@ -606,6 +605,10 @@ main(int ac, char **av) | |||
606 | /* Initialize the command to execute on remote host. */ | 605 | /* Initialize the command to execute on remote host. */ |
607 | buffer_init(&command); | 606 | buffer_init(&command); |
608 | 607 | ||
608 | if (options.request_tty == REQUEST_TTY_YES || | ||
609 | options.request_tty == REQUEST_TTY_FORCE) | ||
610 | tty_flag = 1; | ||
611 | |||
609 | /* | 612 | /* |
610 | * Save the command to execute on the remote host in a buffer. There | 613 | * Save the command to execute on the remote host in a buffer. There |
611 | * is no limit on the length of the command, except by the maximum | 614 | * is no limit on the length of the command, except by the maximum |
@@ -613,7 +616,7 @@ main(int ac, char **av) | |||
613 | */ | 616 | */ |
614 | if (!ac) { | 617 | if (!ac) { |
615 | /* No command specified - execute shell on a tty. */ | 618 | /* No command specified - execute shell on a tty. */ |
616 | tty_flag = 1; | 619 | tty_flag = options.request_tty != REQUEST_TTY_NO; |
617 | if (subsystem_flag) { | 620 | if (subsystem_flag) { |
618 | fprintf(stderr, | 621 | fprintf(stderr, |
619 | "You must specify a subsystem to invoke.\n"); | 622 | "You must specify a subsystem to invoke.\n"); |
@@ -636,13 +639,14 @@ main(int ac, char **av) | |||
636 | 639 | ||
637 | /* Allocate a tty by default if no command specified. */ | 640 | /* Allocate a tty by default if no command specified. */ |
638 | if (buffer_len(&command) == 0) | 641 | if (buffer_len(&command) == 0) |
639 | tty_flag = 1; | 642 | tty_flag = options.request_tty != REQUEST_TTY_NO; |
640 | 643 | ||
641 | /* Force no tty */ | 644 | /* Force no tty */ |
642 | if (no_tty_flag || muxclient_command != 0) | 645 | if (options.request_tty == REQUEST_TTY_NO || muxclient_command != 0) |
643 | tty_flag = 0; | 646 | tty_flag = 0; |
644 | /* Do not allocate a tty if stdin is not a tty. */ | 647 | /* Do not allocate a tty if stdin is not a tty. */ |
645 | if ((!isatty(fileno(stdin)) || stdin_null_flag) && !force_tty_flag) { | 648 | if ((!isatty(fileno(stdin)) || stdin_null_flag) && |
649 | options.request_tty != REQUEST_TTY_FORCE) { | ||
646 | if (tty_flag) | 650 | if (tty_flag) |
647 | logit("Pseudo-terminal will not be allocated because " | 651 | logit("Pseudo-terminal will not be allocated because " |
648 | "stdin is not a terminal."); | 652 | "stdin is not a terminal."); |
@@ -946,8 +950,7 @@ control_persist_detach(void) | |||
946 | /* Parent: set up mux slave to connect to backgrounded master */ | 950 | /* Parent: set up mux slave to connect to backgrounded master */ |
947 | debug2("%s: background process is %ld", __func__, (long)pid); | 951 | debug2("%s: background process is %ld", __func__, (long)pid); |
948 | stdin_null_flag = ostdin_null_flag; | 952 | stdin_null_flag = ostdin_null_flag; |
949 | no_shell_flag = ono_shell_flag; | 953 | options.request_tty = orequest_tty; |
950 | no_tty_flag = ono_tty_flag; | ||
951 | tty_flag = otty_flag; | 954 | tty_flag = otty_flag; |
952 | close(muxserver_sock); | 955 | close(muxserver_sock); |
953 | muxserver_sock = -1; | 956 | muxserver_sock = -1; |
@@ -1394,11 +1397,11 @@ ssh_session2(void) | |||
1394 | if (options.control_persist && muxserver_sock != -1) { | 1397 | if (options.control_persist && muxserver_sock != -1) { |
1395 | ostdin_null_flag = stdin_null_flag; | 1398 | ostdin_null_flag = stdin_null_flag; |
1396 | ono_shell_flag = no_shell_flag; | 1399 | ono_shell_flag = no_shell_flag; |
1397 | ono_tty_flag = no_tty_flag; | 1400 | orequest_tty = options.request_tty; |
1398 | otty_flag = tty_flag; | 1401 | otty_flag = tty_flag; |
1399 | stdin_null_flag = 1; | 1402 | stdin_null_flag = 1; |
1400 | no_shell_flag = 1; | 1403 | no_shell_flag = 1; |
1401 | no_tty_flag = 1; | 1404 | options.request_tty == REQUEST_TTY_NO; |
1402 | tty_flag = 0; | 1405 | tty_flag = 0; |
1403 | if (!fork_after_authentication_flag) | 1406 | if (!fork_after_authentication_flag) |
1404 | need_controlpersist_detach = 1; | 1407 | need_controlpersist_detach = 1; |