diff options
Diffstat (limited to 'src/lib/libcrypto/engine/eng_list.c')
-rw-r--r-- | src/lib/libcrypto/engine/eng_list.c | 307 |
1 files changed, 148 insertions, 159 deletions
diff --git a/src/lib/libcrypto/engine/eng_list.c b/src/lib/libcrypto/engine/eng_list.c index 05ed61a38a..053767c646 100644 --- a/src/lib/libcrypto/engine/eng_list.c +++ b/src/lib/libcrypto/engine/eng_list.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: eng_list.c,v 1.9 2014/06/12 15:49:29 deraadt Exp $ */ | 1 | /* $OpenBSD: eng_list.c,v 1.10 2014/06/22 12:15:53 jsing Exp $ */ |
2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | 2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL |
3 | * project 2000. | 3 | * project 2000. |
4 | */ | 4 | */ |
@@ -10,7 +10,7 @@ | |||
10 | * are met: | 10 | * are met: |
11 | * | 11 | * |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * | 14 | * |
15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
@@ -57,7 +57,7 @@ | |||
57 | */ | 57 | */ |
58 | /* ==================================================================== | 58 | /* ==================================================================== |
59 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 59 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
60 | * ECDH support in OpenSSL originally developed by | 60 | * ECDH support in OpenSSL originally developed by |
61 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | 61 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. |
62 | */ | 62 | */ |
63 | 63 | ||
@@ -79,71 +79,64 @@ static ENGINE *engine_list_tail = NULL; | |||
79 | /* This cleanup function is only needed internally. If it should be called, we | 79 | /* This cleanup function is only needed internally. If it should be called, we |
80 | * register it with the "ENGINE_cleanup()" stack to be called during cleanup. */ | 80 | * register it with the "ENGINE_cleanup()" stack to be called during cleanup. */ |
81 | 81 | ||
82 | static void engine_list_cleanup(void) | 82 | static void |
83 | { | 83 | engine_list_cleanup(void) |
84 | { | ||
84 | ENGINE *iterator = engine_list_head; | 85 | ENGINE *iterator = engine_list_head; |
85 | 86 | ||
86 | while(iterator != NULL) | 87 | while (iterator != NULL) { |
87 | { | ||
88 | ENGINE_remove(iterator); | 88 | ENGINE_remove(iterator); |
89 | iterator = engine_list_head; | 89 | iterator = engine_list_head; |
90 | } | ||
91 | return; | ||
92 | } | 90 | } |
91 | return; | ||
92 | } | ||
93 | 93 | ||
94 | /* These static functions starting with a lower case "engine_" always | 94 | /* These static functions starting with a lower case "engine_" always |
95 | * take place when CRYPTO_LOCK_ENGINE has been locked up. */ | 95 | * take place when CRYPTO_LOCK_ENGINE has been locked up. */ |
96 | static int engine_list_add(ENGINE *e) | 96 | static int |
97 | { | 97 | engine_list_add(ENGINE *e) |
98 | { | ||
98 | int conflict = 0; | 99 | int conflict = 0; |
99 | ENGINE *iterator = NULL; | 100 | ENGINE *iterator = NULL; |
100 | 101 | ||
101 | if(e == NULL) | 102 | if (e == NULL) { |
102 | { | ||
103 | ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, | 103 | ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, |
104 | ERR_R_PASSED_NULL_PARAMETER); | 104 | ERR_R_PASSED_NULL_PARAMETER); |
105 | return 0; | 105 | return 0; |
106 | } | 106 | } |
107 | iterator = engine_list_head; | 107 | iterator = engine_list_head; |
108 | while(iterator && !conflict) | 108 | while (iterator && !conflict) { |
109 | { | ||
110 | conflict = (strcmp(iterator->id, e->id) == 0); | 109 | conflict = (strcmp(iterator->id, e->id) == 0); |
111 | iterator = iterator->next; | 110 | iterator = iterator->next; |
112 | } | 111 | } |
113 | if(conflict) | 112 | if (conflict) { |
114 | { | ||
115 | ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, | 113 | ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, |
116 | ENGINE_R_CONFLICTING_ENGINE_ID); | 114 | ENGINE_R_CONFLICTING_ENGINE_ID); |
117 | return 0; | 115 | return 0; |
118 | } | 116 | } |
119 | if(engine_list_head == NULL) | 117 | if (engine_list_head == NULL) { |
120 | { | ||
121 | /* We are adding to an empty list. */ | 118 | /* We are adding to an empty list. */ |
122 | if(engine_list_tail) | 119 | if (engine_list_tail) { |
123 | { | ||
124 | ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, | 120 | ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, |
125 | ENGINE_R_INTERNAL_LIST_ERROR); | 121 | ENGINE_R_INTERNAL_LIST_ERROR); |
126 | return 0; | 122 | return 0; |
127 | } | 123 | } |
128 | engine_list_head = e; | 124 | engine_list_head = e; |
129 | e->prev = NULL; | 125 | e->prev = NULL; |
130 | /* The first time the list allocates, we should register the | 126 | /* The first time the list allocates, we should register the |
131 | * cleanup. */ | 127 | * cleanup. */ |
132 | engine_cleanup_add_last(engine_list_cleanup); | 128 | engine_cleanup_add_last(engine_list_cleanup); |
133 | } | 129 | } else { |
134 | else | ||
135 | { | ||
136 | /* We are adding to the tail of an existing list. */ | 130 | /* We are adding to the tail of an existing list. */ |
137 | if((engine_list_tail == NULL) || | 131 | if ((engine_list_tail == NULL) || |
138 | (engine_list_tail->next != NULL)) | 132 | (engine_list_tail->next != NULL)) { |
139 | { | ||
140 | ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, | 133 | ENGINEerr(ENGINE_F_ENGINE_LIST_ADD, |
141 | ENGINE_R_INTERNAL_LIST_ERROR); | 134 | ENGINE_R_INTERNAL_LIST_ERROR); |
142 | return 0; | 135 | return 0; |
143 | } | 136 | } |
144 | engine_list_tail->next = e; | 137 | engine_list_tail->next = e; |
145 | e->prev = engine_list_tail; | 138 | e->prev = engine_list_tail; |
146 | } | 139 | } |
147 | /* Having the engine in the list assumes a structural | 140 | /* Having the engine in the list assumes a structural |
148 | * reference. */ | 141 | * reference. */ |
149 | e->struct_ref++; | 142 | e->struct_ref++; |
@@ -152,169 +145,168 @@ static int engine_list_add(ENGINE *e) | |||
152 | engine_list_tail = e; | 145 | engine_list_tail = e; |
153 | e->next = NULL; | 146 | e->next = NULL; |
154 | return 1; | 147 | return 1; |
155 | } | 148 | } |
156 | 149 | ||
157 | static int engine_list_remove(ENGINE *e) | 150 | static int |
158 | { | 151 | engine_list_remove(ENGINE *e) |
152 | { | ||
159 | ENGINE *iterator; | 153 | ENGINE *iterator; |
160 | 154 | ||
161 | if(e == NULL) | 155 | if (e == NULL) { |
162 | { | ||
163 | ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE, | 156 | ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE, |
164 | ERR_R_PASSED_NULL_PARAMETER); | 157 | ERR_R_PASSED_NULL_PARAMETER); |
165 | return 0; | 158 | return 0; |
166 | } | 159 | } |
167 | /* We need to check that e is in our linked list! */ | 160 | /* We need to check that e is in our linked list! */ |
168 | iterator = engine_list_head; | 161 | iterator = engine_list_head; |
169 | while(iterator && (iterator != e)) | 162 | while (iterator && (iterator != e)) |
170 | iterator = iterator->next; | 163 | iterator = iterator->next; |
171 | if(iterator == NULL) | 164 | if (iterator == NULL) { |
172 | { | ||
173 | ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE, | 165 | ENGINEerr(ENGINE_F_ENGINE_LIST_REMOVE, |
174 | ENGINE_R_ENGINE_IS_NOT_IN_LIST); | 166 | ENGINE_R_ENGINE_IS_NOT_IN_LIST); |
175 | return 0; | 167 | return 0; |
176 | } | 168 | } |
177 | /* un-link e from the chain. */ | 169 | /* un-link e from the chain. */ |
178 | if(e->next) | 170 | if (e->next) |
179 | e->next->prev = e->prev; | 171 | e->next->prev = e->prev; |
180 | if(e->prev) | 172 | if (e->prev) |
181 | e->prev->next = e->next; | 173 | e->prev->next = e->next; |
182 | /* Correct our head/tail if necessary. */ | 174 | /* Correct our head/tail if necessary. */ |
183 | if(engine_list_head == e) | 175 | if (engine_list_head == e) |
184 | engine_list_head = e->next; | 176 | engine_list_head = e->next; |
185 | if(engine_list_tail == e) | 177 | if (engine_list_tail == e) |
186 | engine_list_tail = e->prev; | 178 | engine_list_tail = e->prev; |
187 | engine_free_util(e, 0); | 179 | engine_free_util(e, 0); |
188 | return 1; | 180 | return 1; |
189 | } | 181 | } |
190 | 182 | ||
191 | /* Get the first/last "ENGINE" type available. */ | 183 | /* Get the first/last "ENGINE" type available. */ |
192 | ENGINE *ENGINE_get_first(void) | 184 | ENGINE * |
193 | { | 185 | ENGINE_get_first(void) |
186 | { | ||
194 | ENGINE *ret; | 187 | ENGINE *ret; |
195 | 188 | ||
196 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | 189 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
197 | ret = engine_list_head; | 190 | ret = engine_list_head; |
198 | if(ret) | 191 | if (ret) { |
199 | { | ||
200 | ret->struct_ref++; | 192 | ret->struct_ref++; |
201 | engine_ref_debug(ret, 0, 1) | 193 | engine_ref_debug(ret, 0, 1) |
202 | } | 194 | } |
203 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | 195 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
204 | return ret; | 196 | return ret; |
205 | } | 197 | } |
206 | 198 | ||
207 | ENGINE *ENGINE_get_last(void) | 199 | ENGINE * |
208 | { | 200 | ENGINE_get_last(void) |
201 | { | ||
209 | ENGINE *ret; | 202 | ENGINE *ret; |
210 | 203 | ||
211 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | 204 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
212 | ret = engine_list_tail; | 205 | ret = engine_list_tail; |
213 | if(ret) | 206 | if (ret) { |
214 | { | ||
215 | ret->struct_ref++; | 207 | ret->struct_ref++; |
216 | engine_ref_debug(ret, 0, 1) | 208 | engine_ref_debug(ret, 0, 1) |
217 | } | 209 | } |
218 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | 210 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
219 | return ret; | 211 | return ret; |
220 | } | 212 | } |
221 | 213 | ||
222 | /* Iterate to the next/previous "ENGINE" type (NULL = end of the list). */ | 214 | /* Iterate to the next/previous "ENGINE" type (NULL = end of the list). */ |
223 | ENGINE *ENGINE_get_next(ENGINE *e) | 215 | ENGINE * |
224 | { | 216 | ENGINE_get_next(ENGINE *e) |
217 | { | ||
225 | ENGINE *ret = NULL; | 218 | ENGINE *ret = NULL; |
226 | if(e == NULL) | 219 | |
227 | { | 220 | if (e == NULL) { |
228 | ENGINEerr(ENGINE_F_ENGINE_GET_NEXT, | 221 | ENGINEerr(ENGINE_F_ENGINE_GET_NEXT, |
229 | ERR_R_PASSED_NULL_PARAMETER); | 222 | ERR_R_PASSED_NULL_PARAMETER); |
230 | return 0; | 223 | return 0; |
231 | } | 224 | } |
232 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | 225 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
233 | ret = e->next; | 226 | ret = e->next; |
234 | if(ret) | 227 | if (ret) { |
235 | { | ||
236 | /* Return a valid structural refernce to the next ENGINE */ | 228 | /* Return a valid structural refernce to the next ENGINE */ |
237 | ret->struct_ref++; | 229 | ret->struct_ref++; |
238 | engine_ref_debug(ret, 0, 1) | 230 | engine_ref_debug(ret, 0, 1) |
239 | } | 231 | } |
240 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | 232 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
241 | /* Release the structural reference to the previous ENGINE */ | 233 | /* Release the structural reference to the previous ENGINE */ |
242 | ENGINE_free(e); | 234 | ENGINE_free(e); |
243 | return ret; | 235 | return ret; |
244 | } | 236 | } |
245 | 237 | ||
246 | ENGINE *ENGINE_get_prev(ENGINE *e) | 238 | ENGINE * |
247 | { | 239 | ENGINE_get_prev(ENGINE *e) |
240 | { | ||
248 | ENGINE *ret = NULL; | 241 | ENGINE *ret = NULL; |
249 | if(e == NULL) | 242 | |
250 | { | 243 | if (e == NULL) { |
251 | ENGINEerr(ENGINE_F_ENGINE_GET_PREV, | 244 | ENGINEerr(ENGINE_F_ENGINE_GET_PREV, |
252 | ERR_R_PASSED_NULL_PARAMETER); | 245 | ERR_R_PASSED_NULL_PARAMETER); |
253 | return 0; | 246 | return 0; |
254 | } | 247 | } |
255 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | 248 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
256 | ret = e->prev; | 249 | ret = e->prev; |
257 | if(ret) | 250 | if (ret) { |
258 | { | ||
259 | /* Return a valid structural reference to the next ENGINE */ | 251 | /* Return a valid structural reference to the next ENGINE */ |
260 | ret->struct_ref++; | 252 | ret->struct_ref++; |
261 | engine_ref_debug(ret, 0, 1) | 253 | engine_ref_debug(ret, 0, 1) |
262 | } | 254 | } |
263 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | 255 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
264 | /* Release the structural reference to the previous ENGINE */ | 256 | /* Release the structural reference to the previous ENGINE */ |
265 | ENGINE_free(e); | 257 | ENGINE_free(e); |
266 | return ret; | 258 | return ret; |
267 | } | 259 | } |
268 | 260 | ||
269 | /* Add another "ENGINE" type into the list. */ | 261 | /* Add another "ENGINE" type into the list. */ |
270 | int ENGINE_add(ENGINE *e) | 262 | int |
271 | { | 263 | ENGINE_add(ENGINE *e) |
264 | { | ||
272 | int to_return = 1; | 265 | int to_return = 1; |
273 | if(e == NULL) | 266 | |
274 | { | 267 | if (e == NULL) { |
275 | ENGINEerr(ENGINE_F_ENGINE_ADD, | 268 | ENGINEerr(ENGINE_F_ENGINE_ADD, |
276 | ERR_R_PASSED_NULL_PARAMETER); | 269 | ERR_R_PASSED_NULL_PARAMETER); |
277 | return 0; | 270 | return 0; |
278 | } | 271 | } |
279 | if((e->id == NULL) || (e->name == NULL)) | 272 | if ((e->id == NULL) || (e->name == NULL)) { |
280 | { | ||
281 | ENGINEerr(ENGINE_F_ENGINE_ADD, | 273 | ENGINEerr(ENGINE_F_ENGINE_ADD, |
282 | ENGINE_R_ID_OR_NAME_MISSING); | 274 | ENGINE_R_ID_OR_NAME_MISSING); |
283 | } | 275 | } |
284 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | 276 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
285 | if(!engine_list_add(e)) | 277 | if (!engine_list_add(e)) { |
286 | { | ||
287 | ENGINEerr(ENGINE_F_ENGINE_ADD, | 278 | ENGINEerr(ENGINE_F_ENGINE_ADD, |
288 | ENGINE_R_INTERNAL_LIST_ERROR); | 279 | ENGINE_R_INTERNAL_LIST_ERROR); |
289 | to_return = 0; | 280 | to_return = 0; |
290 | } | 281 | } |
291 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | 282 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
292 | return to_return; | 283 | return to_return; |
293 | } | 284 | } |
294 | 285 | ||
295 | /* Remove an existing "ENGINE" type from the array. */ | 286 | /* Remove an existing "ENGINE" type from the array. */ |
296 | int ENGINE_remove(ENGINE *e) | 287 | int |
297 | { | 288 | ENGINE_remove(ENGINE *e) |
289 | { | ||
298 | int to_return = 1; | 290 | int to_return = 1; |
299 | if(e == NULL) | 291 | |
300 | { | 292 | if (e == NULL) { |
301 | ENGINEerr(ENGINE_F_ENGINE_REMOVE, | 293 | ENGINEerr(ENGINE_F_ENGINE_REMOVE, |
302 | ERR_R_PASSED_NULL_PARAMETER); | 294 | ERR_R_PASSED_NULL_PARAMETER); |
303 | return 0; | 295 | return 0; |
304 | } | 296 | } |
305 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | 297 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
306 | if(!engine_list_remove(e)) | 298 | if (!engine_list_remove(e)) { |
307 | { | ||
308 | ENGINEerr(ENGINE_F_ENGINE_REMOVE, | 299 | ENGINEerr(ENGINE_F_ENGINE_REMOVE, |
309 | ENGINE_R_INTERNAL_LIST_ERROR); | 300 | ENGINE_R_INTERNAL_LIST_ERROR); |
310 | to_return = 0; | 301 | to_return = 0; |
311 | } | 302 | } |
312 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | 303 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
313 | return to_return; | 304 | return to_return; |
314 | } | 305 | } |
315 | 306 | ||
316 | static void engine_cpy(ENGINE *dest, const ENGINE *src) | 307 | static void |
317 | { | 308 | engine_cpy(ENGINE *dest, const ENGINE *src) |
309 | { | ||
318 | dest->id = src->id; | 310 | dest->id = src->id; |
319 | dest->name = src->name; | 311 | dest->name = src->name; |
320 | #ifndef OPENSSL_NO_RSA | 312 | #ifndef OPENSSL_NO_RSA |
@@ -345,86 +337,83 @@ static void engine_cpy(ENGINE *dest, const ENGINE *src) | |||
345 | dest->load_pubkey = src->load_pubkey; | 337 | dest->load_pubkey = src->load_pubkey; |
346 | dest->cmd_defns = src->cmd_defns; | 338 | dest->cmd_defns = src->cmd_defns; |
347 | dest->flags = src->flags; | 339 | dest->flags = src->flags; |
348 | } | 340 | } |
349 | 341 | ||
350 | ENGINE *ENGINE_by_id(const char *id) | 342 | ENGINE * |
351 | { | 343 | ENGINE_by_id(const char *id) |
344 | { | ||
352 | ENGINE *iterator; | 345 | ENGINE *iterator; |
353 | char *load_dir = NULL; | 346 | char *load_dir = NULL; |
354 | if(id == NULL) | 347 | |
355 | { | 348 | if (id == NULL) { |
356 | ENGINEerr(ENGINE_F_ENGINE_BY_ID, | 349 | ENGINEerr(ENGINE_F_ENGINE_BY_ID, |
357 | ERR_R_PASSED_NULL_PARAMETER); | 350 | ERR_R_PASSED_NULL_PARAMETER); |
358 | return NULL; | 351 | return NULL; |
359 | } | 352 | } |
360 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | 353 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
361 | iterator = engine_list_head; | 354 | iterator = engine_list_head; |
362 | while(iterator && (strcmp(id, iterator->id) != 0)) | 355 | while (iterator && (strcmp(id, iterator->id) != 0)) |
363 | iterator = iterator->next; | 356 | iterator = iterator->next; |
364 | if(iterator) | 357 | if (iterator) { |
365 | { | ||
366 | /* We need to return a structural reference. If this is an | 358 | /* We need to return a structural reference. If this is an |
367 | * ENGINE type that returns copies, make a duplicate - otherwise | 359 | * ENGINE type that returns copies, make a duplicate - otherwise |
368 | * increment the existing ENGINE's reference count. */ | 360 | * increment the existing ENGINE's reference count. */ |
369 | if(iterator->flags & ENGINE_FLAGS_BY_ID_COPY) | 361 | if (iterator->flags & ENGINE_FLAGS_BY_ID_COPY) { |
370 | { | ||
371 | ENGINE *cp = ENGINE_new(); | 362 | ENGINE *cp = ENGINE_new(); |
372 | if(!cp) | 363 | if (!cp) |
373 | iterator = NULL; | 364 | iterator = NULL; |
374 | else | 365 | else { |
375 | { | ||
376 | engine_cpy(cp, iterator); | 366 | engine_cpy(cp, iterator); |
377 | iterator = cp; | 367 | iterator = cp; |
378 | } | ||
379 | } | 368 | } |
380 | else | 369 | } else { |
381 | { | ||
382 | iterator->struct_ref++; | 370 | iterator->struct_ref++; |
383 | engine_ref_debug(iterator, 0, 1) | 371 | engine_ref_debug(iterator, 0, 1) |
384 | } | ||
385 | } | 372 | } |
373 | } | ||
386 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | 374 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
387 | #if 0 | 375 | #if 0 |
388 | if(iterator == NULL) | 376 | if (iterator == NULL) { |
389 | { | ||
390 | ENGINEerr(ENGINE_F_ENGINE_BY_ID, | 377 | ENGINEerr(ENGINE_F_ENGINE_BY_ID, |
391 | ENGINE_R_NO_SUCH_ENGINE); | 378 | ENGINE_R_NO_SUCH_ENGINE); |
392 | ERR_asprintf_error_data("id=%s", id); | 379 | ERR_asprintf_error_data("id=%s", id); |
393 | } | 380 | } |
394 | return iterator; | 381 | return iterator; |
395 | #else | 382 | #else |
396 | /* EEK! Experimental code starts */ | 383 | /* EEK! Experimental code starts */ |
397 | if(iterator) return iterator; | 384 | if (iterator) |
385 | return iterator; | ||
398 | /* Prevent infinite recusrion if we're looking for the dynamic engine. */ | 386 | /* Prevent infinite recusrion if we're looking for the dynamic engine. */ |
399 | if (strcmp(id, "dynamic")) | 387 | if (strcmp(id, "dynamic")) { |
400 | { | 388 | if ((load_dir = getenv("OPENSSL_ENGINES")) == 0) |
401 | if((load_dir = getenv("OPENSSL_ENGINES")) == 0) load_dir = ENGINESDIR; | 389 | load_dir = ENGINESDIR; |
402 | iterator = ENGINE_by_id("dynamic"); | 390 | iterator = ENGINE_by_id("dynamic"); |
403 | if(!iterator || !ENGINE_ctrl_cmd_string(iterator, "ID", id, 0) || | 391 | if (!iterator || |
404 | !ENGINE_ctrl_cmd_string(iterator, "DIR_LOAD", "2", 0) || | 392 | !ENGINE_ctrl_cmd_string(iterator, "ID", id, 0) || |
405 | !ENGINE_ctrl_cmd_string(iterator, "DIR_ADD", | 393 | !ENGINE_ctrl_cmd_string(iterator, "DIR_LOAD", "2", 0) || |
406 | load_dir, 0) || | 394 | !ENGINE_ctrl_cmd_string(iterator, "DIR_ADD", load_dir, 0) || |
407 | !ENGINE_ctrl_cmd_string(iterator, "LIST_ADD", "1", 0) || | 395 | !ENGINE_ctrl_cmd_string(iterator, "LIST_ADD", "1", 0) || |
408 | !ENGINE_ctrl_cmd_string(iterator, "LOAD", NULL, 0)) | 396 | !ENGINE_ctrl_cmd_string(iterator, "LOAD", NULL, 0)) |
409 | goto notfound; | 397 | goto notfound; |
410 | return iterator; | 398 | return iterator; |
411 | } | 399 | } |
400 | |||
412 | notfound: | 401 | notfound: |
413 | ENGINE_free(iterator); | 402 | ENGINE_free(iterator); |
414 | ENGINEerr(ENGINE_F_ENGINE_BY_ID,ENGINE_R_NO_SUCH_ENGINE); | 403 | ENGINEerr(ENGINE_F_ENGINE_BY_ID, ENGINE_R_NO_SUCH_ENGINE); |
415 | ERR_asprintf_error_data("id=%s", id); | 404 | ERR_asprintf_error_data("id=%s", id); |
416 | return NULL; | 405 | return NULL; |
417 | /* EEK! Experimental code ends */ | 406 | /* EEK! Experimental code ends */ |
418 | #endif | 407 | #endif |
419 | } | 408 | } |
420 | 409 | ||
421 | int ENGINE_up_ref(ENGINE *e) | 410 | int |
422 | { | 411 | ENGINE_up_ref(ENGINE *e) |
423 | if (e == NULL) | 412 | { |
424 | { | 413 | if (e == NULL) { |
425 | ENGINEerr(ENGINE_F_ENGINE_UP_REF,ERR_R_PASSED_NULL_PARAMETER); | 414 | ENGINEerr(ENGINE_F_ENGINE_UP_REF, ERR_R_PASSED_NULL_PARAMETER); |
426 | return 0; | 415 | return 0; |
427 | } | ||
428 | CRYPTO_add(&e->struct_ref,1,CRYPTO_LOCK_ENGINE); | ||
429 | return 1; | ||
430 | } | 416 | } |
417 | CRYPTO_add(&e->struct_ref, 1, CRYPTO_LOCK_ENGINE); | ||
418 | return 1; | ||
419 | } | ||