]> andersk Git - openssh.git/blobdiff - session.c
Up ver
[openssh.git] / session.c
index 0679d837cfd576a90277642b5723b69ebf18676f..4b7404f7380c6d62c4d4c5eb74b590e106e4a282 100644 (file)
--- a/session.c
+++ b/session.c
@@ -8,7 +8,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: session.c,v 1.8 2000/04/29 16:06:08 markus Exp $");
+RCSID("$OpenBSD: session.c,v 1.12 2000/05/03 18:03:07 markus Exp $");
 
 #include "xmalloc.h"
 #include "ssh.h"
@@ -57,6 +57,7 @@ struct Session {
 Session *session_new(void);
 void   session_set_fds(Session *s, int fdin, int fdout, int fderr);
 void   session_pty_cleanup(Session *s);
+void   session_proctitle(Session *s);
 void   do_exec_pty(Session *s, const char *command, struct passwd * pw);
 void   do_exec_no_pty(Session *s, const char *command, struct passwd * pw);
 
@@ -82,6 +83,10 @@ static char *xauthfile;
 /* data */
 #define MAX_SESSIONS 10
 Session        sessions[MAX_SESSIONS];
+#ifdef WITH_AIXAUTHENTICATE
+/* AIX's lastlogin message, set in auth1.c */
+char *aixloginmsg;
+#endif /* WITH_AIXAUTHENTICATE */
 
 /* Flags set in auth-rsa from authorized_keys flags.  These are set in auth-rsa.c. */
 int no_port_forwarding_flag = 0;
@@ -240,6 +245,8 @@ do_authenticated(struct passwd * pw)
                        tty_parse_modes(s->ttyfd, &n_bytes);
                        packet_integrity_check(plen, 4 + dlen + 4 * 4 + n_bytes, type);
 
+                       session_proctitle(s);
+
                        /* Indicate that we now have a pty. */
                        success = 1;
                        have_pty = 1;
@@ -312,7 +319,7 @@ do_authenticated(struct passwd * pw)
                                break;
                        }
                        debug("Received TCP/IP port forwarding request.");
-                       channel_input_port_forward_request(pw->pw_uid == 0);
+                       channel_input_port_forward_request(pw->pw_uid == 0, options.gateway_ports);
                        success = 1;
                        break;
 
@@ -397,7 +404,7 @@ do_exec_no_pty(Session *s, const char *command, struct passwd * pw)
        if (s == NULL)
                fatal("do_exec_no_pty: no session");
 
-       setproctitle("%s@notty", pw->pw_name);
+       session_proctitle(s);
 
 #ifdef USE_PAM
                        do_pam_setcred();
@@ -527,7 +534,6 @@ do_exec_pty(Session *s, const char *command, struct passwd * pw)
                last_login_time = get_last_login_time(pw->pw_uid, pw->pw_name,
                                                      buf, sizeof(buf));
        }
-       setproctitle("%s@%s", pw->pw_name, strrchr(s->tty, '/') + 1);
 
 #ifdef USE_PAM
                        do_pam_session(pw->pw_name, s->tty);
@@ -563,7 +569,7 @@ do_exec_pty(Session *s, const char *command, struct passwd * pw)
                /* Close the extra descriptor for the pseudo tty. */
                close(ttyfd);
 
-///XXXX ? move to do_child() ??
+/* XXXX ? move to do_child() ??*/
                /*
                 * Get IP address of client.  This is needed because we want
                 * to record where the user logged in from.  If the
@@ -629,6 +635,15 @@ do_exec_pty(Session *s, const char *command, struct passwd * pw)
                                fclose(f);
                        }
                }
+#if defined(WITH_AIXAUTHENTICATE)
+               /*
+                * AIX handles the lastlog info differently.  Display it here.
+                */
+               if (command == NULL && aixloginmsg && *aixloginmsg &&
+                   !quiet_login && !options.use_login) {
+                       printf("%s\n", aixloginmsg);
+               }
+#endif
                /* Do common processing for the child, such as execing the command. */
                do_child(command, pw, s->term, s->display, s->auth_proto, s->auth_data, s->tty);
                /* NOTREACHED */
@@ -1020,13 +1035,20 @@ do_child(const char *command, struct passwd * pw, const char *term,
                else {
                        /* Add authority data to .Xauthority if appropriate. */
                        if (auth_proto != NULL && auth_data != NULL) {
-                               if (debug_flag)
+                               char *screen = strchr(display, ':');
+                               if (debug_flag) {
                                        fprintf(stderr, "Running %.100s add %.100s %.100s %.100s\n",
-                                               XAUTH_PATH, display, auth_proto, auth_data);
-
+                                           XAUTH_PATH, display, auth_proto, auth_data);
+                                       if (screen != NULL)
+                                               fprintf(stderr, "Adding %.*s/unix%s %s %s\n",
+                                                   screen-display, display, screen, auth_proto, auth_data);
+                               }
                                f = popen(XAUTH_PATH " -q -", "w");
                                if (f) {
                                        fprintf(f, "add %s %s %s\n", display, auth_proto, auth_data);
+                                       if (screen != NULL) 
+                                               fprintf(f, "add %.*s/unix%s %s %s\n",
+                                                    screen-display, display, screen, auth_proto, auth_data);
                                        pclose(f);
                                } else
                                        fprintf(stderr, "Could not run %s -q -\n", XAUTH_PATH);
@@ -1257,6 +1279,8 @@ session_pty_req(Session *s)
        /* Get window size from the packet. */
        pty_change_window_size(s->ptyfd, s->row, s->col, s->xpixel, s->ypixel);
 
+       session_proctitle(s);
+
        /* XXX parse and set terminal modes */
        xfree(term_modes);
        return 1;
@@ -1456,7 +1480,11 @@ session_exit_message(Session *s, int status)
                channel_request_start(s->chanid,
                    "exit-signal", 0);
                packet_put_int(WTERMSIG(status));
+#ifdef WCOREDUMP
                packet_put_char(WCOREDUMP(status));
+#else /* WCOREDUMP */
+               packet_put_char(0);
+#endif /* WCOREDUMP */
                packet_put_cstring("");
                packet_put_cstring("");
                packet_send();
@@ -1499,6 +1527,7 @@ session_close(Session *s)
 {
        session_pty_cleanup(s);
        session_free(s);
+       session_proctitle(s);
 }
 
 void
@@ -1542,6 +1571,34 @@ session_close_by_channel(int id, void *arg)
        }
 }
 
+char *
+session_tty_list(void)
+{
+       static char buf[1024];
+       int i;
+       buf[0] = '\0';
+       for(i = 0; i < MAX_SESSIONS; i++) {
+               Session *s = &sessions[i];
+               if (s->used && s->ttyfd != -1) {
+                       if (buf[0] != '\0')
+                               strlcat(buf, ",", sizeof buf);
+                       strlcat(buf, strrchr(s->tty, '/') + 1, sizeof buf);
+               }
+       }
+       if (buf[0] == '\0')
+               strlcpy(buf, "notty", sizeof buf);
+       return buf;
+}
+
+void
+session_proctitle(Session *s)
+{
+       if (s->pw == NULL)
+               error("no user for session %d", s->self);
+       else
+               setproctitle("%s@%s", s->pw->pw_name, session_tty_list());
+}
+
 void
 do_authenticated2(void)
 {
This page took 0.107056 seconds and 4 git commands to generate.