1*de0e0e4dSAntonio Huete Jimenez /* $OpenBSD: conf.h,v 1.16 2022/07/12 14:42:48 kn Exp $ */
2f5b1c8a1SJohn Marino /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3f5b1c8a1SJohn Marino  * All rights reserved.
4f5b1c8a1SJohn Marino  *
5f5b1c8a1SJohn Marino  * This package is an SSL implementation written
6f5b1c8a1SJohn Marino  * by Eric Young (eay@cryptsoft.com).
7f5b1c8a1SJohn Marino  * The implementation was written so as to conform with Netscapes SSL.
8f5b1c8a1SJohn Marino  *
9f5b1c8a1SJohn Marino  * This library is free for commercial and non-commercial use as long as
10f5b1c8a1SJohn Marino  * the following conditions are aheared to.  The following conditions
11f5b1c8a1SJohn Marino  * apply to all code found in this distribution, be it the RC4, RSA,
12f5b1c8a1SJohn Marino  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13f5b1c8a1SJohn Marino  * included with this distribution is covered by the same copyright terms
14f5b1c8a1SJohn Marino  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15f5b1c8a1SJohn Marino  *
16f5b1c8a1SJohn Marino  * Copyright remains Eric Young's, and as such any Copyright notices in
17f5b1c8a1SJohn Marino  * the code are not to be removed.
18f5b1c8a1SJohn Marino  * If this package is used in a product, Eric Young should be given attribution
19f5b1c8a1SJohn Marino  * as the author of the parts of the library used.
20f5b1c8a1SJohn Marino  * This can be in the form of a textual message at program startup or
21f5b1c8a1SJohn Marino  * in documentation (online or textual) provided with the package.
22f5b1c8a1SJohn Marino  *
23f5b1c8a1SJohn Marino  * Redistribution and use in source and binary forms, with or without
24f5b1c8a1SJohn Marino  * modification, are permitted provided that the following conditions
25f5b1c8a1SJohn Marino  * are met:
26f5b1c8a1SJohn Marino  * 1. Redistributions of source code must retain the copyright
27f5b1c8a1SJohn Marino  *    notice, this list of conditions and the following disclaimer.
28f5b1c8a1SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
29f5b1c8a1SJohn Marino  *    notice, this list of conditions and the following disclaimer in the
30f5b1c8a1SJohn Marino  *    documentation and/or other materials provided with the distribution.
31f5b1c8a1SJohn Marino  * 3. All advertising materials mentioning features or use of this software
32f5b1c8a1SJohn Marino  *    must display the following acknowledgement:
33f5b1c8a1SJohn Marino  *    "This product includes cryptographic software written by
34f5b1c8a1SJohn Marino  *     Eric Young (eay@cryptsoft.com)"
35f5b1c8a1SJohn Marino  *    The word 'cryptographic' can be left out if the rouines from the library
36f5b1c8a1SJohn Marino  *    being used are not cryptographic related :-).
37f5b1c8a1SJohn Marino  * 4. If you include any Windows specific code (or a derivative thereof) from
38f5b1c8a1SJohn Marino  *    the apps directory (application code) you must include an acknowledgement:
39f5b1c8a1SJohn Marino  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40f5b1c8a1SJohn Marino  *
41f5b1c8a1SJohn Marino  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42f5b1c8a1SJohn Marino  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43f5b1c8a1SJohn Marino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44f5b1c8a1SJohn Marino  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45f5b1c8a1SJohn Marino  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46f5b1c8a1SJohn Marino  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47f5b1c8a1SJohn Marino  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48f5b1c8a1SJohn Marino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49f5b1c8a1SJohn Marino  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50f5b1c8a1SJohn Marino  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51f5b1c8a1SJohn Marino  * SUCH DAMAGE.
52f5b1c8a1SJohn Marino  *
53f5b1c8a1SJohn Marino  * The licence and distribution terms for any publically available version or
54f5b1c8a1SJohn Marino  * derivative of this code cannot be changed.  i.e. this code cannot simply be
55f5b1c8a1SJohn Marino  * copied and put under another distribution licence
56f5b1c8a1SJohn Marino  * [including the GNU Public Licence.]
57f5b1c8a1SJohn Marino  */
58f5b1c8a1SJohn Marino 
59f5b1c8a1SJohn Marino #ifndef  HEADER_CONF_H
60f5b1c8a1SJohn Marino #define HEADER_CONF_H
61f5b1c8a1SJohn Marino 
62f5b1c8a1SJohn Marino #include <openssl/opensslconf.h>
63f5b1c8a1SJohn Marino 
64f5b1c8a1SJohn Marino #include <openssl/bio.h>
65f5b1c8a1SJohn Marino #include <openssl/lhash.h>
66f5b1c8a1SJohn Marino #include <openssl/stack.h>
67f5b1c8a1SJohn Marino #include <openssl/safestack.h>
68f5b1c8a1SJohn Marino 
69f5b1c8a1SJohn Marino #include <openssl/ossl_typ.h>
70f5b1c8a1SJohn Marino 
71f5b1c8a1SJohn Marino #ifdef  __cplusplus
72f5b1c8a1SJohn Marino extern "C" {
73f5b1c8a1SJohn Marino #endif
74f5b1c8a1SJohn Marino 
75f5b1c8a1SJohn Marino typedef struct {
76f5b1c8a1SJohn Marino 	char *section;
77f5b1c8a1SJohn Marino 	char *name;
78f5b1c8a1SJohn Marino 	char *value;
79f5b1c8a1SJohn Marino } CONF_VALUE;
80f5b1c8a1SJohn Marino 
81f5b1c8a1SJohn Marino DECLARE_STACK_OF(CONF_VALUE)
82f5b1c8a1SJohn Marino DECLARE_LHASH_OF(CONF_VALUE);
83f5b1c8a1SJohn Marino 
84f5b1c8a1SJohn Marino struct conf_st;
85f5b1c8a1SJohn Marino struct conf_method_st;
86f5b1c8a1SJohn Marino typedef struct conf_method_st CONF_METHOD;
87f5b1c8a1SJohn Marino 
88f5b1c8a1SJohn Marino struct conf_method_st {
89f5b1c8a1SJohn Marino 	const char *name;
90f5b1c8a1SJohn Marino 	CONF *(*create)(CONF_METHOD *meth);
91f5b1c8a1SJohn Marino 	int (*init)(CONF *conf);
92f5b1c8a1SJohn Marino 	int (*destroy)(CONF *conf);
93f5b1c8a1SJohn Marino 	int (*destroy_data)(CONF *conf);
94f5b1c8a1SJohn Marino 	int (*load_bio)(CONF *conf, BIO *bp, long *eline);
95f5b1c8a1SJohn Marino 	int (*dump)(const CONF *conf, BIO *bp);
96f5b1c8a1SJohn Marino 	int (*is_number)(const CONF *conf, char c);
97f5b1c8a1SJohn Marino 	int (*to_int)(const CONF *conf, char c);
98f5b1c8a1SJohn Marino 	int (*load)(CONF *conf, const char *name, long *eline);
99f5b1c8a1SJohn Marino };
100f5b1c8a1SJohn Marino 
101f5b1c8a1SJohn Marino /* Module definitions */
102f5b1c8a1SJohn Marino 
103f5b1c8a1SJohn Marino typedef struct conf_imodule_st CONF_IMODULE;
104f5b1c8a1SJohn Marino typedef struct conf_module_st CONF_MODULE;
105f5b1c8a1SJohn Marino 
106f5b1c8a1SJohn Marino DECLARE_STACK_OF(CONF_MODULE)
107f5b1c8a1SJohn Marino DECLARE_STACK_OF(CONF_IMODULE)
108f5b1c8a1SJohn Marino 
109f5b1c8a1SJohn Marino /* DSO module function typedefs */
110f5b1c8a1SJohn Marino typedef int conf_init_func(CONF_IMODULE *md, const CONF *cnf);
111f5b1c8a1SJohn Marino typedef void conf_finish_func(CONF_IMODULE *md);
112f5b1c8a1SJohn Marino 
113f5b1c8a1SJohn Marino #define	CONF_MFLAGS_IGNORE_ERRORS	0x1
114f5b1c8a1SJohn Marino #define CONF_MFLAGS_IGNORE_RETURN_CODES	0x2
115f5b1c8a1SJohn Marino #define CONF_MFLAGS_SILENT		0x4
116f5b1c8a1SJohn Marino #define CONF_MFLAGS_NO_DSO		0x8
117f5b1c8a1SJohn Marino #define CONF_MFLAGS_IGNORE_MISSING_FILE	0x10
118f5b1c8a1SJohn Marino #define CONF_MFLAGS_DEFAULT_SECTION	0x20
119f5b1c8a1SJohn Marino 
120f5b1c8a1SJohn Marino int CONF_set_default_method(CONF_METHOD *meth);
121f5b1c8a1SJohn Marino void CONF_set_nconf(CONF *conf, LHASH_OF(CONF_VALUE) *hash);
122f5b1c8a1SJohn Marino LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf, const char *file,
123f5b1c8a1SJohn Marino     long *eline);
124f5b1c8a1SJohn Marino LHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp,
125f5b1c8a1SJohn Marino     long *eline);
126f5b1c8a1SJohn Marino LHASH_OF(CONF_VALUE) *CONF_load_bio(LHASH_OF(CONF_VALUE) *conf, BIO *bp, long *eline);
127f5b1c8a1SJohn Marino STACK_OF(CONF_VALUE) *CONF_get_section(LHASH_OF(CONF_VALUE) *conf,
128f5b1c8a1SJohn Marino     const char *section);
129f5b1c8a1SJohn Marino char *CONF_get_string(LHASH_OF(CONF_VALUE) *conf, const char *group,
130f5b1c8a1SJohn Marino     const char *name);
131f5b1c8a1SJohn Marino long CONF_get_number(LHASH_OF(CONF_VALUE) *conf, const char *group,
132f5b1c8a1SJohn Marino     const char *name);
133f5b1c8a1SJohn Marino void CONF_free(LHASH_OF(CONF_VALUE) *conf);
134f5b1c8a1SJohn Marino int CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out);
135f5b1c8a1SJohn Marino int CONF_dump_bio(LHASH_OF(CONF_VALUE) *conf, BIO *out);
136f5b1c8a1SJohn Marino 
137f5b1c8a1SJohn Marino void OPENSSL_config(const char *config_name);
138f5b1c8a1SJohn Marino void OPENSSL_no_config(void);
139f5b1c8a1SJohn Marino 
140f5b1c8a1SJohn Marino /* New conf code.  The semantics are different from the functions above.
141f5b1c8a1SJohn Marino    If that wasn't the case, the above functions would have been replaced */
142f5b1c8a1SJohn Marino 
143f5b1c8a1SJohn Marino struct conf_st {
144f5b1c8a1SJohn Marino 	CONF_METHOD *meth;
145f5b1c8a1SJohn Marino 	void *meth_data;
146f5b1c8a1SJohn Marino 	LHASH_OF(CONF_VALUE) *data;
147f5b1c8a1SJohn Marino };
148f5b1c8a1SJohn Marino 
149f5b1c8a1SJohn Marino CONF *NCONF_new(CONF_METHOD *meth);
150f5b1c8a1SJohn Marino CONF_METHOD *NCONF_default(void);
151f5b1c8a1SJohn Marino CONF_METHOD *NCONF_WIN32(void);
152f5b1c8a1SJohn Marino void NCONF_free(CONF *conf);
153f5b1c8a1SJohn Marino void NCONF_free_data(CONF *conf);
154f5b1c8a1SJohn Marino 
155f5b1c8a1SJohn Marino int NCONF_load(CONF *conf, const char *file, long *eline);
156f5b1c8a1SJohn Marino int NCONF_load_fp(CONF *conf, FILE *fp, long *eline);
157f5b1c8a1SJohn Marino int NCONF_load_bio(CONF *conf, BIO *bp, long *eline);
158f5b1c8a1SJohn Marino STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf, const char *section);
159f5b1c8a1SJohn Marino char *NCONF_get_string(const CONF *conf, const char *group, const char *name);
160f5b1c8a1SJohn Marino int NCONF_get_number_e(const CONF *conf, const char *group, const char *name,
161f5b1c8a1SJohn Marino     long *result);
162f5b1c8a1SJohn Marino int NCONF_dump_fp(const CONF *conf, FILE *out);
163f5b1c8a1SJohn Marino int NCONF_dump_bio(const CONF *conf, BIO *out);
164f5b1c8a1SJohn Marino 
165f5b1c8a1SJohn Marino #define NCONF_get_number(c,g,n,r) NCONF_get_number_e(c,g,n,r)
166f5b1c8a1SJohn Marino 
167f5b1c8a1SJohn Marino /* Module functions */
168f5b1c8a1SJohn Marino 
169f5b1c8a1SJohn Marino int CONF_modules_load(const CONF *cnf, const char *appname,
170f5b1c8a1SJohn Marino     unsigned long flags);
171f5b1c8a1SJohn Marino int CONF_modules_load_file(const char *filename, const char *appname,
172f5b1c8a1SJohn Marino     unsigned long flags);
173f5b1c8a1SJohn Marino void CONF_modules_unload(int all);
174f5b1c8a1SJohn Marino void CONF_modules_finish(void);
175f5b1c8a1SJohn Marino void CONF_modules_free(void);
176f5b1c8a1SJohn Marino int CONF_module_add(const char *name, conf_init_func *ifunc,
177f5b1c8a1SJohn Marino     conf_finish_func *ffunc);
178f5b1c8a1SJohn Marino 
179f5b1c8a1SJohn Marino const char *CONF_imodule_get_name(const CONF_IMODULE *md);
180f5b1c8a1SJohn Marino const char *CONF_imodule_get_value(const CONF_IMODULE *md);
181f5b1c8a1SJohn Marino void *CONF_imodule_get_usr_data(const CONF_IMODULE *md);
182f5b1c8a1SJohn Marino void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data);
183f5b1c8a1SJohn Marino CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md);
184f5b1c8a1SJohn Marino unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md);
185f5b1c8a1SJohn Marino void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags);
186f5b1c8a1SJohn Marino void *CONF_module_get_usr_data(CONF_MODULE *pmod);
187f5b1c8a1SJohn Marino void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data);
188f5b1c8a1SJohn Marino 
189f5b1c8a1SJohn Marino char *CONF_get1_default_config_file(void);
190f5b1c8a1SJohn Marino 
191f5b1c8a1SJohn Marino int CONF_parse_list(const char *list, int sep, int nospc,
192f5b1c8a1SJohn Marino     int (*list_cb)(const char *elem, int len, void *usr), void *arg);
193f5b1c8a1SJohn Marino 
194f5b1c8a1SJohn Marino void OPENSSL_load_builtin_modules(void);
195f5b1c8a1SJohn Marino 
196f5b1c8a1SJohn Marino void ERR_load_CONF_strings(void);
197f5b1c8a1SJohn Marino 
198f5b1c8a1SJohn Marino /* Error codes for the CONF functions. */
199f5b1c8a1SJohn Marino 
200f5b1c8a1SJohn Marino /* Function codes. */
201f5b1c8a1SJohn Marino #define CONF_F_CONF_DUMP_FP				 104
202f5b1c8a1SJohn Marino #define CONF_F_CONF_LOAD				 100
203f5b1c8a1SJohn Marino #define CONF_F_CONF_LOAD_BIO				 102
204f5b1c8a1SJohn Marino #define CONF_F_CONF_LOAD_FP				 103
205f5b1c8a1SJohn Marino #define CONF_F_CONF_MODULES_LOAD			 116
206f5b1c8a1SJohn Marino #define CONF_F_CONF_PARSE_LIST				 119
207f5b1c8a1SJohn Marino #define CONF_F_DEF_LOAD					 120
208f5b1c8a1SJohn Marino #define CONF_F_DEF_LOAD_BIO				 121
209f5b1c8a1SJohn Marino #define CONF_F_MODULE_INIT				 115
210f5b1c8a1SJohn Marino #define CONF_F_MODULE_LOAD_DSO				 117
211f5b1c8a1SJohn Marino #define CONF_F_MODULE_RUN				 118
212f5b1c8a1SJohn Marino #define CONF_F_NCONF_DUMP_BIO				 105
213f5b1c8a1SJohn Marino #define CONF_F_NCONF_DUMP_FP				 106
214f5b1c8a1SJohn Marino #define CONF_F_NCONF_GET_NUMBER				 107
215f5b1c8a1SJohn Marino #define CONF_F_NCONF_GET_NUMBER_E			 112
216f5b1c8a1SJohn Marino #define CONF_F_NCONF_GET_SECTION			 108
217f5b1c8a1SJohn Marino #define CONF_F_NCONF_GET_STRING				 109
218f5b1c8a1SJohn Marino #define CONF_F_NCONF_LOAD				 113
219f5b1c8a1SJohn Marino #define CONF_F_NCONF_LOAD_BIO				 110
220f5b1c8a1SJohn Marino #define CONF_F_NCONF_LOAD_FP				 114
221f5b1c8a1SJohn Marino #define CONF_F_NCONF_NEW				 111
222f5b1c8a1SJohn Marino #define CONF_F_STR_COPY					 101
223f5b1c8a1SJohn Marino 
224f5b1c8a1SJohn Marino /* Reason codes. */
225f5b1c8a1SJohn Marino #define CONF_R_ERROR_LOADING_DSO			 110
226f5b1c8a1SJohn Marino #define CONF_R_LIST_CANNOT_BE_NULL			 115
227f5b1c8a1SJohn Marino #define CONF_R_MISSING_CLOSE_SQUARE_BRACKET		 100
228f5b1c8a1SJohn Marino #define CONF_R_MISSING_EQUAL_SIGN			 101
229f5b1c8a1SJohn Marino #define CONF_R_MISSING_FINISH_FUNCTION			 111
230f5b1c8a1SJohn Marino #define CONF_R_MISSING_INIT_FUNCTION			 112
231f5b1c8a1SJohn Marino #define CONF_R_MODULE_INITIALIZATION_ERROR		 109
232f5b1c8a1SJohn Marino #define CONF_R_NO_CLOSE_BRACE				 102
233f5b1c8a1SJohn Marino #define CONF_R_NO_CONF					 105
234f5b1c8a1SJohn Marino #define CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE		 106
235f5b1c8a1SJohn Marino #define CONF_R_NO_SECTION				 107
236f5b1c8a1SJohn Marino #define CONF_R_NO_SUCH_FILE				 114
237f5b1c8a1SJohn Marino #define CONF_R_NO_VALUE					 108
238f5b1c8a1SJohn Marino #define CONF_R_UNABLE_TO_CREATE_NEW_SECTION		 103
239f5b1c8a1SJohn Marino #define CONF_R_UNKNOWN_MODULE_NAME			 113
240cca6fc52SDaniel Fojt #define CONF_R_VARIABLE_EXPANSION_TOO_LONG		 116
241f5b1c8a1SJohn Marino #define CONF_R_VARIABLE_HAS_NO_VALUE			 104
242f5b1c8a1SJohn Marino 
243f5b1c8a1SJohn Marino #ifdef  __cplusplus
244f5b1c8a1SJohn Marino }
245f5b1c8a1SJohn Marino #endif
246f5b1c8a1SJohn Marino #endif
247