]> andersk Git - openssh.git/blobdiff - ssh.c
- djm@cvs.openbsd.org 2006/02/12 06:45:34
[openssh.git] / ssh.c
diff --git a/ssh.c b/ssh.c
index 8a4a0e4c978770a0dad4328cb6a76917ae1ad518..4a373356f6fa0c4fd053c194c36420e1a8f1f6ab 100644 (file)
--- a/ssh.c
+++ b/ssh.c
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: ssh.c,v 1.255 2005/12/06 22:38:27 reyk Exp $");
+RCSID("$OpenBSD: ssh.c,v 1.261 2006/02/12 06:45:34 djm Exp $");
+
+#include <sys/resource.h>
+#include <sys/ioctl.h>
+
+#include <paths.h>
 
 #include <openssl/evp.h>
 #include <openssl/err.h>
@@ -164,7 +169,7 @@ usage(void)
 "           [-R [bind_address:]port:host:hostport] [-S ctl_path]\n"
 "           [-w tunnel:tunnel] [user@]hostname [command]\n"
        );
-       exit(1);
+       exit(255);
 }
 
 static int ssh_session(void);
@@ -223,7 +228,7 @@ main(int ac, char **av)
        pw = getpwuid(original_real_uid);
        if (!pw) {
                logit("You don't exist, go away!");
-               exit(1);
+               exit(255);
        }
        /* Take a copy of the returned structure. */
        pw = pwcopy(pw);
@@ -341,11 +346,12 @@ again:
                                exit(0);
                        break;
                case 'w':
-                       options.tun_open = 1;
+                       if (options.tun_open == -1)
+                               options.tun_open = SSH_TUNMODE_DEFAULT;
                        options.tun_local = a2tun(optarg, &options.tun_remote);
-                       if (options.tun_local < -1) {
+                       if (options.tun_local == SSH_TUNID_ERR) {
                                fprintf(stderr, "Bad tun device '%s'\n", optarg);
-                               exit(1);
+                               exit(255);
                        }
                        break;
                case 'q':
@@ -363,7 +369,7 @@ again:
                        else {
                                fprintf(stderr, "Bad escape character '%s'.\n",
                                    optarg);
-                               exit(1);
+                               exit(255);
                        }
                        break;
                case 'c':
@@ -378,7 +384,7 @@ again:
                                        fprintf(stderr,
                                            "Unknown cipher type '%s'\n",
                                            optarg);
-                                       exit(1);
+                                       exit(255);
                                }
                                if (options.cipher == SSH_CIPHER_3DES)
                                        options.ciphers = "3des-cbc";
@@ -394,7 +400,7 @@ again:
                        else {
                                fprintf(stderr, "Unknown mac type '%s'\n",
                                    optarg);
-                               exit(1);
+                               exit(255);
                        }
                        break;
                case 'M':
@@ -407,7 +413,7 @@ again:
                        options.port = a2port(optarg);
                        if (options.port == 0) {
                                fprintf(stderr, "Bad port '%s'\n", optarg);
-                               exit(1);
+                               exit(255);
                        }
                        break;
                case 'l':
@@ -421,7 +427,7 @@ again:
                                fprintf(stderr,
                                    "Bad local forwarding specification '%s'\n",
                                    optarg);
-                               exit(1);
+                               exit(255);
                        }
                        break;
 
@@ -432,7 +438,7 @@ again:
                                fprintf(stderr,
                                    "Bad remote forwarding specification "
                                    "'%s'\n", optarg);
-                               exit(1);
+                               exit(255);
                        }
                        break;
 
@@ -443,7 +449,7 @@ again:
                        if ((fwd.listen_host = hpdelim(&cp)) == NULL) {
                                fprintf(stderr, "Bad dynamic forwarding "
                                    "specification '%.100s'\n", optarg);
-                               exit(1);
+                               exit(255);
                        }
                        if (cp != NULL) {
                                fwd.listen_port = a2port(cp);
@@ -456,7 +462,7 @@ again:
                        if (fwd.listen_port == 0) {
                                fprintf(stderr, "Bad dynamic port '%s'\n",
                                    optarg);
-                               exit(1);
+                               exit(255);
                        }
                        add_local_forward(&options, &fwd);
                        xfree(p);
@@ -477,7 +483,7 @@ again:
                        line = xstrdup(optarg);
                        if (process_config_line(&options, host ? host : "",
                            line, "command-line", 0, &dummy) != 0)
-                               exit(1);
+                               exit(255);
                        xfree(line);
                        break;
                case 's':
@@ -632,11 +638,15 @@ again:
                options.control_path = NULL;
 
        if (options.control_path != NULL) {
+               char me[NI_MAXHOST];
+
+               if (gethostname(me, sizeof(me)) == -1)
+                       fatal("gethostname: %s", strerror(errno));
                snprintf(buf, sizeof(buf), "%d", options.port);
                cp = tilde_expand_filename(options.control_path,
                    original_real_uid);
                options.control_path = percent_expand(cp, "p", buf, "h", host,
-                   "r", options.user, (char *)NULL);
+                   "r", options.user, "l", me, (char *)NULL);
                xfree(cp);
        }
        if (mux_command != 0 && options.control_path == NULL)
@@ -653,7 +663,7 @@ again:
            original_effective_uid == 0 && options.use_privileged_port,
 #endif
            options.proxy_command) != 0)
-               exit(1);
+               exit(255);
 
        /*
         * If we successfully made the connection, load the host private key
@@ -1067,21 +1077,28 @@ ssh_session2_setup(int id, void *arg)
                packet_send();
        }
 
-       if (options.tun_open) {
+       if (options.tun_open != SSH_TUNMODE_NO) {
                Channel *c;
                int fd;
 
                debug("Requesting tun.");
-               if ((fd = tun_open(options.tun_local)) >= 0) {
+               if ((fd = tun_open(options.tun_local,
+                   options.tun_open)) >= 0) {
                        c = channel_new("tun", SSH_CHANNEL_OPENING, fd, fd, -1,
                            CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_PACKET_DEFAULT,
                            0, "tun", 1);
                        c->datagram = 1;
+#if defined(SSH_TUN_FILTER)
+                       if (options.tun_open == SSH_TUNMODE_POINTOPOINT)
+                               channel_register_filter(c->self, sys_tun_infilter,
+                                   sys_tun_outfilter);
+#endif
                        packet_start(SSH2_MSG_CHANNEL_OPEN);
                        packet_put_cstring("tun@openssh.com");
                        packet_put_int(c->self);
                        packet_put_int(c->local_window_max);
                        packet_put_int(c->local_maxpacket);
+                       packet_put_int(options.tun_open);
                        packet_put_int(options.tun_remote);
                        packet_send();
                }
This page took 0.042275 seconds and 4 git commands to generate.