Imported Upstream version 6.2p2
[platform/upstream/openssh.git] / ssh.c
diff --git a/ssh.c b/ssh.c
index 68e1315..5ec89f2 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh.c,v 1.368 2011/10/24 02:10:46 djm Exp $ */
+/* $OpenBSD: ssh.c,v 1.373 2013/02/22 22:09:01 djm Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -405,12 +405,7 @@ main(int ac, char **av)
                                    strerror(errno));
                                break;
                        }
-                       if (options.num_identity_files >=
-                           SSH_MAX_IDENTITY_FILES)
-                               fatal("Too many identity files specified "
-                                   "(max %d)", SSH_MAX_IDENTITY_FILES);
-                       options.identity_files[options.num_identity_files++] =
-                           xstrdup(optarg);
+                       add_identity_file(&options, NULL, optarg, 1);
                        break;
                case 'I':
 #ifdef ENABLE_PKCS11
@@ -584,7 +579,8 @@ main(int ac, char **av)
                        dummy = 1;
                        line = xstrdup(optarg);
                        if (process_config_line(&options, host ? host : "",
-                           line, "command-line", 0, &dummy) != 0)
+                           line, "command-line", 0, &dummy, SSHCONF_USERCONF)
+                           != 0)
                                exit(255);
                        xfree(line);
                        break;
@@ -638,10 +634,6 @@ main(int ac, char **av)
        /* Initialize the command to execute on remote host. */
        buffer_init(&command);
 
-       if (options.request_tty == REQUEST_TTY_YES ||
-           options.request_tty == REQUEST_TTY_FORCE)
-               tty_flag = 1;
-
        /*
         * Save the command to execute on the remote host in a buffer. There
         * is no limit on the length of the command, except by the maximum
@@ -649,7 +641,6 @@ main(int ac, char **av)
         */
        if (!ac) {
                /* No command specified - execute shell on a tty. */
-               tty_flag = options.request_tty != REQUEST_TTY_NO;
                if (subsystem_flag) {
                        fprintf(stderr,
                            "You must specify a subsystem to invoke.\n");
@@ -670,22 +661,6 @@ main(int ac, char **av)
                fatal("Cannot fork into background without a command "
                    "to execute.");
 
-       /* Allocate a tty by default if no command specified. */
-       if (buffer_len(&command) == 0)
-               tty_flag = options.request_tty != REQUEST_TTY_NO;
-
-       /* Force no tty */
-       if (options.request_tty == REQUEST_TTY_NO || muxclient_command != 0)
-               tty_flag = 0;
-       /* Do not allocate a tty if stdin is not a tty. */
-       if ((!isatty(fileno(stdin)) || stdin_null_flag) &&
-           options.request_tty != REQUEST_TTY_FORCE) {
-               if (tty_flag)
-                       logit("Pseudo-terminal will not be allocated because "
-                           "stdin is not a terminal.");
-               tty_flag = 0;
-       }
-
        /*
         * Initialize "log" output.  Since we are the client all output
         * actually goes to stderr.
@@ -699,14 +674,15 @@ main(int ac, char **av)
         * file if the user specifies a config file on the command line.
         */
        if (config != NULL) {
-               if (!read_config_file(config, host, &options, 0))
+               if (!read_config_file(config, host, &options, SSHCONF_USERCONF))
                        fatal("Can't open user config file %.100s: "
                            "%.100s", config, strerror(errno));
        } else {
                r = snprintf(buf, sizeof buf, "%s/%s", pw->pw_dir,
                    _PATH_SSH_USER_CONFFILE);
                if (r > 0 && (size_t)r < sizeof(buf))
-                       (void)read_config_file(buf, host, &options, 1);
+                       (void)read_config_file(buf, host, &options,
+                            SSHCONF_CHECKPERM|SSHCONF_USERCONF);
 
                /* Read systemwide configuration file after user config. */
                (void)read_config_file(_PATH_HOST_CONFIG_FILE, host,
@@ -721,6 +697,26 @@ main(int ac, char **av)
        /* reinit */
        log_init(argv0, options.log_level, SYSLOG_FACILITY_USER, !use_syslog);
 
+       if (options.request_tty == REQUEST_TTY_YES ||
+           options.request_tty == REQUEST_TTY_FORCE)
+               tty_flag = 1;
+
+       /* Allocate a tty by default if no command specified. */
+       if (buffer_len(&command) == 0)
+               tty_flag = options.request_tty != REQUEST_TTY_NO;
+
+       /* Force no tty */
+       if (options.request_tty == REQUEST_TTY_NO || muxclient_command != 0)
+               tty_flag = 0;
+       /* Do not allocate a tty if stdin is not a tty. */
+       if ((!isatty(fileno(stdin)) || stdin_null_flag) &&
+           options.request_tty != REQUEST_TTY_FORCE) {
+               if (tty_flag)
+                       logit("Pseudo-terminal will not be allocated because "
+                           "stdin is not a terminal.");
+               tty_flag = 0;
+       }
+
        seed_rng();
 
        if (options.user == NULL)
@@ -1359,6 +1355,10 @@ ssh_session2_setup(int id, int success, void *arg)
                packet_send();
        }
 
+       /* Tell the packet module whether this is an interactive session. */
+       packet_set_interactive(interactive,
+           options.ip_qos_interactive, options.ip_qos_bulk);
+
        client_session2_setup(id, tty_flag, subsystem_flag, getenv("TERM"),
            NULL, fileno(stdin), &command, environ);
 }
@@ -1536,7 +1536,8 @@ load_public_identity_files(void)
                fatal("load_public_identity_files: gethostname: %s",
                    strerror(errno));
        for (i = 0; i < options.num_identity_files; i++) {
-               if (n_ids >= SSH_MAX_IDENTITY_FILES) {
+               if (n_ids >= SSH_MAX_IDENTITY_FILES ||
+                   strcasecmp(options.identity_files[i], "none") == 0) {
                        xfree(options.identity_files[i]);
                        continue;
                }