diff options
Diffstat (limited to 'ssh.c')
-rw-r--r-- | ssh.c | 60 |
1 files changed, 39 insertions, 21 deletions
@@ -40,7 +40,7 @@ | |||
40 | */ | 40 | */ |
41 | 41 | ||
42 | #include "includes.h" | 42 | #include "includes.h" |
43 | RCSID("$OpenBSD: ssh.c,v 1.179 2002/06/12 01:09:52 markus Exp $"); | 43 | RCSID("$OpenBSD: ssh.c,v 1.186 2002/09/19 01:58:18 djm Exp $"); |
44 | 44 | ||
45 | #include <openssl/evp.h> | 45 | #include <openssl/evp.h> |
46 | #include <openssl/err.h> | 46 | #include <openssl/err.h> |
@@ -146,6 +146,9 @@ int subsystem_flag = 0; | |||
146 | /* # of replies received for global requests */ | 146 | /* # of replies received for global requests */ |
147 | static int client_global_request_id = 0; | 147 | static int client_global_request_id = 0; |
148 | 148 | ||
149 | /* pid of proxycommand child process */ | ||
150 | pid_t proxy_command_pid = 0; | ||
151 | |||
149 | /* Prints a help message to the user. This function never returns. */ | 152 | /* Prints a help message to the user. This function never returns. */ |
150 | 153 | ||
151 | static void | 154 | static void |
@@ -174,7 +177,6 @@ usage(void) | |||
174 | fprintf(stderr, " -v Verbose; display verbose debugging messages.\n"); | 177 | fprintf(stderr, " -v Verbose; display verbose debugging messages.\n"); |
175 | fprintf(stderr, " Multiple -v increases verbosity.\n"); | 178 | fprintf(stderr, " Multiple -v increases verbosity.\n"); |
176 | fprintf(stderr, " -V Display version number only.\n"); | 179 | fprintf(stderr, " -V Display version number only.\n"); |
177 | fprintf(stderr, " -P Don't allocate a privileged port.\n"); | ||
178 | fprintf(stderr, " -q Quiet; don't display any warning messages.\n"); | 180 | fprintf(stderr, " -q Quiet; don't display any warning messages.\n"); |
179 | fprintf(stderr, " -f Fork into background after authentication.\n"); | 181 | fprintf(stderr, " -f Fork into background after authentication.\n"); |
180 | fprintf(stderr, " -e char Set escape character; ``none'' = disable (default: ~).\n"); | 182 | fprintf(stderr, " -e char Set escape character; ``none'' = disable (default: ~).\n"); |
@@ -229,6 +231,15 @@ main(int ac, char **av) | |||
229 | */ | 231 | */ |
230 | original_real_uid = getuid(); | 232 | original_real_uid = getuid(); |
231 | original_effective_uid = geteuid(); | 233 | original_effective_uid = geteuid(); |
234 | |||
235 | /* | ||
236 | * Use uid-swapping to give up root privileges for the duration of | ||
237 | * option processing. We will re-instantiate the rights when we are | ||
238 | * ready to create the privileged port, and will permanently drop | ||
239 | * them when the port has been created (actually, when the connection | ||
240 | * has been made, as we may need to create the port several times). | ||
241 | */ | ||
242 | PRIV_END; | ||
232 | 243 | ||
233 | #ifdef HAVE_SETRLIMIT | 244 | #ifdef HAVE_SETRLIMIT |
234 | /* If we are installed setuid root be careful to not drop core. */ | 245 | /* If we are installed setuid root be careful to not drop core. */ |
@@ -249,15 +260,6 @@ main(int ac, char **av) | |||
249 | pw = pwcopy(pw); | 260 | pw = pwcopy(pw); |
250 | 261 | ||
251 | /* | 262 | /* |
252 | * Use uid-swapping to give up root privileges for the duration of | ||
253 | * option processing. We will re-instantiate the rights when we are | ||
254 | * ready to create the privileged port, and will permanently drop | ||
255 | * them when the port has been created (actually, when the connection | ||
256 | * has been made, as we may need to create the port several times). | ||
257 | */ | ||
258 | PRIV_END; | ||
259 | |||
260 | /* | ||
261 | * Set our umask to something reasonable, as some files are created | 263 | * Set our umask to something reasonable, as some files are created |
262 | * with the default umask. This will make them world-readable but | 264 | * with the default umask. This will make them world-readable but |
263 | * writable only by the owner, which is ok for all files for which we | 265 | * writable only by the owner, which is ok for all files for which we |
@@ -303,7 +305,7 @@ again: | |||
303 | case 'g': | 305 | case 'g': |
304 | options.gateway_ports = 1; | 306 | options.gateway_ports = 1; |
305 | break; | 307 | break; |
306 | case 'P': | 308 | case 'P': /* deprecated */ |
307 | options.use_privileged_port = 0; | 309 | options.use_privileged_port = 0; |
308 | break; | 310 | break; |
309 | case 'a': | 311 | case 'a': |
@@ -552,7 +554,7 @@ again: | |||
552 | if (buffer_len(&command) == 0) | 554 | if (buffer_len(&command) == 0) |
553 | tty_flag = 1; | 555 | tty_flag = 1; |
554 | 556 | ||
555 | /* Force no tty*/ | 557 | /* Force no tty */ |
556 | if (no_tty_flag) | 558 | if (no_tty_flag) |
557 | tty_flag = 0; | 559 | tty_flag = 0; |
558 | /* Do not allocate a tty if stdin is not a tty. */ | 560 | /* Do not allocate a tty if stdin is not a tty. */ |
@@ -637,7 +639,8 @@ again: | |||
637 | if (options.rhosts_rsa_authentication || | 639 | if (options.rhosts_rsa_authentication || |
638 | options.hostbased_authentication) { | 640 | options.hostbased_authentication) { |
639 | sensitive_data.nkeys = 3; | 641 | sensitive_data.nkeys = 3; |
640 | sensitive_data.keys = xmalloc(sensitive_data.nkeys*sizeof(Key)); | 642 | sensitive_data.keys = xmalloc(sensitive_data.nkeys * |
643 | sizeof(Key)); | ||
641 | 644 | ||
642 | PRIV_START; | 645 | PRIV_START; |
643 | sensitive_data.keys[0] = key_load_private_type(KEY_RSA1, | 646 | sensitive_data.keys[0] = key_load_private_type(KEY_RSA1, |
@@ -648,7 +651,8 @@ again: | |||
648 | _PATH_HOST_RSA_KEY_FILE, "", NULL); | 651 | _PATH_HOST_RSA_KEY_FILE, "", NULL); |
649 | PRIV_END; | 652 | PRIV_END; |
650 | 653 | ||
651 | if (sensitive_data.keys[0] == NULL && | 654 | if (options.hostbased_authentication == 1 && |
655 | sensitive_data.keys[0] == NULL && | ||
652 | sensitive_data.keys[1] == NULL && | 656 | sensitive_data.keys[1] == NULL && |
653 | sensitive_data.keys[2] == NULL) { | 657 | sensitive_data.keys[2] == NULL) { |
654 | sensitive_data.keys[1] = key_load_public( | 658 | sensitive_data.keys[1] = key_load_public( |
@@ -721,6 +725,14 @@ again: | |||
721 | 725 | ||
722 | exit_status = compat20 ? ssh_session2() : ssh_session(); | 726 | exit_status = compat20 ? ssh_session2() : ssh_session(); |
723 | packet_close(); | 727 | packet_close(); |
728 | |||
729 | /* | ||
730 | * Send SIGHUP to proxy command if used. We don't wait() in | ||
731 | * case it hangs and instead rely on init to reap the child | ||
732 | */ | ||
733 | if (proxy_command_pid > 1) | ||
734 | kill(proxy_command_pid, SIGHUP); | ||
735 | |||
724 | return exit_status; | 736 | return exit_status; |
725 | } | 737 | } |
726 | 738 | ||
@@ -732,11 +744,19 @@ x11_get_proto(char **_proto, char **_data) | |||
732 | FILE *f; | 744 | FILE *f; |
733 | int got_data = 0, i; | 745 | int got_data = 0, i; |
734 | char *display; | 746 | char *display; |
747 | struct stat st; | ||
735 | 748 | ||
736 | *_proto = proto; | 749 | *_proto = proto; |
737 | *_data = data; | 750 | *_data = data; |
738 | proto[0] = data[0] = '\0'; | 751 | proto[0] = data[0] = '\0'; |
739 | if (options.xauth_location && (display = getenv("DISPLAY"))) { | 752 | if (!options.xauth_location || |
753 | (stat(options.xauth_location, &st) == -1)) { | ||
754 | debug("No xauth program."); | ||
755 | } else { | ||
756 | if ((display = getenv("DISPLAY")) == NULL) { | ||
757 | debug("x11_get_proto: DISPLAY not set"); | ||
758 | return; | ||
759 | } | ||
740 | /* Try to get Xauthority information for the display. */ | 760 | /* Try to get Xauthority information for the display. */ |
741 | if (strncmp(display, "localhost:", 10) == 0) | 761 | if (strncmp(display, "localhost:", 10) == 0) |
742 | /* | 762 | /* |
@@ -751,7 +771,7 @@ x11_get_proto(char **_proto, char **_data) | |||
751 | else | 771 | else |
752 | snprintf(line, sizeof line, "%s list %.200s 2>" | 772 | snprintf(line, sizeof line, "%s list %.200s 2>" |
753 | _PATH_DEVNULL, options.xauth_location, display); | 773 | _PATH_DEVNULL, options.xauth_location, display); |
754 | debug2("x11_get_proto %s", line); | 774 | debug2("x11_get_proto: %s", line); |
755 | f = popen(line, "r"); | 775 | f = popen(line, "r"); |
756 | if (f && fgets(line, sizeof(line), f) && | 776 | if (f && fgets(line, sizeof(line), f) && |
757 | sscanf(line, "%*s %511s %511s", proto, data) == 2) | 777 | sscanf(line, "%*s %511s %511s", proto, data) == 2) |
@@ -770,6 +790,7 @@ x11_get_proto(char **_proto, char **_data) | |||
770 | if (!got_data) { | 790 | if (!got_data) { |
771 | u_int32_t rand = 0; | 791 | u_int32_t rand = 0; |
772 | 792 | ||
793 | log("Warning: No xauth data; using fake authentication data for X11 forwarding."); | ||
773 | strlcpy(proto, "MIT-MAGIC-COOKIE-1", sizeof proto); | 794 | strlcpy(proto, "MIT-MAGIC-COOKIE-1", sizeof proto); |
774 | for (i = 0; i < 16; i++) { | 795 | for (i = 0; i < 16; i++) { |
775 | if (i % 4 == 0) | 796 | if (i % 4 == 0) |
@@ -819,11 +840,8 @@ check_agent_present(void) | |||
819 | { | 840 | { |
820 | if (options.forward_agent) { | 841 | if (options.forward_agent) { |
821 | /* Clear agent forwarding if we don\'t have an agent. */ | 842 | /* Clear agent forwarding if we don\'t have an agent. */ |
822 | int authfd = ssh_get_authentication_socket(); | 843 | if (!ssh_agent_present()) |
823 | if (authfd < 0) | ||
824 | options.forward_agent = 0; | 844 | options.forward_agent = 0; |
825 | else | ||
826 | ssh_close_authentication_socket(authfd); | ||
827 | } | 845 | } |
828 | } | 846 | } |
829 | 847 | ||