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

Diff for /src/usr.bin/ssh/sshconnect.c between version 1.147.2.2 and 1.148

version 1.147.2.2, 2004/08/19 22:37:32 version 1.148, 2003/09/18 07:52:54
Line 31 
Line 31 
 #include "readconf.h"  #include "readconf.h"
 #include "atomicio.h"  #include "atomicio.h"
 #include "misc.h"  #include "misc.h"
   #include "readpass.h"
   
   #ifdef DNS
 #include "dns.h"  #include "dns.h"
   #endif
   
 char *client_version_string = NULL;  char *client_version_string = NULL;
 char *server_version_string = NULL;  char *server_version_string = NULL;
   
 int matching_host_key_dns = 0;  #ifdef DNS
   int verified_host_key_dns = 0;
   #endif
   
 /* import */  /* import */
 extern Options options;  extern Options options;
Line 47 
Line 52 
 extern pid_t proxy_command_pid;  extern pid_t proxy_command_pid;
   
 static int show_other_keys(const char *, Key *);  static int show_other_keys(const char *, Key *);
 static void warn_changed_key(Key *);  
   
 /*  /*
  * Connect to the given ssh server using a proxy command.   * Connect to the given ssh server using a proxy command.
Line 69 
Line 73 
          * Build the final command string in the buffer by making the           * Build the final command string in the buffer by making the
          * appropriate substitutions to the given proxy command.           * appropriate substitutions to the given proxy command.
          *           *
          * Use "exec" to avoid "sh -c" processes on some platforms           * Use "exec" to avoid "sh -c" processes on some platforms
          * (e.g. Solaris)           * (e.g. Solaris)
          */           */
         buffer_init(&command);          buffer_init(&command);
Line 226 
Line 230 
         if (timeout <= 0)          if (timeout <= 0)
                 return (connect(sockfd, serv_addr, addrlen));                  return (connect(sockfd, serv_addr, addrlen));
   
         set_nonblock(sockfd);          if (fcntl(sockfd, F_SETFL, O_NONBLOCK) < 0)
                   return (-1);
   
         rc = connect(sockfd, serv_addr, addrlen);          rc = connect(sockfd, serv_addr, addrlen);
         if (rc == 0) {          if (rc == 0)
                 unset_nonblock(sockfd);  
                 return (0);                  return (0);
         }  
         if (errno != EINPROGRESS)          if (errno != EINPROGRESS)
                 return (-1);                  return (-1);
   
Line 256 
Line 260 
                 break;                  break;
         case -1:          case -1:
                 /* Select error */                  /* Select error */
                 debug("select: %s", strerror(errno));                  debug("select: %s", strerror(errno));
                 break;                  break;
         case 1:          case 1:
                 /* Completed or failed */                  /* Completed or failed */
                 optval = 0;                  optval = 0;
                 optlen = sizeof(optval);                  optlen = sizeof(optval);
                 if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &optval,                  if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &optval,
                     &optlen) == -1) {                      &optlen) == -1) {
                         debug("getsockopt: %s", strerror(errno));                          debug("getsockopt: %s", strerror(errno));
                         break;                          break;
                 }                  }
                 if (optval != 0) {                  if (optval != 0) {
Line 272 
Line 276 
                         break;                          break;
                 }                  }
                 result = 0;                  result = 0;
                 unset_nonblock(sockfd);  
                 break;                  break;
         default:          default:
                 /* Should not occur */                  /* Should not occur */
Line 411 
Line 414 
   
         debug("Connection established.");          debug("Connection established.");
   
         /* Set SO_KEEPALIVE if requested. */          /* Set keepalives if requested. */
         if (options.tcp_keep_alive &&          if (options.keepalives &&
             setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on,              setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on,
             sizeof(on)) < 0)              sizeof(on)) < 0)
                 error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno));                  error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno));
Line 559 
Line 562 
     int readonly, const char *user_hostfile, const char *system_hostfile)      int readonly, const char *user_hostfile, const char *system_hostfile)
 {  {
         Key *file_key;          Key *file_key;
         const char *type = key_type(host_key);          char *type = key_type(host_key);
         char *ip = NULL;          char *ip = NULL;
         char hostline[1000], *hostp, *fp;          char hostline[1000], *hostp, *fp;
         HostStatus host_status;          HostStatus host_status;
Line 719 
Line 722 
                         /* The default */                          /* The default */
                         fp = key_fingerprint(host_key, SSH_FP_MD5, SSH_FP_HEX);                          fp = key_fingerprint(host_key, SSH_FP_MD5, SSH_FP_HEX);
                         msg2[0] = '\0';                          msg2[0] = '\0';
   #ifdef DNS
                         if (options.verify_host_key_dns) {                          if (options.verify_host_key_dns) {
                                 if (matching_host_key_dns)                                  if (verified_host_key_dns)
                                         snprintf(msg2, sizeof(msg2),                                          snprintf(msg2, sizeof(msg2),
                                             "Matching host key fingerprint"                                              "Matching host key fingerprint"
                                             " found in DNS.\n");                                              " found in DNS.\n");
Line 729 
Line 733 
                                             "No matching host key fingerprint"                                              "No matching host key fingerprint"
                                             " found in DNS.\n");                                              " found in DNS.\n");
                         }                          }
   #endif
                         snprintf(msg, sizeof(msg),                          snprintf(msg, sizeof(msg),
                             "The authenticity of host '%.200s (%s)' can't be "                              "The authenticity of host '%.200s (%s)' can't be "
                             "established%s\n"                              "established%s\n"
Line 759 
Line 764 
                 break;                  break;
         case HOST_CHANGED:          case HOST_CHANGED:
                 if (options.check_host_ip && host_ip_differ) {                  if (options.check_host_ip && host_ip_differ) {
                         char *key_msg;                          char *msg;
                         if (ip_status == HOST_NEW)                          if (ip_status == HOST_NEW)
                                 key_msg = "is unknown";                                  msg = "is unknown";
                         else if (ip_status == HOST_OK)                          else if (ip_status == HOST_OK)
                                 key_msg = "is unchanged";                                  msg = "is unchanged";
                         else                          else
                                 key_msg = "has a different value";                                  msg = "has a different value";
                         error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");                          error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
                         error("@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @");                          error("@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @");
                         error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");                          error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
                         error("The %s host key for %s has changed,", type, host);                          error("The %s host key for %s has changed,", type, host);
                         error("and the key for the according IP address %s", ip);                          error("and the key for the according IP address %s", ip);
                         error("%s. This could either mean that", key_msg);                          error("%s. This could either mean that", msg);
                         error("DNS SPOOFING is happening or the IP address for the host");                          error("DNS SPOOFING is happening or the IP address for the host");
                         error("and its host key have changed at the same time.");                          error("and its host key have changed at the same time.");
                         if (ip_status != HOST_NEW)                          if (ip_status != HOST_NEW)
                                 error("Offending key for IP in %s:%d", ip_file, ip_line);                                  error("Offending key for IP in %s:%d", ip_file, ip_line);
                 }                  }
                 /* The host key has changed. */                  /* The host key has changed. */
                 warn_changed_key(host_key);                  fp = key_fingerprint(host_key, SSH_FP_MD5, SSH_FP_HEX);
                   error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
                   error("@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @");
                   error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
                   error("IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!");
                   error("Someone could be eavesdropping on you right now (man-in-the-middle attack)!");
                   error("It is also possible that the %s host key has just been changed.", type);
                   error("The fingerprint for the %s key sent by the remote host is\n%s.",
                       type, fp);
                   error("Please contact your system administrator.");
                 error("Add correct host key in %.100s to get rid of this message.",                  error("Add correct host key in %.100s to get rid of this message.",
                     user_hostfile);                      user_hostfile);
                 error("Offending key in %s:%d", host_file, host_line);                  error("Offending key in %s:%d", host_file, host_line);
                   xfree(fp);
   
                 /*                  /*
                  * If strict host key checking is in use, the user will have                   * If strict host key checking is in use, the user will have
Line 884 
Line 899 
 verify_host_key(char *host, struct sockaddr *hostaddr, Key *host_key)  verify_host_key(char *host, struct sockaddr *hostaddr, Key *host_key)
 {  {
         struct stat st;          struct stat st;
         int flags = 0;  
   
         if (options.verify_host_key_dns &&  #ifdef DNS
             verify_host_key_dns(host, hostaddr, host_key, &flags) == 0) {          if (options.verify_host_key_dns) {
                   switch(verify_host_key_dns(host, hostaddr, host_key)) {
                 if (flags & DNS_VERIFY_FOUND) {                  case DNS_VERIFY_OK:
   #ifdef DNSSEC
                         if (options.verify_host_key_dns == 1 &&                          return 0;
                             flags & DNS_VERIFY_MATCH &&  #else
                             flags & DNS_VERIFY_SECURE)                          verified_host_key_dns = 1;
                                 return 0;                          break;
   #endif
                         if (flags & DNS_VERIFY_MATCH) {                  case DNS_VERIFY_FAILED:
                                 matching_host_key_dns = 1;                          return -1;
                         } else {                  case DNS_VERIFY_ERROR:
                                 warn_changed_key(host_key);                          break;
                                 error("Update the SSHFP RR in DNS with the new "                  default:
                                     "host key to get rid of this message.");                          debug3("bad return value from verify_host_key_dns");
                         }                          break;
                 }                  }
         }          }
   #endif /* DNS */
   
         /* return ok if the key can be found in an old keyfile */          /* return ok if the key can be found in an old keyfile */
         if (stat(options.system_hostfile2, &st) == 0 ||          if (stat(options.system_hostfile2, &st) == 0 ||
Line 1029 
Line 1044 
                 debug2("no key of type %d for host %s", type[i], host);                  debug2("no key of type %d for host %s", type[i], host);
         }          }
         return (found);          return (found);
 }  
   
 static void  
 warn_changed_key(Key *host_key)  
 {  
         char *fp;  
         const char *type = key_type(host_key);  
   
         fp = key_fingerprint(host_key, SSH_FP_MD5, SSH_FP_HEX);  
   
         error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");  
         error("@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @");  
         error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");  
         error("IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!");  
         error("Someone could be eavesdropping on you right now (man-in-the-middle attack)!");  
         error("It is also possible that the %s host key has just been changed.", type);  
         error("The fingerprint for the %s key sent by the remote host is\n%s.",  
             type, fp);  
         error("Please contact your system administrator.");  
   
         xfree(fp);  
 }  }

Legend:
Removed from v.1.147.2.2  
changed lines
  Added in v.1.148