diff options
author | beck <> | 2002-05-15 02:29:21 +0000 |
---|---|---|
committer | beck <> | 2002-05-15 02:29:21 +0000 |
commit | b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9 (patch) | |
tree | fa27cf82a1250b64ed3bf5f4a18c7354d470bbcc /src/lib/libcrypto/conf/conf_lib.c | |
parent | e471e1ea98d673597b182ea85f29e30c97cd08b5 (diff) | |
download | openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.gz openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.bz2 openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.zip |
OpenSSL 0.9.7 stable 2002 05 08 merge
Diffstat (limited to 'src/lib/libcrypto/conf/conf_lib.c')
-rw-r--r-- | src/lib/libcrypto/conf/conf_lib.c | 158 |
1 files changed, 83 insertions, 75 deletions
diff --git a/src/lib/libcrypto/conf/conf_lib.c b/src/lib/libcrypto/conf/conf_lib.c index 11ec639732..7998f34c7b 100644 --- a/src/lib/libcrypto/conf/conf_lib.c +++ b/src/lib/libcrypto/conf/conf_lib.c | |||
@@ -67,6 +67,17 @@ const char *CONF_version="CONF" OPENSSL_VERSION_PTEXT; | |||
67 | 67 | ||
68 | static CONF_METHOD *default_CONF_method=NULL; | 68 | static CONF_METHOD *default_CONF_method=NULL; |
69 | 69 | ||
70 | /* Init a 'CONF' structure from an old LHASH */ | ||
71 | |||
72 | void CONF_set_nconf(CONF *conf, LHASH *hash) | ||
73 | { | ||
74 | if (default_CONF_method == NULL) | ||
75 | default_CONF_method = NCONF_default(); | ||
76 | |||
77 | default_CONF_method->init(conf); | ||
78 | conf->data = hash; | ||
79 | } | ||
80 | |||
70 | /* The following section contains the "CONF classic" functions, | 81 | /* The following section contains the "CONF classic" functions, |
71 | rewritten in terms of the new CONF interface. */ | 82 | rewritten in terms of the new CONF interface. */ |
72 | 83 | ||
@@ -81,7 +92,7 @@ LHASH *CONF_load(LHASH *conf, const char *file, long *eline) | |||
81 | LHASH *ltmp; | 92 | LHASH *ltmp; |
82 | BIO *in=NULL; | 93 | BIO *in=NULL; |
83 | 94 | ||
84 | #ifdef VMS | 95 | #ifdef OPENSSL_SYS_VMS |
85 | in=BIO_new_file(file, "r"); | 96 | in=BIO_new_file(file, "r"); |
86 | #else | 97 | #else |
87 | in=BIO_new_file(file, "rb"); | 98 | in=BIO_new_file(file, "rb"); |
@@ -98,7 +109,7 @@ LHASH *CONF_load(LHASH *conf, const char *file, long *eline) | |||
98 | return ltmp; | 109 | return ltmp; |
99 | } | 110 | } |
100 | 111 | ||
101 | #ifndef NO_FP_API | 112 | #ifndef OPENSSL_NO_FP_API |
102 | LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline) | 113 | LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline) |
103 | { | 114 | { |
104 | BIO *btmp; | 115 | BIO *btmp; |
@@ -118,18 +129,15 @@ LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline) | |||
118 | CONF ctmp; | 129 | CONF ctmp; |
119 | int ret; | 130 | int ret; |
120 | 131 | ||
121 | if (default_CONF_method == NULL) | 132 | CONF_set_nconf(&ctmp, conf); |
122 | default_CONF_method = NCONF_default(); | ||
123 | 133 | ||
124 | default_CONF_method->init(&ctmp); | ||
125 | ctmp.data = conf; | ||
126 | ret = NCONF_load_bio(&ctmp, bp, eline); | 134 | ret = NCONF_load_bio(&ctmp, bp, eline); |
127 | if (ret) | 135 | if (ret) |
128 | return ctmp.data; | 136 | return ctmp.data; |
129 | return NULL; | 137 | return NULL; |
130 | } | 138 | } |
131 | 139 | ||
132 | STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,char *section) | 140 | STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,const char *section) |
133 | { | 141 | { |
134 | if (conf == NULL) | 142 | if (conf == NULL) |
135 | { | 143 | { |
@@ -138,17 +146,12 @@ STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,char *section) | |||
138 | else | 146 | else |
139 | { | 147 | { |
140 | CONF ctmp; | 148 | CONF ctmp; |
141 | 149 | CONF_set_nconf(&ctmp, conf); | |
142 | if (default_CONF_method == NULL) | ||
143 | default_CONF_method = NCONF_default(); | ||
144 | |||
145 | default_CONF_method->init(&ctmp); | ||
146 | ctmp.data = conf; | ||
147 | return NCONF_get_section(&ctmp, section); | 150 | return NCONF_get_section(&ctmp, section); |
148 | } | 151 | } |
149 | } | 152 | } |
150 | 153 | ||
151 | char *CONF_get_string(LHASH *conf,char *group,char *name) | 154 | char *CONF_get_string(LHASH *conf,const char *group,const char *name) |
152 | { | 155 | { |
153 | if (conf == NULL) | 156 | if (conf == NULL) |
154 | { | 157 | { |
@@ -157,48 +160,43 @@ char *CONF_get_string(LHASH *conf,char *group,char *name) | |||
157 | else | 160 | else |
158 | { | 161 | { |
159 | CONF ctmp; | 162 | CONF ctmp; |
160 | 163 | CONF_set_nconf(&ctmp, conf); | |
161 | if (default_CONF_method == NULL) | ||
162 | default_CONF_method = NCONF_default(); | ||
163 | |||
164 | default_CONF_method->init(&ctmp); | ||
165 | ctmp.data = conf; | ||
166 | return NCONF_get_string(&ctmp, group, name); | 164 | return NCONF_get_string(&ctmp, group, name); |
167 | } | 165 | } |
168 | } | 166 | } |
169 | 167 | ||
170 | long CONF_get_number(LHASH *conf,char *group,char *name) | 168 | long CONF_get_number(LHASH *conf,const char *group,const char *name) |
171 | { | 169 | { |
170 | int status; | ||
171 | long result = 0; | ||
172 | |||
172 | if (conf == NULL) | 173 | if (conf == NULL) |
173 | { | 174 | { |
174 | return NCONF_get_number(NULL, group, name); | 175 | status = NCONF_get_number_e(NULL, group, name, &result); |
175 | } | 176 | } |
176 | else | 177 | else |
177 | { | 178 | { |
178 | CONF ctmp; | 179 | CONF ctmp; |
180 | CONF_set_nconf(&ctmp, conf); | ||
181 | status = NCONF_get_number_e(&ctmp, group, name, &result); | ||
182 | } | ||
179 | 183 | ||
180 | if (default_CONF_method == NULL) | 184 | if (status == 0) |
181 | default_CONF_method = NCONF_default(); | 185 | { |
182 | 186 | /* This function does not believe in errors... */ | |
183 | default_CONF_method->init(&ctmp); | 187 | ERR_get_error(); |
184 | ctmp.data = conf; | ||
185 | return NCONF_get_number(&ctmp, group, name); | ||
186 | } | 188 | } |
189 | return result; | ||
187 | } | 190 | } |
188 | 191 | ||
189 | void CONF_free(LHASH *conf) | 192 | void CONF_free(LHASH *conf) |
190 | { | 193 | { |
191 | CONF ctmp; | 194 | CONF ctmp; |
192 | 195 | CONF_set_nconf(&ctmp, conf); | |
193 | if (default_CONF_method == NULL) | ||
194 | default_CONF_method = NCONF_default(); | ||
195 | |||
196 | default_CONF_method->init(&ctmp); | ||
197 | ctmp.data = conf; | ||
198 | NCONF_free_data(&ctmp); | 196 | NCONF_free_data(&ctmp); |
199 | } | 197 | } |
200 | 198 | ||
201 | #ifndef NO_FP_API | 199 | #ifndef OPENSSL_NO_FP_API |
202 | int CONF_dump_fp(LHASH *conf, FILE *out) | 200 | int CONF_dump_fp(LHASH *conf, FILE *out) |
203 | { | 201 | { |
204 | BIO *btmp; | 202 | BIO *btmp; |
@@ -217,12 +215,7 @@ int CONF_dump_fp(LHASH *conf, FILE *out) | |||
217 | int CONF_dump_bio(LHASH *conf, BIO *out) | 215 | int CONF_dump_bio(LHASH *conf, BIO *out) |
218 | { | 216 | { |
219 | CONF ctmp; | 217 | CONF ctmp; |
220 | 218 | CONF_set_nconf(&ctmp, conf); | |
221 | if (default_CONF_method == NULL) | ||
222 | default_CONF_method = NCONF_default(); | ||
223 | |||
224 | default_CONF_method->init(&ctmp); | ||
225 | ctmp.data = conf; | ||
226 | return NCONF_dump_bio(&ctmp, out); | 219 | return NCONF_dump_bio(&ctmp, out); |
227 | } | 220 | } |
228 | 221 | ||
@@ -265,34 +258,23 @@ void NCONF_free_data(CONF *conf) | |||
265 | 258 | ||
266 | int NCONF_load(CONF *conf, const char *file, long *eline) | 259 | int NCONF_load(CONF *conf, const char *file, long *eline) |
267 | { | 260 | { |
268 | int ret; | 261 | if (conf == NULL) |
269 | BIO *in=NULL; | ||
270 | |||
271 | #ifdef VMS | ||
272 | in=BIO_new_file(file, "r"); | ||
273 | #else | ||
274 | in=BIO_new_file(file, "rb"); | ||
275 | #endif | ||
276 | if (in == NULL) | ||
277 | { | 262 | { |
278 | CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB); | 263 | CONFerr(CONF_F_NCONF_LOAD,CONF_R_NO_CONF); |
279 | return 0; | 264 | return 0; |
280 | } | 265 | } |
281 | 266 | ||
282 | ret = NCONF_load_bio(conf, in, eline); | 267 | return conf->meth->load(conf, file, eline); |
283 | BIO_free(in); | ||
284 | |||
285 | return ret; | ||
286 | } | 268 | } |
287 | 269 | ||
288 | #ifndef NO_FP_API | 270 | #ifndef OPENSSL_NO_FP_API |
289 | int NCONF_load_fp(CONF *conf, FILE *fp,long *eline) | 271 | int NCONF_load_fp(CONF *conf, FILE *fp,long *eline) |
290 | { | 272 | { |
291 | BIO *btmp; | 273 | BIO *btmp; |
292 | int ret; | 274 | int ret; |
293 | if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) | 275 | if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) |
294 | { | 276 | { |
295 | CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB); | 277 | CONFerr(CONF_F_NCONF_LOAD_FP,ERR_R_BUF_LIB); |
296 | return 0; | 278 | return 0; |
297 | } | 279 | } |
298 | ret = NCONF_load_bio(conf, btmp, eline); | 280 | ret = NCONF_load_bio(conf, btmp, eline); |
@@ -309,10 +291,10 @@ int NCONF_load_bio(CONF *conf, BIO *bp,long *eline) | |||
309 | return 0; | 291 | return 0; |
310 | } | 292 | } |
311 | 293 | ||
312 | return conf->meth->load(conf, bp, eline); | 294 | return conf->meth->load_bio(conf, bp, eline); |
313 | } | 295 | } |
314 | 296 | ||
315 | STACK_OF(CONF_VALUE) *NCONF_get_section(CONF *conf,char *section) | 297 | STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,const char *section) |
316 | { | 298 | { |
317 | if (conf == NULL) | 299 | if (conf == NULL) |
318 | { | 300 | { |
@@ -329,7 +311,7 @@ STACK_OF(CONF_VALUE) *NCONF_get_section(CONF *conf,char *section) | |||
329 | return _CONF_get_section_values(conf, section); | 311 | return _CONF_get_section_values(conf, section); |
330 | } | 312 | } |
331 | 313 | ||
332 | char *NCONF_get_string(CONF *conf,char *group,char *name) | 314 | char *NCONF_get_string(const CONF *conf,const char *group,const char *name) |
333 | { | 315 | { |
334 | char *s = _CONF_get_string(conf, group, name); | 316 | char *s = _CONF_get_string(conf, group, name); |
335 | 317 | ||
@@ -343,29 +325,39 @@ char *NCONF_get_string(CONF *conf,char *group,char *name) | |||
343 | CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE); | 325 | CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE); |
344 | return NULL; | 326 | return NULL; |
345 | } | 327 | } |
328 | CONFerr(CONF_F_NCONF_GET_STRING, | ||
329 | CONF_R_NO_VALUE); | ||
330 | ERR_add_error_data(4,"group=",group," name=",name); | ||
346 | return NULL; | 331 | return NULL; |
347 | } | 332 | } |
348 | 333 | ||
349 | long NCONF_get_number(CONF *conf,char *group,char *name) | 334 | int NCONF_get_number_e(const CONF *conf,const char *group,const char *name, |
335 | long *result) | ||
350 | { | 336 | { |
351 | #if 0 /* As with _CONF_get_string(), we rely on the possibility of finding | 337 | char *str; |
352 | an environment variable with a suitable name. Unfortunately, there's | 338 | |
353 | no way with the current API to see if we found one or not... | 339 | if (result == NULL) |
354 | The meaning of this is that if a number is not found anywhere, it | ||
355 | will always default to 0. */ | ||
356 | if (conf == NULL) | ||
357 | { | 340 | { |
358 | CONFerr(CONF_F_NCONF_GET_NUMBER, | 341 | CONFerr(CONF_F_NCONF_GET_NUMBER_E,ERR_R_PASSED_NULL_PARAMETER); |
359 | CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE); | ||
360 | return 0; | 342 | return 0; |
361 | } | 343 | } |
362 | #endif | 344 | |
363 | 345 | str = NCONF_get_string(conf,group,name); | |
364 | return _CONF_get_number(conf, group, name); | 346 | |
347 | if (str == NULL) | ||
348 | return 0; | ||
349 | |||
350 | for (*result = 0;conf->meth->is_number(conf, *str);) | ||
351 | { | ||
352 | *result = (*result)*10 + conf->meth->to_int(conf, *str); | ||
353 | str++; | ||
354 | } | ||
355 | |||
356 | return 1; | ||
365 | } | 357 | } |
366 | 358 | ||
367 | #ifndef NO_FP_API | 359 | #ifndef OPENSSL_NO_FP_API |
368 | int NCONF_dump_fp(CONF *conf, FILE *out) | 360 | int NCONF_dump_fp(const CONF *conf, FILE *out) |
369 | { | 361 | { |
370 | BIO *btmp; | 362 | BIO *btmp; |
371 | int ret; | 363 | int ret; |
@@ -379,7 +371,7 @@ int NCONF_dump_fp(CONF *conf, FILE *out) | |||
379 | } | 371 | } |
380 | #endif | 372 | #endif |
381 | 373 | ||
382 | int NCONF_dump_bio(CONF *conf, BIO *out) | 374 | int NCONF_dump_bio(const CONF *conf, BIO *out) |
383 | { | 375 | { |
384 | if (conf == NULL) | 376 | if (conf == NULL) |
385 | { | 377 | { |
@@ -390,3 +382,19 @@ int NCONF_dump_bio(CONF *conf, BIO *out) | |||
390 | return conf->meth->dump(conf, out); | 382 | return conf->meth->dump(conf, out); |
391 | } | 383 | } |
392 | 384 | ||
385 | /* This function should be avoided */ | ||
386 | #undef NCONF_get_number | ||
387 | long NCONF_get_number(CONF *conf,char *group,char *name) | ||
388 | { | ||
389 | int status; | ||
390 | long ret=0; | ||
391 | |||
392 | status = NCONF_get_number_e(conf, group, name, &ret); | ||
393 | if (status == 0) | ||
394 | { | ||
395 | /* This function does not believe in errors... */ | ||
396 | ERR_get_error(); | ||
397 | } | ||
398 | return ret; | ||
399 | } | ||
400 | |||