1CONF_MODULES_LOAD_FILE(3) OpenSSL CONF_MODULES_LOAD_FILE(3)
2
3
4
6 CONF_modules_load_file, CONF_modules_load - OpenSSL configuration
7 functions
8
10 #include <openssl/conf.h>
11
12 int CONF_modules_load_file(const char *filename, const char *appname,
13 unsigned long flags);
14 int CONF_modules_load(const CONF *cnf, const char *appname,
15 unsigned long flags);
16
18 The function CONF_modules_load_file() configures OpenSSL using file
19 filename and application name appname. If filename is NULL the standard
20 OpenSSL configuration file is used. If appname is NULL the standard
21 OpenSSL application name openssl_conf is used. The behaviour can be
22 customized using flags.
23
24 CONF_modules_load() is identical to CONF_modules_load_file() except it
25 reads configuration information from cnf.
26
28 The following flags are currently recognized:
29
30 CONF_MFLAGS_IGNORE_ERRORS if set errors returned by individual
31 configuration modules are ignored. If not set the first module error is
32 considered fatal and no further modules are loaded.
33
34 Normally any modules errors will add error information to the error
35 queue. If CONF_MFLAGS_SILENT is set no error information is added.
36
37 If CONF_MFLAGS_NO_DSO is set configuration module loading from DSOs is
38 disabled.
39
40 CONF_MFLAGS_IGNORE_MISSING_FILE if set will make
41 CONF_load_modules_file() ignore missing configuration files. Normally a
42 missing configuration file return an error.
43
44 CONF_MFLAGS_DEFAULT_SECTION if set and appname is not NULL will use the
45 default section pointed to by openssl_conf if appname does not exist.
46
47 By using CONF_modules_load_file() with appropriate flags an application
48 can customise application configuration to best suit its needs. In some
49 cases the use of a configuration file is optional and its absence is
50 not an error: in this case CONF_MFLAGS_IGNORE_MISSING_FILE would be
51 set.
52
53 Errors during configuration may also be handled differently by
54 different applications. For example in some cases an error may simply
55 print out a warning message and the application continue. In other
56 cases an application might consider a configuration file error as fatal
57 and exit immediately.
58
59 Applications can use the CONF_modules_load() function if they wish to
60 load a configuration file themselves and have finer control over how
61 errors are treated.
62
64 Load a configuration file and print out any errors and exit (missing
65 file considered 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
73 Load default configuration file using the section indicated by "myapp",
74 tolerate 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
83 Load custom configuration file and section, only print warnings on
84 error, missing 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
92 Load 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
118 These functions return 1 for success and a zero or negative value for
119 failure. If module errors are not ignored the return code will reflect
120 the return value of the failing module (this will always be zero or
121 negative).
122
124 config(5), OPENSSL_config(3)
125
127 Copyright 2004-2017 The OpenSSL Project Authors. All Rights Reserved.
128
129 Licensed under the OpenSSL license (the "License"). You may not use
130 this file except in compliance with the License. You can obtain a copy
131 in the file LICENSE in the source distribution or at
132 <https://www.openssl.org/source/license.html>.
133
134
135
1361.1.1 2018-09-11 CONF_MODULES_LOAD_FILE(3)