]> andersk Git - openssh.git/blobdiff - ssh.c
- (djm) Add --with-superuser-path=xxx configure option to specify what $PATH
[openssh.git] / ssh.c
diff --git a/ssh.c b/ssh.c
index e4db59bcc98468738eb82546ff24bff1ad302142..afaf20bec9dfcbaef53df523bf94b0a15b7aaa0f 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -13,6 +13,7 @@
  * called by a name other than "ssh" or "Secure Shell".
  *
  * Copyright (c) 1999 Niels Provos.  All rights reserved.
+ * Copyright (c) 2000, 2001, 2002 Markus Friedl.  All rights reserved.
  *
  * Modified to work with SSL by Niels Provos <provos@citi.umich.edu>
  * in Canada (German citizen).
@@ -39,7 +40,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: ssh.c,v 1.157 2001/12/28 15:06:00 markus Exp $");
+RCSID("$OpenBSD: ssh.c,v 1.170 2002/04/22 21:04:52 markus Exp $");
 
 #include <openssl/evp.h>
 #include <openssl/err.h>
@@ -70,7 +71,6 @@ RCSID("$OpenBSD: ssh.c,v 1.157 2001/12/28 15:06:00 markus Exp $");
 #include "sshtty.h"
 
 #ifdef SMARTCARD
-#include <openssl/engine.h>
 #include "scard.h"
 #endif
 
@@ -146,6 +146,9 @@ Buffer command;
 /* Should we execute a command or invoke a subsystem? */
 int subsystem_flag = 0;
 
+/* # of replies received for global requests */
+static int client_global_request_id = 0;
+
 /* Prints a help message to the user.  This function never returns. */
 
 static void
@@ -475,7 +478,7 @@ again:
                                /* NOTREACHED */
                        }
                        if ((fwd_port = a2port(sfwd_port)) == 0 ||
-                           (fwd_host_port = a2port(sfwd_host_port)) == 0) {
+                           (fwd_host_port = a2port(sfwd_host_port)) == 0) {
                                fprintf(stderr,
                                    "Bad forwarding port(s) '%s'\n", optarg);
                                exit(1);
@@ -793,14 +796,27 @@ x11_get_proto(char **_proto, char **_data)
        static char proto[512], data[512];
        FILE *f;
        int got_data = 0, i;
+       char *display;
 
        *_proto = proto;
        *_data = data;
        proto[0] = data[0] = '\0';
-       if (options.xauth_location) {
+       if (options.xauth_location && (display = getenv("DISPLAY"))) {
                /* Try to get Xauthority information for the display. */
-               snprintf(line, sizeof line, "%.100s list %.200s 2>" _PATH_DEVNULL,
-                   options.xauth_location, getenv("DISPLAY"));
+               if (strncmp(display, "localhost:", 10) == 0)
+                       /*
+                        * Handle FamilyLocal case where $DISPLAY does
+                        * not match an authorization entry.  For this we
+                        * just try "xauth list unix:displaynum.screennum".
+                        * XXX: "localhost" match to determine FamilyLocal
+                        *      is not perfect.
+                        */
+                       snprintf(line, sizeof line, "%.100s list unix:%s 2>"
+                           _PATH_DEVNULL, options.xauth_location, display+10);
+               else
+                       snprintf(line, sizeof line, "%.100s list %.200s 2>"
+                           _PATH_DEVNULL, options.xauth_location, display);
+               debug2("x11_get_proto %s", line);
                f = popen(line, "r");
                if (f && fgets(line, sizeof(line), f) &&
                    sscanf(line, "%*s %511s %511s", proto, data) == 2)
@@ -841,7 +857,7 @@ ssh_init_forwarding(void)
                    options.local_forwards[i].port,
                    options.local_forwards[i].host,
                    options.local_forwards[i].host_port);
-               success += channel_request_local_forwarding(
+               success += channel_setup_local_fwd_listener(
                    options.local_forwards[i].port,
                    options.local_forwards[i].host,
                    options.local_forwards[i].host_port,
@@ -1028,6 +1044,27 @@ client_subsystem_reply(int type, u_int32_t seq, void *ctxt)
                    len, (u_char *)buffer_ptr(&command), id);
 }
 
+void
+client_global_request_reply(int type, u_int32_t seq, void *ctxt)
+{
+       int i;
+
+       i = client_global_request_id++;
+       if (i >= options.num_remote_forwards) {
+               debug("client_global_request_reply: too many replies %d > %d",
+                   i, options.num_remote_forwards);
+               return;
+       }
+       debug("remote forward %s for: listen %d, connect %s:%d",
+           type == SSH2_MSG_REQUEST_SUCCESS ? "success" : "failure",
+           options.remote_forwards[i].port,
+           options.remote_forwards[i].host,
+           options.remote_forwards[i].host_port);
+       if (type == SSH2_MSG_REQUEST_FAILURE)
+               log("Warning: remote port forwarding failed for listen port %d",
+                   options.remote_forwards[i].port);
+}
+
 /* request pty/x11/agent/tcpfwd/shell for channel */
 static void
 ssh_session2_setup(int id, void *arg)
@@ -1097,11 +1134,10 @@ ssh_session2_setup(int id, void *arg)
                packet_put_string(buffer_ptr(&command), buffer_len(&command));
                packet_send();
        } else {
-               channel_request(id, "shell", 0);
+               channel_request_start(id, "shell", 0);
+               packet_send();
        }
-       /* channel_callback(id, SSH2_MSG_OPEN_CONFIGMATION, client_init, 0); */
 
-       /* register different callback, etc. XXX */
        packet_set_interactive(interactive);
 }
 
@@ -1133,24 +1169,20 @@ ssh_session2_open(void)
 
        window = CHAN_SES_WINDOW_DEFAULT;
        packetmax = CHAN_SES_PACKET_DEFAULT;
-       if (!tty_flag) {
-               window *= 2;
-               packetmax *=2;
+       if (tty_flag) {
+               window >>= 1;
+               packetmax >>= 1;
        }
        c = channel_new(
            "session", SSH_CHANNEL_OPENING, in, out, err,
            window, packetmax, CHAN_EXTENDED_WRITE,
            xstrdup("client-session"), /*nonblock*/0);
-       if (c == NULL)
-               fatal("ssh_session2_open: channel_new failed");
 
        debug3("ssh_session2_open: channel_new: %d", c->self);
 
        channel_send_open(c->self);
        if (!no_shell_flag)
-               channel_register_callback(c->self,
-                   SSH2_MSG_CHANNEL_OPEN_CONFIRMATION,
-                   ssh_session2_setup, (void *)0);
+               channel_register_confirm(c->self, ssh_session2_setup);
 
        return c->self;
 }
@@ -1179,40 +1211,29 @@ static void
 load_public_identity_files(void)
 {
        char *filename;
-       Key *public;
        int i = 0;
-
+       Key *public;
 #ifdef SMARTCARD
+       Key **keys;
+
        if (options.smartcard_device != NULL &&
-           options.num_identity_files + 1 < SSH_MAX_IDENTITY_FILES &&
-           (public = sc_get_key(options.smartcard_device)) != NULL ) {
-               Key *new;
-
-               if (options.num_identity_files + 2 > SSH_MAX_IDENTITY_FILES)
-                       options.num_identity_files = SSH_MAX_IDENTITY_FILES - 2;
-               memmove(&options.identity_files[2], &options.identity_files[0],
-                   sizeof(char *) * options.num_identity_files);
-               options.num_identity_files += 2;
-               i = 2;
-
-               /* XXX ssh1 vs ssh2 */
-               new = key_new(KEY_RSA);
-               new->flags = KEY_FLAG_EXT;
-               BN_copy(new->rsa->n, public->rsa->n);
-               BN_copy(new->rsa->e, public->rsa->e);
-               RSA_set_method(new->rsa, sc_get_engine());
-               options.identity_keys[0] = new;
-               options.identity_files[0] = xstrdup("smartcard rsa key");;
-
-               new = key_new(KEY_RSA1);
-               new->flags = KEY_FLAG_EXT;
-               BN_copy(new->rsa->n, public->rsa->n);
-               BN_copy(new->rsa->e, public->rsa->e);
-               RSA_set_method(new->rsa, sc_get_engine());
-               options.identity_keys[1] = new;
-               options.identity_files[1] = xstrdup("smartcard rsa1 key");
-
-               key_free(public);
+           options.num_identity_files < SSH_MAX_IDENTITY_FILES &&
+           (keys = sc_get_keys(options.smartcard_device, NULL)) != NULL ) {
+               int count = 0;
+               for (i = 0; keys[i] != NULL; i++) {
+                       count++;
+                       memmove(&options.identity_files[1], &options.identity_files[0],
+                           sizeof(char *) * (SSH_MAX_IDENTITY_FILES - 1));
+                       memmove(&options.identity_keys[1], &options.identity_keys[0],
+                           sizeof(Key *) * (SSH_MAX_IDENTITY_FILES - 1));
+                       options.num_identity_files++;
+                       options.identity_keys[0] = keys[i];
+                       options.identity_files[0] = xstrdup("smartcard key");;
+               }
+               if (options.num_identity_files > SSH_MAX_IDENTITY_FILES)
+                       options.num_identity_files = SSH_MAX_IDENTITY_FILES;
+               i = count;
+               xfree(keys);
        }
 #endif /* SMARTCARD */
        for (; i < options.num_identity_files; i++) {
This page took 0.041496 seconds and 4 git commands to generate.