xref: /freebsd-src/crypto/openssl/doc/man3/CONF_modules_load_file.pod (revision 610a21fd82f731685fabbf6da5387e981b07fbbd)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5e71b7053SJung-uk KimCONF_modules_load_file, CONF_modules_load - OpenSSL configuration functions
6e71b7053SJung-uk Kim
7e71b7053SJung-uk Kim=head1 SYNOPSIS
8e71b7053SJung-uk Kim
9e71b7053SJung-uk Kim #include <openssl/conf.h>
10e71b7053SJung-uk Kim
11e71b7053SJung-uk Kim int CONF_modules_load_file(const char *filename, const char *appname,
12e71b7053SJung-uk Kim                            unsigned long flags);
13e71b7053SJung-uk Kim int CONF_modules_load(const CONF *cnf, const char *appname,
14e71b7053SJung-uk Kim                       unsigned long flags);
15e71b7053SJung-uk Kim
16e71b7053SJung-uk Kim=head1 DESCRIPTION
17e71b7053SJung-uk Kim
18e71b7053SJung-uk KimThe function CONF_modules_load_file() configures OpenSSL using file
19e71b7053SJung-uk KimB<filename> and application name B<appname>. If B<filename> is NULL
20e71b7053SJung-uk Kimthe standard OpenSSL configuration file is used. If B<appname> is
21e71b7053SJung-uk KimNULL the standard OpenSSL application name B<openssl_conf> is used.
22e71b7053SJung-uk KimThe behaviour can be customized using B<flags>.
23e71b7053SJung-uk Kim
24e71b7053SJung-uk KimCONF_modules_load() is identical to CONF_modules_load_file() except it
25e71b7053SJung-uk Kimreads configuration information from B<cnf>.
26e71b7053SJung-uk Kim
27e71b7053SJung-uk Kim=head1 NOTES
28e71b7053SJung-uk Kim
29e71b7053SJung-uk KimThe following B<flags> are currently recognized:
30e71b7053SJung-uk Kim
316935a639SJung-uk KimIf B<CONF_MFLAGS_IGNORE_ERRORS> is set errors returned by individual
32e71b7053SJung-uk Kimconfiguration modules are ignored. If not set the first module error is
33e71b7053SJung-uk Kimconsidered fatal and no further modules are loaded.
34e71b7053SJung-uk Kim
35e71b7053SJung-uk KimNormally any modules errors will add error information to the error queue. If
36e71b7053SJung-uk KimB<CONF_MFLAGS_SILENT> is set no error information is added.
37e71b7053SJung-uk Kim
386935a639SJung-uk KimIf B<CONF_MFLAGS_IGNORE_RETURN_CODES> is set the function unconditionally
396935a639SJung-uk Kimreturns success.
406935a639SJung-uk KimThis is used by default in L<OPENSSL_init_crypto(3)> to ignore any errors in
416935a639SJung-uk Kimthe default system-wide configuration file, as having all OpenSSL applications
426935a639SJung-uk Kimfail to start when there are potentially minor issues in the file is too risky.
436935a639SJung-uk KimApplications calling B<CONF_modules_load_file> explicitly should not generally
446935a639SJung-uk Kimset this flag.
456935a639SJung-uk Kim
46e71b7053SJung-uk KimIf B<CONF_MFLAGS_NO_DSO> is set configuration module loading from DSOs is
47e71b7053SJung-uk Kimdisabled.
48e71b7053SJung-uk Kim
49e71b7053SJung-uk KimB<CONF_MFLAGS_IGNORE_MISSING_FILE> if set will make CONF_load_modules_file()
50e71b7053SJung-uk Kimignore missing configuration files. Normally a missing configuration file
51e71b7053SJung-uk Kimreturn an error.
52e71b7053SJung-uk Kim
53e71b7053SJung-uk KimB<CONF_MFLAGS_DEFAULT_SECTION> if set and B<appname> is not NULL will use the
54e71b7053SJung-uk Kimdefault section pointed to by B<openssl_conf> if B<appname> does not exist.
55e71b7053SJung-uk Kim
56e71b7053SJung-uk KimBy using CONF_modules_load_file() with appropriate flags an application can
57e71b7053SJung-uk Kimcustomise application configuration to best suit its needs. In some cases the
58e71b7053SJung-uk Kimuse of a configuration file is optional and its absence is not an error: in
59e71b7053SJung-uk Kimthis case B<CONF_MFLAGS_IGNORE_MISSING_FILE> would be set.
60e71b7053SJung-uk Kim
61e71b7053SJung-uk KimErrors during configuration may also be handled differently by different
62e71b7053SJung-uk Kimapplications. For example in some cases an error may simply print out a warning
63e71b7053SJung-uk Kimmessage and the application continue. In other cases an application might
64e71b7053SJung-uk Kimconsider a configuration file error as fatal and exit immediately.
65e71b7053SJung-uk Kim
66e71b7053SJung-uk KimApplications can use the CONF_modules_load() function if they wish to load a
67e71b7053SJung-uk Kimconfiguration file themselves and have finer control over how errors are
68e71b7053SJung-uk Kimtreated.
69e71b7053SJung-uk Kim
70*610a21fdSJung-uk Kim=head1 RETURN VALUES
71*610a21fdSJung-uk Kim
72*610a21fdSJung-uk KimThese functions return 1 for success and a zero or negative value for
73*610a21fdSJung-uk Kimfailure. If module errors are not ignored the return code will reflect the
74*610a21fdSJung-uk Kimreturn value of the failing module (this will always be zero or negative).
75*610a21fdSJung-uk Kim
76e71b7053SJung-uk Kim=head1 EXAMPLES
77e71b7053SJung-uk Kim
78e71b7053SJung-uk KimLoad a configuration file and print out any errors and exit (missing file
79e71b7053SJung-uk Kimconsidered fatal):
80e71b7053SJung-uk Kim
81e71b7053SJung-uk Kim if (CONF_modules_load_file(NULL, NULL, 0) <= 0) {
82e71b7053SJung-uk Kim     fprintf(stderr, "FATAL: error loading configuration file\n");
83e71b7053SJung-uk Kim     ERR_print_errors_fp(stderr);
84e71b7053SJung-uk Kim     exit(1);
85e71b7053SJung-uk Kim }
86e71b7053SJung-uk Kim
87e71b7053SJung-uk KimLoad default configuration file using the section indicated by "myapp",
88e71b7053SJung-uk Kimtolerate missing files, but exit on other errors:
89e71b7053SJung-uk Kim
90e71b7053SJung-uk Kim if (CONF_modules_load_file(NULL, "myapp",
91e71b7053SJung-uk Kim                            CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
92e71b7053SJung-uk Kim     fprintf(stderr, "FATAL: error loading configuration file\n");
93e71b7053SJung-uk Kim     ERR_print_errors_fp(stderr);
94e71b7053SJung-uk Kim     exit(1);
95e71b7053SJung-uk Kim }
96e71b7053SJung-uk Kim
97e71b7053SJung-uk KimLoad custom configuration file and section, only print warnings on error,
98e71b7053SJung-uk Kimmissing configuration file ignored:
99e71b7053SJung-uk Kim
100e71b7053SJung-uk Kim if (CONF_modules_load_file("/something/app.cnf", "myapp",
101e71b7053SJung-uk Kim                            CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
102e71b7053SJung-uk Kim     fprintf(stderr, "WARNING: error loading configuration file\n");
103e71b7053SJung-uk Kim     ERR_print_errors_fp(stderr);
104e71b7053SJung-uk Kim }
105e71b7053SJung-uk Kim
106e71b7053SJung-uk KimLoad and parse configuration file manually, custom error handling:
107e71b7053SJung-uk Kim
108e71b7053SJung-uk Kim FILE *fp;
109e71b7053SJung-uk Kim CONF *cnf = NULL;
110e71b7053SJung-uk Kim long eline;
111e71b7053SJung-uk Kim
112e71b7053SJung-uk Kim fp = fopen("/somepath/app.cnf", "r");
113e71b7053SJung-uk Kim if (fp == NULL) {
114e71b7053SJung-uk Kim     fprintf(stderr, "Error opening configuration file\n");
115e71b7053SJung-uk Kim     /* Other missing configuration file behaviour */
116e71b7053SJung-uk Kim } else {
117e71b7053SJung-uk Kim     cnf = NCONF_new(NULL);
118e71b7053SJung-uk Kim     if (NCONF_load_fp(cnf, fp, &eline) == 0) {
119e71b7053SJung-uk Kim         fprintf(stderr, "Error on line %ld of configuration file\n", eline);
120e71b7053SJung-uk Kim         ERR_print_errors_fp(stderr);
121e71b7053SJung-uk Kim         /* Other malformed configuration file behaviour */
122e71b7053SJung-uk Kim     } else if (CONF_modules_load(cnf, "appname", 0) <= 0) {
123e71b7053SJung-uk Kim         fprintf(stderr, "Error configuring application\n");
124e71b7053SJung-uk Kim         ERR_print_errors_fp(stderr);
125e71b7053SJung-uk Kim         /* Other configuration error behaviour */
126e71b7053SJung-uk Kim     }
127e71b7053SJung-uk Kim     fclose(fp);
128e71b7053SJung-uk Kim     NCONF_free(cnf);
129e71b7053SJung-uk Kim }
130e71b7053SJung-uk Kim
131e71b7053SJung-uk Kim=head1 SEE ALSO
132e71b7053SJung-uk Kim
133e71b7053SJung-uk KimL<config(5)>, L<OPENSSL_config(3)>
134e71b7053SJung-uk Kim
135e71b7053SJung-uk Kim=head1 COPYRIGHT
136e71b7053SJung-uk Kim
1376935a639SJung-uk KimCopyright 2004-2019 The OpenSSL Project Authors. All Rights Reserved.
138e71b7053SJung-uk Kim
139e71b7053SJung-uk KimLicensed under the OpenSSL license (the "License").  You may not use
140e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
141e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
142e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
143e71b7053SJung-uk Kim
144e71b7053SJung-uk Kim=cut
145