]> andersk Git - openssh.git/blobdiff - ssh.c
- (tim) [configure.ac sshd.8] Enable locked account check (a "*LK*" string)
[openssh.git] / ssh.c
diff --git a/ssh.c b/ssh.c
index 2e93b161ae1a8e2ec6ad1771145f60d0b534ec8c..2227755cdfbf2164ea54ab6ce3ac390c15060e0e 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -40,7 +40,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: ssh.c,v 1.244 2005/06/17 22:53:46 djm Exp $");
+RCSID("$OpenBSD: ssh.c,v 1.254 2005/10/30 08:52:18 djm Exp $");
 
 #include <openssl/evp.h>
 #include <openssl/err.h>
@@ -158,7 +158,7 @@ usage(void)
 {
        fprintf(stderr,
 "usage: ssh [-1246AaCfgkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec]\n"
-"           [-D port] [-e escape_char] [-F configfile]\n"
+"           [-D [bind_address:]port] [-e escape_char] [-F configfile]\n"
 "           [-i identity_file] [-L [bind_address:]port:host:hostport]\n"
 "           [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]\n"
 "           [-R [bind_address:]port:host:hostport] [-S ctl_path]\n"
@@ -188,6 +188,9 @@ main(int ac, char **av)
        struct servent *sp;
        Forward fwd;
 
+       /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
+       sanitise_stdfd();
+
        __progname = ssh_get_progname(av[0]);
        init_rng();
 
@@ -439,7 +442,7 @@ again:
                                fwd.listen_host = cleanhostname(fwd.listen_host);
                        } else {
                                fwd.listen_port = a2port(fwd.listen_host);
-                               fwd.listen_host = "";
+                               fwd.listen_host = NULL;
                        }
 
                        if (fwd.listen_port == 0) {
@@ -607,9 +610,18 @@ again:
                                *p = tolower(*p);
        }
 
+       /* Get default port if port has not been set. */
+       if (options.port == 0) {
+               sp = getservbyname(SSH_SERVICE_NAME, "tcp");
+               options.port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT;
+       }
+
        if (options.proxy_command != NULL &&
            strcmp(options.proxy_command, "none") == 0)
                options.proxy_command = NULL;
+       if (options.control_path != NULL &&
+           strcmp(options.control_path, "none") == 0)
+               options.control_path = NULL;
 
        if (options.control_path != NULL) {
                snprintf(buf, sizeof(buf), "%d", options.port);
@@ -624,12 +636,6 @@ again:
        if (options.control_path != NULL)
                control_client(options.control_path);
 
-       /* Get default port if port has not been set. */
-       if (options.port == 0) {
-               sp = getservbyname(SSH_SERVICE_NAME, "tcp");
-               options.port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT;
-       }
-
        /* Open a connection to the remote host. */
        if (ssh_connect(host, &hostaddr, options.port,
            options.address_family, options.connection_attempts,
@@ -692,7 +698,7 @@ again:
 
        /*
         * Now that we are back to our own permissions, create ~/.ssh
-        * directory if it doesn\'t already exist.
+        * directory if it doesn't already exist.
         */
        snprintf(buf, sizeof buf, "%.100s%s%.100s", pw->pw_dir, strcmp(pw->pw_dir, "/") ? "/" : "", _PATH_SSH_USER_DIR);
        if (stat(buf, &st) < 0)
@@ -787,9 +793,8 @@ ssh_init_forwarding(void)
        for (i = 0; i < options.num_remote_forwards; i++) {
                debug("Remote connections from %.200s:%d forwarded to "
                    "local address %.200s:%d",
-                   (options.remote_forwards[i].listen_host == NULL) ? 
-                   (options.gateway_ports ? "*" : "LOCALHOST") : 
-                   options.remote_forwards[i].listen_host,
+                   (options.remote_forwards[i].listen_host == NULL) ?
+                   "LOCALHOST" : options.remote_forwards[i].listen_host,
                    options.remote_forwards[i].listen_port,
                    options.remote_forwards[i].connect_host,
                    options.remote_forwards[i].connect_port);
@@ -805,7 +810,7 @@ static void
 check_agent_present(void)
 {
        if (options.forward_agent) {
-               /* Clear agent forwarding if we don\'t have an agent. */
+               /* Clear agent forwarding if we don't have an agent. */
                if (!ssh_agent_present())
                        options.forward_agent = 0;
        }
@@ -1007,7 +1012,7 @@ ssh_control_listener(void)
                fatal("ControlPath too long");
 
        if ((control_fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
-               fatal("%s socket(): %s\n", __func__, strerror(errno));
+               fatal("%s socket(): %s", __func__, strerror(errno));
 
        old_umask = umask(0177);
        if (bind(control_fd, (struct sockaddr*)&addr, addr_len) == -1) {
@@ -1016,12 +1021,12 @@ ssh_control_listener(void)
                        fatal("ControlSocket %s already exists",
                            options.control_path);
                else
-                       fatal("%s bind(): %s\n", __func__, strerror(errno));
+                       fatal("%s bind(): %s", __func__, strerror(errno));
        }
        umask(old_umask);
 
        if (listen(control_fd, 64) == -1)
-               fatal("%s listen(): %s\n", __func__, strerror(errno));
+               fatal("%s listen(): %s", __func__, strerror(errno));
 
        set_nonblock(control_fd);
 }
@@ -1034,7 +1039,7 @@ ssh_session2_setup(int id, void *arg)
        const char *display;
        int interactive = tty_flag;
 
-       display = getenv("DISPLAY");    
+       display = getenv("DISPLAY");
        if (options.forward_x11 && display != NULL) {
                char *proto, *data;
                /* Get reasonable local authentication information. */
@@ -1247,41 +1252,44 @@ control_client(const char *path)
                        error("Control socket connect(%.100s): %s", path,
                            strerror(errno));
                }
-               close(sock);
-               return;
-       }
+               close(sock);
+               return;
+       }
 
-       if (stdin_null_flag) {
-               if ((fd = open(_PATH_DEVNULL, O_RDONLY)) == -1)
-                       fatal("open(/dev/null): %s", strerror(errno));
-               if (dup2(fd, STDIN_FILENO) == -1)
-                       fatal("dup2: %s", strerror(errno));
-               if (fd > STDERR_FILENO)
-                       close(fd);
-       }
+       if (stdin_null_flag) {
+               if ((fd = open(_PATH_DEVNULL, O_RDONLY)) == -1)
+                       fatal("open(/dev/null): %s", strerror(errno));
+               if (dup2(fd, STDIN_FILENO) == -1)
+                       fatal("dup2: %s", strerror(errno));
+               if (fd > STDERR_FILENO)
+                       close(fd);
+       }
 
-       if ((term = getenv("TERM")) == NULL)
-               term = "";
+       term = getenv("TERM");
 
        flags = 0;
        if (tty_flag)
                flags |= SSHMUX_FLAG_TTY;
        if (subsystem_flag)
                flags |= SSHMUX_FLAG_SUBSYS;
+       if (options.forward_x11)
+               flags |= SSHMUX_FLAG_X11_FWD;
+       if (options.forward_agent)
+               flags |= SSHMUX_FLAG_AGENT_FWD;
 
        buffer_init(&m);
 
        /* Send our command to server */
        buffer_put_int(&m, mux_command);
        buffer_put_int(&m, flags);
-       if (ssh_msg_send(sock, /* version */1, &m) == -1)
+       if (ssh_msg_send(sock, SSHMUX_VER, &m) == -1)
                fatal("%s: msg_send", __func__);
        buffer_clear(&m);
 
        /* Get authorisation status and PID of controlee */
        if (ssh_msg_recv(sock, &m) == -1)
                fatal("%s: msg_recv", __func__);
-       if (buffer_get_char(&m) != 1)
+       if (buffer_get_char(&m) != SSHMUX_VER)
                fatal("%s: wrong version", __func__);
        if (buffer_get_int(&m) != 1)
                fatal("Connection to master denied");
@@ -1305,7 +1313,7 @@ control_client(const char *path)
        }
 
        /* SSHMUX_COMMAND_OPEN */
-       buffer_put_cstring(&m, term);
+       buffer_put_cstring(&m, term ? term : "");
        buffer_append(&command, "\0", 1);
        buffer_put_cstring(&m, buffer_ptr(&command));
 
@@ -1327,7 +1335,7 @@ control_client(const char *path)
                        }
        }
 
-       if (ssh_msg_send(sock, /* version */1, &m) == -1)
+       if (ssh_msg_send(sock, SSHMUX_VER, &m) == -1)
                fatal("%s: msg_send", __func__);
 
        mm_send_fd(sock, STDIN_FILENO);
@@ -1338,7 +1346,7 @@ control_client(const char *path)
        buffer_clear(&m);
        if (ssh_msg_recv(sock, &m) == -1)
                fatal("%s: msg_recv", __func__);
-       if (buffer_get_char(&m) != 1)
+       if (buffer_get_char(&m) != SSHMUX_VER)
                fatal("%s: wrong version", __func__);
        buffer_free(&m);
 
This page took 0.041678 seconds and 4 git commands to generate.