summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/conf/conf_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/conf/conf_lib.c')
-rw-r--r--src/lib/libcrypto/conf/conf_lib.c312
1 files changed, 156 insertions, 156 deletions
diff --git a/src/lib/libcrypto/conf/conf_lib.c b/src/lib/libcrypto/conf/conf_lib.c
index 6f8866fa1a..469af6e825 100644
--- a/src/lib/libcrypto/conf/conf_lib.c
+++ b/src/lib/libcrypto/conf/conf_lib.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
@@ -65,66 +65,67 @@
65 65
66const char CONF_version[]="CONF" OPENSSL_VERSION_PTEXT; 66const char CONF_version[]="CONF" OPENSSL_VERSION_PTEXT;
67 67
68static CONF_METHOD *default_CONF_method=NULL; 68static CONF_METHOD *default_CONF_method = NULL;
69 69
70/* Init a 'CONF' structure from an old LHASH */ 70/* Init a 'CONF' structure from an old LHASH */
71 71
72void CONF_set_nconf(CONF *conf, LHASH_OF(CONF_VALUE) *hash) 72void
73 { 73CONF_set_nconf(CONF *conf, LHASH_OF(CONF_VALUE) *hash)
74{
74 if (default_CONF_method == NULL) 75 if (default_CONF_method == NULL)
75 default_CONF_method = NCONF_default(); 76 default_CONF_method = NCONF_default();
76
77 default_CONF_method->init(conf); 77 default_CONF_method->init(conf);
78 conf->data = hash; 78 conf->data = hash;
79 } 79}
80 80
81/* The following section contains the "CONF classic" functions, 81/* The following section contains the "CONF classic" functions,
82 rewritten in terms of the new CONF interface. */ 82 rewritten in terms of the new CONF interface. */
83 83
84int CONF_set_default_method(CONF_METHOD *meth) 84int
85 { 85CONF_set_default_method(CONF_METHOD *meth)
86{
86 default_CONF_method = meth; 87 default_CONF_method = meth;
87 return 1; 88 return 1;
88 } 89}
89 90
90LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf, const char *file, 91LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf, const char *file,
91 long *eline) 92 long *eline)
92 { 93{
93 LHASH_OF(CONF_VALUE) *ltmp; 94 LHASH_OF(CONF_VALUE) *ltmp;
94 BIO *in=NULL; 95 BIO *in = NULL;
95 96
96 in=BIO_new_file(file, "rb"); 97 in = BIO_new_file(file, "rb");
97 if (in == NULL) 98 if (in == NULL) {
98 { 99 CONFerr(CONF_F_CONF_LOAD, ERR_R_SYS_LIB);
99 CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
100 return NULL; 100 return NULL;
101 } 101 }
102 102
103 ltmp = CONF_load_bio(conf, in, eline); 103 ltmp = CONF_load_bio(conf, in, eline);
104 BIO_free(in); 104 BIO_free(in);
105 105
106 return ltmp; 106 return ltmp;
107 } 107}
108 108
109#ifndef OPENSSL_NO_FP_API 109#ifndef OPENSSL_NO_FP_API
110LHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp, 110LHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp,
111 long *eline) 111 long *eline)
112 { 112{
113 BIO *btmp; 113 BIO *btmp;
114 LHASH_OF(CONF_VALUE) *ltmp; 114 LHASH_OF(CONF_VALUE) *ltmp;
115 if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) { 115
116 CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB); 116 if (!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) {
117 CONFerr(CONF_F_CONF_LOAD_FP, ERR_R_BUF_LIB);
117 return NULL; 118 return NULL;
118 } 119 }
119 ltmp = CONF_load_bio(conf, btmp, eline); 120 ltmp = CONF_load_bio(conf, btmp, eline);
120 BIO_free(btmp); 121 BIO_free(btmp);
121 return ltmp; 122 return ltmp;
122 } 123}
123#endif 124#endif
124 125
125LHASH_OF(CONF_VALUE) *CONF_load_bio(LHASH_OF(CONF_VALUE) *conf, BIO *bp, 126LHASH_OF(CONF_VALUE) *CONF_load_bio(LHASH_OF(CONF_VALUE) *conf, BIO *bp,
126 long *eline) 127 long *eline)
127 { 128{
128 CONF ctmp; 129 CONF ctmp;
129 int ret; 130 int ret;
130 131
@@ -134,92 +135,89 @@ LHASH_OF(CONF_VALUE) *CONF_load_bio(LHASH_OF(CONF_VALUE) *conf, BIO *bp,
134 if (ret) 135 if (ret)
135 return ctmp.data; 136 return ctmp.data;
136 return NULL; 137 return NULL;
137 } 138}
138 139
139STACK_OF(CONF_VALUE) *CONF_get_section(LHASH_OF(CONF_VALUE) *conf, 140STACK_OF(CONF_VALUE) *CONF_get_section(LHASH_OF(CONF_VALUE) *conf,
140 const char *section) 141 const char *section)
141 { 142{
142 if (conf == NULL) 143 if (conf == NULL) {
143 {
144 return NULL; 144 return NULL;
145 } 145 } else {
146 else
147 {
148 CONF ctmp; 146 CONF ctmp;
149 CONF_set_nconf(&ctmp, conf); 147 CONF_set_nconf(&ctmp, conf);
150 return NCONF_get_section(&ctmp, section); 148 return NCONF_get_section(&ctmp, section);
151 }
152 } 149 }
150}
153 151
154char *CONF_get_string(LHASH_OF(CONF_VALUE) *conf,const char *group, 152char *
155 const char *name) 153CONF_get_string(LHASH_OF(CONF_VALUE) *conf, const char *group,
156 { 154 const char *name)
157 if (conf == NULL) 155{
158 { 156 if (conf == NULL) {
159 return NCONF_get_string(NULL, group, name); 157 return NCONF_get_string(NULL, group, name);
160 } 158 } else {
161 else
162 {
163 CONF ctmp; 159 CONF ctmp;
164 CONF_set_nconf(&ctmp, conf); 160 CONF_set_nconf(&ctmp, conf);
165 return NCONF_get_string(&ctmp, group, name); 161 return NCONF_get_string(&ctmp, group, name);
166 }
167 } 162 }
163}
168 164
169long CONF_get_number(LHASH_OF(CONF_VALUE) *conf,const char *group, 165long
170 const char *name) 166CONF_get_number(LHASH_OF(CONF_VALUE) *conf, const char *group,
171 { 167 const char *name)
168{
172 int status; 169 int status;
173 long result = 0; 170 long result = 0;
174 171
175 if (conf == NULL) 172 if (conf == NULL) {
176 {
177 status = NCONF_get_number_e(NULL, group, name, &result); 173 status = NCONF_get_number_e(NULL, group, name, &result);
178 } 174 } else {
179 else
180 {
181 CONF ctmp; 175 CONF ctmp;
182 CONF_set_nconf(&ctmp, conf); 176 CONF_set_nconf(&ctmp, conf);
183 status = NCONF_get_number_e(&ctmp, group, name, &result); 177 status = NCONF_get_number_e(&ctmp, group, name, &result);
184 } 178 }
185 179
186 if (status == 0) 180 if (status == 0) {
187 {
188 /* This function does not believe in errors... */ 181 /* This function does not believe in errors... */
189 ERR_clear_error(); 182 ERR_clear_error();
190 }
191 return result;
192 } 183 }
184 return result;
185}
193 186
194void CONF_free(LHASH_OF(CONF_VALUE) *conf) 187void
195 { 188CONF_free(LHASH_OF(CONF_VALUE) *conf)
189{
196 CONF ctmp; 190 CONF ctmp;
191
197 CONF_set_nconf(&ctmp, conf); 192 CONF_set_nconf(&ctmp, conf);
198 NCONF_free_data(&ctmp); 193 NCONF_free_data(&ctmp);
199 } 194}
200 195
201#ifndef OPENSSL_NO_FP_API 196#ifndef OPENSSL_NO_FP_API
202int CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out) 197int
203 { 198CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out)
199{
204 BIO *btmp; 200 BIO *btmp;
205 int ret; 201 int ret;
206 202
207 if(!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) { 203 if (!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) {
208 CONFerr(CONF_F_CONF_DUMP_FP,ERR_R_BUF_LIB); 204 CONFerr(CONF_F_CONF_DUMP_FP, ERR_R_BUF_LIB);
209 return 0; 205 return 0;
210 } 206 }
211 ret = CONF_dump_bio(conf, btmp); 207 ret = CONF_dump_bio(conf, btmp);
212 BIO_free(btmp); 208 BIO_free(btmp);
213 return ret; 209 return ret;
214 } 210}
215#endif 211#endif
216 212
217int CONF_dump_bio(LHASH_OF(CONF_VALUE) *conf, BIO *out) 213int
218 { 214CONF_dump_bio(LHASH_OF(CONF_VALUE) *conf, BIO *out)
215{
219 CONF ctmp; 216 CONF ctmp;
217
220 CONF_set_nconf(&ctmp, conf); 218 CONF_set_nconf(&ctmp, conf);
221 return NCONF_dump_bio(&ctmp, out); 219 return NCONF_dump_bio(&ctmp, out);
222 } 220}
223 221
224/* The following section contains the "New CONF" functions. They are 222/* The following section contains the "New CONF" functions. They are
225 completely centralised around a new CONF structure that may contain 223 completely centralised around a new CONF structure that may contain
@@ -227,177 +225,179 @@ int CONF_dump_bio(LHASH_OF(CONF_VALUE) *conf, BIO *out)
227 These functions are also written in terms of the bridge functions used 225 These functions are also written in terms of the bridge functions used
228 by the "CONF classic" functions, for consistency. */ 226 by the "CONF classic" functions, for consistency. */
229 227
230CONF *NCONF_new(CONF_METHOD *meth) 228CONF *
231 { 229NCONF_new(CONF_METHOD *meth)
230{
232 CONF *ret; 231 CONF *ret;
233 232
234 if (meth == NULL) 233 if (meth == NULL)
235 meth = NCONF_default(); 234 meth = NCONF_default();
236 235
237 ret = meth->create(meth); 236 ret = meth->create(meth);
238 if (ret == NULL) 237 if (ret == NULL) {
239 { 238 CONFerr(CONF_F_NCONF_NEW, ERR_R_MALLOC_FAILURE);
240 CONFerr(CONF_F_NCONF_NEW,ERR_R_MALLOC_FAILURE); 239 return (NULL);
241 return(NULL); 240 }
242 }
243 241
244 return ret; 242 return ret;
245 } 243}
246 244
247void NCONF_free(CONF *conf) 245void
248 { 246NCONF_free(CONF *conf)
247{
249 if (conf == NULL) 248 if (conf == NULL)
250 return; 249 return;
251 conf->meth->destroy(conf); 250 conf->meth->destroy(conf);
252 } 251}
253 252
254void NCONF_free_data(CONF *conf) 253void
255 { 254NCONF_free_data(CONF *conf)
255{
256 if (conf == NULL) 256 if (conf == NULL)
257 return; 257 return;
258 conf->meth->destroy_data(conf); 258 conf->meth->destroy_data(conf);
259 } 259}
260 260
261int NCONF_load(CONF *conf, const char *file, long *eline) 261int
262 { 262NCONF_load(CONF *conf, const char *file, long *eline)
263 if (conf == NULL) 263{
264 { 264 if (conf == NULL) {
265 CONFerr(CONF_F_NCONF_LOAD,CONF_R_NO_CONF); 265 CONFerr(CONF_F_NCONF_LOAD, CONF_R_NO_CONF);
266 return 0; 266 return 0;
267 } 267 }
268 268
269 return conf->meth->load(conf, file, eline); 269 return conf->meth->load(conf, file, eline);
270 } 270}
271 271
272#ifndef OPENSSL_NO_FP_API 272#ifndef OPENSSL_NO_FP_API
273int NCONF_load_fp(CONF *conf, FILE *fp,long *eline) 273int
274 { 274NCONF_load_fp(CONF *conf, FILE *fp, long *eline)
275{
275 BIO *btmp; 276 BIO *btmp;
276 int ret; 277 int ret;
277 if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) 278
278 { 279 if (!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) {
279 CONFerr(CONF_F_NCONF_LOAD_FP,ERR_R_BUF_LIB); 280 CONFerr(CONF_F_NCONF_LOAD_FP, ERR_R_BUF_LIB);
280 return 0; 281 return 0;
281 } 282 }
282 ret = NCONF_load_bio(conf, btmp, eline); 283 ret = NCONF_load_bio(conf, btmp, eline);
283 BIO_free(btmp); 284 BIO_free(btmp);
284 return ret; 285 return ret;
285 } 286}
286#endif 287#endif
287 288
288int NCONF_load_bio(CONF *conf, BIO *bp,long *eline) 289int
289 { 290NCONF_load_bio(CONF *conf, BIO *bp, long *eline)
290 if (conf == NULL) 291{
291 { 292 if (conf == NULL) {
292 CONFerr(CONF_F_NCONF_LOAD_BIO,CONF_R_NO_CONF); 293 CONFerr(CONF_F_NCONF_LOAD_BIO, CONF_R_NO_CONF);
293 return 0; 294 return 0;
294 } 295 }
295 296
296 return conf->meth->load_bio(conf, bp, eline); 297 return conf->meth->load_bio(conf, bp, eline);
297 } 298}
298 299
299STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,const char *section) 300STACK_OF(CONF_VALUE) *
300 { 301NCONF_get_section(const CONF *conf, const char *section)
301 if (conf == NULL) 302{
302 { 303 if (conf == NULL) {
303 CONFerr(CONF_F_NCONF_GET_SECTION,CONF_R_NO_CONF); 304 CONFerr(CONF_F_NCONF_GET_SECTION, CONF_R_NO_CONF);
304 return NULL; 305 return NULL;
305 } 306 }
306 307
307 if (section == NULL) 308 if (section == NULL) {
308 { 309 CONFerr(CONF_F_NCONF_GET_SECTION, CONF_R_NO_SECTION);
309 CONFerr(CONF_F_NCONF_GET_SECTION,CONF_R_NO_SECTION);
310 return NULL; 310 return NULL;
311 } 311 }
312 312
313 return _CONF_get_section_values(conf, section); 313 return _CONF_get_section_values(conf, section);
314 } 314}
315 315
316char *NCONF_get_string(const CONF *conf,const char *group,const char *name) 316char *
317 { 317NCONF_get_string(const CONF *conf, const char *group, const char *name)
318{
318 char *s = _CONF_get_string(conf, group, name); 319 char *s = _CONF_get_string(conf, group, name);
319 320
320 /* Since we may get a value from an environment variable even 321 /* Since we may get a value from an environment variable even
321 if conf is NULL, let's check the value first */ 322 if conf is NULL, let's check the value first */
322 if (s) return s; 323 if (s)
324 return s;
323 325
324 if (conf == NULL) 326 if (conf == NULL) {
325 {
326 CONFerr(CONF_F_NCONF_GET_STRING, 327 CONFerr(CONF_F_NCONF_GET_STRING,
327 CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE); 328 CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE);
328 return NULL; 329 return NULL;
329 }
330 CONFerr(CONF_F_NCONF_GET_STRING,
331 CONF_R_NO_VALUE);
332 ERR_add_error_data(4,"group=",group," name=",name);
333 return NULL;
334 } 330 }
331 CONFerr(CONF_F_NCONF_GET_STRING, CONF_R_NO_VALUE);
332 ERR_add_error_data(4, "group=", group, " name=", name);
333 return NULL;
334}
335 335
336int NCONF_get_number_e(const CONF *conf,const char *group,const char *name, 336int
337 long *result) 337NCONF_get_number_e(const CONF *conf, const char *group, const char *name,
338 { 338 long *result)
339{
339 char *str; 340 char *str;
340 341
341 if (result == NULL) 342 if (result == NULL) {
342 { 343 CONFerr(CONF_F_NCONF_GET_NUMBER_E, ERR_R_PASSED_NULL_PARAMETER);
343 CONFerr(CONF_F_NCONF_GET_NUMBER_E,ERR_R_PASSED_NULL_PARAMETER);
344 return 0; 344 return 0;
345 } 345 }
346 346
347 str = NCONF_get_string(conf,group,name); 347 str = NCONF_get_string(conf, group, name);
348 348
349 if (str == NULL) 349 if (str == NULL)
350 return 0; 350 return 0;
351 351
352 for (*result = 0;conf->meth->is_number(conf, *str);) 352 for (*result = 0; conf->meth->is_number(conf, *str); ) {
353 { 353 *result = (*result) * 10 + conf->meth->to_int(conf, *str);
354 *result = (*result)*10 + conf->meth->to_int(conf, *str);
355 str++; 354 str++;
356 } 355 }
357 356
358 return 1; 357 return 1;
359 } 358}
360 359
361#ifndef OPENSSL_NO_FP_API 360#ifndef OPENSSL_NO_FP_API
362int NCONF_dump_fp(const CONF *conf, FILE *out) 361int
363 { 362NCONF_dump_fp(const CONF *conf, FILE *out)
363{
364 BIO *btmp; 364 BIO *btmp;
365 int ret; 365 int ret;
366 if(!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) { 366 if (!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) {
367 CONFerr(CONF_F_NCONF_DUMP_FP,ERR_R_BUF_LIB); 367 CONFerr(CONF_F_NCONF_DUMP_FP, ERR_R_BUF_LIB);
368 return 0; 368 return 0;
369 } 369 }
370 ret = NCONF_dump_bio(conf, btmp); 370 ret = NCONF_dump_bio(conf, btmp);
371 BIO_free(btmp); 371 BIO_free(btmp);
372 return ret; 372 return ret;
373 } 373}
374#endif 374#endif
375 375
376int NCONF_dump_bio(const CONF *conf, BIO *out) 376int
377 { 377NCONF_dump_bio(const CONF *conf, BIO *out)
378 if (conf == NULL) 378{
379 { 379 if (conf == NULL) {
380 CONFerr(CONF_F_NCONF_DUMP_BIO,CONF_R_NO_CONF); 380 CONFerr(CONF_F_NCONF_DUMP_BIO, CONF_R_NO_CONF);
381 return 0; 381 return 0;
382 } 382 }
383 383
384 return conf->meth->dump(conf, out); 384 return conf->meth->dump(conf, out);
385 } 385}
386 386
387 387
388/* This function should be avoided */ 388/* This function should be avoided */
389#if 0 389#if 0
390long NCONF_get_number(CONF *conf,char *group,char *name) 390long
391 { 391NCONF_get_number(CONF *conf, char *group, char *name)
392{
392 int status; 393 int status;
393 long ret=0; 394 long ret = 0;
394 395
395 status = NCONF_get_number_e(conf, group, name, &ret); 396 status = NCONF_get_number_e(conf, group, name, &ret);
396 if (status == 0) 397 if (status == 0) {
397 {
398 /* This function does not believe in errors... */ 398 /* This function does not believe in errors... */
399 ERR_get_error(); 399 ERR_get_error();
400 }
401 return ret;
402 } 400 }
401 return ret;
402}
403#endif 403#endif