Change dir_ctrl to check for the environment variable before using the default
[openssl.git] / crypto / x509 / by_dir.c
index c5920cc7dd9e4c5b029ea8f05fe4e3bf47a093f5..d56679177bf4451c86b87f5164b252967e81035c 100644 (file)
@@ -122,19 +122,19 @@ 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);
+                       else
                        {
                        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
-                               {
-                               dir=(char *)Getenv(X509_get_default_cert_dir_env());
-                               ret=add_cert_dir(ld,dir,X509_FILETYPE_PEM);
-                               }
-                       }
+
                else
                        ret=add_cert_dir(ld,argp,(int)argl);
                break;
@@ -302,8 +302,38 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
                k=0;
                for (;;)
                        {
-                       sprintf(b->data,"%s/%08lx.%s%d",ctx->dirs[i],h,
-                               postfix,k);
+                       char c = '/';
+#ifdef OPENSSL_SYS_VMS
+                       c = ctx->dirs[i][strlen(ctx->dirs[i])-1];
+                       if (c != ':' && c != '>' && c != ']')
+                               {
+                               /* If no separator is present, we assume the
+                                  directory specifier is a logical name, and
+                                  add a colon.  We really should use better
+                                  VMS routines for merging things like this,
+                                  but this will do for now...
+                                  -- Richard Levitte */
+                               c = ':';
+                               }
+                       else
+                               {
+                               c = '\0';
+                               }
+#endif
+                       if (c == '\0')
+                               {
+                               /* This is special.  When c == '\0', no
+                                  directory separator should be added. */
+                               BIO_snprintf(b->data,b->max,
+                                       "%s%08lx.%s%d",ctx->dirs[i],h,
+                                       postfix,k);
+                               }
+                       else
+                               {
+                               BIO_snprintf(b->data,b->max,
+                                       "%s%c%08lx.%s%d",ctx->dirs[i],c,h,
+                                       postfix,k);
+                               }
                        k++;
                        if (stat(b->data,&st) < 0)
                                break;
@@ -326,7 +356,9 @@ 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);
-               tmp=(X509_OBJECT *)lh_retrieve(xl->store_ctx->certs,&stmp);
+               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);
 
                if (tmp != NULL)