diff options
Diffstat (limited to 'src/lib/libcrypto/conf/conf_lib.c')
| -rw-r--r-- | src/lib/libcrypto/conf/conf_lib.c | 196 |
1 files changed, 122 insertions, 74 deletions
diff --git a/src/lib/libcrypto/conf/conf_lib.c b/src/lib/libcrypto/conf/conf_lib.c index 4c8ca9e9ae..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,66 +129,74 @@ 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 | CONF ctmp; | 142 | if (conf == NULL) |
| 135 | 143 | { | |
| 136 | if (default_CONF_method == NULL) | 144 | return NULL; |
| 137 | default_CONF_method = NCONF_default(); | 145 | } |
| 138 | 146 | else | |
| 139 | default_CONF_method->init(&ctmp); | 147 | { |
| 140 | ctmp.data = conf; | 148 | CONF ctmp; |
| 141 | return NCONF_get_section(&ctmp, section); | 149 | CONF_set_nconf(&ctmp, conf); |
| 150 | return NCONF_get_section(&ctmp, section); | ||
| 151 | } | ||
| 142 | } | 152 | } |
| 143 | 153 | ||
| 144 | char *CONF_get_string(LHASH *conf,char *group,char *name) | 154 | char *CONF_get_string(LHASH *conf,const char *group,const char *name) |
| 145 | { | 155 | { |
| 146 | CONF ctmp; | 156 | if (conf == NULL) |
| 147 | 157 | { | |
| 148 | if (default_CONF_method == NULL) | 158 | return NCONF_get_string(NULL, group, name); |
| 149 | default_CONF_method = NCONF_default(); | 159 | } |
| 150 | 160 | else | |
| 151 | default_CONF_method->init(&ctmp); | 161 | { |
| 152 | ctmp.data = conf; | 162 | CONF ctmp; |
| 153 | return NCONF_get_string(&ctmp, group, name); | 163 | CONF_set_nconf(&ctmp, conf); |
| 164 | return NCONF_get_string(&ctmp, group, name); | ||
| 165 | } | ||
| 154 | } | 166 | } |
| 155 | 167 | ||
| 156 | long CONF_get_number(LHASH *conf,char *group,char *name) | 168 | long CONF_get_number(LHASH *conf,const char *group,const char *name) |
| 157 | { | 169 | { |
| 158 | CONF ctmp; | 170 | int status; |
| 171 | long result = 0; | ||
| 159 | 172 | ||
| 160 | if (default_CONF_method == NULL) | 173 | if (conf == NULL) |
| 161 | default_CONF_method = NCONF_default(); | 174 | { |
| 175 | status = NCONF_get_number_e(NULL, group, name, &result); | ||
| 176 | } | ||
| 177 | else | ||
| 178 | { | ||
| 179 | CONF ctmp; | ||
| 180 | CONF_set_nconf(&ctmp, conf); | ||
| 181 | status = NCONF_get_number_e(&ctmp, group, name, &result); | ||
| 182 | } | ||
| 162 | 183 | ||
| 163 | default_CONF_method->init(&ctmp); | 184 | if (status == 0) |
| 164 | ctmp.data = conf; | 185 | { |
| 165 | return NCONF_get_number(&ctmp, group, name); | 186 | /* This function does not believe in errors... */ |
| 187 | ERR_get_error(); | ||
| 188 | } | ||
| 189 | return result; | ||
| 166 | } | 190 | } |
| 167 | 191 | ||
| 168 | void CONF_free(LHASH *conf) | 192 | void CONF_free(LHASH *conf) |
| 169 | { | 193 | { |
| 170 | CONF ctmp; | 194 | CONF ctmp; |
| 171 | 195 | CONF_set_nconf(&ctmp, conf); | |
| 172 | if (default_CONF_method == NULL) | ||
| 173 | default_CONF_method = NCONF_default(); | ||
| 174 | |||
| 175 | default_CONF_method->init(&ctmp); | ||
| 176 | ctmp.data = conf; | ||
| 177 | NCONF_free_data(&ctmp); | 196 | NCONF_free_data(&ctmp); |
| 178 | } | 197 | } |
| 179 | 198 | ||
| 180 | #ifndef NO_FP_API | 199 | #ifndef OPENSSL_NO_FP_API |
| 181 | int CONF_dump_fp(LHASH *conf, FILE *out) | 200 | int CONF_dump_fp(LHASH *conf, FILE *out) |
| 182 | { | 201 | { |
| 183 | BIO *btmp; | 202 | BIO *btmp; |
| @@ -196,12 +215,7 @@ int CONF_dump_fp(LHASH *conf, FILE *out) | |||
| 196 | int CONF_dump_bio(LHASH *conf, BIO *out) | 215 | int CONF_dump_bio(LHASH *conf, BIO *out) |
| 197 | { | 216 | { |
| 198 | CONF ctmp; | 217 | CONF ctmp; |
| 199 | 218 | CONF_set_nconf(&ctmp, conf); | |
| 200 | if (default_CONF_method == NULL) | ||
| 201 | default_CONF_method = NCONF_default(); | ||
| 202 | |||
| 203 | default_CONF_method->init(&ctmp); | ||
| 204 | ctmp.data = conf; | ||
| 205 | return NCONF_dump_bio(&ctmp, out); | 219 | return NCONF_dump_bio(&ctmp, out); |
| 206 | } | 220 | } |
| 207 | 221 | ||
| @@ -244,34 +258,23 @@ void NCONF_free_data(CONF *conf) | |||
| 244 | 258 | ||
| 245 | int NCONF_load(CONF *conf, const char *file, long *eline) | 259 | int NCONF_load(CONF *conf, const char *file, long *eline) |
| 246 | { | 260 | { |
| 247 | int ret; | 261 | if (conf == NULL) |
| 248 | BIO *in=NULL; | ||
| 249 | |||
| 250 | #ifdef VMS | ||
| 251 | in=BIO_new_file(file, "r"); | ||
| 252 | #else | ||
| 253 | in=BIO_new_file(file, "rb"); | ||
| 254 | #endif | ||
| 255 | if (in == NULL) | ||
| 256 | { | 262 | { |
| 257 | CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB); | 263 | CONFerr(CONF_F_NCONF_LOAD,CONF_R_NO_CONF); |
| 258 | return 0; | 264 | return 0; |
| 259 | } | 265 | } |
| 260 | 266 | ||
| 261 | ret = NCONF_load_bio(conf, in, eline); | 267 | return conf->meth->load(conf, file, eline); |
| 262 | BIO_free(in); | ||
| 263 | |||
| 264 | return ret; | ||
| 265 | } | 268 | } |
| 266 | 269 | ||
| 267 | #ifndef NO_FP_API | 270 | #ifndef OPENSSL_NO_FP_API |
| 268 | int NCONF_load_fp(CONF *conf, FILE *fp,long *eline) | 271 | int NCONF_load_fp(CONF *conf, FILE *fp,long *eline) |
| 269 | { | 272 | { |
| 270 | BIO *btmp; | 273 | BIO *btmp; |
| 271 | int ret; | 274 | int ret; |
| 272 | if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) | 275 | if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) |
| 273 | { | 276 | { |
| 274 | CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB); | 277 | CONFerr(CONF_F_NCONF_LOAD_FP,ERR_R_BUF_LIB); |
| 275 | return 0; | 278 | return 0; |
| 276 | } | 279 | } |
| 277 | ret = NCONF_load_bio(conf, btmp, eline); | 280 | ret = NCONF_load_bio(conf, btmp, eline); |
| @@ -288,10 +291,10 @@ int NCONF_load_bio(CONF *conf, BIO *bp,long *eline) | |||
| 288 | return 0; | 291 | return 0; |
| 289 | } | 292 | } |
| 290 | 293 | ||
| 291 | return conf->meth->load(conf, bp, eline); | 294 | return conf->meth->load_bio(conf, bp, eline); |
| 292 | } | 295 | } |
| 293 | 296 | ||
| 294 | 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) |
| 295 | { | 298 | { |
| 296 | if (conf == NULL) | 299 | if (conf == NULL) |
| 297 | { | 300 | { |
| @@ -299,33 +302,62 @@ STACK_OF(CONF_VALUE) *NCONF_get_section(CONF *conf,char *section) | |||
| 299 | return NULL; | 302 | return NULL; |
| 300 | } | 303 | } |
| 301 | 304 | ||
| 305 | if (section == NULL) | ||
| 306 | { | ||
| 307 | CONFerr(CONF_F_NCONF_GET_SECTION,CONF_R_NO_SECTION); | ||
| 308 | return NULL; | ||
| 309 | } | ||
| 310 | |||
| 302 | return _CONF_get_section_values(conf, section); | 311 | return _CONF_get_section_values(conf, section); |
| 303 | } | 312 | } |
| 304 | 313 | ||
| 305 | char *NCONF_get_string(CONF *conf,char *group,char *name) | 314 | char *NCONF_get_string(const CONF *conf,const char *group,const char *name) |
| 306 | { | 315 | { |
| 316 | char *s = _CONF_get_string(conf, group, name); | ||
| 317 | |||
| 318 | /* Since we may get a value from an environment variable even | ||
| 319 | if conf is NULL, let's check the value first */ | ||
| 320 | if (s) return s; | ||
| 321 | |||
| 307 | if (conf == NULL) | 322 | if (conf == NULL) |
| 308 | { | 323 | { |
| 309 | CONFerr(CONF_F_NCONF_GET_STRING,CONF_R_NO_CONF); | 324 | CONFerr(CONF_F_NCONF_GET_STRING, |
| 325 | CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE); | ||
| 310 | return NULL; | 326 | return NULL; |
| 311 | } | 327 | } |
| 312 | 328 | CONFerr(CONF_F_NCONF_GET_STRING, | |
| 313 | return _CONF_get_string(conf, group, name); | 329 | CONF_R_NO_VALUE); |
| 330 | ERR_add_error_data(4,"group=",group," name=",name); | ||
| 331 | return NULL; | ||
| 314 | } | 332 | } |
| 315 | 333 | ||
| 316 | 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) | ||
| 317 | { | 336 | { |
| 318 | if (conf == NULL) | 337 | char *str; |
| 338 | |||
| 339 | if (result == NULL) | ||
| 319 | { | 340 | { |
| 320 | CONFerr(CONF_F_NCONF_GET_NUMBER,CONF_R_NO_CONF); | 341 | CONFerr(CONF_F_NCONF_GET_NUMBER_E,ERR_R_PASSED_NULL_PARAMETER); |
| 321 | return 0; | 342 | return 0; |
| 322 | } | 343 | } |
| 323 | 344 | ||
| 324 | return _CONF_get_number(conf, group, name); | 345 | str = NCONF_get_string(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; | ||
| 325 | } | 357 | } |
| 326 | 358 | ||
| 327 | #ifndef NO_FP_API | 359 | #ifndef OPENSSL_NO_FP_API |
| 328 | int NCONF_dump_fp(CONF *conf, FILE *out) | 360 | int NCONF_dump_fp(const CONF *conf, FILE *out) |
| 329 | { | 361 | { |
| 330 | BIO *btmp; | 362 | BIO *btmp; |
| 331 | int ret; | 363 | int ret; |
| @@ -339,7 +371,7 @@ int NCONF_dump_fp(CONF *conf, FILE *out) | |||
| 339 | } | 371 | } |
| 340 | #endif | 372 | #endif |
| 341 | 373 | ||
| 342 | int NCONF_dump_bio(CONF *conf, BIO *out) | 374 | int NCONF_dump_bio(const CONF *conf, BIO *out) |
| 343 | { | 375 | { |
| 344 | if (conf == NULL) | 376 | if (conf == NULL) |
| 345 | { | 377 | { |
| @@ -350,3 +382,19 @@ int NCONF_dump_bio(CONF *conf, BIO *out) | |||
| 350 | return conf->meth->dump(conf, out); | 382 | return conf->meth->dump(conf, out); |
| 351 | } | 383 | } |
| 352 | 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 | |||
