[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.137 and 1.138

version 1.137, 2020/01/25 23:02:13 version 1.138, 2020/04/08 00:09:24
Line 190 
Line 190 
 }  }
   
 static int  static int
 sshkey_try_load_public(struct sshkey *k, const char *filename, char **commentp)  sshkey_try_load_public(struct sshkey **kp, const char *filename,
       char **commentp)
 {  {
         FILE *f;          FILE *f;
         char *line = NULL, *cp;          char *line = NULL, *cp;
         size_t linesize = 0;          size_t linesize = 0;
         int r;          int r;
           struct sshkey *k = NULL;
   
           *kp = NULL;
         if (commentp != NULL)          if (commentp != NULL)
                 *commentp = NULL;                  *commentp = NULL;
         if ((f = fopen(filename, "r")) == NULL)          if ((f = fopen(filename, "r")) == NULL)
                 return SSH_ERR_SYSTEM_ERROR;                  return SSH_ERR_SYSTEM_ERROR;
           if ((k = sshkey_new(KEY_UNSPEC)) == NULL) {
                   fclose(f);
                   return SSH_ERR_ALLOC_FAIL;
           }
         while (getline(&line, &linesize, f) != -1) {          while (getline(&line, &linesize, f) != -1) {
                 cp = line;                  cp = line;
                 switch (*cp) {                  switch (*cp) {
Line 225 
Line 232 
                                         if (*commentp == NULL)                                          if (*commentp == NULL)
                                                 r = SSH_ERR_ALLOC_FAIL;                                                  r = SSH_ERR_ALLOC_FAIL;
                                 }                                  }
                                   /* success */
                                   *kp = k;
                                 free(line);                                  free(line);
                                 fclose(f);                                  fclose(f);
                                 return r;                                  return r;
                         }                          }
                 }                  }
         }          }
           free(k);
         free(line);          free(line);
         fclose(f);          fclose(f);
         return SSH_ERR_INVALID_FORMAT;          return SSH_ERR_INVALID_FORMAT;
Line 240 
Line 250 
 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;          char *pubfile = NULL;
         char *file = NULL;  
         int r;          int r;
   
         if (keyp != NULL)          if (keyp != NULL)
Line 249 
Line 258 
         if (commentp != NULL)          if (commentp != NULL)
                 *commentp = NULL;                  *commentp = NULL;
   
         if ((pub = sshkey_new(KEY_UNSPEC)) == NULL)          if ((r = sshkey_try_load_public(keyp, filename, commentp)) == 0)
                 return SSH_ERR_ALLOC_FAIL;  
         if ((r = sshkey_try_load_public(pub, filename, commentp)) == 0) {  
                 if (keyp != NULL) {  
                         *keyp = pub;  
                         pub = NULL;  
                 }  
                 r = 0;  
                 goto out;                  goto out;
         }  
         sshkey_free(pub);  
   
         /* try .pub suffix */          /* try .pub suffix */
         if (asprintf(&file, "%s.pub", filename) == -1)          if (asprintf(&pubfile, "%s.pub", filename) == -1)
                 return SSH_ERR_ALLOC_FAIL;                  return SSH_ERR_ALLOC_FAIL;
         if ((pub = sshkey_new(KEY_UNSPEC)) == NULL) {          if ((r = sshkey_try_load_public(keyp, pubfile, commentp)) == 0)
                 r = SSH_ERR_ALLOC_FAIL;  
                 goto out;                  goto out;
         }  
         if ((r = sshkey_try_load_public(pub, file, commentp)) == 0) {  
                 if (keyp != NULL) {  
                         *keyp = pub;  
                         pub = NULL;  
                 }  
                 r = 0;  
         }  
  out:   out:
         free(file);          free(pubfile);
         sshkey_free(pub);  
         return r;          return r;
 }  }
   
Line 295 
Line 286 
         if (asprintf(&file, "%s-cert.pub", filename) == -1)          if (asprintf(&file, "%s-cert.pub", filename) == -1)
                 return SSH_ERR_ALLOC_FAIL;                  return SSH_ERR_ALLOC_FAIL;
   
         if ((pub = sshkey_new(KEY_UNSPEC)) == NULL) {          r = sshkey_try_load_public(keyp, file, NULL);
                 goto out;  
         }  
         if ((r = sshkey_try_load_public(pub, file, NULL)) != 0)  
                 goto out;  
         /* success */  
         if (keyp != NULL) {  
                 *keyp = pub;  
                 pub = NULL;  
         }  
         r = 0;  
  out:  
         free(file);          free(file);
         sshkey_free(pub);          sshkey_free(pub);
         return r;          return r;

Legend:
Removed from v.1.137  
changed lines
  Added in v.1.138