X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=apps%2Frehash.c;h=bb41d3129f9c518566bb4c1f072d803c6856b87a;hp=ad7108aad9511ab1c08d439ade5f8323d8c4f7d1;hb=3be71a31a1dda204bb95462a92cf7f247e64b939;hpb=624265c60e07f8e5f251d0f5b79e34cf0221af73 diff --git a/apps/rehash.c b/apps/rehash.c index ad7108aad9..bb41d3129f 100644 --- a/apps/rehash.c +++ b/apps/rehash.c @@ -1,6 +1,6 @@ /* - * Copyright 2015-2017 The OpenSSL Project Authors. All Rights Reserved. - * Copyright (c) 2013-2014 Timo Teräs + * Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved. + * Copyright (c) 2013-2014 Timo Teräs * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -9,6 +9,7 @@ */ #include "apps.h" +#include "progs.h" #if defined(OPENSSL_SYS_UNIX) || defined(__APPLE__) || \ (defined(__VMS) && defined(__DECC) && __CRTL_VER >= 80300000) @@ -125,9 +126,10 @@ static int add_entry(enum Type type, unsigned int hash, const char *filename, for (ep = bp->first_entry; ep; ep = ep->next) { if (digest && memcmp(digest, ep->digest, evpmdsize) == 0) { BIO_printf(bio_err, - "%s: skipping duplicate %s in %s\n", opt_getprog(), + "%s: warning: skipping duplicate %s in %s\n", + opt_getprog(), type == TYPE_CERT ? "certificate" : "CRL", filename); - return 1; + return 0; } if (strcmp(filename, ep->filename) == 0) { found = ep; @@ -139,7 +141,7 @@ static int add_entry(enum Type type, unsigned int hash, const char *filename, if (ep == NULL) { if (bp->num_needed >= MAX_COLLISIONS) { BIO_printf(bio_err, - "%s: hash table overflow for %s\n", + "%s: error: hash table overflow for %s\n", opt_getprog(), filename); return 1; } @@ -230,7 +232,7 @@ static int do_file(const char *filename, const char *fullpath, enum Hash h) /* Does it have X.509 data in it? */ if ((b = BIO_new_file(fullpath, "r")) == NULL) { - BIO_printf(bio_err, "%s: skipping %s, cannot open file\n", + BIO_printf(bio_err, "%s: error: skipping %s, cannot open file\n", opt_getprog(), filename); errs++; goto end; @@ -242,7 +244,7 @@ static int do_file(const char *filename, const char *fullpath, enum Hash h) if (sk_X509_INFO_num(inf) != 1) { BIO_printf(bio_err, - "%s: skipping %s," + "%s: warning: skipping %s," "it does not contain exactly one certificate or CRL\n", opt_getprog(), filename); /* This is not an error. */ @@ -292,24 +294,6 @@ static int ends_with_dirsep(const char *path) return *path == '/'; } -static int massage_filename(char *name) -{ -# ifdef __VMS - char *p = strchr(name, ';'); - char *q = p; - - if (q != NULL) { - for (q++; *q != '\0'; q++) { - if (!isdigit(*q)) - return 1; - } - } - - *p = '\0'; -# endif - return 1; -} - /* * Process a directory; return number of errors found. */ @@ -324,7 +308,7 @@ static int do_dir(const char *dirname, enum Hash h) size_t i; const char *pathsep; const char *filename; - char *buf, *copy; + char *buf, *copy = NULL; STACK_OF(OPENSSL_STRING) *files = NULL; if (app_access(dirname, W_OK) < 0) { @@ -341,14 +325,16 @@ static int do_dir(const char *dirname, enum Hash h) if ((files = sk_OPENSSL_STRING_new_null()) == NULL) { BIO_printf(bio_err, "Skipping %s, out of memory\n", dirname); - exit(1); + errs = 1; + goto err; } while ((filename = OPENSSL_DIR_read(&d, dirname)) != NULL) { - if ((copy = strdup(filename)) == NULL - || !massage_filename(copy) + if ((copy = OPENSSL_strdup(filename)) == NULL || sk_OPENSSL_STRING_push(files, copy) == 0) { + OPENSSL_free(copy); BIO_puts(bio_err, "out of memory\n"); - exit(1); + errs = 1; + goto err; } } OPENSSL_DIR_end(&d); @@ -366,7 +352,6 @@ static int do_dir(const char *dirname, enum Hash h) continue; errs += do_file(filename, buf, h); } - sk_OPENSSL_STRING_pop_free(files, str_free); for (i = 0; i < OSSL_NELEM(hash_table); i++) { for (bp = hash_table[i]; bp; bp = nextbp) { @@ -434,6 +419,8 @@ static int do_dir(const char *dirname, enum Hash h) hash_table[i] = NULL; } + err: + sk_OPENSSL_STRING_pop_free(files, str_free); OPENSSL_free(buf); return errs; } @@ -497,13 +484,14 @@ int rehash_main(int argc, char **argv) if (*argv != NULL) { while (*argv != NULL) errs += do_dir(*argv++, h); - } else if ((env = getenv("SSL_CERT_DIR")) != NULL) { + } else if ((env = getenv(X509_get_default_cert_dir_env())) != NULL) { + char lsc[2] = { LIST_SEPARATOR_CHAR, '\0' }; m = OPENSSL_strdup(env); - for (e = strtok(m, ":"); e != NULL; e = strtok(NULL, ":")) + for (e = strtok(m, lsc); e != NULL; e = strtok(NULL, lsc)) errs += do_dir(e, h); OPENSSL_free(m); } else { - errs += do_dir("/etc/ssl/certs", h); + errs += do_dir(X509_get_default_cert_dir(), h); } end: @@ -518,7 +506,7 @@ const OPTIONS rehash_options[] = { int rehash_main(int argc, char **argv) { BIO_printf(bio_err, "Not available; use c_rehash script\n"); - return (1); + return 1; } #endif /* defined(OPENSSL_SYS_UNIX) || defined(__APPLE__) */