diff options
Diffstat (limited to 'src/lib/libcrypto/x509/by_dir.c')
-rw-r--r-- | src/lib/libcrypto/x509/by_dir.c | 96 |
1 files changed, 44 insertions, 52 deletions
diff --git a/src/lib/libcrypto/x509/by_dir.c b/src/lib/libcrypto/x509/by_dir.c index 11725ec94c..448bd7e69c 100644 --- a/src/lib/libcrypto/x509/by_dir.c +++ b/src/lib/libcrypto/x509/by_dir.c | |||
@@ -59,13 +59,20 @@ | |||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <time.h> | 60 | #include <time.h> |
61 | #include <errno.h> | 61 | #include <errno.h> |
62 | #include <sys/types.h> | ||
63 | #include <sys/stat.h> | ||
64 | 62 | ||
65 | #include "cryptlib.h" | 63 | #include "cryptlib.h" |
66 | #include "lhash.h" | 64 | |
67 | #include "x509.h" | 65 | #ifndef NO_SYS_TYPES_H |
68 | #include "pem.h" | 66 | # include <sys/types.h> |
67 | #endif | ||
68 | #ifdef MAC_OS_pre_X | ||
69 | # include <stat.h> | ||
70 | #else | ||
71 | # include <sys/stat.h> | ||
72 | #endif | ||
73 | |||
74 | #include <openssl/lhash.h> | ||
75 | #include <openssl/x509.h> | ||
69 | 76 | ||
70 | typedef struct lookup_dir_st | 77 | typedef struct lookup_dir_st |
71 | { | 78 | { |
@@ -76,21 +83,13 @@ typedef struct lookup_dir_st | |||
76 | int num_dirs_alloced; | 83 | int num_dirs_alloced; |
77 | } BY_DIR; | 84 | } BY_DIR; |
78 | 85 | ||
79 | #ifndef NOPROTO | 86 | static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, |
80 | static int dir_ctrl(X509_LOOKUP *ctx,int cmd,char *argp,long argl,char **ret); | 87 | char **ret); |
81 | static int new_dir(X509_LOOKUP *lu); | 88 | static int new_dir(X509_LOOKUP *lu); |
82 | static void free_dir(X509_LOOKUP *lu); | 89 | static void free_dir(X509_LOOKUP *lu); |
83 | static int add_cert_dir(BY_DIR *ctx,char *dir,int type); | 90 | static int add_cert_dir(BY_DIR *ctx,const char *dir,int type); |
84 | static int get_cert_by_subject(X509_LOOKUP *xl,int type,X509_NAME *name, | 91 | static int get_cert_by_subject(X509_LOOKUP *xl,int type,X509_NAME *name, |
85 | X509_OBJECT *ret); | 92 | X509_OBJECT *ret); |
86 | #else | ||
87 | static int dir_ctrl(); | ||
88 | static int new_dir(); | ||
89 | static void free_dir(); | ||
90 | static int add_cert_dir(); | ||
91 | static int get_cert_by_subject(); | ||
92 | #endif | ||
93 | |||
94 | X509_LOOKUP_METHOD x509_dir_lookup= | 93 | X509_LOOKUP_METHOD x509_dir_lookup= |
95 | { | 94 | { |
96 | "Load certs from files in a directory", | 95 | "Load certs from files in a directory", |
@@ -105,17 +104,13 @@ X509_LOOKUP_METHOD x509_dir_lookup= | |||
105 | NULL, /* get_by_alias */ | 104 | NULL, /* get_by_alias */ |
106 | }; | 105 | }; |
107 | 106 | ||
108 | X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir() | 107 | X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void) |
109 | { | 108 | { |
110 | return(&x509_dir_lookup); | 109 | return(&x509_dir_lookup); |
111 | } | 110 | } |
112 | 111 | ||
113 | static int dir_ctrl(ctx,cmd,argp,argl,retp) | 112 | static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, |
114 | X509_LOOKUP *ctx; | 113 | char **retp) |
115 | int cmd; | ||
116 | long argl; | ||
117 | char *argp; | ||
118 | char **retp; | ||
119 | { | 114 | { |
120 | int ret=0; | 115 | int ret=0; |
121 | BY_DIR *ld; | 116 | BY_DIR *ld; |
@@ -147,16 +142,15 @@ char **retp; | |||
147 | return(ret); | 142 | return(ret); |
148 | } | 143 | } |
149 | 144 | ||
150 | static int new_dir(lu) | 145 | static int new_dir(X509_LOOKUP *lu) |
151 | X509_LOOKUP *lu; | ||
152 | { | 146 | { |
153 | BY_DIR *a; | 147 | BY_DIR *a; |
154 | 148 | ||
155 | if ((a=(BY_DIR *)Malloc(sizeof(BY_DIR))) == NULL) | 149 | if ((a=(BY_DIR *)OPENSSL_malloc(sizeof(BY_DIR))) == NULL) |
156 | return(0); | 150 | return(0); |
157 | if ((a->buffer=BUF_MEM_new()) == NULL) | 151 | if ((a->buffer=BUF_MEM_new()) == NULL) |
158 | { | 152 | { |
159 | Free(a); | 153 | OPENSSL_free(a); |
160 | return(0); | 154 | return(0); |
161 | } | 155 | } |
162 | a->num_dirs=0; | 156 | a->num_dirs=0; |
@@ -167,32 +161,32 @@ X509_LOOKUP *lu; | |||
167 | return(1); | 161 | return(1); |
168 | } | 162 | } |
169 | 163 | ||
170 | static void free_dir(lu) | 164 | static void free_dir(X509_LOOKUP *lu) |
171 | X509_LOOKUP *lu; | ||
172 | { | 165 | { |
173 | BY_DIR *a; | 166 | BY_DIR *a; |
174 | int i; | 167 | int i; |
175 | 168 | ||
176 | a=(BY_DIR *)lu->method_data; | 169 | a=(BY_DIR *)lu->method_data; |
177 | for (i=0; i<a->num_dirs; i++) | 170 | for (i=0; i<a->num_dirs; i++) |
178 | if (a->dirs[i] != NULL) Free(a->dirs[i]); | 171 | if (a->dirs[i] != NULL) OPENSSL_free(a->dirs[i]); |
179 | if (a->dirs != NULL) Free(a->dirs); | 172 | if (a->dirs != NULL) OPENSSL_free(a->dirs); |
180 | if (a->dirs_type != NULL) Free(a->dirs_type); | 173 | if (a->dirs_type != NULL) OPENSSL_free(a->dirs_type); |
181 | if (a->buffer != NULL) BUF_MEM_free(a->buffer); | 174 | if (a->buffer != NULL) BUF_MEM_free(a->buffer); |
182 | Free(a); | 175 | OPENSSL_free(a); |
183 | } | 176 | } |
184 | 177 | ||
185 | static int add_cert_dir(ctx,dir, type) | 178 | static int add_cert_dir(BY_DIR *ctx, const char *dir, int type) |
186 | BY_DIR *ctx; | ||
187 | char *dir; | ||
188 | int type; | ||
189 | { | 179 | { |
190 | int j,len; | 180 | int j,len; |
191 | int *ip; | 181 | int *ip; |
192 | char *s,*ss,*p; | 182 | const char *s,*ss,*p; |
193 | char **pp; | 183 | char **pp; |
194 | 184 | ||
195 | if (dir == NULL) return(0); | 185 | if (dir == NULL || !*dir) |
186 | { | ||
187 | X509err(X509_F_ADD_CERT_DIR,X509_R_INVALID_DIRECTORY); | ||
188 | return 0; | ||
189 | } | ||
196 | 190 | ||
197 | s=dir; | 191 | s=dir; |
198 | p=s; | 192 | p=s; |
@@ -210,9 +204,9 @@ int type; | |||
210 | if (ctx->num_dirs_alloced < (ctx->num_dirs+1)) | 204 | if (ctx->num_dirs_alloced < (ctx->num_dirs+1)) |
211 | { | 205 | { |
212 | ctx->num_dirs_alloced+=10; | 206 | ctx->num_dirs_alloced+=10; |
213 | pp=(char **)Malloc(ctx->num_dirs_alloced* | 207 | pp=(char **)OPENSSL_malloc(ctx->num_dirs_alloced* |
214 | sizeof(char *)); | 208 | sizeof(char *)); |
215 | ip=(int *)Malloc(ctx->num_dirs_alloced* | 209 | ip=(int *)OPENSSL_malloc(ctx->num_dirs_alloced* |
216 | sizeof(int)); | 210 | sizeof(int)); |
217 | if ((pp == NULL) || (ip == NULL)) | 211 | if ((pp == NULL) || (ip == NULL)) |
218 | { | 212 | { |
@@ -224,14 +218,14 @@ int type; | |||
224 | memcpy(ip,ctx->dirs_type,(ctx->num_dirs_alloced-10)* | 218 | memcpy(ip,ctx->dirs_type,(ctx->num_dirs_alloced-10)* |
225 | sizeof(int)); | 219 | sizeof(int)); |
226 | if (ctx->dirs != NULL) | 220 | if (ctx->dirs != NULL) |
227 | Free((char *)ctx->dirs); | 221 | OPENSSL_free(ctx->dirs); |
228 | if (ctx->dirs_type != NULL) | 222 | if (ctx->dirs_type != NULL) |
229 | Free((char *)ctx->dirs_type); | 223 | OPENSSL_free(ctx->dirs_type); |
230 | ctx->dirs=pp; | 224 | ctx->dirs=pp; |
231 | ctx->dirs_type=ip; | 225 | ctx->dirs_type=ip; |
232 | } | 226 | } |
233 | ctx->dirs_type[ctx->num_dirs]=type; | 227 | ctx->dirs_type[ctx->num_dirs]=type; |
234 | ctx->dirs[ctx->num_dirs]=(char *)Malloc((unsigned int)len+1); | 228 | ctx->dirs[ctx->num_dirs]=(char *)OPENSSL_malloc((unsigned int)len+1); |
235 | if (ctx->dirs[ctx->num_dirs] == NULL) return(0); | 229 | if (ctx->dirs[ctx->num_dirs] == NULL) return(0); |
236 | strncpy(ctx->dirs[ctx->num_dirs],ss,(unsigned int)len); | 230 | strncpy(ctx->dirs[ctx->num_dirs],ss,(unsigned int)len); |
237 | ctx->dirs[ctx->num_dirs][len]='\0'; | 231 | ctx->dirs[ctx->num_dirs][len]='\0'; |
@@ -243,11 +237,8 @@ int type; | |||
243 | return(1); | 237 | return(1); |
244 | } | 238 | } |
245 | 239 | ||
246 | static int get_cert_by_subject(xl,type,name,ret) | 240 | static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, |
247 | X509_LOOKUP *xl; | 241 | X509_OBJECT *ret) |
248 | int type; | ||
249 | X509_NAME *name; | ||
250 | X509_OBJECT *ret; | ||
251 | { | 242 | { |
252 | BY_DIR *ctx; | 243 | BY_DIR *ctx; |
253 | union { | 244 | union { |
@@ -266,7 +257,7 @@ X509_OBJECT *ret; | |||
266 | BUF_MEM *b=NULL; | 257 | BUF_MEM *b=NULL; |
267 | struct stat st; | 258 | struct stat st; |
268 | X509_OBJECT stmp,*tmp; | 259 | X509_OBJECT stmp,*tmp; |
269 | char *postfix=""; | 260 | const char *postfix=""; |
270 | 261 | ||
271 | if (name == NULL) return(0); | 262 | if (name == NULL) return(0); |
272 | 263 | ||
@@ -335,8 +326,9 @@ X509_OBJECT *ret; | |||
335 | /* we have added it to the cache so now pull | 326 | /* we have added it to the cache so now pull |
336 | * it out again */ | 327 | * it out again */ |
337 | CRYPTO_r_lock(CRYPTO_LOCK_X509_STORE); | 328 | CRYPTO_r_lock(CRYPTO_LOCK_X509_STORE); |
338 | tmp=(X509_OBJECT *)lh_retrieve(xl->store_ctx->certs, | 329 | j = sk_X509_OBJECT_find(xl->store_ctx->objs,&stmp); |
339 | (char *)&stmp); | 330 | if(j != -1) tmp=sk_X509_OBJECT_value(xl->store_ctx->objs,j); |
331 | else tmp = NULL; | ||
340 | CRYPTO_r_unlock(CRYPTO_LOCK_X509_STORE); | 332 | CRYPTO_r_unlock(CRYPTO_LOCK_X509_STORE); |
341 | 333 | ||
342 | if (tmp != NULL) | 334 | if (tmp != NULL) |