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

Diff for /src/usr.bin/ssh/authfile.c between version 1.124 and 1.125

version 1.124, 2017/04/30 23:10:43 version 1.125, 2017/05/30 08:49:32
Line 311 
Line 311 
         return SSH_ERR_INVALID_FORMAT;          return SSH_ERR_INVALID_FORMAT;
 }  }
   
 /* load public key from ssh v1 private or any pubkey file */  /* load public key from any pubkey file */
 int  int
 sshkey_load_public(const char *filename, struct sshkey **keyp, char **commentp)  sshkey_load_public(const char *filename, struct sshkey **keyp, char **commentp)
 {  {
         struct sshkey *pub = NULL;          struct sshkey *pub = NULL;
         char file[PATH_MAX];          char *file = NULL;
         int r, fd;          int r;
   
         if (keyp != NULL)          if (keyp != NULL)
                 *keyp = NULL;                  *keyp = NULL;
         if (commentp != NULL)          if (commentp != NULL)
                 *commentp = NULL;                  *commentp = NULL;
   
         /* XXX should load file once and attempt to parse each format */  
   
         if ((fd = open(filename, O_RDONLY)) < 0)  
                 goto skip;  
         close(fd);  
   
         /* try ssh2 public key */  
         if ((pub = sshkey_new(KEY_UNSPEC)) == NULL)          if ((pub = sshkey_new(KEY_UNSPEC)) == NULL)
                 return SSH_ERR_ALLOC_FAIL;                  return SSH_ERR_ALLOC_FAIL;
         if ((r = sshkey_try_load_public(pub, filename, commentp)) == 0) {          if ((r = sshkey_try_load_public(pub, filename, commentp)) == 0) {
                 if (keyp != NULL)                  if (keyp != NULL) {
                         *keyp = pub;                          *keyp = pub;
                 return 0;                          pub = NULL;
                   }
                   r = 0;
                   goto out;
         }          }
         sshkey_free(pub);          sshkey_free(pub);
   
   
  skip:  
         /* try .pub suffix */          /* try .pub suffix */
         if ((pub = sshkey_new(KEY_UNSPEC)) == NULL)          if (asprintf(&file, "%s.pub", filename) == -1)
                 return SSH_ERR_ALLOC_FAIL;                  return SSH_ERR_ALLOC_FAIL;
         r = SSH_ERR_ALLOC_FAIL; /* in case strlcpy or strlcat fail */          if ((pub = sshkey_new(KEY_UNSPEC)) == NULL) {
         if ((strlcpy(file, filename, sizeof file) < sizeof(file)) &&                  r = SSH_ERR_ALLOC_FAIL;
             (strlcat(file, ".pub", sizeof file) < sizeof(file)) &&                  goto out;
             (r = sshkey_try_load_public(pub, file, commentp)) == 0) {          }
                 if (keyp != NULL)          if ((r = sshkey_try_load_public(pub, file, commentp)) == 0) {
                   if (keyp != NULL) {
                         *keyp = pub;                          *keyp = pub;
                 return 0;                          pub = NULL;
                   }
                   r = 0;
         }          }
    out:
           free(file);
         sshkey_free(pub);          sshkey_free(pub);
   
         return r;          return r;
 }  }
   

Legend:
Removed from v.1.124  
changed lines
  Added in v.1.125