xref: /openbsd-src/lib/libcrypto/man/CONF_modules_load_file.3 (revision 99fd087599a8791921855f21bd7e36130f39aadc)
1.\"	$OpenBSD: CONF_modules_load_file.3,v 1.9 2019/06/14 13:41:31 schwarze Exp $
2.\"	OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
5.\" Copyright (c) 2000, 2015 The OpenSSL Project.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\"
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
17.\"    distribution.
18.\"
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/)"
23.\"
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.
28.\"
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.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\"    acknowledgment:
35.\"    "This product includes software developed by the OpenSSL Project
36.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
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.
50.\"
51.Dd $Mdocdate: June 14 2019 $
52.Dt CONF_MODULES_LOAD_FILE 3
53.Os
54.Sh NAME
55.Nm CONF_modules_load_file ,
56.Nm CONF_modules_load
57.Nd OpenSSL configuration functions
58.Sh SYNOPSIS
59.In openssl/conf.h
60.Ft int
61.Fo CONF_modules_load_file
62.Fa "const char *filename"
63.Fa "const char *appname"
64.Fa "unsigned long flags"
65.Fc
66.Ft int
67.Fo CONF_modules_load
68.Fa "const CONF *cnf"
69.Fa "const char *appname"
70.Fa "unsigned long flags"
71.Fc
72.Sh DESCRIPTION
73The function
74.Fn CONF_modules_load_file
75configures OpenSSL using the file
76.Fa filename
77in
78.Xr openssl.cnf 5
79format and the application name
80.Fa appname .
81If
82.Fa filename
83is
84.Dv NULL ,
85the standard OpenSSL configuration file
86.Pa /etc/ssl/openssl.cnf
87is used.
88If
89.Fa appname
90is
91.Dv NULL ,
92the standard OpenSSL application name
93.Qq openssl_conf
94is used.
95The behaviour can be customized using
96.Fa flags .
97.Pp
98See the
99.Sx EXAMPLES
100section for additional functions that may need to be called.
101Calling configuration functions in the right order for the intended
102effect can be tricky because many configuration functions internally
103call each other.
104.Pp
105.Fn CONF_modules_load
106is identical to
107.Fn CONF_modules_load_file
108except it reads configuration information from
109.Fa cnf .
110.Pp
111The following
112.Fa flags
113are currently recognized:
114.Bl -tag -width Ds
115.It Dv CONF_MFLAGS_IGNORE_ERRORS
116Ignore errors returned by individual configuration modules.
117By default, the first module error is considered fatal and no further
118modules are loaded.
119.It Dv CONF_MFLAGS_SILENT
120Do not add any error information.
121By default, all module errors add error information to the error queue.
122.It Dv CONF_MFLAGS_NO_DSO
123Disable loading of configuration modules from DSOs.
124.It Dv CONF_MFLAGS_IGNORE_MISSING_FILE
125Let
126.Fn CONF_modules_load_file
127ignore missing configuration files.
128By default, a missing configuration file returns an error.
129.It CONF_MFLAGS_DEFAULT_SECTION
130If
131.Fa appname
132is not
133.Dv NULL
134but does not exist, fall back to the default section
135.Qq openssl_conf .
136.El
137.Pp
138By using
139.Fn CONF_modules_load_file
140with appropriate flags, an application can customise application
141configuration to best suit its needs.
142In some cases the use of a configuration file is optional and its
143absence is not an error: in this case
144.Dv CONF_MFLAGS_IGNORE_MISSING_FILE
145would be set.
146.Pp
147Errors during configuration may also be handled differently by
148different applications.
149For example in some cases an error may simply print out a warning
150message and the application may continue.
151In other cases an application might consider a configuration file
152error fatal and exit immediately.
153.Pp
154Applications can use the
155.Fn CONF_modules_load
156function if they wish to load a configuration file themselves and
157have finer control over how errors are treated.
158.Sh RETURN VALUES
159These functions return 1 for success and zero or a negative value for
160failure.
161If module errors are not ignored, the return code will reflect the return
162value of the failing module (this will always be zero or negative).
163.Sh FILES
164.Bl -tag -width /etc/ssl/openssl.cnf -compact
165.It Pa /etc/ssl/openssl.cnf
166standard configuration file
167.El
168.Sh EXAMPLES
169Load a configuration file and print out any errors and exit (missing
170file considered fatal):
171.Bd -literal
172if (CONF_modules_load_file(NULL, NULL, 0) <= 0) {
173	fprintf(stderr, "FATAL: error loading configuration file\en");
174	ERR_print_errors_fp(stderr);
175	exit(1);
176}
177.Ed
178.Pp
179Load default configuration file using the section indicated
180by "myapp", tolerate missing files, but exit on other errors:
181.Bd -literal
182if (CONF_modules_load_file(NULL, "myapp",
183    CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
184	fprintf(stderr, "FATAL: error loading configuration file\en");
185	ERR_print_errors_fp(stderr);
186	exit(1);
187}
188.Ed
189.Pp
190Load custom configuration file and section instead of the standard one,
191only print warnings on error, missing configuration file ignored:
192.Bd -literal
193OPENSSL_no_config();
194ENGINE_load_builtin_engines();
195OPENSSL_load_builtin_modules();
196if (CONF_modules_load_file("/something/app.cnf", "myapp",
197    CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
198	fprintf(stderr, "WARNING: error loading configuration file\en");
199	ERR_print_errors_fp(stderr);
200}
201.Ed
202.Pp
203In the previous example, the call to
204.Xr OPENSSL_no_config 3
205is required first to suppress automatic loading
206of the standard configuration file, and the calls to
207.Xr ENGINE_load_builtin_engines 3
208and
209.Xr OPENSSL_load_builtin_modules 3
210are needed so that the configuration of builtin modules and engines
211is also loaded in addition to the configuration of
212.Qq myapp .
213.Pp
214Load and parse configuration file manually, custom error handling:
215.Bd -literal
216FILE	*fp;
217CONF	*cnf = NULL;
218long	 eline;
219
220fp = fopen("/somepath/app.cnf", "r");
221if (fp == NULL) {
222	fprintf(stderr, "Error opening configuration file\en");
223	/* Other missing configuration file behaviour */
224} else {
225	cnf = NCONF_new(NULL);
226	if (NCONF_load_fp(cnf, fp, &eline) == 0) {
227		fprintf(stderr, "Error on line %ld of configuration file\en",
228		    eline);
229		ERR_print_errors_fp(stderr);
230		/* Other malformed configuration file behaviour */
231	} else if (CONF_modules_load(cnf, "appname", 0) <= 0) {
232		fprintf(stderr, "Error configuring application\en");
233		ERR_print_errors_fp(stderr);
234		/* Other configuration error behaviour */
235	}
236	fclose(fp);
237	NCONF_free(cnf);
238}
239.Ed
240.Sh SEE ALSO
241.Xr CONF_modules_free 3 ,
242.Xr ENGINE_load_builtin_engines 3 ,
243.Xr ERR 3 ,
244.Xr OPENSSL_config 3 ,
245.Xr OPENSSL_load_builtin_modules 3
246.Sh HISTORY
247.Fn CONF_modules_load_file
248and
249.Fn CONF_modules_load
250first appeared in OpenSSL 0.9.7 and have been available since
251.Ox 3.2 .
252