2 /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
5 /* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
34 * 6. Redistributions of any form whatsoever must retain the following
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
60 #include <openssl/crypto.h>
61 #include <openssl/err.h>
62 #include <openssl/conf.h>
63 #include <openssl/conf_api.h>
64 #include <openssl/lhash.h>
66 const char *CONF_version="CONF" OPENSSL_VERSION_PTEXT;
68 static CONF_METHOD *default_CONF_method=NULL;
70 /* The following section contains the "CONF classic" functions,
71 rewritten in terms of the new CONF interface. */
73 int CONF_set_default_method(CONF_METHOD *meth)
75 default_CONF_method = meth;
79 LHASH *CONF_load(LHASH *conf, const char *file, long *eline)
85 in=BIO_new_file(file, "r");
87 in=BIO_new_file(file, "rb");
91 CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
95 ltmp = CONF_load_bio(conf, in, eline);
102 LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline)
106 if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE))) {
107 CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB);
110 ltmp = CONF_load_bio(conf, btmp, eline);
116 LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline)
121 if (default_CONF_method == NULL)
122 default_CONF_method = NCONF_default();
124 default_CONF_method->init(&ctmp);
126 ret = NCONF_load_bio(&ctmp, bp, eline);
132 STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,char *section)
136 if (default_CONF_method == NULL)
137 default_CONF_method = NCONF_default();
139 default_CONF_method->init(&ctmp);
141 return NCONF_get_section(&ctmp, section);
144 char *CONF_get_string(LHASH *conf,char *group,char *name)
148 if (default_CONF_method == NULL)
149 default_CONF_method = NCONF_default();
151 default_CONF_method->init(&ctmp);
153 return NCONF_get_string(&ctmp, group, name);
156 long CONF_get_number(LHASH *conf,char *group,char *name)
160 if (default_CONF_method == NULL)
161 default_CONF_method = NCONF_default();
163 default_CONF_method->init(&ctmp);
165 return NCONF_get_number(&ctmp, group, name);
168 void CONF_free(LHASH *conf)
172 if (default_CONF_method == NULL)
173 default_CONF_method = NCONF_default();
175 default_CONF_method->init(&ctmp);
177 NCONF_free_data(&ctmp);
181 int CONF_dump_fp(LHASH *conf, FILE *out)
186 if(!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) {
187 CONFerr(CONF_F_CONF_DUMP_FP,ERR_R_BUF_LIB);
190 ret = CONF_dump_bio(conf, btmp);
196 int CONF_dump_bio(LHASH *conf, BIO *out)
200 if (default_CONF_method == NULL)
201 default_CONF_method = NCONF_default();
203 default_CONF_method->init(&ctmp);
205 return NCONF_dump_bio(&ctmp, out);
208 /* The following section contains the "New CONF" functions. They are
209 completely centralised around a new CONF structure that may contain
210 basically anything, but at least a method pointer and a table of data.
211 These functions are also written in terms of the bridge functions used
212 by the "CONF classic" functions, for consistency. */
214 CONF *NCONF_new(CONF_METHOD *meth)
219 meth = NCONF_default();
221 ret = meth->create(meth);
224 CONFerr(CONF_F_NCONF_NEW,ERR_R_MALLOC_FAILURE);
231 void NCONF_free(CONF *conf)
235 conf->meth->destroy(conf);
238 void NCONF_free_data(CONF *conf)
242 conf->meth->destroy_data(conf);
245 int NCONF_load(CONF *conf, const char *file, long *eline)
251 in=BIO_new_file(file, "r");
253 in=BIO_new_file(file, "rb");
257 CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
261 ret = NCONF_load_bio(conf, in, eline);
268 int NCONF_load_fp(CONF *conf, FILE *fp,long *eline)
272 if(!(btmp = BIO_new_fp(fp, BIO_NOCLOSE)))
274 CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB);
277 ret = NCONF_load_bio(conf, btmp, eline);
283 int NCONF_load_bio(CONF *conf, BIO *bp,long *eline)
287 CONFerr(CONF_F_NCONF_LOAD_BIO,CONF_R_NO_CONF);
291 return conf->meth->load(conf, bp, eline);
294 STACK_OF(CONF_VALUE) *NCONF_get_section(CONF *conf,char *section)
298 CONFerr(CONF_F_NCONF_GET_SECTION,CONF_R_NO_CONF);
302 return _CONF_get_section_values(conf, section);
305 char *NCONF_get_string(CONF *conf,char *group,char *name)
309 CONFerr(CONF_F_NCONF_GET_STRING,CONF_R_NO_CONF);
313 return _CONF_get_string(conf, group, name);
316 long NCONF_get_number(CONF *conf,char *group,char *name)
320 CONFerr(CONF_F_NCONF_GET_NUMBER,CONF_R_NO_CONF);
324 return _CONF_get_number(conf, group, name);
328 int NCONF_dump_fp(CONF *conf, FILE *out)
332 if(!(btmp = BIO_new_fp(out, BIO_NOCLOSE))) {
333 CONFerr(CONF_F_NCONF_DUMP_FP,ERR_R_BUF_LIB);
336 ret = NCONF_dump_bio(conf, btmp);
342 int NCONF_dump_bio(CONF *conf, BIO *out)
346 CONFerr(CONF_F_NCONF_DUMP_BIO,CONF_R_NO_CONF);
350 return conf->meth->dump(conf, out);