1=pod
2
3=head1 NAME
4
5CONF_modules_load_file, CONF_modules_load - OpenSSL configuration functions
6
7=head1 SYNOPSIS
8
9 #include <openssl/conf.h>
10
11 int CONF_modules_load_file(const char *filename, const char *appname,
12                            unsigned long flags);
13 int CONF_modules_load(const CONF *cnf, const char *appname,
14                       unsigned long flags);
15
16=head1 DESCRIPTION
17
18The function CONF_modules_load_file() configures OpenSSL using file
19B<filename> and application name B<appname>. If B<filename> is NULL
20the standard OpenSSL configuration file is used. If B<appname> is
21NULL the standard OpenSSL application name B<openssl_conf> is used.
22The behaviour can be customized using B<flags>.
23
24CONF_modules_load() is identical to CONF_modules_load_file() except it
25reads configuration information from B<cnf>.
26
27=head1 NOTES
28
29The following B<flags> are currently recognized:
30
31B<CONF_MFLAGS_IGNORE_ERRORS> if set errors returned by individual
32configuration modules are ignored. If not set the first module error is
33considered fatal and no further modules are loaded.
34
35Normally any modules errors will add error information to the error queue. If
36B<CONF_MFLAGS_SILENT> is set no error information is added.
37
38If B<CONF_MFLAGS_NO_DSO> is set configuration module loading from DSOs is
39disabled.
40
41B<CONF_MFLAGS_IGNORE_MISSING_FILE> if set will make CONF_load_modules_file()
42ignore missing configuration files. Normally a missing configuration file
43return an error.
44
45B<CONF_MFLAGS_DEFAULT_SECTION> if set and B<appname> is not NULL will use the
46default section pointed to by B<openssl_conf> if B<appname> does not exist.
47
48By using CONF_modules_load_file() with appropriate flags an application can
49customise application configuration to best suit its needs. In some cases the
50use of a configuration file is optional and its absence is not an error: in
51this case B<CONF_MFLAGS_IGNORE_MISSING_FILE> would be set.
52
53Errors during configuration may also be handled differently by different
54applications. For example in some cases an error may simply print out a warning
55message and the application continue. In other cases an application might
56consider a configuration file error as fatal and exit immediately.
57
58Applications can use the CONF_modules_load() function if they wish to load a
59configuration file themselves and have finer control over how errors are
60treated.
61
62=head1 EXAMPLES
63
64Load a configuration file and print out any errors and exit (missing file
65considered fatal):
66
67 if (CONF_modules_load_file(NULL, NULL, 0) <= 0) {
68     fprintf(stderr, "FATAL: error loading configuration file\n");
69     ERR_print_errors_fp(stderr);
70     exit(1);
71 }
72
73Load default configuration file using the section indicated by "myapp",
74tolerate missing files, but exit on other errors:
75
76 if (CONF_modules_load_file(NULL, "myapp",
77                            CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
78     fprintf(stderr, "FATAL: error loading configuration file\n");
79     ERR_print_errors_fp(stderr);
80     exit(1);
81 }
82
83Load custom configuration file and section, only print warnings on error,
84missing configuration file ignored:
85
86 if (CONF_modules_load_file("/something/app.cnf", "myapp",
87                            CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
88     fprintf(stderr, "WARNING: error loading configuration file\n");
89     ERR_print_errors_fp(stderr);
90 }
91
92Load and parse configuration file manually, custom error handling:
93
94 FILE *fp;
95 CONF *cnf = NULL;
96 long eline;
97
98 fp = fopen("/somepath/app.cnf", "r");
99 if (fp == NULL) {
100     fprintf(stderr, "Error opening configuration file\n");
101     /* Other missing configuration file behaviour */
102 } else {
103     cnf = NCONF_new(NULL);
104     if (NCONF_load_fp(cnf, fp, &eline) == 0) {
105         fprintf(stderr, "Error on line %ld of configuration file\n", eline);
106         ERR_print_errors_fp(stderr);
107         /* Other malformed configuration file behaviour */
108     } else if (CONF_modules_load(cnf, "appname", 0) <= 0) {
109         fprintf(stderr, "Error configuring application\n");
110         ERR_print_errors_fp(stderr);
111         /* Other configuration error behaviour */
112     }
113     fclose(fp);
114     NCONF_free(cnf);
115 }
116
117=head1 RETURN VALUES
118
119These functions return 1 for success and a zero or negative value for
120failure. If module errors are not ignored the return code will reflect the
121return value of the failing module (this will always be zero or negative).
122
123=head1 SEE ALSO
124
125L<config(5)>, L<OPENSSL_config(3)>
126
127=head1 COPYRIGHT
128
129Copyright 2004-2017 The OpenSSL Project Authors. All Rights Reserved.
130
131Licensed under the OpenSSL license (the "License").  You may not use
132this file except in compliance with the License.  You can obtain a copy
133in the file LICENSE in the source distribution or at
134L<https://www.openssl.org/source/license.html>.
135
136=cut
137