]> andersk Git - openssh.git/blobdiff - channels.c
- markus@cvs.openbsd.org 2001/01/31 13:37:24
[openssh.git] / channels.c
index 82a2db05e151d3af84ffd587bdb3b72cc1ec298a..354160e8fa31a9e11cd41c353470ef5d7695da28 100644 (file)
@@ -40,7 +40,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: channels.c,v 1.85 2001/01/29 19:42:35 markus Exp $");
+RCSID("$OpenBSD: channels.c,v 1.89 2001/02/04 15:32:23 stevesk Exp $");
 
 #include <openssl/rsa.h>
 #include <openssl/dsa.h>
@@ -600,7 +600,7 @@ channel_post_port_listener(Channel *c, fd_set * readset, fd_set * writeset)
        struct sockaddr addr;
        int newsock, newch;
        socklen_t addrlen;
-       char buf[1024], *remote_hostname, *rtype;
+       char buf[1024], *remote_ipaddr, *rtype;
        int remote_port;
 
        rtype = (c->type == SSH_CHANNEL_RPORT_LISTENER) ?
@@ -616,13 +616,13 @@ channel_post_port_listener(Channel *c, fd_set * readset, fd_set * writeset)
                        error("accept: %.100s", strerror(errno));
                        return;
                }
-               remote_hostname = get_remote_hostname(newsock);
+               remote_ipaddr = get_peer_ipaddr(newsock);
                remote_port = get_peer_port(newsock);
                snprintf(buf, sizeof buf,
                    "listen port %d for %.100s port %d, "
                    "connect from %.200s port %d",
                    c->listening_port, c->path, c->host_port,
-                   remote_hostname, remote_port);
+                   remote_ipaddr, remote_port);
 
                newch = channel_new(rtype,
                    SSH_CHANNEL_OPENING, newsock, newsock, -1,
@@ -644,7 +644,7 @@ channel_post_port_listener(Channel *c, fd_set * readset, fd_set * writeset)
                                packet_put_int(c->host_port);
                        }
                        /* originator host and port */
-                       packet_put_cstring(remote_hostname);
+                       packet_put_cstring(remote_ipaddr);
                        packet_put_int(remote_port);
                        packet_send();
                } else {
@@ -657,7 +657,7 @@ channel_post_port_listener(Channel *c, fd_set * readset, fd_set * writeset)
                        }
                        packet_send();
                }
-               xfree(remote_hostname);
+               xfree(remote_ipaddr);
        }
 }
 
@@ -704,7 +704,7 @@ channel_post_connecting(Channel *c, fd_set * readset, fd_set * writeset)
                int err = 0;
                int sz = sizeof(err);
                c->type = SSH_CHANNEL_OPEN;
-                if (getsockopt(c->sock, SOL_SOCKET, SO_ERROR, (char *)&err, &sz) < 0) {
+               if (getsockopt(c->sock, SOL_SOCKET, SO_ERROR, (char *)&err, &sz) < 0) {
                        debug("getsockopt SO_ERROR failed");
                } else {
                        if (err == 0) {
@@ -1317,7 +1317,8 @@ channel_input_open_confirmation(int type, int plen, void *ctxt)
 void
 channel_input_open_failure(int type, int plen, void *ctxt)
 {
-       int id;
+       int id, reason;
+       char *msg = NULL, *lang = NULL;
        Channel *c;
 
        if (!compat20)
@@ -1330,13 +1331,18 @@ channel_input_open_failure(int type, int plen, void *ctxt)
                packet_disconnect("Received open failure for "
                    "non-opening channel %d.", id);
        if (compat20) {
-               int reason = packet_get_int();
-               char *msg  = packet_get_string(NULL);
-               char *lang  = packet_get_string(NULL);
-               log("channel_open_failure: %d: reason %d: %s", id, reason, msg);
+               reason = packet_get_int();
+               if (packet_remaining() > 0) {
+                       msg  = packet_get_string(NULL);
+                       lang = packet_get_string(NULL);
+               }
                packet_done();
-               xfree(msg);
-               xfree(lang);
+               log("channel_open_failure: %d: reason %d %s", id,
+                   reason, msg ? msg : "<no additional info>");
+               if (msg != NULL)
+                       xfree(msg);
+               if (lang != NULL)
+                       xfree(lang);
        }
        /* Free the channel.  This will also close the socket. */
        channel_free(id);
@@ -1525,11 +1531,11 @@ channel_open_message()
  * Initiate forwarding of connections to local port "port" through the secure
  * channel to host:port from remote side.
  */
-void
+int
 channel_request_local_forwarding(u_short listen_port, const char *host_to_connect,
     u_short port_to_connect, int gateway_ports)
 {
-       channel_request_forwarding(
+       return channel_request_forwarding(
            NULL, listen_port,
            host_to_connect, port_to_connect,
            gateway_ports, /*remote_fwd*/ 0);
@@ -1539,7 +1545,7 @@ channel_request_local_forwarding(u_short listen_port, const char *host_to_connec
  * If 'remote_fwd' is true we have a '-R style' listener for protocol 2
  * (SSH_CHANNEL_RPORT_LISTENER).
  */
-void
+int
 channel_request_forwarding(
     const char *listen_address, u_short listen_port,
     const char *host_to_connect, u_short port_to_connect,
@@ -1551,16 +1557,20 @@ channel_request_forwarding(
        const char *host;
        struct linger linger;
 
+       success = 0;
+
        if (remote_fwd) {
                host = listen_address;
-               ctype = SSH_CHANNEL_RPORT_LISTENER;
+               ctype = SSH_CHANNEL_RPORT_LISTENER;
        } else {
                host = host_to_connect;
                ctype  =SSH_CHANNEL_PORT_LISTENER;
        }
 
-       if (strlen(host) > sizeof(channels[0].path) - 1)
-               packet_disconnect("Forward host name too long.");
+       if (strlen(host) > sizeof(channels[0].path) - 1) {
+               error("Forward host name too long.");
+               return success;
+       }
 
        /* XXX listen_address is currently ignored */
        /*
@@ -1575,7 +1585,6 @@ channel_request_forwarding(
        if (getaddrinfo(NULL, strport, &hints, &aitop) != 0)
                packet_disconnect("getaddrinfo: fatal error");
 
-       success = 0;
        for (ai = aitop; ai; ai = ai->ai_next) {
                if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6)
                        continue;
@@ -1608,7 +1617,7 @@ channel_request_forwarding(
                                error("bind: %.100s", strerror(errno));
                        else
                                verbose("bind: %.100s", strerror(errno));
-                               
+
                        close(sock);
                        continue;
                }
@@ -1628,8 +1637,10 @@ channel_request_forwarding(
                success = 1;
        }
        if (success == 0)
-               packet_disconnect("cannot listen port: %d", listen_port);       /*XXX ?disconnect? */
+               error("channel_request_forwarding: cannot listen to port: %d",
+                   listen_port);
        freeaddrinfo(aitop);
+       return success;
 }
 
 /*
@@ -1762,14 +1773,14 @@ channel_connect_to(const char *host, u_short host_port)
                        error("connect %.100s port %s: %.100s", ntop, strport,
                            strerror(errno));
                        close(sock);
-                       continue;       /* fail -- try next */  
+                       continue;       /* fail -- try next */
                }
                break; /* success */
 
        }
        freeaddrinfo(aitop);
        if (!ai) {
-               error("connect %.100s port %d: failed.", host, host_port);      
+               error("connect %.100s port %d: failed.", host, host_port);
                return -1;
        }
        /* success */
@@ -1954,7 +1965,7 @@ x11_create_display_inet(int screen_number, int x11_display_offset)
                fatal("gethostname: %.100s", strerror(errno));
 
 #ifdef IPADDR_IN_DISPLAY
-       /* 
+       /*
         * HPUX detects the local hostname in the DISPLAY variable and tries
         * to set up a shared memory connection to the server, which it
         * incorrectly supposes to be local.
@@ -1983,7 +1994,7 @@ x11_create_display_inet(int screen_number, int x11_display_offset)
                memcpy(&my_addr, he->h_addr_list[0], sizeof(struct in_addr));
 
                /* Set DISPLAY to <ip address>:screen.display */
-               snprintf(display, sizeof(display), "%.50s:%d.%d", inet_ntoa(my_addr), 
+               snprintf(display, sizeof(display), "%.50s:%d.%d", inet_ntoa(my_addr),
                         display_number, screen_number);
        }
 #else /* IPADDR_IN_DISPLAY */
@@ -2501,7 +2512,7 @@ channel_cancel_cleanup(int id)
        }
        c->dettach_user = NULL;
 }
-void   
+void
 channel_register_filter(int id, channel_filter_fn *fn)
 {
        Channel *c = channel_lookup(id);
This page took 0.052473 seconds and 4 git commands to generate.