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

Diff for /src/usr.bin/ssh/clientloop.c between version 1.278 and 1.279

version 1.278, 2015/12/26 07:46:03 version 1.279, 2016/01/13 23:04:47
Line 280 
Line 280 
 {  {
         size_t i, dlen;          size_t i, dlen;
   
           if (display == NULL)
                   return 0;
   
         dlen = strlen(display);          dlen = strlen(display);
         for (i = 0; i < dlen; i++) {          for (i = 0; i < dlen; i++) {
                 if (!isalnum((u_char)display[i]) &&                  if (!isalnum((u_char)display[i]) &&
Line 293 
Line 296 
   
 #define SSH_X11_PROTO           "MIT-MAGIC-COOKIE-1"  #define SSH_X11_PROTO           "MIT-MAGIC-COOKIE-1"
 #define X11_TIMEOUT_SLACK       60  #define X11_TIMEOUT_SLACK       60
 void  int
 client_x11_get_proto(const char *display, const char *xauth_path,  client_x11_get_proto(const char *display, const char *xauth_path,
     u_int trusted, u_int timeout, char **_proto, char **_data)      u_int trusted, u_int timeout, char **_proto, char **_data)
 {  {
         char cmd[1024];          char cmd[1024], line[512], xdisplay[512];
         char line[512];          char xauthfile[PATH_MAX], xauthdir[PATH_MAX];
         char xdisplay[512];  
         static char proto[512], data[512];          static char proto[512], data[512];
         FILE *f;          FILE *f;
         int got_data = 0, generated = 0, do_unlink = 0, i;          int got_data = 0, generated = 0, do_unlink = 0, i, r;
         char xauthdir[PATH_MAX] = "", xauthfile[PATH_MAX] = "";  
         struct stat st;          struct stat st;
         u_int now, x11_timeout_real;          u_int now, x11_timeout_real;
   
         *_proto = proto;          *_proto = proto;
         *_data = data;          *_data = data;
         proto[0] = data[0] = '\0';          proto[0] = data[0] = xauthfile[0] = xauthdir[0] = '\0';
   
         if (xauth_path == NULL ||(stat(xauth_path, &st) == -1)) {          if (!client_x11_display_valid(display)) {
                 debug("No xauth program.");                  logit("DISPLAY \"%s\" invalid; disabling X11 forwarding",
         } else if (!client_x11_display_valid(display)) {  
                 logit("DISPLAY '%s' invalid, falling back to fake xauth data",  
                     display);                      display);
         } else {                  return -1;
                 if (display == NULL) {          }
                         debug("x11_get_proto: DISPLAY not set");          if (xauth_path != NULL && stat(xauth_path, &st) == -1) {
                         return;                  debug("No xauth program.");
                 }                  xauth_path = NULL;
           }
   
           if (xauth_path != NULL) {
                 /*                  /*
                  * Handle FamilyLocal case where $DISPLAY does                   * Handle FamilyLocal case where $DISPLAY does
                  * not match an authorization entry.  For this we                   * not match an authorization entry.  For this we
Line 329 
Line 331 
                  *      is not perfect.                   *      is not perfect.
                  */                   */
                 if (strncmp(display, "localhost:", 10) == 0) {                  if (strncmp(display, "localhost:", 10) == 0) {
                         snprintf(xdisplay, sizeof(xdisplay), "unix:%s",                          if ((r = snprintf(xdisplay, sizeof(xdisplay), "unix:%s",
                             display + 10);                              display + 10)) < 0 ||
                               (size_t)r >= sizeof(xdisplay)) {
                                   error("%s: display name too long", __func__);
                                   return -1;
                           }
                         display = xdisplay;                          display = xdisplay;
                 }                  }
                 if (trusted == 0) {                  if (trusted == 0) {
                         mktemp_proto(xauthdir, PATH_MAX);  
                         /*                          /*
                            * Generate an untrusted X11 auth cookie.
                            *
                          * The authentication cookie should briefly outlive                           * The authentication cookie should briefly outlive
                          * ssh's willingness to forward X11 connections to                           * ssh's willingness to forward X11 connections to
                          * avoid nasty fail-open behaviour in the X server.                           * avoid nasty fail-open behaviour in the X server.
                          */                           */
                           mktemp_proto(xauthdir, sizeof(xauthdir));
                           if (mkdtemp(xauthdir) == NULL) {
                                   error("%s: mkdtemp: %s",
                                       __func__, strerror(errno));
                                   return -1;
                           }
                           do_unlink = 1;
                           if ((r = snprintf(xauthfile, sizeof(xauthfile),
                               "%s/xauthfile", xauthdir)) < 0 ||
                               (size_t)r >= sizeof(xauthfile)) {
                                   error("%s: xauthfile path too long", __func__);
                                   unlink(xauthfile);
                                   rmdir(xauthdir);
                                   return -1;
                           }
   
                         if (timeout >= UINT_MAX - X11_TIMEOUT_SLACK)                          if (timeout >= UINT_MAX - X11_TIMEOUT_SLACK)
                                 x11_timeout_real = UINT_MAX;                                  x11_timeout_real = UINT_MAX;
                         else                          else
                                 x11_timeout_real = timeout + X11_TIMEOUT_SLACK;                                  x11_timeout_real = timeout + X11_TIMEOUT_SLACK;
                         if (mkdtemp(xauthdir) != NULL) {                          if ((r = snprintf(cmd, sizeof(cmd),
                                 do_unlink = 1;                              "%s -f %s generate %s " SSH_X11_PROTO
                                 snprintf(xauthfile, PATH_MAX, "%s/xauthfile",                              " untrusted timeout %u 2>" _PATH_DEVNULL,
                                     xauthdir);                              xauth_path, xauthfile, display,
                                 snprintf(cmd, sizeof(cmd),                              x11_timeout_real)) < 0 ||
                                     "%s -f %s generate %s " SSH_X11_PROTO                              (size_t)r >= sizeof(cmd))
                                     " untrusted timeout %u 2>" _PATH_DEVNULL,                                  fatal("%s: cmd too long", __func__);
                                     xauth_path, xauthfile, display,                          debug2("%s: %s", __func__, cmd);
                                     x11_timeout_real);                          if (x11_refuse_time == 0) {
                                 debug2("x11_get_proto: %s", cmd);                                  now = monotime() + 1;
                                 if (x11_refuse_time == 0) {                                  if (UINT_MAX - timeout < now)
                                         now = monotime() + 1;                                          x11_refuse_time = UINT_MAX;
                                         if (UINT_MAX - timeout < now)                                  else
                                                 x11_refuse_time = UINT_MAX;                                          x11_refuse_time = now + timeout;
                                         else                                  channel_set_x11_refuse_time(x11_refuse_time);
                                                 x11_refuse_time = now + timeout;  
                                         channel_set_x11_refuse_time(  
                                             x11_refuse_time);  
                                 }  
                                 if (system(cmd) == 0)  
                                         generated = 1;  
                         }                          }
                           if (system(cmd) == 0)
                                   generated = 1;
                 }                  }
   
                 /*                  /*
Line 387 
Line 406 
                                 got_data = 1;                                  got_data = 1;
                         if (f)                          if (f)
                                 pclose(f);                                  pclose(f);
                 } else                  }
                         error("Warning: untrusted X11 forwarding setup failed: "  
                             "xauth key data not generated");  
         }          }
   
         if (do_unlink) {          if (do_unlink) {
Line 397 
Line 414 
                 rmdir(xauthdir);                  rmdir(xauthdir);
         }          }
   
           /* Don't fall back to fake X11 data for untrusted forwarding */
           if (!trusted && !got_data) {
                   error("Warning: untrusted X11 forwarding setup failed: "
                       "xauth key data not generated");
                   return -1;
           }
   
         /*          /*
          * If we didn't get authentication data, just make up some           * If we didn't get authentication data, just make up some
          * data.  The forwarding code will check the validity of the           * data.  The forwarding code will check the validity of the
Line 419 
Line 443 
                         rnd >>= 8;                          rnd >>= 8;
                 }                  }
         }          }
   
           return 0;
 }  }
   
 /*  /*

Legend:
Removed from v.1.278  
changed lines
  Added in v.1.279