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

Diff for /src/usr.bin/ssh/ssh-keyscan.c between version 1.50 and 1.50.2.2

version 1.50, 2004/08/11 21:44:32 version 1.50.2.2, 2005/09/02 03:45:01
Line 29 
Line 29 
 #include "log.h"  #include "log.h"
 #include "atomicio.h"  #include "atomicio.h"
 #include "misc.h"  #include "misc.h"
   #include "hostfile.h"
   
 /* Flag indicating whether IPv4 or IPv6.  This can be set on the command line.  /* Flag indicating whether IPv4 or IPv6.  This can be set on the command line.
    Default value is AF_UNSPEC means both IPv4 and IPv6. */     Default value is AF_UNSPEC means both IPv4 and IPv6. */
Line 42 
Line 43 
   
 int get_keytypes = KT_RSA1;     /* Get only RSA1 keys by default */  int get_keytypes = KT_RSA1;     /* Get only RSA1 keys by default */
   
   int hash_hosts = 0;             /* Hash hostname on output */
   
 #define MAXMAXFD 256  #define MAXMAXFD 256
   
 /* The number of seconds after which to give up on a TCP connection */  /* The number of seconds after which to give up on a TCP connection */
Line 164 
Line 167 
 static char *  static char *
 Linebuf_getline(Linebuf * lb)  Linebuf_getline(Linebuf * lb)
 {  {
         int n = 0;          size_t n = 0;
         void *p;          void *p;
   
         lb->lineno++;          lb->lineno++;
Line 357 
Line 360 
 static void  static void
 keyprint(con *c, Key *key)  keyprint(con *c, Key *key)
 {  {
           char *host = c->c_output_name ? c->c_output_name : c->c_name;
   
         if (!key)          if (!key)
                 return;                  return;
           if (hash_hosts && (host = host_hash(host, NULL, 0)) == NULL)
                   fatal("host_hash failed");
   
         fprintf(stdout, "%s ", c->c_output_name ? c->c_output_name : c->c_name);          fprintf(stdout, "%s ", host);
         key_write(key, stdout);          key_write(key, stdout);
         fputs("\n", stdout);          fputs("\n", stdout);
 }  }
Line 477 
Line 484 
 static void  static void
 congreet(int s)  congreet(int s)
 {  {
         int remote_major = 0, remote_minor = 0, n = 0;          int n = 0, remote_major = 0, remote_minor = 0;
         char buf[256], *cp;          char buf[256], *cp;
         char remote_version[sizeof buf];          char remote_version[sizeof buf];
         size_t bufsiz;          size_t bufsiz;
Line 490 
Line 497 
                         *cp = '\n';                          *cp = '\n';
                 cp++;                  cp++;
         }          }
         if (n < 0) {          if (n == 0) {
                 if (errno != ECONNREFUSED)                  switch (errno) {
                   case EPIPE:
                           error("%s: Connection closed by remote host", c->c_name);
                           break;
                   case ECONNREFUSED:
                           break;
                   default:
                         error("read (%s): %s", c->c_name, strerror(errno));                          error("read (%s): %s", c->c_name, strerror(errno));
                           break;
                   }
                 conrecycle(s);                  conrecycle(s);
                 return;                  return;
         }          }
         if (n == 0) {  
                 error("%s: Connection closed by remote host", c->c_name);  
                 conrecycle(s);  
                 return;  
         }  
         if (*cp != '\n' && *cp != '\r') {          if (*cp != '\n' && *cp != '\r') {
                 error("%s: bad greeting", c->c_name);                  error("%s: bad greeting", c->c_name);
                 confree(s);                  confree(s);
Line 527 
Line 537 
         n = snprintf(buf, sizeof buf, "SSH-%d.%d-OpenSSH-keyscan\r\n",          n = snprintf(buf, sizeof buf, "SSH-%d.%d-OpenSSH-keyscan\r\n",
             c->c_keytype == KT_RSA1? PROTOCOL_MAJOR_1 : PROTOCOL_MAJOR_2,              c->c_keytype == KT_RSA1? PROTOCOL_MAJOR_1 : PROTOCOL_MAJOR_2,
             c->c_keytype == KT_RSA1? PROTOCOL_MINOR_1 : PROTOCOL_MINOR_2);              c->c_keytype == KT_RSA1? PROTOCOL_MINOR_1 : PROTOCOL_MINOR_2);
         if (atomicio(vwrite, s, buf, n) != n) {          if (n < 0 || (size_t)n >= sizeof(buf)) {
                   error("snprintf: buffer too small");
                   confree(s);
                   return;
           }
           if (atomicio(vwrite, s, buf, n) != (size_t)n) {
                 error("write (%s): %s", c->c_name, strerror(errno));                  error("write (%s): %s", c->c_name, strerror(errno));
                 confree(s);                  confree(s);
                 return;                  return;
Line 545 
Line 560 
 conread(int s)  conread(int s)
 {  {
         con *c = &fdcon[s];          con *c = &fdcon[s];
         int n;          size_t n;
   
         if (c->c_status == CS_CON) {          if (c->c_status == CS_CON) {
                 congreet(s);                  congreet(s);
                 return;                  return;
         }          }
         n = atomicio(read, s, c->c_data + c->c_off, c->c_len - c->c_off);          n = atomicio(read, s, c->c_data + c->c_off, c->c_len - c->c_off);
         if (n < 0) {          if (n == 0) {
                 error("read (%s): %s", c->c_name, strerror(errno));                  error("read (%s): %s", c->c_name, strerror(errno));
                 confree(s);                  confree(s);
                 return;                  return;
Line 667 
Line 682 
 static void  static void
 usage(void)  usage(void)
 {  {
         fprintf(stderr, "usage: %s [-v46] [-p port] [-T timeout] [-t type] [-f file]\n"          fprintf(stderr, "usage: %s [-46Hv] [-f file] [-p port] [-T timeout] [-t type]\n"
             "\t\t   [host | addrlist namelist] [...]\n",              "\t\t   [host | addrlist namelist] [...]\n",
             __progname);              __progname);
         exit(1);          exit(1);
Line 688 
Line 703 
         if (argc <= 1)          if (argc <= 1)
                 usage();                  usage();
   
         while ((opt = getopt(argc, argv, "v46p:T:t:f:")) != -1) {          while ((opt = getopt(argc, argv, "Hv46p:T:t:f:")) != -1) {
                 switch (opt) {                  switch (opt) {
                   case 'H':
                           hash_hosts = 1;
                           break;
                 case 'p':                  case 'p':
                         ssh_port = a2port(optarg);                          ssh_port = a2port(optarg);
                         if (ssh_port == 0) {                          if (ssh_port == 0) {

Legend:
Removed from v.1.50  
changed lines
  Added in v.1.50.2.2