]> andersk Git - openssh.git/blobdiff - sshconnect.c
Whoops, forgot changelog
[openssh.git] / sshconnect.c
index d74658c9687bc8866da8264a33a52d67864329b1..d6072b36c65eebf034722674b2b857664df41af8 100644 (file)
@@ -2,13 +2,18 @@
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
  *                    All rights reserved
- * Created: Sat Mar 18 22:15:47 1995 ylo
  * Code to connect to a remote host, and to perform the client side of the
  * login (authentication) dialog.
+ *
+ * As far as I am concerned, the code I have written for this software
+ * can be used freely for any purpose.  Any derived versions of this
+ * software must be clearly marked as such, and if the derived work is
+ * incompatible with the protocol description in the RFC file, it must be
+ * called by a name other than "ssh" or "Secure Shell".
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: sshconnect.c,v 1.72 2000/05/04 09:50:22 markus Exp $");
+RCSID("$OpenBSD: sshconnect.c,v 1.79 2000/09/17 15:52:51 markus Exp $");
 
 #include <openssl/bn.h>
 #include <openssl/dsa.h>
@@ -108,15 +113,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. */
@@ -193,8 +198,8 @@ ssh_connect(const char *host, struct sockaddr_storage * hostaddr,
        int gaierr;
        struct linger linger;
 
-       debug("ssh_connect: getuid %d geteuid %d anon %d",
-             (int) getuid(), (int) geteuid(), anonymous);
+       debug("ssh_connect: getuid %u geteuid %u anon %d",
+             (u_int) getuid(), (u_int) geteuid(), anonymous);
 
        /* Get default port if port has not been set. */
        if (port == 0) {
@@ -243,7 +248,11 @@ ssh_connect(const char *host, struct sockaddr_storage * hostaddr,
 
                        /* Create a socket for connecting. */
                        sock = ssh_create_socket(original_real_uid,
+#ifdef HAVE_CYGWIN
+                           !anonymous && port < IPPORT_RESERVED,
+#else
                            !anonymous && geteuid() == 0 && port < IPPORT_RESERVED,
+#endif
                            ai->ai_family);
                        if (sock < 0)
                                continue;
@@ -301,21 +310,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 +323,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);
 
        /*
@@ -445,8 +444,10 @@ read_yes_or_no(const char *prompt, int defval)
                        retval = defval;
                if (strcmp(buf, "yes") == 0)
                        retval = 1;
-               if (strcmp(buf, "no") == 0)
+               else if (strcmp(buf, "no") == 0)
                        retval = 0;
+               else
+                       fprintf(stderr, "Please type 'yes' or 'no'.\n");
 
                if (retval != -1) {
                        if (f != stdin)
@@ -679,7 +680,7 @@ ssh_login(int host_key_valid, RSA *own_host_key, const char *orighost,
        /* Get local user name.  Use it as server user if no user name was given. */
        pw = getpwuid(original_real_uid);
        if (!pw)
-               fatal("User id %d not found from user database.", original_real_uid);
+               fatal("User id %u not found from user database.", original_real_uid);
        local_user = xstrdup(pw->pw_name);
        server_user = options.user ? options.user : local_user;
 
This page took 0.039527 seconds and 4 git commands to generate.