1/*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10#ifndef HEADER_CONF_H
11# define HEADER_CONF_H
12
13# include <openssl/bio.h>
14# include <openssl/lhash.h>
15# include <openssl/stack.h>
16# include <openssl/safestack.h>
17# include <openssl/e_os2.h>
18
19# include <openssl/ossl_typ.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25typedef struct {
26 char *section;
27 char *name;
28 char *value;
29} CONF_VALUE;
30
31DEFINE_STACK_OF(CONF_VALUE)
32DEFINE_LHASH_OF(CONF_VALUE);
33
34struct conf_st;
35struct conf_method_st;
36typedef struct conf_method_st CONF_METHOD;
37
38struct conf_method_st {
39 const char *name;
40 CONF *(*create) (CONF_METHOD *meth);
41 int (*init) (CONF *conf);
42 int (*destroy) (CONF *conf);
43 int (*destroy_data) (CONF *conf);
44 int (*load_bio) (CONF *conf, BIO *bp, long *eline);
45 int (*dump) (const CONF *conf, BIO *bp);
46 int (*is_number) (const CONF *conf, char c);
47 int (*to_int) (const CONF *conf, char c);
48 int (*load) (CONF *conf, const char *name, long *eline);
49};
50
51/* Module definitions */
52
53typedef struct conf_imodule_st CONF_IMODULE;
54typedef struct conf_module_st CONF_MODULE;
55
56DEFINE_STACK_OF(CONF_MODULE)
57DEFINE_STACK_OF(CONF_IMODULE)
58
59/* DSO module function typedefs */
60typedef int conf_init_func (CONF_IMODULE *md, const CONF *cnf);
61typedef void conf_finish_func (CONF_IMODULE *md);
62
63# define CONF_MFLAGS_IGNORE_ERRORS 0x1
64# define CONF_MFLAGS_IGNORE_RETURN_CODES 0x2
65# define CONF_MFLAGS_SILENT 0x4
66# define CONF_MFLAGS_NO_DSO 0x8
67# define CONF_MFLAGS_IGNORE_MISSING_FILE 0x10
68# define CONF_MFLAGS_DEFAULT_SECTION 0x20
69
70int CONF_set_default_method(CONF_METHOD *meth);
71void CONF_set_nconf(CONF *conf, LHASH_OF(CONF_VALUE) *hash);
72LHASH_OF(CONF_VALUE) *CONF_load(LHASH_OF(CONF_VALUE) *conf, const char *file,
73 long *eline);
74# ifndef OPENSSL_NO_STDIO
75LHASH_OF(CONF_VALUE) *CONF_load_fp(LHASH_OF(CONF_VALUE) *conf, FILE *fp,
76 long *eline);
77# endif
78LHASH_OF(CONF_VALUE) *CONF_load_bio(LHASH_OF(CONF_VALUE) *conf, BIO *bp,
79 long *eline);
80STACK_OF(CONF_VALUE) *CONF_get_section(LHASH_OF(CONF_VALUE) *conf,
81 const char *section);
82char *CONF_get_string(LHASH_OF(CONF_VALUE) *conf, const char *group,
83 const char *name);
84long CONF_get_number(LHASH_OF(CONF_VALUE) *conf, const char *group,
85 const char *name);
86void CONF_free(LHASH_OF(CONF_VALUE) *conf);
87#ifndef OPENSSL_NO_STDIO
88int CONF_dump_fp(LHASH_OF(CONF_VALUE) *conf, FILE *out);
89#endif
90int CONF_dump_bio(LHASH_OF(CONF_VALUE) *conf, BIO *out);
91
92DEPRECATEDIN_1_1_0(void OPENSSL_config(const char *config_name))
93
94#if OPENSSL_API_COMPAT < 0x10100000L
95# define OPENSSL_no_config() \
96 OPENSSL_init_crypto(OPENSSL_INIT_NO_LOAD_CONFIG, NULL)
97#endif
98
99/*
100 * New conf code. The semantics are different from the functions above. If
101 * that wasn't the case, the above functions would have been replaced
102 */
103
104struct conf_st {
105 CONF_METHOD *meth;
106 void *meth_data;
107 LHASH_OF(CONF_VALUE) *data;
108};
109
110CONF *NCONF_new(CONF_METHOD *meth);
111CONF_METHOD *NCONF_default(void);
112CONF_METHOD *NCONF_WIN32(void);
113void NCONF_free(CONF *conf);
114void NCONF_free_data(CONF *conf);
115
116int NCONF_load(CONF *conf, const char *file, long *eline);
117# ifndef OPENSSL_NO_STDIO
118int NCONF_load_fp(CONF *conf, FILE *fp, long *eline);
119# endif
120int NCONF_load_bio(CONF *conf, BIO *bp, long *eline);
121STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,
122 const char *section);
123char *NCONF_get_string(const CONF *conf, const char *group, const char *name);
124int NCONF_get_number_e(const CONF *conf, const char *group, const char *name,
125 long *result);
126#ifndef OPENSSL_NO_STDIO
127int NCONF_dump_fp(const CONF *conf, FILE *out);
128#endif
129int NCONF_dump_bio(const CONF *conf, BIO *out);
130
131#define NCONF_get_number(c,g,n,r) NCONF_get_number_e(c,g,n,r)
132
133/* Module functions */
134
135int CONF_modules_load(const CONF *cnf, const char *appname,
136 unsigned long flags);
137int CONF_modules_load_file(const char *filename, const char *appname,
138 unsigned long flags);
139void CONF_modules_unload(int all);
140void CONF_modules_finish(void);
141#if OPENSSL_API_COMPAT < 0x10100000L
142# define CONF_modules_free() while(0) continue
143#endif
144int CONF_module_add(const char *name, conf_init_func *ifunc,
145 conf_finish_func *ffunc);
146
147const char *CONF_imodule_get_name(const CONF_IMODULE *md);
148const char *CONF_imodule_get_value(const CONF_IMODULE *md);
149void *CONF_imodule_get_usr_data(const CONF_IMODULE *md);
150void CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data);
151CONF_MODULE *CONF_imodule_get_module(const CONF_IMODULE *md);
152unsigned long CONF_imodule_get_flags(const CONF_IMODULE *md);
153void CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags);
154void *CONF_module_get_usr_data(CONF_MODULE *pmod);
155void CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data);
156
157char *CONF_get1_default_config_file(void);
158
159int CONF_parse_list(const char *list, int sep, int nospc,
160 int (*list_cb) (const char *elem, int len, void *usr),
161 void *arg);
162
163void OPENSSL_load_builtin_modules(void);
164
165/* BEGIN ERROR CODES */
166/*
167 * The following lines are auto generated by the script mkerr.pl. Any changes
168 * made after this point may be overwritten when the script is next run.
169 */
170
171int ERR_load_CONF_strings(void);
172
173/* Error codes for the CONF functions. */
174
175/* Function codes. */
176# define CONF_F_CONF_DUMP_FP 104
177# define CONF_F_CONF_LOAD 100
178# define CONF_F_CONF_LOAD_FP 103
179# define CONF_F_CONF_PARSE_LIST 119
180# define CONF_F_DEF_LOAD 120
181# define CONF_F_DEF_LOAD_BIO 121
182# define CONF_F_MODULE_INIT 115
183# define CONF_F_MODULE_LOAD_DSO 117
184# define CONF_F_MODULE_RUN 118
185# define CONF_F_NCONF_DUMP_BIO 105
186# define CONF_F_NCONF_DUMP_FP 106
187# define CONF_F_NCONF_GET_NUMBER_E 112
188# define CONF_F_NCONF_GET_SECTION 108
189# define CONF_F_NCONF_GET_STRING 109
190# define CONF_F_NCONF_LOAD 113
191# define CONF_F_NCONF_LOAD_BIO 110
192# define CONF_F_NCONF_LOAD_FP 114
193# define CONF_F_NCONF_NEW 111
194# define CONF_F_STR_COPY 101
195
196/* Reason codes. */
197# define CONF_R_ERROR_LOADING_DSO 110
198# define CONF_R_LIST_CANNOT_BE_NULL 115
199# define CONF_R_MISSING_CLOSE_SQUARE_BRACKET 100
200# define CONF_R_MISSING_EQUAL_SIGN 101
201# define CONF_R_MISSING_INIT_FUNCTION 112
202# define CONF_R_MODULE_INITIALIZATION_ERROR 109
203# define CONF_R_NO_CLOSE_BRACE 102
204# define CONF_R_NO_CONF 105
205# define CONF_R_NO_CONF_OR_ENVIRONMENT_VARIABLE 106
206# define CONF_R_NO_SECTION 107
207# define CONF_R_NO_SUCH_FILE 114
208# define CONF_R_NO_VALUE 108
209# define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103
210# define CONF_R_UNKNOWN_MODULE_NAME 113
211# define CONF_R_VARIABLE_EXPANSION_TOO_LONG 116
212# define CONF_R_VARIABLE_HAS_NO_VALUE 104
213
214# ifdef __cplusplus
215}
216# endif
217#endif
218