]> andersk Git - openssh.git/blobdiff - ssh.c
- (stevesk) [auth1.c] fix password auth for protocol 1 when
[openssh.git] / ssh.c
diff --git a/ssh.c b/ssh.c
index 76d45c96aa9ef6e6def3251bf0668e4a728080dc..c89b4135de7f6ff04d047830fe28abf757b5db92 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.155 2001/12/28 12:14:27 markus Exp $");
+RCSID("$OpenBSD: ssh.c,v 1.169 2002/03/26 11:37:05 markus Exp $");
 
 #include <openssl/evp.h>
 #include <openssl/err.h>
@@ -70,7 +71,6 @@ RCSID("$OpenBSD: ssh.c,v 1.155 2001/12/28 12:14:27 markus Exp $");
 #include "sshtty.h"
 
 #ifdef SMARTCARD
-#include <openssl/engine.h>
 #include "scard.h"
 #endif
 
@@ -475,7 +475,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 +793,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 +854,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,
@@ -880,7 +893,6 @@ static int
 ssh_session(void)
 {
        int type;
-       int plen;
        int interactive = 0;
        int have_tty = 0;
        struct winsize ws;
@@ -898,7 +910,7 @@ ssh_session(void)
                packet_put_int(options.compression_level);
                packet_send();
                packet_write_wait();
-               type = packet_read(&plen);
+               type = packet_read();
                if (type == SSH_SMSG_SUCCESS)
                        packet_start_compression(options.compression_level);
                else if (type == SSH_SMSG_FAILURE)
@@ -936,7 +948,7 @@ ssh_session(void)
                packet_write_wait();
 
                /* Read response from the server. */
-               type = packet_read(&plen);
+               type = packet_read();
                if (type == SSH_SMSG_SUCCESS) {
                        interactive = 1;
                        have_tty = 1;
@@ -955,7 +967,7 @@ ssh_session(void)
                x11_request_forwarding_with_spoofing(0, proto, data);
 
                /* Read response from the server. */
-               type = packet_read(&plen);
+               type = packet_read();
                if (type == SSH_SMSG_SUCCESS) {
                        interactive = 1;
                } else if (type == SSH_SMSG_FAILURE) {
@@ -975,7 +987,7 @@ ssh_session(void)
                auth_request_forwarding();
 
                /* Read response from the server. */
-               type = packet_read(&plen);
+               type = packet_read();
                packet_check_eom();
                if (type != SSH_SMSG_SUCCESS)
                        log("Warning: Remote host denied authentication agent forwarding.");
@@ -1015,7 +1027,7 @@ ssh_session(void)
 }
 
 static void
-client_subsystem_reply(int type, int plen, u_int32_t seq, void *ctxt)
+client_subsystem_reply(int type, u_int32_t seq, void *ctxt)
 {
        int id, len;
 
@@ -1098,11 +1110,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);
 }
 
@@ -1134,24 +1145,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;
 }
@@ -1180,40 +1187,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.043494 seconds and 4 git commands to generate.