]> andersk Git - openssh.git/blobdiff - session.c
- markus@cvs.openbsd.org 2002/02/07 09:35:39
[openssh.git] / session.c
index 61284104908db4ff08e43ee77d9b8ebbed1b6b05..431936ac65aacafff86ee7f913816525ac0733f4 100644 (file)
--- a/session.c
+++ b/session.c
@@ -33,7 +33,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: session.c,v 1.115 2001/12/27 20:39:58 markus Exp $");
+RCSID("$OpenBSD: session.c,v 1.124 2002/02/06 14:37:22 markus Exp $");
 
 #include "ssh.h"
 #include "ssh1.h"
@@ -111,7 +111,7 @@ struct Session {
        int     display_number;
        char    *display;
        int     screen;
-       char    *auth_display[2];
+       char    *auth_display;
        char    *auth_proto;
        char    *auth_data;
        int     single_connection;
@@ -195,7 +195,7 @@ do_authenticated(Authctxt *authctxt)
 #ifdef WITH_AIXAUTHENTICATE
        /* We don't have a pty yet, so just label the line as "ssh" */
        if (loginsuccess(authctxt->user,
-           get_canonical_hostname(options.reverse_mapping_check),
+           get_canonical_hostname(options.verify_reverse_mapping),
            "ssh", &aixloginmsg) < 0)
                aixloginmsg = NULL;
 #endif /* WITH_AIXAUTHENTICATE */
@@ -233,7 +233,7 @@ do_authenticated1(Authctxt *authctxt)
 {
        Session *s;
        char *command;
-       int success, type, plen, screen_flag;
+       int success, type, screen_flag;
        int compression_level = 0, enable_compression_after_reply = 0;
        u_int proto_len, data_len, dlen;
 
@@ -249,13 +249,13 @@ do_authenticated1(Authctxt *authctxt)
                success = 0;
 
                /* Get a packet from the client. */
-               type = packet_read(&plen);
+               type = packet_read();
 
                /* Process the packet. */
                switch (type) {
                case SSH_CMSG_REQUEST_COMPRESSION:
                        compression_level = packet_get_int();
-                       packet_done();
+                       packet_check_eom();
                        if (compression_level < 1 || compression_level > 9) {
                                packet_send_debug("Received illegal compression level %d.",
                                    compression_level);
@@ -286,7 +286,7 @@ do_authenticated1(Authctxt *authctxt)
                        } else {
                                s->screen = 0;
                        }
-                       packet_done();
+                       packet_check_eom();
                        success = session_setup_x11fwd(s);
                        if (!success) {
                                xfree(s->auth_proto);
@@ -330,7 +330,7 @@ do_authenticated1(Authctxt *authctxt)
                                verbose("Kerberos TGT passing disabled.");
                        } else {
                                char *kdata = packet_get_string(&dlen);
-                               packet_done();
+                               packet_check_eom();
 
                                /* XXX - 0x41, see creds_to_radix version */
                                if (kdata[0] != 0x41) {
@@ -364,7 +364,7 @@ do_authenticated1(Authctxt *authctxt)
                        } else {
                                /* Accept AFS token. */
                                char *token = packet_get_string(&dlen);
-                               packet_done();
+                               packet_check_eom();
 
                                if (auth_afs_token(s->authctxt, token))
                                        success = 1;
@@ -386,7 +386,7 @@ do_authenticated1(Authctxt *authctxt)
                        } else {
                                do_exec(s, NULL);
                        }
-                       packet_done();
+                       packet_check_eom();
                        session_close(s);
                        return;
 
@@ -656,7 +656,7 @@ do_pre_login(Session *s)
        }
 
        record_utmp_only(pid, s->tty, s->pw->pw_name,
-           get_remote_name_or_ip(utmp_len, options.reverse_mapping_check),
+           get_remote_name_or_ip(utmp_len, options.verify_reverse_mapping),
            (struct sockaddr *)&from);
 }
 #endif
@@ -717,7 +717,7 @@ do_login(Session *s, const char *command)
 
        /* Record that there was a login on that tty from the remote host. */
        record_login(pid, s->tty, pw->pw_name, pw->pw_uid,
-           get_remote_name_or_ip(utmp_len, options.reverse_mapping_check),
+           get_remote_name_or_ip(utmp_len, options.verify_reverse_mapping),
            (struct sockaddr *)&from);
 
 #ifdef USE_PAM
@@ -1287,7 +1287,7 @@ do_child(Session *s, const char *command)
        /* we have to stash the hostname before we close our socket. */
        if (options.use_login)
                hostname = get_remote_name_or_ip(utmp_len,
-                   options.reverse_mapping_check);
+                   options.verify_reverse_mapping);
        /*
         * Close the connection descriptors; note that this is the child, and
         * the server will still have the socket open, and it is important
@@ -1390,25 +1390,16 @@ do_child(Session *s, const char *command)
                                fprintf(stderr,
                                    "Running %.100s add "
                                    "%.100s %.100s %.100s\n",
-                                   options.xauth_location, s->auth_display[0],
+                                   options.xauth_location, s->auth_display,
                                    s->auth_proto, s->auth_data);
-                               if (s->auth_display[1])
-                                       fprintf(stderr,
-                                           "add %.100s %.100s %.100s\n",
-                                           s->auth_display[1],
-                                           s->auth_proto, s->auth_data);
                        }
                        snprintf(cmd, sizeof cmd, "%s -q -",
                            options.xauth_location);
                        f = popen(cmd, "w");
                        if (f) {
                                fprintf(f, "add %s %s %s\n",
-                                   s->auth_display[0], s->auth_proto,
+                                   s->auth_display, s->auth_proto,
                                    s->auth_data);
-                               if (s->auth_display[1])
-                                       fprintf(f, "add %s %s %s\n",
-                                           s->auth_display[1], s->auth_proto,
-                                           s->auth_data);
                                pclose(f);
                        } else {
                                fprintf(stderr, "Could not run %s\n",
@@ -1575,7 +1566,7 @@ session_window_change_req(Session *s)
        s->row = packet_get_int();
        s->xpixel = packet_get_int();
        s->ypixel = packet_get_int();
-       packet_done();
+       packet_check_eom();
        pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
        return 1;
 }
@@ -1640,7 +1631,7 @@ session_pty_req(Session *s)
        /* Set window size from the packet. */
        pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
 
-       packet_done();
+       packet_check_eom();
        session_proctitle(s);
        return 1;
 }
@@ -1654,8 +1645,8 @@ session_subsystem_req(Session *s)
        char *cmd, *subsys = packet_get_string(&len);
        int i;
 
-       packet_done();
-       log("subsystem request for %s", subsys);
+       packet_check_eom();
+       log("subsystem request for %.100s", subsys);
 
        for (i = 0; i < options.num_subsystems; i++) {
                if (strcmp(subsys, options.subsystem_name[i]) == 0) {
@@ -1669,11 +1660,12 @@ session_subsystem_req(Session *s)
                        s->is_subsystem = 1;
                        do_exec(s, cmd);
                        success = 1;
+                       break;
                }
        }
 
        if (!success)
-               log("subsystem request for %s failed, subsystem not found",
+               log("subsystem request for %.100s failed, subsystem not found",
                    subsys);
 
        xfree(subsys);
@@ -1689,7 +1681,7 @@ session_x11_req(Session *s)
        s->auth_proto = packet_get_string(NULL);
        s->auth_data = packet_get_string(NULL);
        s->screen = packet_get_int();
-       packet_done();
+       packet_check_eom();
 
        success = session_setup_x11fwd(s);
        if (!success) {
@@ -1704,7 +1696,7 @@ session_x11_req(Session *s)
 static int
 session_shell_req(Session *s)
 {
-       packet_done();
+       packet_check_eom();
        do_exec(s, NULL);
        return 1;
 }
@@ -1714,7 +1706,7 @@ session_exec_req(Session *s)
 {
        u_int len;
        char *command = packet_get_string(&len);
-       packet_done();
+       packet_check_eom();
        do_exec(s, command);
        xfree(command);
        return 1;
@@ -1724,7 +1716,7 @@ static int
 session_auth_agent_req(Session *s)
 {
        static int called = 0;
-       packet_done();
+       packet_check_eom();
        if (no_agent_forwarding_flag) {
                debug("session_auth_agent_req: no_agent_forwarding_flag");
                return 0;
@@ -1737,28 +1729,18 @@ session_auth_agent_req(Session *s)
        }
 }
 
-void
-session_input_channel_req(int id, void *arg)
+int
+session_input_channel_req(Channel *c, const char *rtype)
 {
-       u_int len;
-       int reply;
        int success = 0;
-       char *rtype;
        Session *s;
-       Channel *c;
 
-       rtype = packet_get_string(&len);
-       reply = packet_get_char();
-
-       s = session_by_channel(id);
-       if (s == NULL)
-               fatal("session_input_channel_req: channel %d: no session", id);
-       c = channel_lookup(id);
-       if (c == NULL)
-               fatal("session_input_channel_req: channel %d: bad channel", id);
-
-       debug("session_input_channel_req: session %d channel %d request %s reply %d",
-           s->self, id, rtype, reply);
+       if ((s = session_by_channel(c->self)) == NULL) {
+               log("session_input_channel_req: no session %d req %.100s",
+                   c->self, rtype);
+               return 0;
+       }
+       debug("session_input_channel_req: session %d req %s", s->self, rtype);
 
        /*
         * a session is in LARVAL state until a shell, a command
@@ -1782,14 +1764,7 @@ session_input_channel_req(int id, void *arg)
        if (strcmp(rtype, "window-change") == 0) {
                success = session_window_change_req(s);
        }
-
-       if (reply) {
-               packet_start(success ?
-                   SSH2_MSG_CHANNEL_SUCCESS : SSH2_MSG_CHANNEL_FAILURE);
-               packet_put_int(c->remote_id);
-               packet_send();
-       }
-       xfree(rtype);
+       return success;
 }
 
 void
@@ -1850,23 +1825,19 @@ static void
 session_exit_message(Session *s, int status)
 {
        Channel *c;
-       if (s == NULL)
-               fatal("session_close: no session");
-       c = channel_lookup(s->chanid);
-       if (c == NULL)
+
+       if ((c = channel_lookup(s->chanid)) == NULL)
                fatal("session_exit_message: session %d: no channel %d",
                    s->self, s->chanid);
        debug("session_exit_message: session %d channel %d pid %d",
            s->self, s->chanid, s->pid);
 
        if (WIFEXITED(status)) {
-               channel_request_start(s->chanid,
-                   "exit-status", 0);
+               channel_request_start(s->chanid, "exit-status", 0);
                packet_put_int(WEXITSTATUS(status));
                packet_send();
        } else if (WIFSIGNALED(status)) {
-               channel_request_start(s->chanid,
-                   "exit-signal", 0);
+               channel_request_start(s->chanid, "exit-signal", 0);
                packet_put_int(WTERMSIG(status));
 #ifdef WCOREDUMP
                packet_put_char(WCOREDUMP(status));
@@ -1907,10 +1878,8 @@ session_close(Session *s)
                xfree(s->term);
        if (s->display)
                xfree(s->display);
-       if (s->auth_display[0])
-               xfree(s->auth_display[0]);
-       if (s->auth_display[1])
-               xfree(s->auth_display[1]);
+       if (s->auth_display)
+               xfree(s->auth_display);
        if (s->auth_data)
                xfree(s->auth_data);
        if (s->auth_proto)
@@ -2032,7 +2001,7 @@ session_setup_x11fwd(Session *s)
                return 0;
        }
        s->display_number = x11_create_display_inet(options.x11_display_offset,
-           options.gateway_ports, s->single_connection);
+           options.x11_use_localhost, s->single_connection);
        if (s->display_number == -1) {
                debug("x11_create_display_inet failed.");
                return 0;
@@ -2046,31 +2015,13 @@ session_setup_x11fwd(Session *s)
         * authorization entry is added with xauth(1).  This will be
         * different than the DISPLAY string for localhost displays.
         */
-       s->auth_display[1] = NULL;
-       if (!options.gateway_ports) {
-               struct utsname uts;
-
+       if (options.x11_use_localhost) {
                snprintf(display, sizeof display, "localhost:%d.%d",
                    s->display_number, s->screen);
-               snprintf(auth_display, sizeof auth_display, "%.400s/unix:%d.%d",
-                   hostname, s->display_number, s->screen);
+               snprintf(auth_display, sizeof auth_display, "unix:%d.%d",
+                   s->display_number, s->screen);
                s->display = xstrdup(display);
-               s->auth_display[0] = xstrdup(auth_display);
-               /*
-                * Xlib may use gethostbyname() or uname() hostname to
-                * look up authorization data for FamilyLocal; see:
-                * xc/lib/xtrans/Xtrans.c:TRANS(GetHostname)
-                * We just add authorization entries with both
-                * hostname and nodename if they are different.
-                */
-               if (uname(&uts) == -1)
-                       fatal("uname: %.100s", strerror(errno));
-               if (strcmp(hostname, uts.nodename) != 0) {
-                       snprintf(auth_display, sizeof auth_display,
-                           "%.400s/unix:%d.%d", uts.nodename,
-                           s->display_number, s->screen);
-                       s->auth_display[1] = xstrdup(auth_display);
-               }
+               s->auth_display = xstrdup(auth_display);
        } else {
 #ifdef IPADDR_IN_DISPLAY
                struct hostent *he;
@@ -2090,7 +2041,7 @@ session_setup_x11fwd(Session *s)
                    s->display_number, s->screen);
 #endif
                s->display = xstrdup(display);
-               s->auth_display[0] = xstrdup(display);
+               s->auth_display = xstrdup(display);
        }
 
        return 1;
This page took 0.054478 seconds and 4 git commands to generate.