[BACK]Return to session.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Diff for /src/usr.bin/ssh/session.c between version 1.172 and 1.172.2.1

version 1.172, 2004/01/30 09:48:57 version 1.172.2.1, 2004/08/19 04:13:27
Line 42 
Line 42 
 #include "sshpty.h"  #include "sshpty.h"
 #include "packet.h"  #include "packet.h"
 #include "buffer.h"  #include "buffer.h"
 #include "mpaux.h"  #include "match.h"
 #include "uidswap.h"  #include "uidswap.h"
 #include "compat.h"  #include "compat.h"
 #include "channels.h"  #include "channels.h"
Line 94 
Line 94 
 extern u_int utmp_len;  extern u_int utmp_len;
 extern int startup_pipe;  extern int startup_pipe;
 extern void destroy_sensitive_data(void);  extern void destroy_sensitive_data(void);
   extern Buffer loginmsg;
   
 /* original command from peer. */  /* original command from peer. */
 const char *original_command = NULL;  const char *original_command = NULL;
Line 189 
Line 190 
         return 1;          return 1;
 }  }
   
   static void
   display_loginmsg(void)
   {
           if (buffer_len(&loginmsg) > 0) {
                   buffer_append(&loginmsg, "\0", 1);
                   printf("%s", (char *)buffer_ptr(&loginmsg));
                   buffer_clear(&loginmsg);
           }
   }
   
 void  void
 do_authenticated(Authctxt *authctxt)  do_authenticated(Authctxt *authctxt)
Line 251 
Line 261 
                         compression_level = packet_get_int();                          compression_level = packet_get_int();
                         packet_check_eom();                          packet_check_eom();
                         if (compression_level < 1 || compression_level > 9) {                          if (compression_level < 1 || compression_level > 9) {
                                 packet_send_debug("Received illegal compression level %d.",                                  packet_send_debug("Received invalid compression level %d.",
                                     compression_level);                                      compression_level);
                                 break;                                  break;
                         }                          }
Line 451 
Line 461 
         close(perr[1]);          close(perr[1]);
   
         if (compat20) {          if (compat20) {
                 session_set_fds(s, pin[1], pout[0], s->is_subsystem ? -1 : perr[0]);                  if (s->is_subsystem) {
                           close(perr[0]);
                           perr[0] = -1;
                   }
                   session_set_fds(s, pin[1], pout[0], perr[0]);
         } else {          } else {
                 /* Enter the interactive session. */                  /* Enter the interactive session. */
                 server_loop(pid, pin[1], pout[0], perr[0]);                  server_loop(pid, pin[1], pout[0], perr[0]);
Line 582 
Line 596 
                 do_exec_no_pty(s, command);                  do_exec_no_pty(s, command);
   
         original_command = NULL;          original_command = NULL;
   
           /*
            * Clear loginmsg: it's the child's responsibility to display
            * it to the user, otherwise multiple sessions may accumulate
            * multiple copies of the login messages.
            */
           buffer_clear(&loginmsg);
 }  }
   
   
Line 589 
Line 610 
 void  void
 do_login(Session *s, const char *command)  do_login(Session *s, const char *command)
 {  {
         char *time_string;  
         socklen_t fromlen;          socklen_t fromlen;
         struct sockaddr_storage from;          struct sockaddr_storage from;
         struct passwd * pw = s->pw;          struct passwd * pw = s->pw;
Line 619 
Line 639 
         if (check_quietlogin(s, command))          if (check_quietlogin(s, command))
                 return;                  return;
   
         if (options.print_lastlog && s->last_login_time != 0) {          display_loginmsg();
                 time_string = ctime(&s->last_login_time);  
                 if (strchr(time_string, '\n'))  
                         *strchr(time_string, '\n') = 0;  
                 if (strcmp(s->hostname, "") == 0)  
                         printf("Last login: %s\r\n", time_string);  
                 else  
                         printf("Last login: %s from %s\r\n", time_string,  
                             s->hostname);  
         }  
   
         do_motd();          do_motd();
 }  }
Line 793 
Line 804 
   
         if (!options.use_login) {          if (!options.use_login) {
                 /* Set basic environment. */                  /* Set basic environment. */
                   for (i = 0; i < s->num_env; i++)
                           child_set_env(&env, &envsize, s->env[i].name,
                               s->env[i].val);
   
                 child_set_env(&env, &envsize, "USER", pw->pw_name);                  child_set_env(&env, &envsize, "USER", pw->pw_name);
                 child_set_env(&env, &envsize, "LOGNAME", pw->pw_name);                  child_set_env(&env, &envsize, "LOGNAME", pw->pw_name);
                 child_set_env(&env, &envsize, "HOME", pw->pw_dir);                  child_set_env(&env, &envsize, "HOME", pw->pw_dir);
Line 1009 
Line 1024 
 static void  static void
 do_pwchange(Session *s)  do_pwchange(Session *s)
 {  {
           fflush(NULL);
         fprintf(stderr, "WARNING: Your password has expired.\n");          fprintf(stderr, "WARNING: Your password has expired.\n");
         if (s->ttyfd != -1) {          if (s->ttyfd != -1) {
                 fprintf(stderr,                  fprintf(stderr,
                     "You must change your password now and login again!\n");                      "You must change your password now and login again!\n");
                 execl(_PATH_PASSWD_PROG, "passwd", (char *)NULL);                  execl(_PATH_PASSWD_PROG, "passwd", (char *)NULL);
                 perror("passwd");                  perror("passwd");
Line 1370 
Line 1386 
                 packet_disconnect("Protocol error: you already have a pty.");                  packet_disconnect("Protocol error: you already have a pty.");
                 return 0;                  return 0;
         }          }
         /* Get the time and hostname when the user last logged in. */  
         if (options.print_lastlog) {  
                 s->hostname[0] = '\0';  
                 s->last_login_time = get_last_login_time(s->pw->pw_uid,  
                     s->pw->pw_name, s->hostname, sizeof(s->hostname));  
         }  
   
         s->term = packet_get_string(&len);          s->term = packet_get_string(&len);
   
Line 1502 
Line 1512 
 static int  static int
 session_break_req(Session *s)  session_break_req(Session *s)
 {  {
         u_int break_length;  
   
         break_length = packet_get_int();        /* ignored */          packet_get_int();       /* ignored */
         packet_check_eom();          packet_check_eom();
   
         if (s->ttyfd == -1 ||          if (s->ttyfd == -1 ||
Line 1514 
Line 1523 
 }  }
   
 static int  static int
   session_env_req(Session *s)
   {
           char *name, *val;
           u_int name_len, val_len, i;
   
           name = packet_get_string(&name_len);
           val = packet_get_string(&val_len);
           packet_check_eom();
   
           /* Don't set too many environment variables */
           if (s->num_env > 128) {
                   debug2("Ignoring env request %s: too many env vars", name);
                   goto fail;
           }
   
           for (i = 0; i < options.num_accept_env; i++) {
                   if (match_pattern(name, options.accept_env[i])) {
                           debug2("Setting env %d: %s=%s", s->num_env, name, val);
                           s->env = xrealloc(s->env, sizeof(*s->env) *
                               (s->num_env + 1));
                           s->env[s->num_env].name = name;
                           s->env[s->num_env].val = val;
                           s->num_env++;
                           return (1);
                   }
           }
           debug2("Ignoring env request %s: disallowed name", name);
   
    fail:
           xfree(name);
           xfree(val);
           return (0);
   }
   
   static int
 session_auth_agent_req(Session *s)  session_auth_agent_req(Session *s)
 {  {
         static int called = 0;          static int called = 0;
Line 1560 
Line 1604 
                         success = session_auth_agent_req(s);                          success = session_auth_agent_req(s);
                 } else if (strcmp(rtype, "subsystem") == 0) {                  } else if (strcmp(rtype, "subsystem") == 0) {
                         success = session_subsystem_req(s);                          success = session_subsystem_req(s);
                 } else if (strcmp(rtype, "break") == 0) {                  } else if (strcmp(rtype, "env") == 0) {
                         success = session_break_req(s);                          success = session_env_req(s);
                 }                  }
         }          }
         if (strcmp(rtype, "window-change") == 0) {          if (strcmp(rtype, "window-change") == 0) {
                 success = session_window_change_req(s);                  success = session_window_change_req(s);
           } else if (strcmp(rtype, "break") == 0) {
                   success = session_break_req(s);
         }          }
   
         return success;          return success;
 }  }
   
Line 1695 
Line 1742 
 void  void
 session_close(Session *s)  session_close(Session *s)
 {  {
           int i;
   
         debug("session_close: session %d pid %ld", s->self, (long)s->pid);          debug("session_close: session %d pid %ld", s->self, (long)s->pid);
         if (s->ttyfd != -1)          if (s->ttyfd != -1)
                 session_pty_cleanup(s);                  session_pty_cleanup(s);
Line 1709 
Line 1758 
         if (s->auth_proto)          if (s->auth_proto)
                 xfree(s->auth_proto);                  xfree(s->auth_proto);
         s->used = 0;          s->used = 0;
           for (i = 0; i < s->num_env; i++) {
                   xfree(s->env[i].name);
                   xfree(s->env[i].val);
           }
           if (s->env != NULL)
                   xfree(s->env);
         session_proctitle(s);          session_proctitle(s);
 }  }
   

Legend:
Removed from v.1.172  
changed lines
  Added in v.1.172.2.1