|
Lines 157-165
Sensitive sensitive_data;
Link Here
|
| 157 |
uid_t original_real_uid; |
157 |
uid_t original_real_uid; |
| 158 |
uid_t original_effective_uid; |
158 |
uid_t original_effective_uid; |
| 159 |
|
159 |
|
| 160 |
/* command to be executed */ |
|
|
| 161 |
Buffer command; |
| 162 |
|
| 163 |
/* Should we execute a command or invoke a subsystem? */ |
160 |
/* Should we execute a command or invoke a subsystem? */ |
| 164 |
int subsystem_flag = 0; |
161 |
int subsystem_flag = 0; |
| 165 |
|
162 |
|
|
Lines 567-583
main(int ac, char **av)
Link Here
|
| 567 |
SSLeay_add_all_algorithms(); |
564 |
SSLeay_add_all_algorithms(); |
| 568 |
ERR_load_crypto_strings(); |
565 |
ERR_load_crypto_strings(); |
| 569 |
|
566 |
|
| 570 |
/* Initialize the command to execute on remote host. */ |
|
|
| 571 |
buffer_init(&command); |
| 572 |
|
| 573 |
/* |
567 |
/* |
| 574 |
* Save the command to execute on the remote host in a buffer. There |
568 |
* Save the command to execute on the remote host in a buffer. There |
| 575 |
* is no limit on the length of the command, except by the maximum |
569 |
* is no limit on the length of the command, except by the maximum |
| 576 |
* packet size. Also sets the tty flag if there is no command. |
570 |
* packet size. |
| 577 |
*/ |
571 |
*/ |
| 578 |
if (!ac) { |
572 |
if (!ac) { |
| 579 |
/* No command specified - execute shell on a tty. */ |
|
|
| 580 |
tty_flag = 1; |
| 581 |
if (subsystem_flag) { |
573 |
if (subsystem_flag) { |
| 582 |
fprintf(stderr, |
574 |
fprintf(stderr, |
| 583 |
"You must specify a subsystem to invoke.\n"); |
575 |
"You must specify a subsystem to invoke.\n"); |
|
Lines 587-618
main(int ac, char **av)
Link Here
|
| 587 |
/* A command has been specified. Store it into the buffer. */ |
579 |
/* A command has been specified. Store it into the buffer. */ |
| 588 |
for (i = 0; i < ac; i++) { |
580 |
for (i = 0; i < ac; i++) { |
| 589 |
if (i) |
581 |
if (i) |
| 590 |
buffer_append(&command, " ", 1); |
582 |
buffer_append(&options.remote_command, " ", 1); |
| 591 |
buffer_append(&command, av[i], strlen(av[i])); |
583 |
buffer_append(&options.remote_command, av[i], strlen(av[i])); |
| 592 |
} |
584 |
} |
| 593 |
} |
585 |
} |
| 594 |
|
586 |
|
| 595 |
/* Cannot fork to background if no command. */ |
587 |
/* Cannot fork to background if no command. */ |
| 596 |
if (fork_after_authentication_flag && buffer_len(&command) == 0 && |
588 |
if (fork_after_authentication_flag && buffer_len(&options.remote_command) == 0 && |
| 597 |
!no_shell_flag) |
589 |
!no_shell_flag) |
| 598 |
fatal("Cannot fork into background without a command " |
590 |
fatal("Cannot fork into background without a command " |
| 599 |
"to execute."); |
591 |
"to execute."); |
| 600 |
|
592 |
|
| 601 |
/* Allocate a tty by default if no command specified. */ |
|
|
| 602 |
if (buffer_len(&command) == 0) |
| 603 |
tty_flag = 1; |
| 604 |
|
| 605 |
/* Force no tty */ |
| 606 |
if (no_tty_flag) |
| 607 |
tty_flag = 0; |
| 608 |
/* Do not allocate a tty if stdin is not a tty. */ |
| 609 |
if ((!isatty(fileno(stdin)) || stdin_null_flag) && !force_tty_flag) { |
| 610 |
if (tty_flag && options.log_level > SYSLOG_LEVEL_QUIET) |
| 611 |
logit("Pseudo-terminal will not be allocated because " |
| 612 |
"stdin is not a terminal."); |
| 613 |
tty_flag = 0; |
| 614 |
} |
| 615 |
|
| 616 |
/* |
593 |
/* |
| 617 |
* Initialize "log" output. Since we are the client all output |
594 |
* Initialize "log" output. Since we are the client all output |
| 618 |
* actually goes to stderr. |
595 |
* actually goes to stderr. |
|
Lines 639-644
main(int ac, char **av)
Link Here
|
| 639 |
&options, 0); |
616 |
&options, 0); |
| 640 |
} |
617 |
} |
| 641 |
|
618 |
|
|
|
619 |
if (buffer_len(&options.remote_command) > 0) { |
| 620 |
buffer_append(&options.remote_command, "\0", 1); |
| 621 |
if (strcmp((u_char*)buffer_ptr(&options.remote_command), "none") == 0) { |
| 622 |
buffer_clear(&options.remote_command); |
| 623 |
} |
| 624 |
} |
| 625 |
|
| 626 |
if (no_tty_flag) { |
| 627 |
options.pseudo_tty = 0; |
| 628 |
} else if (force_tty_flag) { |
| 629 |
options.pseudo_tty = 2; |
| 630 |
} else if (tty_flag) { |
| 631 |
options.pseudo_tty = 1; |
| 632 |
} |
| 633 |
|
| 634 |
/* Allocate a tty by default if no command specified. */ |
| 635 |
if (buffer_len(&options.remote_command) == 0 && options.pseudo_tty == -1) |
| 636 |
options.pseudo_tty = 1; |
| 637 |
|
| 642 |
/* Fill configuration defaults. */ |
638 |
/* Fill configuration defaults. */ |
| 643 |
fill_default_options(&options); |
639 |
fill_default_options(&options); |
| 644 |
|
640 |
|
|
Lines 695-700
main(int ac, char **av)
Link Here
|
| 695 |
options.control_path = NULL; |
691 |
options.control_path = NULL; |
| 696 |
} |
692 |
} |
| 697 |
|
693 |
|
|
|
694 |
/* Do not allocate a tty if stdin is not a tty. */ |
| 695 |
if ((!isatty(fileno(stdin)) || stdin_null_flag) && options.pseudo_tty < 2) { |
| 696 |
if (options.pseudo_tty && options.log_level > SYSLOG_LEVEL_QUIET) |
| 697 |
logit("Pseudo-terminal will not be allocated because " |
| 698 |
"stdin is not a terminal."); |
| 699 |
options.pseudo_tty = 0; |
| 700 |
} |
| 701 |
|
| 702 |
if (options.pseudo_tty == 2) |
| 703 |
options.pseudo_tty = 1; |
| 704 |
|
| 698 |
if (options.control_path != NULL) { |
705 |
if (options.control_path != NULL) { |
| 699 |
char thishost[NI_MAXHOST]; |
706 |
char thishost[NI_MAXHOST]; |
| 700 |
|
707 |
|
|
Lines 985-991
ssh_session(void)
Link Here
|
| 985 |
"compression response."); |
992 |
"compression response."); |
| 986 |
} |
993 |
} |
| 987 |
/* Allocate a pseudo tty if appropriate. */ |
994 |
/* Allocate a pseudo tty if appropriate. */ |
| 988 |
if (tty_flag) { |
995 |
if (options.pseudo_tty) { |
| 989 |
debug("Requesting pty."); |
996 |
debug("Requesting pty."); |
| 990 |
|
997 |
|
| 991 |
/* Start the packet. */ |
998 |
/* Start the packet. */ |
|
Lines 1089-1102
ssh_session(void)
Link Here
|
| 1089 |
* If a command was specified on the command line, execute the |
1096 |
* If a command was specified on the command line, execute the |
| 1090 |
* command now. Otherwise request the server to start a shell. |
1097 |
* command now. Otherwise request the server to start a shell. |
| 1091 |
*/ |
1098 |
*/ |
| 1092 |
if (buffer_len(&command) > 0) { |
1099 |
if (buffer_len(&options.remote_command) > 0) { |
| 1093 |
int len = buffer_len(&command); |
1100 |
int len = buffer_len(&options.remote_command); |
| 1094 |
if (len > 900) |
1101 |
if (len > 900) |
| 1095 |
len = 900; |
1102 |
len = 900; |
| 1096 |
debug("Sending command: %.*s", len, |
1103 |
debug("Sending command: %.*s", len, |
| 1097 |
(u_char *)buffer_ptr(&command)); |
1104 |
(u_char *)buffer_ptr(&options.remote_command)); |
| 1098 |
packet_start(SSH_CMSG_EXEC_CMD); |
1105 |
packet_start(SSH_CMSG_EXEC_CMD); |
| 1099 |
packet_put_string(buffer_ptr(&command), buffer_len(&command)); |
1106 |
packet_put_string(buffer_ptr(&options.remote_command), buffer_len(&options.remote_command)); |
| 1100 |
packet_send(); |
1107 |
packet_send(); |
| 1101 |
packet_write_wait(); |
1108 |
packet_write_wait(); |
| 1102 |
} else { |
1109 |
} else { |
|
Lines 1107-1113
ssh_session(void)
Link Here
|
| 1107 |
} |
1114 |
} |
| 1108 |
|
1115 |
|
| 1109 |
/* Enter the interactive session. */ |
1116 |
/* Enter the interactive session. */ |
| 1110 |
return client_loop(have_tty, tty_flag ? |
1117 |
return client_loop(have_tty, options.pseudo_tty ? |
| 1111 |
options.escape_char : SSH_ESCAPECHAR_NONE, 0); |
1118 |
options.escape_char : SSH_ESCAPECHAR_NONE, 0); |
| 1112 |
} |
1119 |
} |
| 1113 |
|
1120 |
|
|
Lines 1117-1123
ssh_session2_setup(int id, void *arg)
Link Here
|
| 1117 |
{ |
1124 |
{ |
| 1118 |
extern char **environ; |
1125 |
extern char **environ; |
| 1119 |
const char *display; |
1126 |
const char *display; |
| 1120 |
int interactive = tty_flag; |
1127 |
int interactive = options.pseudo_tty; |
| 1121 |
|
1128 |
|
| 1122 |
display = getenv("DISPLAY"); |
1129 |
display = getenv("DISPLAY"); |
| 1123 |
if (options.forward_x11 && display != NULL) { |
1130 |
if (options.forward_x11 && display != NULL) { |
|
Lines 1140-1147
ssh_session2_setup(int id, void *arg)
Link Here
|
| 1140 |
packet_send(); |
1147 |
packet_send(); |
| 1141 |
} |
1148 |
} |
| 1142 |
|
1149 |
|
| 1143 |
client_session2_setup(id, tty_flag, subsystem_flag, getenv("TERM"), |
1150 |
client_session2_setup(id, options.pseudo_tty, subsystem_flag, getenv("TERM"), |
| 1144 |
NULL, fileno(stdin), &command, environ); |
1151 |
NULL, fileno(stdin), &options.remote_command, environ); |
| 1145 |
|
1152 |
|
| 1146 |
packet_set_interactive(interactive); |
1153 |
packet_set_interactive(interactive); |
| 1147 |
} |
1154 |
} |
|
Lines 1174-1180
ssh_session2_open(void)
Link Here
|
| 1174 |
|
1181 |
|
| 1175 |
window = CHAN_SES_WINDOW_DEFAULT; |
1182 |
window = CHAN_SES_WINDOW_DEFAULT; |
| 1176 |
packetmax = CHAN_SES_PACKET_DEFAULT; |
1183 |
packetmax = CHAN_SES_PACKET_DEFAULT; |
| 1177 |
if (tty_flag) { |
1184 |
if (options.pseudo_tty) { |
| 1178 |
window >>= 1; |
1185 |
window >>= 1; |
| 1179 |
packetmax >>= 1; |
1186 |
packetmax >>= 1; |
| 1180 |
} |
1187 |
} |
|
Lines 1229-1235
ssh_session2(void)
Link Here
|
| 1229 |
fatal("daemon() failed: %.200s", strerror(errno)); |
1236 |
fatal("daemon() failed: %.200s", strerror(errno)); |
| 1230 |
} |
1237 |
} |
| 1231 |
|
1238 |
|
| 1232 |
return client_loop(tty_flag, tty_flag ? |
1239 |
return client_loop(options.pseudo_tty, options.pseudo_tty ? |
| 1233 |
options.escape_char : SSH_ESCAPECHAR_NONE, id); |
1240 |
options.escape_char : SSH_ESCAPECHAR_NONE, id); |
| 1234 |
} |
1241 |
} |
| 1235 |
|
1242 |
|