]> andersk Git - openssh.git/blobdiff - ssh.c
- dtucker@cvs.openbsd.org 2006/08/01 11:34:36
[openssh.git] / ssh.c
diff --git a/ssh.c b/ssh.c
index 5eddd41d5d4ad2d178d41e1f6e51365cc847b53a..e08239c6183e30582e65daec6348656211323e2c 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh.c,v 1.275 2006/03/30 10:41:25 djm Exp $ */
+/* $OpenBSD: ssh.c,v 1.290 2006/07/26 13:57:17 stevesk Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
 #endif
 #include <sys/resource.h>
 #include <sys/ioctl.h>
+#include <sys/socket.h>
 #include <sys/un.h>
 
 #include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <netdb.h>
 #ifdef HAVE_PATHS_H
 #include <paths.h>
 #endif
+#include <pwd.h>
 #include <signal.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 
 #include <openssl/evp.h>
 #include <openssl/err.h>
@@ -86,6 +95,7 @@
 #include "msg.h"
 #include "monitor_fdpass.h"
 #include "uidswap.h"
+#include "version.h"
 
 #ifdef SMARTCARD
 #include "scard.h"
@@ -176,7 +186,7 @@ usage(void)
 "           [-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"
-"           [-w tunnel:tunnel] [user@]hostname [command]\n"
+"           [-w local_tun[:remote_tun]] [user@]hostname [command]\n"
        );
        exit(255);
 }
@@ -693,11 +703,11 @@ main(int ac, char **av)
 
                PRIV_START;
                sensitive_data.keys[0] = key_load_private_type(KEY_RSA1,
-                   _PATH_HOST_KEY_FILE, "", NULL);
+                   _PATH_HOST_KEY_FILE, "", NULL, NULL);
                sensitive_data.keys[1] = key_load_private_type(KEY_DSA,
-                   _PATH_HOST_DSA_KEY_FILE, "", NULL);
+                   _PATH_HOST_DSA_KEY_FILE, "", NULL, NULL);
                sensitive_data.keys[2] = key_load_private_type(KEY_RSA,
-                   _PATH_HOST_RSA_KEY_FILE, "", NULL);
+                   _PATH_HOST_RSA_KEY_FILE, "", NULL, NULL);
                PRIV_END;
 
                if (options.hostbased_authentication == 1 &&
@@ -813,6 +823,8 @@ ssh_init_forwarding(void)
                    options.local_forwards[i].connect_port,
                    options.gateway_ports);
        }
+       if (i > 0 && success != i && options.exit_on_forward_failure)
+               fatal("Could not request local forwarding.");
        if (i > 0 && success == 0)
                error("Could not request local forwarding.");
 
@@ -825,11 +837,17 @@ ssh_init_forwarding(void)
                    options.remote_forwards[i].listen_port,
                    options.remote_forwards[i].connect_host,
                    options.remote_forwards[i].connect_port);
-               channel_request_remote_forwarding(
+               if (channel_request_remote_forwarding(
                    options.remote_forwards[i].listen_host,
                    options.remote_forwards[i].listen_port,
                    options.remote_forwards[i].connect_host,
-                   options.remote_forwards[i].connect_port);
+                   options.remote_forwards[i].connect_port) < 0) {
+                       if (options.exit_on_forward_failure)
+                               fatal("Could not request remote forwarding.");
+                       else
+                               logit("Warning: Could not request remote "
+                                   "forwarding.");
+               }
        }
 }
 
@@ -1011,9 +1029,16 @@ client_global_request_reply_fwd(int type, u_int32_t seq, void *ctxt)
            options.remote_forwards[i].listen_port,
            options.remote_forwards[i].connect_host,
            options.remote_forwards[i].connect_port);
-       if (type == SSH2_MSG_REQUEST_FAILURE)
-               logit("Warning: remote port forwarding failed for listen "
-                   "port %d", options.remote_forwards[i].listen_port);
+       if (type == SSH2_MSG_REQUEST_FAILURE) {
+               if (options.exit_on_forward_failure)
+                       fatal("Error: remote port forwarding failed for "
+                           "listen port %d",
+                           options.remote_forwards[i].listen_port);
+               else
+                       logit("Warning: remote port forwarding failed for "
+                           "listen port %d",
+                           options.remote_forwards[i].listen_port);
+       }
 }
 
 static void
@@ -1258,15 +1283,14 @@ control_client_sigrelay(int signo)
 static int
 env_permitted(char *env)
 {
-       int i;
+       int i, ret;
        char name[1024], *cp;
 
-       if (strlcpy(name, env, sizeof(name)) >= sizeof(name))
-               fatal("env_permitted: name too long");
-       if ((cp = strchr(name, '=')) == NULL)
+       if ((cp = strchr(env, '=')) == NULL || cp == env)
                return (0);
-
-       *cp = '\0';
+       ret = snprintf(name, sizeof(name), "%.*s", (int)(cp - env), env);
+       if (ret <= 0 || (size_t)ret >= sizeof(name))
+               fatal("env_permitted: name '%.100s...' too long", env);
 
        for (i = 0; i < options.num_send_env; i++)
                if (match_pattern(name, options.send_env[i]))
This page took 0.050356 seconds and 4 git commands to generate.