diff options
Diffstat (limited to 'src/lib/libcrypto/conf/conf_mod.c')
-rw-r--r-- | src/lib/libcrypto/conf/conf_mod.c | 370 |
1 files changed, 182 insertions, 188 deletions
diff --git a/src/lib/libcrypto/conf/conf_mod.c b/src/lib/libcrypto/conf/conf_mod.c index af33451844..80266e43d8 100644 --- a/src/lib/libcrypto/conf/conf_mod.c +++ b/src/lib/libcrypto/conf/conf_mod.c | |||
@@ -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 |
@@ -74,20 +74,19 @@ | |||
74 | * static modules. | 74 | * static modules. |
75 | */ | 75 | */ |
76 | 76 | ||
77 | struct conf_module_st | 77 | struct conf_module_st { |
78 | { | ||
79 | /* DSO of this module or NULL if static */ | 78 | /* DSO of this module or NULL if static */ |
80 | DSO *dso; | 79 | DSO *dso; |
81 | /* Name of the module */ | 80 | /* Name of the module */ |
82 | char *name; | 81 | char *name; |
83 | /* Init function */ | 82 | /* Init function */ |
84 | conf_init_func *init; | 83 | conf_init_func *init; |
85 | /* Finish function */ | 84 | /* Finish function */ |
86 | conf_finish_func *finish; | 85 | conf_finish_func *finish; |
87 | /* Number of successfully initialized modules */ | 86 | /* Number of successfully initialized modules */ |
88 | int links; | 87 | int links; |
89 | void *usr_data; | 88 | void *usr_data; |
90 | }; | 89 | }; |
91 | 90 | ||
92 | 91 | ||
93 | /* This structure contains information about modules that have been | 92 | /* This structure contains information about modules that have been |
@@ -95,14 +94,13 @@ struct conf_module_st | |||
95 | * given module. | 94 | * given module. |
96 | */ | 95 | */ |
97 | 96 | ||
98 | struct conf_imodule_st | 97 | struct conf_imodule_st { |
99 | { | ||
100 | CONF_MODULE *pmod; | 98 | CONF_MODULE *pmod; |
101 | char *name; | 99 | char *name; |
102 | char *value; | 100 | char *value; |
103 | unsigned long flags; | 101 | unsigned long flags; |
104 | void *usr_data; | 102 | void *usr_data; |
105 | }; | 103 | }; |
106 | 104 | ||
107 | static STACK_OF(CONF_MODULE) *supported_modules = NULL; | 105 | static STACK_OF(CONF_MODULE) *supported_modules = NULL; |
108 | static STACK_OF(CONF_IMODULE) *initialized_modules = NULL; | 106 | static STACK_OF(CONF_IMODULE) *initialized_modules = NULL; |
@@ -110,20 +108,20 @@ static STACK_OF(CONF_IMODULE) *initialized_modules = NULL; | |||
110 | static void module_free(CONF_MODULE *md); | 108 | static void module_free(CONF_MODULE *md); |
111 | static void module_finish(CONF_IMODULE *imod); | 109 | static void module_finish(CONF_IMODULE *imod); |
112 | static int module_run(const CONF *cnf, char *name, char *value, | 110 | static int module_run(const CONF *cnf, char *name, char *value, |
113 | unsigned long flags); | 111 | unsigned long flags); |
114 | static CONF_MODULE *module_add(DSO *dso, const char *name, | 112 | static CONF_MODULE *module_add(DSO *dso, const char *name, |
115 | conf_init_func *ifunc, conf_finish_func *ffunc); | 113 | conf_init_func *ifunc, conf_finish_func *ffunc); |
116 | static CONF_MODULE *module_find(char *name); | 114 | static CONF_MODULE *module_find(char *name); |
117 | static int module_init(CONF_MODULE *pmod, char *name, char *value, | 115 | static int module_init(CONF_MODULE *pmod, char *name, char *value, |
118 | const CONF *cnf); | 116 | const CONF *cnf); |
119 | static CONF_MODULE *module_load_dso(const CONF *cnf, char *name, char *value, | 117 | static CONF_MODULE *module_load_dso(const CONF *cnf, char *name, char *value, |
120 | unsigned long flags); | 118 | unsigned long flags); |
121 | 119 | ||
122 | /* Main function: load modules from a CONF structure */ | 120 | /* Main function: load modules from a CONF structure */ |
123 | 121 | ||
124 | int CONF_modules_load(const CONF *cnf, const char *appname, | 122 | int |
125 | unsigned long flags) | 123 | CONF_modules_load(const CONF *cnf, const char *appname, unsigned long flags) |
126 | { | 124 | { |
127 | STACK_OF(CONF_VALUE) *values; | 125 | STACK_OF(CONF_VALUE) *values; |
128 | CONF_VALUE *vl; | 126 | CONF_VALUE *vl; |
129 | char *vsection = NULL; | 127 | char *vsection = NULL; |
@@ -139,33 +137,31 @@ int CONF_modules_load(const CONF *cnf, const char *appname, | |||
139 | if (!appname || (!vsection && (flags & CONF_MFLAGS_DEFAULT_SECTION))) | 137 | if (!appname || (!vsection && (flags & CONF_MFLAGS_DEFAULT_SECTION))) |
140 | vsection = NCONF_get_string(cnf, NULL, "openssl_conf"); | 138 | vsection = NCONF_get_string(cnf, NULL, "openssl_conf"); |
141 | 139 | ||
142 | if (!vsection) | 140 | if (!vsection) { |
143 | { | ||
144 | ERR_clear_error(); | 141 | ERR_clear_error(); |
145 | return 1; | 142 | return 1; |
146 | } | 143 | } |
147 | 144 | ||
148 | values = NCONF_get_section(cnf, vsection); | 145 | values = NCONF_get_section(cnf, vsection); |
149 | 146 | ||
150 | if (!values) | 147 | if (!values) |
151 | return 0; | 148 | return 0; |
152 | 149 | ||
153 | for (i = 0; i < sk_CONF_VALUE_num(values); i++) | 150 | for (i = 0; i < sk_CONF_VALUE_num(values); i++) { |
154 | { | ||
155 | vl = sk_CONF_VALUE_value(values, i); | 151 | vl = sk_CONF_VALUE_value(values, i); |
156 | ret = module_run(cnf, vl->name, vl->value, flags); | 152 | ret = module_run(cnf, vl->name, vl->value, flags); |
157 | if (ret <= 0) | 153 | if (ret <= 0) |
158 | if(!(flags & CONF_MFLAGS_IGNORE_ERRORS)) | 154 | if (!(flags & CONF_MFLAGS_IGNORE_ERRORS)) |
159 | return ret; | 155 | return ret; |
160 | } | 156 | } |
161 | 157 | ||
162 | return 1; | 158 | return 1; |
159 | } | ||
163 | 160 | ||
164 | } | 161 | int |
165 | 162 | CONF_modules_load_file(const char *filename, const char *appname, | |
166 | int CONF_modules_load_file(const char *filename, const char *appname, | 163 | unsigned long flags) |
167 | unsigned long flags) | 164 | { |
168 | { | ||
169 | char *file = NULL; | 165 | char *file = NULL; |
170 | CONF *conf = NULL; | 166 | CONF *conf = NULL; |
171 | int ret = 0; | 167 | int ret = 0; |
@@ -173,39 +169,36 @@ int CONF_modules_load_file(const char *filename, const char *appname, | |||
173 | if (!conf) | 169 | if (!conf) |
174 | goto err; | 170 | goto err; |
175 | 171 | ||
176 | if (filename == NULL) | 172 | if (filename == NULL) { |
177 | { | ||
178 | file = CONF_get1_default_config_file(); | 173 | file = CONF_get1_default_config_file(); |
179 | if (!file) | 174 | if (!file) |
180 | goto err; | 175 | goto err; |
181 | } | 176 | } else |
182 | else | ||
183 | file = (char *)filename; | 177 | file = (char *)filename; |
184 | 178 | ||
185 | if (NCONF_load(conf, file, NULL) <= 0) | 179 | if (NCONF_load(conf, file, NULL) <= 0) { |
186 | { | ||
187 | if ((flags & CONF_MFLAGS_IGNORE_MISSING_FILE) && | 180 | if ((flags & CONF_MFLAGS_IGNORE_MISSING_FILE) && |
188 | (ERR_GET_REASON(ERR_peek_last_error()) == CONF_R_NO_SUCH_FILE)) | 181 | (ERR_GET_REASON(ERR_peek_last_error()) == |
189 | { | 182 | CONF_R_NO_SUCH_FILE)) { |
190 | ERR_clear_error(); | 183 | ERR_clear_error(); |
191 | ret = 1; | 184 | ret = 1; |
192 | } | ||
193 | goto err; | ||
194 | } | 185 | } |
186 | goto err; | ||
187 | } | ||
195 | 188 | ||
196 | ret = CONF_modules_load(conf, appname, flags); | 189 | ret = CONF_modules_load(conf, appname, flags); |
197 | 190 | ||
198 | err: | 191 | err: |
199 | if (filename == NULL) | 192 | if (filename == NULL) |
200 | free(file); | 193 | free(file); |
201 | NCONF_free(conf); | 194 | NCONF_free(conf); |
202 | 195 | ||
203 | return ret; | 196 | return ret; |
204 | } | 197 | } |
205 | 198 | ||
206 | static int module_run(const CONF *cnf, char *name, char *value, | 199 | static int |
207 | unsigned long flags) | 200 | module_run(const CONF *cnf, char *name, char *value, unsigned long flags) |
208 | { | 201 | { |
209 | CONF_MODULE *md; | 202 | CONF_MODULE *md; |
210 | int ret; | 203 | int ret; |
211 | 204 | ||
@@ -215,62 +208,58 @@ static int module_run(const CONF *cnf, char *name, char *value, | |||
215 | if (!md && !(flags & CONF_MFLAGS_NO_DSO)) | 208 | if (!md && !(flags & CONF_MFLAGS_NO_DSO)) |
216 | md = module_load_dso(cnf, name, value, flags); | 209 | md = module_load_dso(cnf, name, value, flags); |
217 | 210 | ||
218 | if (!md) | 211 | if (!md) { |
219 | { | 212 | if (!(flags & CONF_MFLAGS_SILENT)) { |
220 | if (!(flags & CONF_MFLAGS_SILENT)) | ||
221 | { | ||
222 | CONFerr(CONF_F_MODULE_RUN, CONF_R_UNKNOWN_MODULE_NAME); | 213 | CONFerr(CONF_F_MODULE_RUN, CONF_R_UNKNOWN_MODULE_NAME); |
223 | ERR_add_error_data(2, "module=", name); | 214 | ERR_add_error_data(2, "module=", name); |
224 | } | ||
225 | return -1; | ||
226 | } | 215 | } |
216 | return -1; | ||
217 | } | ||
227 | 218 | ||
228 | ret = module_init(md, name, value, cnf); | 219 | ret = module_init(md, name, value, cnf); |
229 | 220 | ||
230 | if (ret <= 0) | 221 | if (ret <= 0) { |
231 | { | 222 | if (!(flags & CONF_MFLAGS_SILENT)) { |
232 | if (!(flags & CONF_MFLAGS_SILENT)) | 223 | char rcode[DECIMAL_SIZE(ret) + 1]; |
233 | { | 224 | CONFerr(CONF_F_MODULE_RUN, |
234 | char rcode[DECIMAL_SIZE(ret)+1]; | 225 | CONF_R_MODULE_INITIALIZATION_ERROR); |
235 | CONFerr(CONF_F_MODULE_RUN, CONF_R_MODULE_INITIALIZATION_ERROR); | ||
236 | snprintf(rcode, sizeof rcode, "%-8d", ret); | 226 | snprintf(rcode, sizeof rcode, "%-8d", ret); |
237 | ERR_add_error_data(6, "module=", name, ", value=", value, ", retcode=", rcode); | 227 | ERR_add_error_data(6, "module=", name, ", value=", |
238 | } | 228 | value, ", retcode=", rcode); |
239 | } | 229 | } |
230 | } | ||
240 | 231 | ||
241 | return ret; | 232 | return ret; |
242 | } | 233 | } |
243 | 234 | ||
244 | /* Load a module from a DSO */ | 235 | /* Load a module from a DSO */ |
245 | static CONF_MODULE *module_load_dso(const CONF *cnf, char *name, char *value, | 236 | static CONF_MODULE * |
246 | unsigned long flags) | 237 | module_load_dso(const CONF *cnf, char *name, char *value, unsigned long flags) |
247 | { | 238 | { |
248 | DSO *dso = NULL; | 239 | DSO *dso = NULL; |
249 | conf_init_func *ifunc; | 240 | conf_init_func *ifunc; |
250 | conf_finish_func *ffunc; | 241 | conf_finish_func *ffunc; |
251 | char *path = NULL; | 242 | char *path = NULL; |
252 | int errcode = 0; | 243 | int errcode = 0; |
253 | CONF_MODULE *md; | 244 | CONF_MODULE *md; |
245 | |||
254 | /* Look for alternative path in module section */ | 246 | /* Look for alternative path in module section */ |
255 | path = NCONF_get_string(cnf, value, "path"); | 247 | path = NCONF_get_string(cnf, value, "path"); |
256 | if (!path) | 248 | if (!path) { |
257 | { | ||
258 | ERR_clear_error(); | 249 | ERR_clear_error(); |
259 | path = name; | 250 | path = name; |
260 | } | 251 | } |
261 | dso = DSO_load(NULL, path, NULL, 0); | 252 | dso = DSO_load(NULL, path, NULL, 0); |
262 | if (!dso) | 253 | if (!dso) { |
263 | { | ||
264 | errcode = CONF_R_ERROR_LOADING_DSO; | 254 | errcode = CONF_R_ERROR_LOADING_DSO; |
265 | goto err; | 255 | goto err; |
266 | } | 256 | } |
267 | ifunc = (conf_init_func *)DSO_bind_func(dso, DSO_mod_init_name); | 257 | ifunc = (conf_init_func *)DSO_bind_func(dso, DSO_mod_init_name); |
268 | if (!ifunc) | 258 | if (!ifunc) { |
269 | { | ||
270 | errcode = CONF_R_MISSING_INIT_FUNCTION; | 259 | errcode = CONF_R_MISSING_INIT_FUNCTION; |
271 | goto err; | 260 | goto err; |
272 | } | 261 | } |
273 | ffunc = (conf_finish_func *)DSO_bind_func(dso, DSO_mod_finish_name); | 262 | ffunc = (conf_finish_func *)DSO_bind_func(dso, DSO_mod_finish_name); |
274 | /* All OK, add module */ | 263 | /* All OK, add module */ |
275 | md = module_add(dso, name, ifunc, ffunc); | 264 | md = module_add(dso, name, ifunc, ffunc); |
276 | 265 | ||
@@ -279,19 +268,21 @@ static CONF_MODULE *module_load_dso(const CONF *cnf, char *name, char *value, | |||
279 | 268 | ||
280 | return md; | 269 | return md; |
281 | 270 | ||
282 | err: | 271 | err: |
283 | if (dso) | 272 | if (dso) |
284 | DSO_free(dso); | 273 | DSO_free(dso); |
285 | CONFerr(CONF_F_MODULE_LOAD_DSO, errcode); | 274 | CONFerr(CONF_F_MODULE_LOAD_DSO, errcode); |
286 | ERR_add_error_data(4, "module=", name, ", path=", path); | 275 | ERR_add_error_data(4, "module=", name, ", path=", path); |
287 | return NULL; | 276 | return NULL; |
288 | } | 277 | } |
289 | 278 | ||
290 | /* add module to list */ | 279 | /* add module to list */ |
291 | static CONF_MODULE *module_add(DSO *dso, const char *name, | 280 | static CONF_MODULE * |
292 | conf_init_func *ifunc, conf_finish_func *ffunc) | 281 | module_add(DSO *dso, const char *name, conf_init_func *ifunc, |
293 | { | 282 | conf_finish_func *ffunc) |
283 | { | ||
294 | CONF_MODULE *tmod = NULL; | 284 | CONF_MODULE *tmod = NULL; |
285 | |||
295 | if (supported_modules == NULL) | 286 | if (supported_modules == NULL) |
296 | supported_modules = sk_CONF_MODULE_new_null(); | 287 | supported_modules = sk_CONF_MODULE_new_null(); |
297 | if (supported_modules == NULL) | 288 | if (supported_modules == NULL) |
@@ -306,47 +297,46 @@ static CONF_MODULE *module_add(DSO *dso, const char *name, | |||
306 | tmod->finish = ffunc; | 297 | tmod->finish = ffunc; |
307 | tmod->links = 0; | 298 | tmod->links = 0; |
308 | 299 | ||
309 | if (!sk_CONF_MODULE_push(supported_modules, tmod)) | 300 | if (!sk_CONF_MODULE_push(supported_modules, tmod)) { |
310 | { | ||
311 | free(tmod); | 301 | free(tmod); |
312 | return NULL; | 302 | return NULL; |
313 | } | 303 | } |
314 | 304 | ||
315 | return tmod; | 305 | return tmod; |
316 | } | 306 | } |
317 | 307 | ||
318 | /* Find a module from the list. We allow module names of the | 308 | /* Find a module from the list. We allow module names of the |
319 | * form modname.XXXX to just search for modname to allow the | 309 | * form modname.XXXX to just search for modname to allow the |
320 | * same module to be initialized more than once. | 310 | * same module to be initialized more than once. |
321 | */ | 311 | */ |
322 | 312 | ||
323 | static CONF_MODULE *module_find(char *name) | 313 | static CONF_MODULE * |
324 | { | 314 | module_find(char *name) |
315 | { | ||
325 | CONF_MODULE *tmod; | 316 | CONF_MODULE *tmod; |
326 | int i, nchar; | 317 | int i, nchar; |
327 | char *p; | 318 | char *p; |
319 | |||
328 | p = strrchr(name, '.'); | 320 | p = strrchr(name, '.'); |
329 | 321 | ||
330 | if (p) | 322 | if (p) |
331 | nchar = p - name; | 323 | nchar = p - name; |
332 | else | 324 | else |
333 | nchar = strlen(name); | 325 | nchar = strlen(name); |
334 | 326 | ||
335 | for (i = 0; i < sk_CONF_MODULE_num(supported_modules); i++) | 327 | for (i = 0; i < sk_CONF_MODULE_num(supported_modules); i++) { |
336 | { | ||
337 | tmod = sk_CONF_MODULE_value(supported_modules, i); | 328 | tmod = sk_CONF_MODULE_value(supported_modules, i); |
338 | if (!strncmp(tmod->name, name, nchar)) | 329 | if (!strncmp(tmod->name, name, nchar)) |
339 | return tmod; | 330 | return tmod; |
340 | } | 331 | } |
341 | 332 | ||
342 | return NULL; | 333 | return NULL; |
343 | 334 | } | |
344 | } | ||
345 | 335 | ||
346 | /* initialize a module */ | 336 | /* initialize a module */ |
347 | static int module_init(CONF_MODULE *pmod, char *name, char *value, | 337 | static int |
348 | const CONF *cnf) | 338 | module_init(CONF_MODULE *pmod, char *name, char *value, const CONF *cnf) |
349 | { | 339 | { |
350 | int ret = 1; | 340 | int ret = 1; |
351 | int init_called = 0; | 341 | int init_called = 0; |
352 | CONF_IMODULE *imod = NULL; | 342 | CONF_IMODULE *imod = NULL; |
@@ -365,68 +355,63 @@ static int module_init(CONF_MODULE *pmod, char *name, char *value, | |||
365 | goto memerr; | 355 | goto memerr; |
366 | 356 | ||
367 | /* Try to initialize module */ | 357 | /* Try to initialize module */ |
368 | if(pmod->init) | 358 | if (pmod->init) { |
369 | { | ||
370 | ret = pmod->init(imod, cnf); | 359 | ret = pmod->init(imod, cnf); |
371 | init_called = 1; | 360 | init_called = 1; |
372 | /* Error occurred, exit */ | 361 | /* Error occurred, exit */ |
373 | if (ret <= 0) | 362 | if (ret <= 0) |
374 | goto err; | 363 | goto err; |
375 | } | 364 | } |
376 | 365 | ||
377 | if (initialized_modules == NULL) | 366 | if (initialized_modules == NULL) { |
378 | { | ||
379 | initialized_modules = sk_CONF_IMODULE_new_null(); | 367 | initialized_modules = sk_CONF_IMODULE_new_null(); |
380 | if (!initialized_modules) | 368 | if (!initialized_modules) { |
381 | { | ||
382 | CONFerr(CONF_F_MODULE_INIT, ERR_R_MALLOC_FAILURE); | 369 | CONFerr(CONF_F_MODULE_INIT, ERR_R_MALLOC_FAILURE); |
383 | goto err; | 370 | goto err; |
384 | } | ||
385 | } | 371 | } |
372 | } | ||
386 | 373 | ||
387 | if (!sk_CONF_IMODULE_push(initialized_modules, imod)) | 374 | if (!sk_CONF_IMODULE_push(initialized_modules, imod)) { |
388 | { | ||
389 | CONFerr(CONF_F_MODULE_INIT, ERR_R_MALLOC_FAILURE); | 375 | CONFerr(CONF_F_MODULE_INIT, ERR_R_MALLOC_FAILURE); |
390 | goto err; | 376 | goto err; |
391 | } | 377 | } |
392 | 378 | ||
393 | pmod->links++; | 379 | pmod->links++; |
394 | 380 | ||
395 | return ret; | 381 | return ret; |
396 | 382 | ||
397 | err: | 383 | err: |
398 | |||
399 | /* We've started the module so we'd better finish it */ | 384 | /* We've started the module so we'd better finish it */ |
400 | if (pmod->finish && init_called) | 385 | if (pmod->finish && init_called) |
401 | pmod->finish(imod); | 386 | pmod->finish(imod); |
402 | 387 | ||
403 | memerr: | 388 | memerr: |
404 | if (imod) | 389 | if (imod) { |
405 | { | ||
406 | if (imod->name) | 390 | if (imod->name) |
407 | free(imod->name); | 391 | free(imod->name); |
408 | if (imod->value) | 392 | if (imod->value) |
409 | free(imod->value); | 393 | free(imod->value); |
410 | free(imod); | 394 | free(imod); |
411 | } | 395 | } |
412 | 396 | ||
413 | return -1; | 397 | return -1; |
414 | 398 | } | |
415 | } | ||
416 | 399 | ||
417 | /* Unload any dynamic modules that have a link count of zero: | 400 | /* Unload any dynamic modules that have a link count of zero: |
418 | * i.e. have no active initialized modules. If 'all' is set | 401 | * i.e. have no active initialized modules. If 'all' is set |
419 | * then all modules are unloaded including static ones. | 402 | * then all modules are unloaded including static ones. |
420 | */ | 403 | */ |
421 | 404 | ||
422 | void CONF_modules_unload(int all) | 405 | void |
423 | { | 406 | CONF_modules_unload(int all) |
407 | { | ||
424 | int i; | 408 | int i; |
425 | CONF_MODULE *md; | 409 | CONF_MODULE *md; |
410 | |||
426 | CONF_modules_finish(); | 411 | CONF_modules_finish(); |
412 | |||
427 | /* unload modules in reverse order */ | 413 | /* unload modules in reverse order */ |
428 | for (i = sk_CONF_MODULE_num(supported_modules) - 1; i >= 0; i--) | 414 | for (i = sk_CONF_MODULE_num(supported_modules) - 1; i >= 0; i--) { |
429 | { | ||
430 | md = sk_CONF_MODULE_value(supported_modules, i); | 415 | md = sk_CONF_MODULE_value(supported_modules, i); |
431 | /* If static or in use and 'all' not set ignore it */ | 416 | /* If static or in use and 'all' not set ignore it */ |
432 | if (((md->links > 0) || !md->dso) && !all) | 417 | if (((md->links > 0) || !md->dso) && !all) |
@@ -434,112 +419,125 @@ void CONF_modules_unload(int all) | |||
434 | /* Since we're working in reverse this is OK */ | 419 | /* Since we're working in reverse this is OK */ |
435 | (void)sk_CONF_MODULE_delete(supported_modules, i); | 420 | (void)sk_CONF_MODULE_delete(supported_modules, i); |
436 | module_free(md); | 421 | module_free(md); |
437 | } | 422 | } |
438 | if (sk_CONF_MODULE_num(supported_modules) == 0) | 423 | if (sk_CONF_MODULE_num(supported_modules) == 0) { |
439 | { | ||
440 | sk_CONF_MODULE_free(supported_modules); | 424 | sk_CONF_MODULE_free(supported_modules); |
441 | supported_modules = NULL; | 425 | supported_modules = NULL; |
442 | } | ||
443 | } | 426 | } |
427 | } | ||
444 | 428 | ||
445 | /* unload a single module */ | 429 | /* unload a single module */ |
446 | static void module_free(CONF_MODULE *md) | 430 | static void |
447 | { | 431 | module_free(CONF_MODULE *md) |
432 | { | ||
448 | if (md->dso) | 433 | if (md->dso) |
449 | DSO_free(md->dso); | 434 | DSO_free(md->dso); |
450 | free(md->name); | 435 | free(md->name); |
451 | free(md); | 436 | free(md); |
452 | } | 437 | } |
453 | 438 | ||
454 | /* finish and free up all modules instances */ | 439 | /* finish and free up all modules instances */ |
455 | 440 | ||
456 | void CONF_modules_finish(void) | 441 | void |
457 | { | 442 | CONF_modules_finish(void) |
443 | { | ||
458 | CONF_IMODULE *imod; | 444 | CONF_IMODULE *imod; |
459 | while (sk_CONF_IMODULE_num(initialized_modules) > 0) | 445 | |
460 | { | 446 | while (sk_CONF_IMODULE_num(initialized_modules) > 0) { |
461 | imod = sk_CONF_IMODULE_pop(initialized_modules); | 447 | imod = sk_CONF_IMODULE_pop(initialized_modules); |
462 | module_finish(imod); | 448 | module_finish(imod); |
463 | } | 449 | } |
464 | sk_CONF_IMODULE_free(initialized_modules); | 450 | sk_CONF_IMODULE_free(initialized_modules); |
465 | initialized_modules = NULL; | 451 | initialized_modules = NULL; |
466 | } | 452 | } |
467 | 453 | ||
468 | /* finish a module instance */ | 454 | /* finish a module instance */ |
469 | 455 | ||
470 | static void module_finish(CONF_IMODULE *imod) | 456 | static void |
471 | { | 457 | module_finish(CONF_IMODULE *imod) |
458 | { | ||
472 | if (imod->pmod->finish) | 459 | if (imod->pmod->finish) |
473 | imod->pmod->finish(imod); | 460 | imod->pmod->finish(imod); |
474 | imod->pmod->links--; | 461 | imod->pmod->links--; |
475 | free(imod->name); | 462 | free(imod->name); |
476 | free(imod->value); | 463 | free(imod->value); |
477 | free(imod); | 464 | free(imod); |
478 | } | 465 | } |
479 | 466 | ||
480 | /* Add a static module to OpenSSL */ | 467 | /* Add a static module to OpenSSL */ |
481 | 468 | ||
482 | int CONF_module_add(const char *name, conf_init_func *ifunc, | 469 | int |
483 | conf_finish_func *ffunc) | 470 | CONF_module_add(const char *name, conf_init_func *ifunc, |
484 | { | 471 | conf_finish_func *ffunc) |
472 | { | ||
485 | if (module_add(NULL, name, ifunc, ffunc)) | 473 | if (module_add(NULL, name, ifunc, ffunc)) |
486 | return 1; | 474 | return 1; |
487 | else | 475 | else |
488 | return 0; | 476 | return 0; |
489 | } | 477 | } |
490 | 478 | ||
491 | void CONF_modules_free(void) | 479 | void |
492 | { | 480 | CONF_modules_free(void) |
481 | { | ||
493 | CONF_modules_finish(); | 482 | CONF_modules_finish(); |
494 | CONF_modules_unload(1); | 483 | CONF_modules_unload(1); |
495 | } | 484 | } |
496 | 485 | ||
497 | /* Utility functions */ | 486 | /* Utility functions */ |
498 | 487 | ||
499 | const char *CONF_imodule_get_name(const CONF_IMODULE *md) | 488 | const char * |
500 | { | 489 | CONF_imodule_get_name(const CONF_IMODULE *md) |
490 | { | ||
501 | return md->name; | 491 | return md->name; |
502 | } | 492 | } |
503 | 493 | ||
504 | const char *CONF_imodule_get_value(const CONF_IMODULE *md) | 494 | const char * |
505 | { | 495 | CONF_imodule_get_value(const CONF_IMODULE *md) |
496 | { | ||
506 | return md->value; | 497 | return md->value; |
507 | } | 498 | } |
508 | 499 | ||
509 | void *CONF_imodule_get_usr_data(const CONF_IMODULE *md) | 500 | void * |
510 | { | 501 | CONF_imodule_get_usr_data(const CONF_IMODULE *md) |
502 | { | ||
511 | return md->usr_data; | 503 | return md->usr_data; |
512 | } | 504 | } |
513 | 505 | ||
514 | void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data) | 506 | void |
515 | { | 507 | CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data) |
508 | { | ||
516 | md->usr_data = usr_data; | 509 | md->usr_data = usr_data; |
517 | } | 510 | } |
518 | 511 | ||
519 | CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md) | 512 | CONF_MODULE * |
520 | { | 513 | CONF_imodule_get_module(const CONF_IMODULE *md) |
514 | { | ||
521 | return md->pmod; | 515 | return md->pmod; |
522 | } | 516 | } |
523 | 517 | ||
524 | unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md) | 518 | unsigned long |
525 | { | 519 | CONF_imodule_get_flags(const CONF_IMODULE *md) |
520 | { | ||
526 | return md->flags; | 521 | return md->flags; |
527 | } | 522 | } |
528 | 523 | ||
529 | void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags) | 524 | void |
530 | { | 525 | CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags) |
526 | { | ||
531 | md->flags = flags; | 527 | md->flags = flags; |
532 | } | 528 | } |
533 | 529 | ||
534 | void *CONF_module_get_usr_data(CONF_MODULE *pmod) | 530 | void * |
535 | { | 531 | CONF_module_get_usr_data(CONF_MODULE *pmod) |
532 | { | ||
536 | return pmod->usr_data; | 533 | return pmod->usr_data; |
537 | } | 534 | } |
538 | 535 | ||
539 | void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data) | 536 | void |
540 | { | 537 | CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data) |
538 | { | ||
541 | pmod->usr_data = usr_data; | 539 | pmod->usr_data = usr_data; |
542 | } | 540 | } |
543 | 541 | ||
544 | /* Return default config file name */ | 542 | /* Return default config file name */ |
545 | 543 | ||
@@ -549,9 +547,10 @@ CONF_get1_default_config_file(void) | |||
549 | char *file; | 547 | char *file; |
550 | 548 | ||
551 | file = getenv("OPENSSL_CONF"); | 549 | file = getenv("OPENSSL_CONF"); |
552 | if (file) | 550 | if (file) |
553 | return BUF_strdup(file); | 551 | return BUF_strdup(file); |
554 | if (asprintf(&file, "%s/openssl.cnf", X509_get_default_cert_area()) == -1) | 552 | if (asprintf(&file, "%s/openssl.cnf", |
553 | X509_get_default_cert_area()) == -1) | ||
555 | return (NULL); | 554 | return (NULL); |
556 | return file; | 555 | return file; |
557 | } | 556 | } |
@@ -562,47 +561,42 @@ CONF_get1_default_config_file(void) | |||
562 | * be used to parse comma separated lists for example. | 561 | * be used to parse comma separated lists for example. |
563 | */ | 562 | */ |
564 | 563 | ||
565 | int CONF_parse_list(const char *list_, int sep, int nospc, | 564 | int |
566 | int (*list_cb)(const char *elem, int len, void *usr), void *arg) | 565 | CONF_parse_list(const char *list_, int sep, int nospc, |
567 | { | 566 | int (*list_cb)(const char *elem, int len, void *usr), void *arg) |
567 | { | ||
568 | int ret; | 568 | int ret; |
569 | const char *lstart, *tmpend, *p; | 569 | const char *lstart, *tmpend, *p; |
570 | 570 | ||
571 | if(list_ == NULL) | 571 | if (list_ == NULL) { |
572 | { | ||
573 | CONFerr(CONF_F_CONF_PARSE_LIST, CONF_R_LIST_CANNOT_BE_NULL); | 572 | CONFerr(CONF_F_CONF_PARSE_LIST, CONF_R_LIST_CANNOT_BE_NULL); |
574 | return 0; | 573 | return 0; |
575 | } | 574 | } |
576 | 575 | ||
577 | lstart = list_; | 576 | lstart = list_; |
578 | for(;;) | 577 | for (;;) { |
579 | { | 578 | if (nospc) { |
580 | if (nospc) | 579 | while (*lstart && isspace((unsigned char)*lstart)) |
581 | { | ||
582 | while(*lstart && isspace((unsigned char)*lstart)) | ||
583 | lstart++; | 580 | lstart++; |
584 | } | 581 | } |
585 | p = strchr(lstart, sep); | 582 | p = strchr(lstart, sep); |
586 | if (p == lstart || !*lstart) | 583 | if (p == lstart || !*lstart) |
587 | ret = list_cb(NULL, 0, arg); | 584 | ret = list_cb(NULL, 0, arg); |
588 | else | 585 | else { |
589 | { | ||
590 | if (p) | 586 | if (p) |
591 | tmpend = p - 1; | 587 | tmpend = p - 1; |
592 | else | 588 | else |
593 | tmpend = lstart + strlen(lstart) - 1; | 589 | tmpend = lstart + strlen(lstart) - 1; |
594 | if (nospc) | 590 | if (nospc) { |
595 | { | 591 | while (isspace((unsigned char)*tmpend)) |
596 | while(isspace((unsigned char)*tmpend)) | ||
597 | tmpend--; | 592 | tmpend--; |
598 | } | ||
599 | ret = list_cb(lstart, tmpend - lstart + 1, arg); | ||
600 | } | 593 | } |
594 | ret = list_cb(lstart, tmpend - lstart + 1, arg); | ||
595 | } | ||
601 | if (ret <= 0) | 596 | if (ret <= 0) |
602 | return ret; | 597 | return ret; |
603 | if (p == NULL) | 598 | if (p == NULL) |
604 | return 1; | 599 | return 1; |
605 | lstart = p + 1; | 600 | lstart = p + 1; |
606 | } | ||
607 | } | 601 | } |
608 | 602 | } | |