RT4033: Use OPENSSL_SYS_UNIX not "unix"
[openssl.git] / apps / rehash.c
index b235e1bf25da4462f0fa7d7920e5a37fee5b0397..c8bfb05b78200ea76629858002dce5149858da99 100644 (file)
@@ -59,7 +59,7 @@
 
 #include "apps.h"
 
-#if defined(unix) || defined(__APPLE__)
+#if defined(OPENSSL_SYS_UNIX) || defined(__APPLE__)
 # include <unistd.h>
 # include <stdio.h>
 # include <limits.h>
@@ -239,16 +239,17 @@ static int do_file(const char *filename, const char *fullpath, enum Hash h)
     BIO *b;
     const char *ext;
     unsigned char digest[EVP_MAX_MD_SIZE];
-    int i, type, errs = 0;
+    int type, errs = 0;
+    size_t i;
 
     /* Does it end with a recognized extension? */
     if ((ext = strrchr(filename, '.')) == NULL)
         goto end;
-    for (i = 0; i < (int)OSSL_NELEM(extensions); i++) {
+    for (i = 0; i < OSSL_NELEM(extensions); i++) {
         if (strcasecmp(extensions[i], ext + 1) == 0)
             break;
     }
-    if (i >= (int)OSSL_NELEM(extensions))
+    if (i >= OSSL_NELEM(extensions))
         goto end;
 
     /* Does it have X.509 data in it? */
@@ -280,6 +281,9 @@ static int do_file(const char *filename, const char *fullpath, enum Hash h)
         type = TYPE_CRL;
         name = X509_CRL_get_issuer(x->crl);
         X509_CRL_digest(x->crl, evpmd, digest, NULL);
+    } else {
+        ++errs;
+        goto end;
     }
     if (name) {
         if ((h == HASH_NEW) || (h == HASH_BOTH))
@@ -303,11 +307,16 @@ static int do_dir(const char *dirname, enum Hash h)
     OPENSSL_DIR_CTX *d = NULL;
     struct stat st;
     unsigned char idmask[MAX_COLLISIONS / 8];
-    int i, n, nextid, buflen, errs = 0;
+    int n, nextid, buflen, errs = 0;
+    size_t i;
     const char *pathsep;
     const char *filename;
     char *buf;
 
+    if (app_access(dirname, W_OK) < 0) {
+        BIO_printf(bio_err, "Skipping %s, can't write\n", dirname);
+        return 1;
+    }
     buflen = strlen(dirname);
     pathsep = (buflen && dirname[buflen - 1] == '/') ? "" : "/";
     buflen += NAME_MAX + 2;
@@ -328,7 +337,7 @@ static int do_dir(const char *dirname, enum Hash h)
     }
     OPENSSL_DIR_end(&d);
 
-    for (i = 0; i < (int)OSSL_NELEM(hash_table); i++) {
+    for (i = 0; i < OSSL_NELEM(hash_table); i++) {
         for (bp = hash_table[i]; bp; bp = nextbp) {
             nextbp = bp->next;
             nextid = 0;
@@ -479,4 +488,4 @@ int rehash_main(int argc, char **argv)
     return (1);
 }
 
-#endif /* defined(unix) || defined(__APPLE__) */
+#endif /* defined(OPENSSL_SYS_UNIX) || defined(__APPLE__) */