Bug Summary

File:out/../deps/openssl/openssl/apps/rehash.c
Warning:line 539, column 5
Value stored to 'argc' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name rehash.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/maurizio/node-v18.6.0/out -resource-dir /usr/local/lib/clang/16.0.0 -D V8_DEPRECATION_WARNINGS -D V8_IMMINENT_DEPRECATION_WARNINGS -D _GLIBCXX_USE_CXX11_ABI=1 -D NODE_OPENSSL_CONF_NAME=nodejs_conf -D NODE_OPENSSL_HAS_QUIC -D __STDC_FORMAT_MACROS -D OPENSSL_NO_PINSHARED -D OPENSSL_THREADS -D OPENSSL_API_COMPAT=0x10100001L -D NDEBUG -D OPENSSL_USE_NODELETE -D L_ENDIAN -D OPENSSL_BUILDING_OPENSSL -D AES_ASM -D BSAES_ASM -D CMLL_ASM -D ECP_NISTZ256_ASM -D GHASH_ASM -D KECCAK1600_ASM -D MD5_ASM -D OPENSSL_BN_ASM_GF2m -D OPENSSL_BN_ASM_MONT -D OPENSSL_BN_ASM_MONT5 -D OPENSSL_CPUID_OBJ -D OPENSSL_IA32_SSE2 -D PADLOCK_ASM -D POLY1305_ASM -D SHA1_ASM -D SHA256_ASM -D SHA512_ASM -D VPAES_ASM -D WHIRLPOOL_ASM -D X25519_ASM -D OPENSSL_PIC -D OPENSSLDIR="/etc/ssl" -D ENGINESDIR="/dev/null" -D TERMIOS -I ../deps/openssl/openssl/apps/include -I ../deps/openssl/openssl -I ../deps/openssl/openssl/include -I ../deps/openssl/openssl/crypto -I ../deps/openssl/openssl/crypto/include -I ../deps/openssl/openssl/crypto/modes -I ../deps/openssl/openssl/crypto/ec/curve448 -I ../deps/openssl/openssl/crypto/ec/curve448/arch_32 -I ../deps/openssl/openssl/providers/common/include -I ../deps/openssl/openssl/providers/implementations/include -I ../deps/openssl/config -I ../deps/openssl/config/archs/linux-x86_64/asm/include -I ../deps/openssl/openssl/include -I ../deps/openssl/openssl/crypto/include -I ../deps/openssl/config/archs/linux-x86_64/asm -internal-isystem /usr/local/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-unused-parameter -Wno-missing-field-initializers -Wno-old-style-declaration -fdebug-compilation-dir=/home/maurizio/node-v18.6.0/out -ferror-limit 19 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-08-22-142216-507842-1 -x c ../deps/openssl/openssl/apps/rehash.c
1/*
2 * Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2013-2014 Timo Teräs <timo.teras@gmail.com>
4 *
5 * Licensed under the Apache License 2.0 (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
9 */
10
11#include "apps.h"
12#include "progs.h"
13
14#if defined(OPENSSL_SYS_UNIX) || defined(__APPLE__) || \
15 (defined(__VMS) && defined(__DECC) && __CRTL_VER >= 80300000)
16# include <unistd.h>
17# include <stdio.h>
18# include <limits.h>
19# include <errno(*__errno_location ()).h>
20# include <string.h>
21# include <ctype.h>
22# include <sys/stat.h>
23
24/*
25 * Make sure that the processing of symbol names is treated the same as when
26 * libcrypto is built. This is done automatically for public headers (see
27 * include/openssl/__DECC_INCLUDE_PROLOGUE.H and __DECC_INCLUDE_EPILOGUE.H),
28 * but not for internal headers.
29 */
30# ifdef __VMS
31# pragma names save
32# pragma names as_is,shortened
33# endif
34
35# include "internal/o_dir.h"
36
37# ifdef __VMS
38# pragma names restore
39# endif
40
41# include <openssl/evp.h>
42# include <openssl/pem.h>
43# include <openssl/x509.h>
44
45# ifndef PATH_MAX4096
46# define PATH_MAX4096 4096
47# endif
48# ifndef NAME_MAX255
49# define NAME_MAX255 255
50# endif
51# define MAX_COLLISIONS256 256
52
53# if defined(OPENSSL_SYS_VXWORKS)
54/*
55 * VxWorks has no symbolic links
56 */
57
58# define lstat(path, buf) stat(path, buf)
59
60int symlink(const char *target, const char *linkpath)
61{
62 errno(*__errno_location ()) = ENOSYS38;
63 return -1;
64}
65
66ssize_t readlink(const char *pathname, char *buf, size_t bufsiz)
67{
68 errno(*__errno_location ()) = ENOSYS38;
69 return -1;
70}
71# endif
72
73typedef struct hentry_st {
74 struct hentry_st *next;
75 char *filename;
76 unsigned short old_id;
77 unsigned char need_symlink;
78 unsigned char digest[EVP_MAX_MD_SIZE64];
79} HENTRY;
80
81typedef struct bucket_st {
82 struct bucket_st *next;
83 HENTRY *first_entry, *last_entry;
84 unsigned int hash;
85 unsigned short type;
86 unsigned short num_needed;
87} BUCKET;
88
89enum Type {
90 /* Keep in sync with |suffixes|, below. */
91 TYPE_CERT=0, TYPE_CRL=1
92};
93
94enum Hash {
95 HASH_OLD, HASH_NEW, HASH_BOTH
96};
97
98
99static int evpmdsize;
100static const EVP_MD *evpmd;
101static int remove_links = 1;
102static int verbose = 0;
103static BUCKET *hash_table[257];
104
105static const char *suffixes[] = { "", "r" };
106static const char *extensions[] = { "pem", "crt", "cer", "crl" };
107
108
109static void bit_set(unsigned char *set, unsigned int bit)
110{
111 set[bit >> 3] |= 1 << (bit & 0x7);
112}
113
114static int bit_isset(unsigned char *set, unsigned int bit)
115{
116 return set[bit >> 3] & (1 << (bit & 0x7));
117}
118
119
120/*
121 * Process an entry; return number of errors.
122 */
123static int add_entry(enum Type type, unsigned int hash, const char *filename,
124 const unsigned char *digest, int need_symlink,
125 unsigned short old_id)
126{
127 static BUCKET nilbucket;
128 static HENTRY nilhentry;
129 BUCKET *bp;
130 HENTRY *ep, *found = NULL((void*)0);
131 unsigned int ndx = (type + hash) % OSSL_NELEM(hash_table)(sizeof(hash_table)/sizeof((hash_table)[0]));
132
133 for (bp = hash_table[ndx]; bp; bp = bp->next)
134 if (bp->type == type && bp->hash == hash)
135 break;
136 if (bp == NULL((void*)0)) {
137 bp = app_malloc(sizeof(*bp), "hash bucket");
138 *bp = nilbucket;
139 bp->next = hash_table[ndx];
140 bp->type = type;
141 bp->hash = hash;
142 hash_table[ndx] = bp;
143 }
144
145 for (ep = bp->first_entry; ep; ep = ep->next) {
146 if (digest && memcmp(digest, ep->digest, evpmdsize) == 0) {
147 BIO_printf(bio_err,
148 "%s: warning: skipping duplicate %s in %s\n",
149 opt_getprog(),
150 type == TYPE_CERT ? "certificate" : "CRL", filename);
151 return 0;
152 }
153 if (strcmp(filename, ep->filename) == 0) {
154 found = ep;
155 if (digest == NULL((void*)0))
156 break;
157 }
158 }
159 ep = found;
160 if (ep == NULL((void*)0)) {
161 if (bp->num_needed >= MAX_COLLISIONS256) {
162 BIO_printf(bio_err,
163 "%s: error: hash table overflow for %s\n",
164 opt_getprog(), filename);
165 return 1;
166 }
167 ep = app_malloc(sizeof(*ep), "collision bucket");
168 *ep = nilhentry;
169 ep->old_id = ~0;
170 ep->filename = OPENSSL_strdup(filename)CRYPTO_strdup(filename, "../deps/openssl/openssl/apps/rehash.c"
, 170)
;
171 if (ep->filename == NULL((void*)0)) {
172 OPENSSL_free(ep)CRYPTO_free(ep, "../deps/openssl/openssl/apps/rehash.c", 172);
173 ep = NULL((void*)0);
174 BIO_printf(bio_err, "out of memory\n");
175 return 1;
176 }
177 if (bp->last_entry)
178 bp->last_entry->next = ep;
179 if (bp->first_entry == NULL((void*)0))
180 bp->first_entry = ep;
181 bp->last_entry = ep;
182 }
183
184 if (old_id < ep->old_id)
185 ep->old_id = old_id;
186 if (need_symlink && !ep->need_symlink) {
187 ep->need_symlink = 1;
188 bp->num_needed++;
189 memcpy(ep->digest, digest, evpmdsize);
190 }
191 return 0;
192}
193
194/*
195 * Check if a symlink goes to the right spot; return 0 if okay.
196 * This can be -1 if bad filename, or an error count.
197 */
198static int handle_symlink(const char *filename, const char *fullpath)
199{
200 unsigned int hash = 0;
201 int i, type, id;
202 unsigned char ch;
203 char linktarget[PATH_MAX4096], *endptr;
204 ossl_ssize_tssize_t n;
205
206 for (i = 0; i < 8; i++) {
207 ch = filename[i];
208 if (!isxdigit(ch)((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int)
_ISxdigit)
)
209 return -1;
210 hash <<= 4;
211 hash += OPENSSL_hexchar2int(ch);
212 }
213 if (filename[i++] != '.')
214 return -1;
215 for (type = OSSL_NELEM(suffixes)(sizeof(suffixes)/sizeof((suffixes)[0])) - 1; type > 0; type--) {
216 const char *suffix = suffixes[type];
217 if (OPENSSL_strncasecmp(suffix, &filename[i], strlen(suffix)) == 0)
218 break;
219 }
220 i += strlen(suffixes[type]);
221
222 id = strtoul(&filename[i], &endptr, 10);
223 if (*endptr != '\0')
224 return -1;
225
226 n = readlink(fullpath, linktarget, sizeof(linktarget));
227 if (n < 0 || n >= (int)sizeof(linktarget))
228 return -1;
229 linktarget[n] = 0;
230
231 return add_entry(type, hash, linktarget, NULL((void*)0), 0, id);
232}
233
234/*
235 * process a file, return number of errors.
236 */
237static int do_file(const char *filename, const char *fullpath, enum Hash h)
238{
239 STACK_OF (X509_INFO)struct stack_st_X509_INFO *inf = NULL((void*)0);
240 X509_INFO *x;
241 const X509_NAME *name = NULL((void*)0);
242 BIO *b;
243 const char *ext;
244 unsigned char digest[EVP_MAX_MD_SIZE64];
245 int type, errs = 0;
246 size_t i;
247
248 /* Does it end with a recognized extension? */
249 if ((ext = strrchr(filename, '.')) == NULL((void*)0))
250 goto end;
251 for (i = 0; i < OSSL_NELEM(extensions)(sizeof(extensions)/sizeof((extensions)[0])); i++) {
252 if (OPENSSL_strcasecmp(extensions[i], ext + 1) == 0)
253 break;
254 }
255 if (i >= OSSL_NELEM(extensions)(sizeof(extensions)/sizeof((extensions)[0])))
256 goto end;
257
258 /* Does it have X.509 data in it? */
259 if ((b = BIO_new_file(fullpath, "r")) == NULL((void*)0)) {
260 BIO_printf(bio_err, "%s: error: skipping %s, cannot open file\n",
261 opt_getprog(), filename);
262 errs++;
263 goto end;
264 }
265 inf = PEM_X509_INFO_read_bio(b, NULL((void*)0), NULL((void*)0), NULL((void*)0));
266 BIO_free(b);
267 if (inf == NULL((void*)0))
268 goto end;
269
270 if (sk_X509_INFO_num(inf)OPENSSL_sk_num(ossl_check_const_X509_INFO_sk_type(inf)) != 1) {
271 BIO_printf(bio_err,
272 "%s: warning: skipping %s,"
273 "it does not contain exactly one certificate or CRL\n",
274 opt_getprog(), filename);
275 /* This is not an error. */
276 goto end;
277 }
278 x = sk_X509_INFO_value(inf, 0)((X509_INFO *)OPENSSL_sk_value(ossl_check_const_X509_INFO_sk_type
(inf), (0)))
;
279 if (x->x509 != NULL((void*)0)) {
280 type = TYPE_CERT;
281 name = X509_get_subject_name(x->x509);
282 if (!X509_digest(x->x509, evpmd, digest, NULL((void*)0))) {
283 BIO_printf(bio_err, "out of memory\n");
284 ++errs;
285 goto end;
286 }
287 } else if (x->crl != NULL((void*)0)) {
288 type = TYPE_CRL;
289 name = X509_CRL_get_issuer(x->crl);
290 if (!X509_CRL_digest(x->crl, evpmd, digest, NULL((void*)0))) {
291 BIO_printf(bio_err, "out of memory\n");
292 ++errs;
293 goto end;
294 }
295 } else {
296 ++errs;
297 goto end;
298 }
299 if (name != NULL((void*)0)) {
300 if (h == HASH_NEW || h == HASH_BOTH) {
301 int ok;
302 unsigned long hash_value =
303 X509_NAME_hash_ex(name,
304 app_get0_libctx(), app_get0_propq(), &ok);
305
306 if (ok) {
307 errs += add_entry(type, hash_value, filename, digest, 1, ~0);
308 } else {
309 BIO_printf(bio_err, "%s: error calculating SHA1 hash value\n",
310 opt_getprog());
311 errs++;
312 }
313 }
314 if ((h == HASH_OLD) || (h == HASH_BOTH))
315 errs += add_entry(type, X509_NAME_hash_old(name),
316 filename, digest, 1, ~0);
317 }
318
319end:
320 sk_X509_INFO_pop_free(inf, X509_INFO_free)OPENSSL_sk_pop_free(ossl_check_X509_INFO_sk_type(inf),ossl_check_X509_INFO_freefunc_type
(X509_INFO_free))
;
321 return errs;
322}
323
324static void str_free(char *s)
325{
326 OPENSSL_free(s)CRYPTO_free(s, "../deps/openssl/openssl/apps/rehash.c", 326);
327}
328
329static int ends_with_dirsep(const char *path)
330{
331 if (*path != '\0')
332 path += strlen(path) - 1;
333# if defined __VMS
334 if (*path == ']' || *path == '>' || *path == ':')
335 return 1;
336# elif defined _WIN32
337 if (*path == '\\')
338 return 1;
339# endif
340 return *path == '/';
341}
342
343/*
344 * Process a directory; return number of errors found.
345 */
346static int do_dir(const char *dirname, enum Hash h)
347{
348 BUCKET *bp, *nextbp;
349 HENTRY *ep, *nextep;
350 OPENSSL_DIR_CTX *d = NULL((void*)0);
351 struct stat st;
352 unsigned char idmask[MAX_COLLISIONS256 / 8];
353 int n, numfiles, nextid, buflen, errs = 0;
354 size_t i;
355 const char *pathsep;
356 const char *filename;
357 char *buf, *copy = NULL((void*)0);
358 STACK_OF(OPENSSL_STRING)struct stack_st_OPENSSL_STRING *files = NULL((void*)0);
359
360 if (app_access(dirname, W_OK2) < 0) {
361 BIO_printf(bio_err, "Skipping %s, can't write\n", dirname);
362 return 1;
363 }
364 buflen = strlen(dirname);
365 pathsep = (buflen && !ends_with_dirsep(dirname)) ? "/": "";
366 buflen += NAME_MAX255 + 1 + 1;
367 buf = app_malloc(buflen, "filename buffer");
368
369 if (verbose)
370 BIO_printf(bio_out, "Doing %s\n", dirname);
371
372 if ((files = sk_OPENSSL_STRING_new_null()((struct stack_st_OPENSSL_STRING *)OPENSSL_sk_new_null())) == NULL((void*)0)) {
373 BIO_printf(bio_err, "Skipping %s, out of memory\n", dirname);
374 errs = 1;
375 goto err;
376 }
377 while ((filename = OPENSSL_DIR_read(&d, dirname)) != NULL((void*)0)) {
378 if ((copy = OPENSSL_strdup(filename)CRYPTO_strdup(filename, "../deps/openssl/openssl/apps/rehash.c"
, 378)
) == NULL((void*)0)
379 || sk_OPENSSL_STRING_push(files, copy)OPENSSL_sk_push(ossl_check_OPENSSL_STRING_sk_type(files), ossl_check_OPENSSL_STRING_type
(copy))
== 0) {
380 OPENSSL_free(copy)CRYPTO_free(copy, "../deps/openssl/openssl/apps/rehash.c", 380
)
;
381 BIO_puts(bio_err, "out of memory\n");
382 errs = 1;
383 goto err;
384 }
385 }
386 OPENSSL_DIR_end(&d);
387 sk_OPENSSL_STRING_sort(files)OPENSSL_sk_sort(ossl_check_OPENSSL_STRING_sk_type(files));
388
389 numfiles = sk_OPENSSL_STRING_num(files)OPENSSL_sk_num(ossl_check_const_OPENSSL_STRING_sk_type(files)
)
;
390 for (n = 0; n < numfiles; ++n) {
391 filename = sk_OPENSSL_STRING_value(files, n)((char *)OPENSSL_sk_value(ossl_check_const_OPENSSL_STRING_sk_type
(files), (n)))
;
392 if (BIO_snprintf(buf, buflen, "%s%s%s",
393 dirname, pathsep, filename) >= buflen)
394 continue;
395 if (lstat(buf, &st) < 0)
396 continue;
397 if (S_ISLNK(st.st_mode)((((st.st_mode)) & 0170000) == (0120000)) && handle_symlink(filename, buf) == 0)
398 continue;
399 errs += do_file(filename, buf, h);
400 }
401
402 for (i = 0; i < OSSL_NELEM(hash_table)(sizeof(hash_table)/sizeof((hash_table)[0])); i++) {
403 for (bp = hash_table[i]; bp; bp = nextbp) {
404 nextbp = bp->next;
405 nextid = 0;
406 memset(idmask, 0, (bp->num_needed + 7) / 8);
407 for (ep = bp->first_entry; ep; ep = ep->next)
408 if (ep->old_id < bp->num_needed)
409 bit_set(idmask, ep->old_id);
410
411 for (ep = bp->first_entry; ep; ep = nextep) {
412 nextep = ep->next;
413 if (ep->old_id < bp->num_needed) {
414 /* Link exists, and is used as-is */
415 BIO_snprintf(buf, buflen, "%08x.%s%d", bp->hash,
416 suffixes[bp->type], ep->old_id);
417 if (verbose)
418 BIO_printf(bio_out, "link %s -> %s\n",
419 ep->filename, buf);
420 } else if (ep->need_symlink) {
421 /* New link needed (it may replace something) */
422 while (bit_isset(idmask, nextid))
423 nextid++;
424
425 BIO_snprintf(buf, buflen, "%s%s%n%08x.%s%d",
426 dirname, pathsep, &n, bp->hash,
427 suffixes[bp->type], nextid);
428 if (verbose)
429 BIO_printf(bio_out, "link %s -> %s\n",
430 ep->filename, &buf[n]);
431 if (unlink(buf) < 0 && errno(*__errno_location ()) != ENOENT2) {
432 BIO_printf(bio_err,
433 "%s: Can't unlink %s, %s\n",
434 opt_getprog(), buf, strerror(errno(*__errno_location ())));
435 errs++;
436 }
437 if (symlink(ep->filename, buf) < 0) {
438 BIO_printf(bio_err,
439 "%s: Can't symlink %s, %s\n",
440 opt_getprog(), ep->filename,
441 strerror(errno(*__errno_location ())));
442 errs++;
443 }
444 bit_set(idmask, nextid);
445 } else if (remove_links) {
446 /* Link to be deleted */
447 BIO_snprintf(buf, buflen, "%s%s%n%08x.%s%d",
448 dirname, pathsep, &n, bp->hash,
449 suffixes[bp->type], ep->old_id);
450 if (verbose)
451 BIO_printf(bio_out, "unlink %s\n",
452 &buf[n]);
453 if (unlink(buf) < 0 && errno(*__errno_location ()) != ENOENT2) {
454 BIO_printf(bio_err,
455 "%s: Can't unlink %s, %s\n",
456 opt_getprog(), buf, strerror(errno(*__errno_location ())));
457 errs++;
458 }
459 }
460 OPENSSL_free(ep->filename)CRYPTO_free(ep->filename, "../deps/openssl/openssl/apps/rehash.c"
, 460)
;
461 OPENSSL_free(ep)CRYPTO_free(ep, "../deps/openssl/openssl/apps/rehash.c", 461);
462 }
463 OPENSSL_free(bp)CRYPTO_free(bp, "../deps/openssl/openssl/apps/rehash.c", 463);
464 }
465 hash_table[i] = NULL((void*)0);
466 }
467
468 err:
469 sk_OPENSSL_STRING_pop_free(files, str_free)OPENSSL_sk_pop_free(ossl_check_OPENSSL_STRING_sk_type(files),
ossl_check_OPENSSL_STRING_freefunc_type(str_free))
;
470 OPENSSL_free(buf)CRYPTO_free(buf, "../deps/openssl/openssl/apps/rehash.c", 470
)
;
471 return errs;
472}
473
474typedef enum OPTION_choice {
475 OPT_COMMONOPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
476 OPT_COMPAT, OPT_OLD, OPT_N, OPT_VERBOSE,
477 OPT_PROV_ENUMOPT_PROV__FIRST=1600, OPT_PROV_PROVIDER, OPT_PROV_PROVIDER_PATH
, OPT_PROV_PROPQUERY, OPT_PROV__LAST
478} OPTION_CHOICE;
479
480const OPTIONS rehash_options[] = {
481 {OPT_HELP_STR, 1, '-', "Usage: %s [options] [directory...]\n"},
482
483 OPT_SECTION("General"){ OPT_SECTION_STR, 1, '-', "General" " options:\n" },
484 {"help", OPT_HELP, '-', "Display this summary"},
485 {"h", OPT_HELP, '-', "Display this summary"},
486 {"compat", OPT_COMPAT, '-', "Create both new- and old-style hash links"},
487 {"old", OPT_OLD, '-', "Use old-style hash to generate links"},
488 {"n", OPT_N, '-', "Do not remove existing links"},
489
490 OPT_SECTION("Output"){ OPT_SECTION_STR, 1, '-', "Output" " options:\n" },
491 {"v", OPT_VERBOSE, '-', "Verbose output"},
492
493 OPT_PROV_OPTIONS{ OPT_SECTION_STR, 1, '-', "Provider" " options:\n" }, { "provider-path"
, OPT_PROV_PROVIDER_PATH, 's', "Provider load path (must be before 'provider' argument if required)"
}, { "provider", OPT_PROV_PROVIDER, 's', "Provider to load (can be specified multiple times)"
}, { "propquery", OPT_PROV_PROPQUERY, 's', "Property query used when fetching algorithms"
}
,
494
495 OPT_PARAMETERS(){ OPT_PARAM_STR, 1, '-', "Parameters:\n" },
496 {"directory", 0, 0, "One or more directories to process (optional)"},
497 {NULL((void*)0)}
498};
499
500
501int rehash_main(int argc, char **argv)
502{
503 const char *env, *prog;
504 char *e, *m;
505 int errs = 0;
506 OPTION_CHOICE o;
507 enum Hash h = HASH_NEW;
508
509 prog = opt_init(argc, argv, rehash_options);
510 while ((o = opt_next()) != OPT_EOF) {
511 switch (o) {
512 case OPT_EOF:
513 case OPT_ERR:
514 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
515 goto end;
516 case OPT_HELP:
517 opt_help(rehash_options);
518 goto end;
519 case OPT_COMPAT:
520 h = HASH_BOTH;
521 break;
522 case OPT_OLD:
523 h = HASH_OLD;
524 break;
525 case OPT_N:
526 remove_links = 0;
527 break;
528 case OPT_VERBOSE:
529 verbose = 1;
530 break;
531 case OPT_PROV_CASESOPT_PROV__FIRST: case OPT_PROV__LAST: break; case OPT_PROV_PROVIDER
: case OPT_PROV_PROVIDER_PATH: case OPT_PROV_PROPQUERY
:
532 if (!opt_provider(o))
533 goto end;
534 break;
535 }
536 }
537
538 /* Optional arguments are directories to scan. */
539 argc = opt_num_rest();
Value stored to 'argc' is never read
540 argv = opt_rest();
541
542 evpmd = EVP_sha1();
543 evpmdsize = EVP_MD_get_size(evpmd);
544
545 if (*argv != NULL((void*)0)) {
546 while (*argv != NULL((void*)0))
547 errs += do_dir(*argv++, h);
548 } else if ((env = getenv(X509_get_default_cert_dir_env())) != NULL((void*)0)) {
549 char lsc[2] = { LIST_SEPARATOR_CHAR':', '\0' };
550 m = OPENSSL_strdup(env)CRYPTO_strdup(env, "../deps/openssl/openssl/apps/rehash.c", 550
)
;
551 for (e = strtok(m, lsc); e != NULL((void*)0); e = strtok(NULL((void*)0), lsc))
552 errs += do_dir(e, h);
553 OPENSSL_free(m)CRYPTO_free(m, "../deps/openssl/openssl/apps/rehash.c", 553);
554 } else {
555 errs += do_dir(X509_get_default_cert_dir(), h);
556 }
557
558 end:
559 return errs;
560}
561
562#else
563const OPTIONS rehash_options[] = {
564 {NULL((void*)0)}
565};
566
567int rehash_main(int argc, char **argv)
568{
569 BIO_printf(bio_err, "Not available; use c_rehash script\n");
570 return 1;
571}
572
573#endif /* defined(OPENSSL_SYS_UNIX) || defined(__APPLE__) */