1 .\" $OpenBSD: CONF_modules_load_file.3,v 1.5 2016/12/11 18:06:09 schwarze Exp $
2 .\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
4 .\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
5 .\" Copyright (c) 2000, 2015 The OpenSSL Project. All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in
16 .\" the documentation and/or other materials provided with the
19 .\" 3. All advertising materials mentioning features or use of this
20 .\" software must display the following acknowledgment:
21 .\" "This product includes software developed by the OpenSSL Project
22 .\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 .\" endorse or promote products derived from this software without
26 .\" prior written permission. For written permission, please contact
27 .\" openssl-core@openssl.org.
29 .\" 5. Products derived from this software may not be called "OpenSSL"
30 .\" nor may "OpenSSL" appear in their names without prior written
31 .\" permission of the OpenSSL Project.
33 .\" 6. Redistributions of any form whatsoever must retain the following
35 .\" "This product includes software developed by the OpenSSL Project
36 .\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 .\" OF THE POSSIBILITY OF SUCH DAMAGE.
51 .Dd $Mdocdate: December 11 2016 $
52 .Dt CONF_MODULES_LOAD_FILE 3
55 .Nm CONF_modules_load_file ,
57 .Nd OpenSSL configuration functions
61 .Fo CONF_modules_load_file
62 .Fa "const char *filename"
63 .Fa "const char *appname"
64 .Fa "unsigned long flags"
69 .Fa "const char *appname"
70 .Fa "unsigned long flags"
74 .Fn CONF_modules_load_file
75 configures OpenSSL using the file
79 format and the application name
85 the standard OpenSSL configuration file
86 .Pa /etc/ssl/openssl.cnf
92 the standard OpenSSL application name
95 The behaviour can be customized using
100 .Fn CONF_modules_load_file
101 except it reads configuration information from
106 are currently recognized:
108 .It Dv CONF_MFLAGS_IGNORE_ERRORS
109 Ignore errors returned by individual configuration modules.
110 By default, the first module error is considered fatal and no further
112 .It Dv CONF_MFLAGS_SILENT
113 Do not add any error information.
114 By default, all module errors add error information to the error queue.
115 .It Dv CONF_MFLAGS_NO_DSO
116 Disable loading of configuration modules from DSOs.
117 .It Dv CONF_MFLAGS_IGNORE_MISSING_FILE
119 .Fn CONF_modules_load_file
120 ignore missing configuration files.
121 By default, a missing configuration file returns an error.
122 .It CONF_MFLAGS_DEFAULT_SECTION
127 but does not exist, fall back to the default section
132 .Fn CONF_modules_load_file
133 with appropriate flags, an application can customise application
134 configuration to best suit its needs.
135 In some cases the use of a configuration file is optional and its
136 absence is not an error: in this case
137 .Dv CONF_MFLAGS_IGNORE_MISSING_FILE
140 Errors during configuration may also be handled differently by
141 different applications.
142 For example in some cases an error may simply print out a warning
143 message and the application may continue.
144 In other cases an application might consider a configuration file
145 error fatal and exit immediately.
147 Applications can use the
148 .Fn CONF_modules_load
149 function if they wish to load a configuration file themselves and
150 have finer control over how errors are treated.
152 These functions return 1 for success and zero or a negative value for
154 If module errors are not ignored, the return code will reflect the return
155 value of the failing module (this will always be zero or negative).
157 .Bl -tag -width /etc/ssl/openssl.cnf -compact
158 .It Pa /etc/ssl/openssl.cnf
159 standard configuration file
162 Load a configuration file and print out any errors and exit (missing
163 file considered fatal):
165 if (CONF_modules_load_file(NULL, NULL, 0) <= 0) {
166 fprintf(stderr, "FATAL: error loading configuration file\n");
167 ERR_print_errors_fp(stderr);
172 Load default configuration file using the section indicated
173 by "myapp", tolerate missing files, but exit on other errors:
175 if (CONF_modules_load_file(NULL, "myapp",
176 CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
177 fprintf(stderr, "FATAL: error loading configuration file\n");
178 ERR_print_errors_fp(stderr);
183 Load custom configuration file and section, only print warnings on
184 error, missing configuration file ignored:
186 if (CONF_modules_load_file("/something/app.cnf", "myapp",
187 CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
188 fprintf(stderr, "WARNING: error loading configuration file\n");
189 ERR_print_errors_fp(stderr);
193 Load and parse configuration file manually, custom error handling:
199 fp = fopen("/somepath/app.cnf", "r");
201 fprintf(stderr, "Error opening configuration file\n");
202 /* Other missing configuration file behaviour */
204 cnf = NCONF_new(NULL);
205 if (NCONF_load_fp(cnf, fp, &eline) == 0) {
206 fprintf(stderr, "Error on line %ld of configuration file\n",
208 ERR_print_errors_fp(stderr);
209 /* Other malformed configuration file behaviour */
210 } else if (CONF_modules_load(cnf, "appname", 0) <= 0) {
211 fprintf(stderr, "Error configuring application\n");
212 ERR_print_errors_fp(stderr);
213 /* Other configuration error behaviour */
220 .Xr CONF_modules_free 3 ,
224 .Fn CONF_modules_load_file
226 .Fn CONF_modules_load
227 first appeared in OpenSSL 0.9.7.