[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.80 and 1.81

version 1.80, 2001/06/04 21:59:43 version 1.81, 2001/06/04 23:16:16
Line 88 
Line 88 
 void    session_set_fds(Session *s, int fdin, int fdout, int fderr);  void    session_set_fds(Session *s, int fdin, int fdout, int fderr);
 void    session_pty_cleanup(Session *s);  void    session_pty_cleanup(Session *s);
 void    session_proctitle(Session *s);  void    session_proctitle(Session *s);
   int     session_setup_x11fwd(Session *s);
 void    do_exec_pty(Session *s, const char *command);  void    do_exec_pty(Session *s, const char *command);
 void    do_exec_no_pty(Session *s, const char *command);  void    do_exec_no_pty(Session *s, const char *command);
 void    do_login(Session *s, const char *command);  void    do_login(Session *s, const char *command);
Line 218 
Line 219 
 {  {
         Session *s;          Session *s;
         char *command;          char *command;
         int success, type, fd, n_bytes, plen, screen_flag, have_pty = 0;          int success, type, n_bytes, plen, screen_flag, have_pty = 0;
         int compression_level = 0, enable_compression_after_reply = 0;          int compression_level = 0, enable_compression_after_reply = 0;
         u_int proto_len, data_len, dlen;          u_int proto_len, data_len, dlen;
         struct stat st;  
   
         s = session_new();          s = session_new();
         s->pw = authctxt->pw;          s->pw = authctxt->pw;
Line 300 
Line 300 
                         break;                          break;
   
                 case SSH_CMSG_X11_REQUEST_FORWARDING:                  case SSH_CMSG_X11_REQUEST_FORWARDING:
                         if (!options.x11_forwarding) {  
                                 packet_send_debug("X11 forwarding disabled in server configuration file.");  
                                 break;  
                         }  
                         if (!options.xauth_location ||  
                             (stat(options.xauth_location, &st) == -1)) {  
                                 packet_send_debug("No xauth program; cannot forward with spoofing.");  
                                 break;  
                         }  
                         if (no_x11_forwarding_flag) {  
                                 packet_send_debug("X11 forwarding not permitted for this authentication.");  
                                 break;  
                         }  
                         debug("Received request for X11 forwarding with auth spoofing.");  
                         if (s->display != NULL)  
                                 packet_disconnect("Protocol error: X11 display already set.");  
   
                         s->auth_proto = packet_get_string(&proto_len);                          s->auth_proto = packet_get_string(&proto_len);
                         s->auth_data = packet_get_string(&data_len);                          s->auth_data = packet_get_string(&data_len);
   
Line 328 
Line 311 
                                 if (!screen_flag)                                  if (!screen_flag)
                                         debug2("Buggy client: "                                          debug2("Buggy client: "
                                             "X11 screen flag missing");                                              "X11 screen flag missing");
                                 packet_integrity_check(plen,  
                                     4 + proto_len + 4 + data_len + 4, type);  
                                 s->screen = packet_get_int();                                  s->screen = packet_get_int();
                         } else {                          } else {
                                 packet_integrity_check(plen,  
                                     4 + proto_len + 4 + data_len, type);  
                                 s->screen = 0;                                  s->screen = 0;
                         }                          }
                         s->display = x11_create_display_inet(s->screen, options.x11_display_offset);                          packet_done();
                           success = session_setup_x11fwd(s);
                         if (s->display == NULL)                          if (!success) {
                                 break;                                  xfree(s->auth_proto);
                                   xfree(s->auth_data);
                         /* Setup to always have a local .Xauthority. */  
                         xauthfile = xmalloc(MAXPATHLEN);  
                         strlcpy(xauthfile, "/tmp/ssh-XXXXXXXX", MAXPATHLEN);  
                         temporarily_use_uid(s->pw);  
                         if (mkdtemp(xauthfile) == NULL) {  
                                 restore_uid();  
                                 error("private X11 dir: mkdtemp %s failed: %s",  
                                     xauthfile, strerror(errno));  
                                 xfree(xauthfile);  
                                 xauthfile = NULL;  
                                 /* XXXX remove listening channels */  
                                 break;  
                         }                          }
                         strlcat(xauthfile, "/cookies", MAXPATHLEN);  
                         fd = open(xauthfile, O_RDWR|O_CREAT|O_EXCL, 0600);  
                         if (fd >= 0)  
                                 close(fd);  
                         restore_uid();  
                         fatal_add_cleanup(xauthfile_cleanup_proc, s->pw);  
                         success = 1;  
                         break;                          break;
   
                 case SSH_CMSG_AGENT_REQUEST_FORWARDING:                  case SSH_CMSG_AGENT_REQUEST_FORWARDING:
Line 1381 
Line 1341 
 int  int
 session_x11_req(Session *s)  session_x11_req(Session *s)
 {  {
         int fd;          int success;
         struct stat st;  
         if (no_x11_forwarding_flag) {  
                 debug("X11 forwarding disabled in user configuration file.");  
                 return 0;  
         }  
         if (!options.x11_forwarding) {  
                 debug("X11 forwarding disabled in server configuration file.");  
                 return 0;  
         }  
         if (!options.xauth_location ||  
             (stat(options.xauth_location, &st) == -1)) {  
                 packet_send_debug("No xauth program; cannot forward with spoofing.");  
                 return 0;  
         }  
         if (xauthfile != NULL) {  
                 debug("X11 fwd already started.");  
                 return 0;  
         }  
   
         debug("Received request for X11 forwarding with auth spoofing.");  
         if (s->display != NULL)  
                 packet_disconnect("Protocol error: X11 display already set.");  
   
         s->single_connection = packet_get_char();          s->single_connection = packet_get_char();
         s->auth_proto = packet_get_string(NULL);          s->auth_proto = packet_get_string(NULL);
         s->auth_data = packet_get_string(NULL);          s->auth_data = packet_get_string(NULL);
         s->screen = packet_get_int();          s->screen = packet_get_int();
         packet_done();          packet_done();
   
         s->display = x11_create_display_inet(s->screen, options.x11_display_offset);          success = session_setup_x11fwd(s);
         if (s->display == NULL) {          if (!success) {
                 xfree(s->auth_proto);                  xfree(s->auth_proto);
                 xfree(s->auth_data);                  xfree(s->auth_data);
                 return 0;  
         }          }
         xauthfile = xmalloc(MAXPATHLEN);          return success;
         strlcpy(xauthfile, "/tmp/ssh-XXXXXXXX", MAXPATHLEN);  
         temporarily_use_uid(s->pw);  
         if (mkdtemp(xauthfile) == NULL) {  
                 restore_uid();  
                 error("private X11 dir: mkdtemp %s failed: %s",  
                     xauthfile, strerror(errno));  
                 xfree(xauthfile);  
                 xauthfile = NULL;  
                 xfree(s->auth_proto);  
                 xfree(s->auth_data);  
                 /* XXXX remove listening channels */  
                 return 0;  
         }  
         strlcat(xauthfile, "/cookies", MAXPATHLEN);  
         fd = open(xauthfile, O_RDWR|O_CREAT|O_EXCL, 0600);  
         if (fd >= 0)  
                 close(fd);  
         restore_uid();  
         fatal_add_cleanup(xauthfile_cleanup_proc, s->pw);  
         return 1;  
 }  }
   
 int  int
Line 1651 
Line 1568 
 void  void
 session_close(Session *s)  session_close(Session *s)
 {  {
           if (s->display) {
                   xauthfile_cleanup_proc(s->pw);
                   fatal_remove_cleanup(xauthfile_cleanup_proc, s->pw);
           }
         session_pty_cleanup(s);          session_pty_cleanup(s);
         session_free(s);          session_free(s);
         session_proctitle(s);          session_proctitle(s);
Line 1723 
Line 1644 
                 error("no user for session %d", s->self);                  error("no user for session %d", s->self);
         else          else
                 setproctitle("%s@%s", s->pw->pw_name, session_tty_list());                  setproctitle("%s@%s", s->pw->pw_name, session_tty_list());
   }
   
   int
   session_setup_x11fwd(Session *s)
   {
           int fd;
           struct stat st;
   
           if (no_x11_forwarding_flag) {
                   packet_send_debug("X11 forwarding disabled in user configuration file.");
                   return 0;
           }
           if (!options.x11_forwarding) {
                   debug("X11 forwarding disabled in server configuration file.");
                   return 0;
           }
           if (!options.xauth_location ||
               (stat(options.xauth_location, &st) == -1)) {
                   packet_send_debug("No xauth program; cannot forward with spoofing.");
                   return 0;
           }
           if (s->display != NULL) {
                   debug("X11 display already set.");
                   return 0;
           }
           xauthfile = xmalloc(MAXPATHLEN);
           strlcpy(xauthfile, "/tmp/ssh-XXXXXXXX", MAXPATHLEN);
           temporarily_use_uid(s->pw);
           if (mkdtemp(xauthfile) == NULL) {
                   restore_uid();
                   error("private X11 dir: mkdtemp %s failed: %s",
                       xauthfile, strerror(errno));
                   xfree(xauthfile);
                   xauthfile = NULL;
                   return 0;
           }
           strlcat(xauthfile, "/cookies", MAXPATHLEN);
           fd = open(xauthfile, O_RDWR|O_CREAT|O_EXCL, 0600);
           if (fd >= 0)
                   close(fd);
           restore_uid();
           s->display = x11_create_display_inet(s->screen, options.x11_display_offset);
           if (s->display == NULL) {
                   xauthfile_cleanup_proc(s->pw);
                   return 0;
           }
           fatal_add_cleanup(xauthfile_cleanup_proc, s->pw);
           return 1;
 }  }
   
 void  void

Legend:
Removed from v.1.80  
changed lines
  Added in v.1.81