]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man3/CONF_modules_load_file.pod
make error tables const and separate header file
[thirdparty/openssl.git] / doc / man3 / CONF_modules_load_file.pod
CommitLineData
f82bb9cb
DSH
1=pod
2
3=head1 NAME
4
1bc74519 5CONF_modules_load_file, CONF_modules_load - OpenSSL configuration functions
f82bb9cb
DSH
6
7=head1 SYNOPSIS
8
9 #include <openssl/conf.h>
10
11 int CONF_modules_load_file(const char *filename, const char *appname,
1bc74519 12 unsigned long flags);
f82bb9cb 13 int CONF_modules_load(const CONF *cnf, const char *appname,
1bc74519 14 unsigned long flags);
f82bb9cb
DSH
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.
186bb907 22The behaviour can be customized using B<flags>.
f82bb9cb 23
186bb907 24CONF_modules_load() is identical to CONF_modules_load_file() except it
3d764db7 25reads configuration information from B<cnf>.
f82bb9cb
DSH
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
3d764db7 33considered fatal and no further modules are loaded.
f82bb9cb
DSH
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
3d764db7
DSH
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
3d764db7
DSH
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 fp = fopen("/somepath/app.cnf", "r");
98 if (fp == NULL) {
99 fprintf(stderr, "Error opening configuration file\n");
100 /* Other missing configuration file behaviour */
101 } else {
102 cnf = NCONF_new(NULL);
103 if (NCONF_load_fp(cnf, fp, &eline) == 0) {
104 fprintf(stderr, "Error on line %ld of configuration file\n", eline);
105 ERR_print_errors_fp(stderr);
106 /* Other malformed configuration file behaviour */
107 } else if (CONF_modules_load(cnf, "appname", 0) <= 0) {
108 fprintf(stderr, "Error configuring application\n");
109 ERR_print_errors_fp(stderr);
110 /* Other configuration error behaviour */
111 }
112 fclose(fp);
113 NCONF_free(cnf);
114 }
115
116=head1 RETURN VALUES
f82bb9cb
DSH
117
118These functions return 1 for success and a zero or negative value for
119failure. If module errors are not ignored the return code will reflect the
120return value of the failing module (this will always be zero or negative).
121
122=head1 SEE ALSO
123
9e183d22 124L<config(5)>, L<OPENSSL_config(3)>
f82bb9cb 125
e2f92610
RS
126=head1 COPYRIGHT
127
73fb82b7 128Copyright 2004-2017 The OpenSSL Project Authors. All Rights Reserved.
e2f92610
RS
129
130Licensed under the OpenSSL license (the "License"). You may not use
131this file except in compliance with the License. You can obtain a copy
132in the file LICENSE in the source distribution or at
133L<https://www.openssl.org/source/license.html>.
134
135=cut