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

Diff for /src/usr.bin/openssl/apps.c between version 1.37 and 1.38

version 1.37, 2015/11/14 14:53:14 version 1.38, 2016/08/26 15:04:15
Line 1269 
Line 1269 
 static IMPLEMENT_LHASH_HASH_FN(index_name, OPENSSL_CSTRING)  static IMPLEMENT_LHASH_HASH_FN(index_name, OPENSSL_CSTRING)
 static IMPLEMENT_LHASH_COMP_FN(index_name, OPENSSL_CSTRING)  static IMPLEMENT_LHASH_COMP_FN(index_name, OPENSSL_CSTRING)
   
 #define BUFLEN 256  
   
 BIGNUM *  BIGNUM *
 load_serial(char *serialfile, int create, ASN1_INTEGER **retai)  load_serial(char *serialfile, int create, ASN1_INTEGER **retai)
 {  {
Line 1297 
Line 1295 
                                 BIO_printf(bio_err, "Out of memory\n");                                  BIO_printf(bio_err, "Out of memory\n");
                 }                  }
         } else {          } else {
                 if (!a2i_ASN1_INTEGER(in, ai, buf, 1024)) {                  if (!a2i_ASN1_INTEGER(in, ai, buf, sizeof buf)) {
                         BIO_printf(bio_err, "unable to load number from %s\n",                          BIO_printf(bio_err, "unable to load number from %s\n",
                             serialfile);                              serialfile);
                         goto err;                          goto err;
Line 1327 
Line 1325 
 save_serial(char *serialfile, char *suffix, BIGNUM *serial,  save_serial(char *serialfile, char *suffix, BIGNUM *serial,
     ASN1_INTEGER **retai)      ASN1_INTEGER **retai)
 {  {
         char buf[1][BUFLEN];          char serialpath[PATH_MAX];
         BIO *out = NULL;          BIO *out = NULL;
         int ret = 0, n;          int ret = 0, n;
         ASN1_INTEGER *ai = NULL;          ASN1_INTEGER *ai = NULL;
         int j;  
   
         if (suffix == NULL)          if (suffix == NULL)
                 j = strlen(serialfile);                  n = strlcpy(serialpath, serialfile, sizeof serialpath);
         else          else
                 j = strlen(serialfile) + strlen(suffix) + 1;                  n = snprintf(serialpath, sizeof serialpath, "%s.%s",
         if (j >= BUFLEN) {  
                 BIO_printf(bio_err, "file name too long\n");  
                 goto err;  
         }  
         if (suffix == NULL)  
                 n = strlcpy(buf[0], serialfile, BUFLEN);  
         else  
                 n = snprintf(buf[0], sizeof buf[0], "%s.%s",  
                     serialfile, suffix);                      serialfile, suffix);
         if (n == -1 || n >= sizeof(buf[0])) {          if (n == -1 || n >= sizeof(serialpath)) {
                 BIO_printf(bio_err, "serial too long\n");                  BIO_printf(bio_err, "serial too long\n");
                 goto err;                  goto err;
         }          }
Line 1355 
Line 1344 
                 ERR_print_errors(bio_err);                  ERR_print_errors(bio_err);
                 goto err;                  goto err;
         }          }
         if (BIO_write_filename(out, buf[0]) <= 0) {          if (BIO_write_filename(out, serialpath) <= 0) {
                 perror(serialfile);                  perror(serialfile);
                 goto err;                  goto err;
         }          }
Line 1383 
Line 1372 
 int  int
 rotate_serial(char *serialfile, char *new_suffix, char *old_suffix)  rotate_serial(char *serialfile, char *new_suffix, char *old_suffix)
 {  {
         char buf[5][BUFLEN];          char opath[PATH_MAX], npath[PATH_MAX];
         int i, j;  
   
         i = strlen(serialfile) + strlen(old_suffix);          if (snprintf(npath, sizeof npath, "%s.%s", serialfile,
         j = strlen(serialfile) + strlen(new_suffix);              new_suffix) >= sizeof npath) {
         if (i > j)  
                 j = i;  
         if (j + 1 >= BUFLEN) {  
                 BIO_printf(bio_err, "file name too long\n");                  BIO_printf(bio_err, "file name too long\n");
                 goto err;                  goto err;
         }          }
         snprintf(buf[0], sizeof buf[0], "%s.%s", serialfile, new_suffix);  
         snprintf(buf[1], sizeof buf[1], "%s.%s", serialfile, old_suffix);  
   
           if (snprintf(opath, sizeof opath, "%s.%s", serialfile,
               old_suffix) >= sizeof opath) {
                   BIO_printf(bio_err, "file name too long\n");
                   goto err;
           }
   
         if (rename(serialfile, buf[1]) < 0 &&          if (rename(serialfile, opath) < 0 &&
             errno != ENOENT && errno != ENOTDIR) {              errno != ENOENT && errno != ENOTDIR) {
                 BIO_printf(bio_err, "unable to rename %s to %s\n",                  BIO_printf(bio_err, "unable to rename %s to %s\n",
                     serialfile, buf[1]);                      serialfile, opath);
                 perror("reason");                  perror("reason");
                 goto err;                  goto err;
         }          }
   
   
         if (rename(buf[0], serialfile) < 0) {          if (rename(npath, serialfile) < 0) {
                 BIO_printf(bio_err, "unable to rename %s to %s\n",                  BIO_printf(bio_err, "unable to rename %s to %s\n",
                     buf[0], serialfile);                      npath, serialfile);
                 perror("reason");                  perror("reason");
                 if (rename(buf[1], serialfile) < 0) {                  if (rename(opath, serialfile) < 0) {
                         BIO_printf(bio_err, "unable to rename %s to %s\n",                          BIO_printf(bio_err, "unable to rename %s to %s\n",
                             buf[1], serialfile);                              opath, serialfile);
                         perror("reason");                          perror("reason");
                 }                  }
                 goto err;                  goto err;
Line 1459 
Line 1447 
         TXT_DB *tmpdb = NULL;          TXT_DB *tmpdb = NULL;
         BIO *in = BIO_new(BIO_s_file());          BIO *in = BIO_new(BIO_s_file());
         CONF *dbattr_conf = NULL;          CONF *dbattr_conf = NULL;
         char buf[1][BUFLEN];          char attrpath[PATH_MAX];
         long errorline = -1;          long errorline = -1;
   
         if (in == NULL) {          if (in == NULL) {
Line 1474 
Line 1462 
         if ((tmpdb = TXT_DB_read(in, DB_NUMBER)) == NULL)          if ((tmpdb = TXT_DB_read(in, DB_NUMBER)) == NULL)
                 goto err;                  goto err;
   
         snprintf(buf[0], sizeof buf[0], "%s.attr", dbfile);          if (snprintf(attrpath, sizeof attrpath, "%s.attr", dbfile)
               >= sizeof attrpath) {
                   BIO_printf(bio_err, "attr filename too long\n");
                   goto err;
           }
   
         dbattr_conf = NCONF_new(NULL);          dbattr_conf = NCONF_new(NULL);
         if (NCONF_load(dbattr_conf, buf[0], &errorline) <= 0) {          if (NCONF_load(dbattr_conf, attrpath, &errorline) <= 0) {
                 if (errorline > 0) {                  if (errorline > 0) {
                         BIO_printf(bio_err,                          BIO_printf(bio_err,
                             "error on line %ld of db attribute file '%s'\n",                              "error on line %ld of db attribute file '%s'\n",
                             errorline, buf[0]);                              errorline, attrpath);
                         goto err;                          goto err;
                 } else {                  } else {
                         NCONF_free(dbattr_conf);                          NCONF_free(dbattr_conf);
Line 1537 
Line 1530 
 }  }
   
 int  int
 save_index(const char *dbfile, const char *suffix, CA_DB *db)  save_index(const char *file, const char *suffix, CA_DB *db)
 {  {
         char buf[3][BUFLEN];          char attrpath[PATH_MAX], dbfile[PATH_MAX];
         BIO *out = BIO_new(BIO_s_file());          BIO *out = BIO_new(BIO_s_file());
         int j;          int j;
   
Line 1547 
Line 1540 
                 ERR_print_errors(bio_err);                  ERR_print_errors(bio_err);
                 goto err;                  goto err;
         }          }
         j = strlen(dbfile) + strlen(suffix);          if (snprintf(attrpath, sizeof attrpath, "%s.attr.%s",
         if (j + 6 >= BUFLEN) {              file, suffix) >= sizeof attrpath) {
                 BIO_printf(bio_err, "file name too long\n");                  BIO_printf(bio_err, "file name too long\n");
                 goto err;                  goto err;
         }          }
         snprintf(buf[2], sizeof buf[2], "%s.attr", dbfile);          if (snprintf(dbfile, sizeof dbfile, "%s.%s",
         snprintf(buf[1], sizeof buf[1], "%s.attr.%s", dbfile, suffix);              file, suffix) >= sizeof dbfile) {
         snprintf(buf[0], sizeof buf[0], "%s.%s", dbfile, suffix);                  BIO_printf(bio_err, "file name too long\n");
                   goto err;
           }
   
           if (BIO_write_filename(out, dbfile) <= 0) {
         if (BIO_write_filename(out, buf[0]) <= 0) {  
                 perror(dbfile);                  perror(dbfile);
                 BIO_printf(bio_err, "unable to open '%s'\n", dbfile);                  BIO_printf(bio_err, "unable to open '%s'\n", dbfile);
                 goto err;                  goto err;
Line 1570 
Line 1564 
   
         out = BIO_new(BIO_s_file());          out = BIO_new(BIO_s_file());
   
           if (BIO_write_filename(out, attrpath) <= 0) {
         if (BIO_write_filename(out, buf[1]) <= 0) {                  perror(attrpath);
                 perror(buf[2]);                  BIO_printf(bio_err, "unable to open '%s'\n", attrpath);
                 BIO_printf(bio_err, "unable to open '%s'\n", buf[2]);  
                 goto err;                  goto err;
         }          }
         BIO_printf(out, "unique_subject = %s\n",          BIO_printf(out, "unique_subject = %s\n",
Line 1589 
Line 1582 
 int  int
 rotate_index(const char *dbfile, const char *new_suffix, const char *old_suffix)  rotate_index(const char *dbfile, const char *new_suffix, const char *old_suffix)
 {  {
         char buf[5][BUFLEN];          char attrpath[PATH_MAX], nattrpath[PATH_MAX], oattrpath[PATH_MAX];
         int i, j;          char dbpath[PATH_MAX], odbpath[PATH_MAX];
   
         i = strlen(dbfile) + strlen(old_suffix);          if (snprintf(attrpath, sizeof attrpath, "%s.attr",
         j = strlen(dbfile) + strlen(new_suffix);              dbfile) >= sizeof attrpath) {
         if (i > j)  
                 j = i;  
         if (j + 6 >= BUFLEN) {  
                 BIO_printf(bio_err, "file name too long\n");                  BIO_printf(bio_err, "file name too long\n");
                 goto err;                  goto err;
         }          }
         snprintf(buf[4], sizeof buf[4], "%s.attr", dbfile);          if (snprintf(nattrpath, sizeof nattrpath, "%s.attr.%s",
         snprintf(buf[2], sizeof buf[2], "%s.attr.%s", dbfile, new_suffix);              dbfile, new_suffix) >= sizeof nattrpath) {
         snprintf(buf[0], sizeof buf[0], "%s.%s", dbfile, new_suffix);                  BIO_printf(bio_err, "file name too long\n");
         snprintf(buf[1], sizeof buf[1], "%s.%s", dbfile, old_suffix);                  goto err;
         snprintf(buf[3], sizeof buf[3], "%s.attr.%s", dbfile, old_suffix);          }
           if (snprintf(oattrpath, sizeof oattrpath, "%s.attr.%s",
               dbfile, old_suffix) >= sizeof oattrpath) {
                   BIO_printf(bio_err, "file name too long\n");
                   goto err;
           }
           if (snprintf(dbpath, sizeof dbpath, "%s.%s",
               dbfile, new_suffix) >= sizeof dbpath) {
                   BIO_printf(bio_err, "file name too long\n");
                   goto err;
           }
           if (snprintf(odbpath, sizeof odbpath, "%s.%s",
               dbfile, old_suffix) >= sizeof odbpath) {
                   BIO_printf(bio_err, "file name too long\n");
                   goto err;
           }
   
           if (rename(dbfile, odbpath) < 0 && errno != ENOENT && errno != ENOTDIR) {
         if (rename(dbfile, buf[1]) < 0 && errno != ENOENT && errno != ENOTDIR) {  
                 BIO_printf(bio_err, "unable to rename %s to %s\n",                  BIO_printf(bio_err, "unable to rename %s to %s\n",
                     dbfile, buf[1]);                      dbfile, odbpath);
                 perror("reason");                  perror("reason");
                 goto err;                  goto err;
         }          }
   
           if (rename(dbpath, dbfile) < 0) {
         if (rename(buf[0], dbfile) < 0) {  
                 BIO_printf(bio_err, "unable to rename %s to %s\n",                  BIO_printf(bio_err, "unable to rename %s to %s\n",
                     buf[0], dbfile);                      dbpath, dbfile);
                 perror("reason");                  perror("reason");
                 if (rename(buf[1], dbfile) < 0) {                  if (rename(odbpath, dbfile) < 0) {
                         BIO_printf(bio_err, "unable to rename %s to %s\n",                          BIO_printf(bio_err, "unable to rename %s to %s\n",
                             buf[1], dbfile);                              odbpath, dbfile);
                         perror("reason");                          perror("reason");
                 }                  }
                 goto err;                  goto err;
         }          }
   
           if (rename(attrpath, oattrpath) < 0 && errno != ENOENT && errno != ENOTDIR) {
         if (rename(buf[4], buf[3]) < 0 && errno != ENOENT && errno != ENOTDIR) {  
                 BIO_printf(bio_err, "unable to rename %s to %s\n",                  BIO_printf(bio_err, "unable to rename %s to %s\n",
                     buf[4], buf[3]);                      attrpath, oattrpath);
                 perror("reason");                  perror("reason");
                 if (rename(dbfile, buf[0]) < 0) {                  if (rename(dbfile, dbpath) < 0) {
                         BIO_printf(bio_err, "unable to rename %s to %s\n",                          BIO_printf(bio_err, "unable to rename %s to %s\n",
                             dbfile, buf[0]);                              dbfile, dbpath);
                         perror("reason");                          perror("reason");
                 }                  }
                 if (rename(buf[1], dbfile) < 0) {                  if (rename(odbpath, dbfile) < 0) {
                         BIO_printf(bio_err, "unable to rename %s to %s\n",                          BIO_printf(bio_err, "unable to rename %s to %s\n",
                             buf[1], dbfile);                              odbpath, dbfile);
                         perror("reason");                          perror("reason");
                 }                  }
                 goto err;                  goto err;
         }          }
   
           if (rename(nattrpath, attrpath) < 0) {
         if (rename(buf[2], buf[4]) < 0) {  
                 BIO_printf(bio_err, "unable to rename %s to %s\n",                  BIO_printf(bio_err, "unable to rename %s to %s\n",
                     buf[2], buf[4]);                      nattrpath, attrpath);
                 perror("reason");                  perror("reason");
                 if (rename(buf[3], buf[4]) < 0) {                  if (rename(oattrpath, attrpath) < 0) {
                         BIO_printf(bio_err, "unable to rename %s to %s\n",                          BIO_printf(bio_err, "unable to rename %s to %s\n",
                             buf[3], buf[4]);                              oattrpath, attrpath);
                         perror("reason");                          perror("reason");
                 }                  }
                 if (rename(dbfile, buf[0]) < 0) {                  if (rename(dbfile, dbpath) < 0) {
                         BIO_printf(bio_err, "unable to rename %s to %s\n",                          BIO_printf(bio_err, "unable to rename %s to %s\n",
                             dbfile, buf[0]);                              dbfile, dbpath);
                         perror("reason");                          perror("reason");
                 }                  }
                 if (rename(buf[1], dbfile) < 0) {                  if (rename(odbpath, dbfile) < 0) {
                         BIO_printf(bio_err, "unable to rename %s to %s\n",                          BIO_printf(bio_err, "unable to rename %s to %s\n",
                             buf[1], dbfile);                              odbpath, dbfile);
                         perror("reason");                          perror("reason");
                 }                  }
                 goto err;                  goto err;

Legend:
Removed from v.1.37  
changed lines
  Added in v.1.38