Source code cleanups: Use void * rather than char * in lhash,
[openssl.git] / crypto / x509 / by_dir.c
index 11725ec94c6e4e26facd6f8370e1cc72d66cfbe1..a81b1900d1e4ad1060b7d21b9b04327faca6d8ae 100644 (file)
 #include <stdio.h>
 #include <time.h>
 #include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 
 #include "cryptlib.h"
-#include "lhash.h"
-#include "x509.h"
-#include "pem.h"
+
+#ifndef NO_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef MAC_OS_pre_X
+# include <stat.h>
+#else
+# include <sys/stat.h>
+#endif
+
+#include <openssl/lhash.h>
+#include <openssl/x509.h>
 
 typedef struct lookup_dir_st
        {
@@ -76,21 +83,13 @@ typedef struct lookup_dir_st
        int num_dirs_alloced;
        } BY_DIR;
 
-#ifndef NOPROTO
-static int dir_ctrl(X509_LOOKUP *ctx,int cmd,char *argp,long argl,char **ret);
+static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
+       char **ret);
 static int new_dir(X509_LOOKUP *lu);
 static void free_dir(X509_LOOKUP *lu);
-static int add_cert_dir(BY_DIR *ctx,char *dir,int type);
+static int add_cert_dir(BY_DIR *ctx,const char *dir,int type);
 static int get_cert_by_subject(X509_LOOKUP *xl,int type,X509_NAME *name,
        X509_OBJECT *ret);
-#else
-static int dir_ctrl();
-static int new_dir();
-static void free_dir();
-static int add_cert_dir();
-static int get_cert_by_subject();
-#endif
-
 X509_LOOKUP_METHOD x509_dir_lookup=
        {
        "Load certs from files in a directory",
@@ -105,17 +104,13 @@ X509_LOOKUP_METHOD x509_dir_lookup=
        NULL,                   /* get_by_alias */
        };
 
-X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir()
+X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void)
        {
        return(&x509_dir_lookup);
        }
 
-static int dir_ctrl(ctx,cmd,argp,argl,retp)
-X509_LOOKUP *ctx;
-int cmd;
-long argl;
-char *argp;
-char **retp;
+static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
+            char **retp)
        {
        int ret=0;
        BY_DIR *ld;
@@ -147,8 +142,7 @@ char **retp;
        return(ret);
        }
 
-static int new_dir(lu)
-X509_LOOKUP *lu;
+static int new_dir(X509_LOOKUP *lu)
        {
        BY_DIR *a;
 
@@ -167,8 +161,7 @@ X509_LOOKUP *lu;
        return(1);
        }
 
-static void free_dir(lu)
-X509_LOOKUP *lu;
+static void free_dir(X509_LOOKUP *lu)
        {
        BY_DIR *a;
        int i;
@@ -182,17 +175,18 @@ X509_LOOKUP *lu;
        Free(a);
        }
 
-static int add_cert_dir(ctx,dir, type)
-BY_DIR *ctx;
-char *dir;
-int type;
+static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
        {
        int j,len;
        int *ip;
-       char *s,*ss,*p;
+       const char *s,*ss,*p;
        char **pp;
 
-       if (dir == NULL) return(0);
+       if (dir == NULL || !*dir)
+           {
+           X509err(X509_F_ADD_CERT_DIR,X509_R_INVALID_DIRECTORY);
+           return 0;
+           }
 
        s=dir;
        p=s;
@@ -243,11 +237,8 @@ int type;
        return(1);
        }
 
-static int get_cert_by_subject(xl,type,name,ret)
-X509_LOOKUP *xl;
-int type;
-X509_NAME *name;
-X509_OBJECT *ret;
+static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
+            X509_OBJECT *ret)
        {
        BY_DIR *ctx;
        union   {
@@ -266,7 +257,7 @@ X509_OBJECT *ret;
        BUF_MEM *b=NULL;
        struct stat st;
        X509_OBJECT stmp,*tmp;
-       char *postfix="";
+       const char *postfix="";
 
        if (name == NULL) return(0);
 
@@ -335,8 +326,7 @@ X509_OBJECT *ret;
                /* 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,
-                       (char *)&stmp);
+               tmp=(X509_OBJECT *)lh_retrieve(xl->store_ctx->certs,&stmp);
                CRYPTO_r_unlock(CRYPTO_LOCK_X509_STORE);
 
                if (tmp != NULL)