Fix strange formatting by indent
[oweals/openssl.git] / crypto / x509 / by_dir.c
index b4a21716f213321348c86f016fbf652e6a1dd339..671bd81d27ba42db9d7acdbd27e8133a1ff84eb2 100644 (file)
 #include <openssl/lhash.h>
 #include <openssl/x509.h>
 
+#ifdef _WIN32
+#define stat   _stat
+#endif
+
 typedef struct lookup_dir_st
        {
        BUF_MEM *buffer;
@@ -122,19 +126,18 @@ static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
                {
        case X509_L_ADD_DIR:
                if (argl == X509_FILETYPE_DEFAULT)
+                       {
                        dir=(char *)Getenv(X509_get_default_cert_dir_env());
                        if (dir)
-                       ret=add_cert_dir(ld,dir,X509_FILETYPE_PEM);
+                               ret=add_cert_dir(ld,dir,X509_FILETYPE_PEM);
                        else
-                       {
-                       ret=add_cert_dir(ld,X509_get_default_cert_dir(),
-                               X509_FILETYPE_PEM);
-                       }
+                               ret=add_cert_dir(ld,X509_get_default_cert_dir(),
+                                       X509_FILETYPE_PEM);
                        if (!ret)
                                {
                                X509err(X509_F_DIR_CTRL,X509_R_LOADING_CERT_DIR);
                                }
-
+                       }
                else
                        ret=add_cert_dir(ld,argp,(int)argl);
                break;
@@ -190,7 +193,7 @@ static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
 
        s=dir;
        p=s;
-       for (;;)
+       for (;;p++)
                {
                if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\0'))
                        {
@@ -199,8 +202,11 @@ static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
                        len=(int)(p-ss);
                        if (len == 0) continue;
                        for (j=0; j<ctx->num_dirs; j++)
-                               if (strncmp(ctx->dirs[j],ss,(unsigned int)len) == 0)
-                                       continue;
+                               if (strlen(ctx->dirs[j]) == (size_t)len &&
+                                   strncmp(ctx->dirs[j],ss,(unsigned int)len) == 0)
+                                       break;
+                       if (j<ctx->num_dirs)
+                               continue;
                        if (ctx->num_dirs_alloced < (ctx->num_dirs+1))
                                {
                                ctx->num_dirs_alloced+=10;
@@ -232,7 +238,6 @@ static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
                        ctx->num_dirs++;
                        }
                if (*p == '\0') break;
-               p++;
                }
        return(1);
        }
@@ -355,11 +360,11 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
 
                /* we have added it to the cache so now pull
                 * it out again */
-               CRYPTO_r_lock(CRYPTO_LOCK_X509_STORE);
+               CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
                j = sk_X509_OBJECT_find(xl->store_ctx->objs,&stmp);
                if(j != -1) tmp=sk_X509_OBJECT_value(xl->store_ctx->objs,j);
                else tmp = NULL;
-               CRYPTO_r_unlock(CRYPTO_LOCK_X509_STORE);
+               CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
 
                if (tmp != NULL)
                        {
@@ -369,7 +374,7 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
                        /* If we were going to up the reference count,
                         * we would need to do it on a perl 'type'
                         * basis */
-       /*              CRYPTO_add(&tmp->data.x509->references,1,
+       /*-             CRYPTO_add(&tmp->data.x509->references,1,
                                CRYPTO_LOCK_X509);*/
                        goto finish;
                        }
@@ -378,4 +383,3 @@ finish:
        if (b != NULL) BUF_MEM_free(b);
        return(ok);
        }
-