]> andersk Git - openssh.git/blobdiff - sshconnect.c
- (djm) Define USE_PIPES to avoid socketpair problems on HPUX 10 and SunOS 4
[openssh.git] / sshconnect.c
index 859450d36c49d14f87c638e48db043d7cc7ebbec..79b6856da2f576a98c7545e890dc814ed3919ebc 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: sshconnect.c,v 1.71 2000/04/26 21:28:33 markus Exp $");
+RCSID("$OpenBSD: sshconnect.c,v 1.76 2000/06/17 20:30:10 markus Exp $");
 
 #include <openssl/bn.h>
 #include <openssl/dsa.h>
@@ -108,15 +108,15 @@ ssh_proxy_connect(const char *host, u_short port, uid_t original_real_uid,
 
                /* Stderr is left as it is so that error messages get
                   printed on the user's terminal. */
-               argv[0] = "/bin/sh";
+               argv[0] = _PATH_BSHELL;
                argv[1] = "-c";
                argv[2] = command_string;
                argv[3] = NULL;
 
                /* Execute the proxy command.  Note that we gave up any
                   extra privileges above. */
-               execv("/bin/sh", argv);
-               perror("/bin/sh");
+               execv(_PATH_BSHELL, argv);
+               perror(_PATH_BSHELL);
                exit(1);
        }
        /* Parent. */
@@ -255,7 +255,7 @@ ssh_connect(const char *host, struct sockaddr_storage * hostaddr,
                        temporarily_use_uid(original_real_uid);
                        if (connect(sock, ai->ai_addr, ai->ai_addrlen) >= 0) {
                                /* Successful connection. */
-                               memcpy(hostaddr, ai->ai_addr, sizeof(*(ai->ai_addr)));
+                               memcpy(hostaddr, ai->ai_addr, ai->ai_addrlen);
                                restore_uid();
                                break;
                        } else {
@@ -301,21 +301,6 @@ ssh_connect(const char *host, struct sockaddr_storage * hostaddr,
        return 1;
 }
 
-char *
-chop(char *s)
-{
-       char *t = s;
-       while (*t) {
-               if(*t == '\n' || *t == '\r') {
-                       *t = '\0';
-                       return s;
-               }
-               t++;
-       }
-       return s;
-
-}
-
 /*
  * Waits for the server identification string, and sends our own
  * identification string.
@@ -329,23 +314,28 @@ ssh_exchange_identification()
        int connection_out = packet_get_connection_out();
 
        /* Read other side\'s version identification. */
-       for (i = 0; i < sizeof(buf) - 1; i++) {
-               int len = read(connection_in, &buf[i], 1);
-               if (len < 0)
-                       fatal("ssh_exchange_identification: read: %.100s", strerror(errno));
-               if (len != 1)
-                       fatal("ssh_exchange_identification: Connection closed by remote host");
-               if (buf[i] == '\r') {
-                       buf[i] = '\n';
-                       buf[i + 1] = 0;
-                       continue;               /**XXX wait for \n */
+       for (;;) {
+               for (i = 0; i < sizeof(buf) - 1; i++) {
+                       int len = atomicio(read, connection_in, &buf[i], 1);
+                       if (len < 0)
+                               fatal("ssh_exchange_identification: read: %.100s", strerror(errno));
+                       if (len != 1)
+                               fatal("ssh_exchange_identification: Connection closed by remote host");
+                       if (buf[i] == '\r') {
+                               buf[i] = '\n';
+                               buf[i + 1] = 0;
+                               continue;               /**XXX wait for \n */
+                       }
+                       if (buf[i] == '\n') {
+                               buf[i + 1] = 0;
+                               break;
+                       }
                }
-               if (buf[i] == '\n') {
-                       buf[i + 1] = 0;
+               buf[sizeof(buf) - 1] = 0;
+               if (strncmp(buf, "SSH-", 4) == 0)
                        break;
-               }
+               debug("ssh_exchange_identification: %s", buf);
        }
-       buf[sizeof(buf) - 1] = 0;
        server_version_string = xstrdup(buf);
 
        /*
@@ -465,6 +455,7 @@ check_host_key(char *host, struct sockaddr *hostaddr, Key *host_key,
        const char *user_hostfile, const char *system_hostfile)
 {
        Key *file_key;
+       char *type = key_type(host_key);
        char *ip = NULL;
        char hostline[1000], *hostp;
        HostStatus host_status;
@@ -551,18 +542,19 @@ check_host_key(char *host, struct sockaddr *hostaddr, Key *host_key,
        switch (host_status) {
        case HOST_OK:
                /* The host is known and the key matches. */
-               debug("Host '%.200s' is known and matches the host key.", host);
+               debug("Host '%.200s' is known and matches the %s host key.",
+                   host, type);
                if (options.check_host_ip) {
                        if (ip_status == HOST_NEW) {
                                if (!add_host_to_hostfile(user_hostfile, ip, host_key))
-                                       log("Failed to add the host key for IP address '%.30s' to the list of known hosts (%.30s).",
-                                           ip, user_hostfile);
+                                       log("Failed to add the %s host key for IP address '%.30s' to the list of known hosts (%.30s).",
+                                           type, ip, user_hostfile);
                                else
-                                       log("Warning: Permanently added host key for IP address '%.30s' to the list of known hosts.",
-                                           ip);
+                                       log("Warning: Permanently added the %s host key for IP address '%.30s' to the list of known hosts.",
+                                           type, ip);
                        } else if (ip_status != HOST_OK)
-                               log("Warning: the host key for '%.200s' differs from the key for the IP address '%.30s'",
-                                   host, ip);
+                               log("Warning: the %s host key for '%.200s' differs from the key for the IP address '%.30s'",
+                                   type, host, ip);
                }
                break;
        case HOST_NEW:
@@ -570,16 +562,16 @@ check_host_key(char *host, struct sockaddr *hostaddr, Key *host_key,
                if (options.strict_host_key_checking == 1) {
                        /* User has requested strict host key checking.  We will not add the host key
                           automatically.  The only alternative left is to abort. */
-                       fatal("No host key is known for %.200s and you have requested strict checking.", host);
+                       fatal("No %s host key is known for %.200s and you have requested strict checking.", type, host);
                } else if (options.strict_host_key_checking == 2) {
                        /* The default */
                        char prompt[1024];
                        char *fp = key_fingerprint(host_key);
                        snprintf(prompt, sizeof(prompt),
                            "The authenticity of host '%.200s' can't be established.\n"
-                           "Key fingerprint is %s.\n"
+                           "%s key fingerprint is %s.\n"
                            "Are you sure you want to continue connecting (yes/no)? ",
-                           host, fp);
+                           host, type, fp);
                        if (!read_yes_or_no(prompt, -1))
                                fatal("Aborted by user!\n");
                }
@@ -594,8 +586,8 @@ check_host_key(char *host, struct sockaddr *hostaddr, Key *host_key,
                        log("Failed to add the host to the list of known hosts (%.500s).",
                            user_hostfile);
                else
-                       log("Warning: Permanently added '%.200s' to the list of known hosts.",
-                           hostp);
+                       log("Warning: Permanently added '%.200s' (%s) to the list of known hosts.",
+                           hostp, type);
                break;
        case HOST_CHANGED:
                if (options.check_host_ip && host_ip_differ) {
@@ -609,7 +601,7 @@ check_host_key(char *host, struct sockaddr *hostaddr, Key *host_key,
                        error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
                        error("@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @");
                        error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
-                       error("The host key for %s has changed,", host);
+                       error("The %s host key for %s has changed,", type, host);
                        error("and the key for the according IP address %s", ip);
                        error("%s. This could either mean that", msg);
                        error("DNS SPOOFING is happening or the IP address for the host");
@@ -621,7 +613,7 @@ check_host_key(char *host, struct sockaddr *hostaddr, Key *host_key,
                error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
                error("IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!");
                error("Someone could be eavesdropping on you right now (man-in-the-middle attack)!");
-               error("It is also possible that the host key has just been changed.");
+               error("It is also possible that the %s host key has just been changed.", type);
                error("Please contact your system administrator.");
                error("Add correct host key in %.100s to get rid of this message.",
                      user_hostfile);
@@ -631,7 +623,7 @@ check_host_key(char *host, struct sockaddr *hostaddr, Key *host_key,
                 * to edit the key manually and we can only abort.
                 */
                if (options.strict_host_key_checking)
-                       fatal("Host key for %.200s has changed and you have requested strict checking.", host);
+                       fatal("%s host key for %.200s has changed and you have requested strict checking.", type, host);
 
                /*
                 * If strict host key checking has not been requested, allow
This page took 0.047284 seconds and 4 git commands to generate.