Blame doc/man3/CONF_modules_load_file.pod

Packit c4476c
=pod
Packit c4476c
Packit c4476c
=head1 NAME
Packit c4476c
Packit c4476c
CONF_modules_load_file, CONF_modules_load - OpenSSL configuration functions
Packit c4476c
Packit c4476c
=head1 SYNOPSIS
Packit c4476c
Packit c4476c
 #include <openssl/conf.h>
Packit c4476c
Packit c4476c
 int CONF_modules_load_file(const char *filename, const char *appname,
Packit c4476c
                            unsigned long flags);
Packit c4476c
 int CONF_modules_load(const CONF *cnf, const char *appname,
Packit c4476c
                       unsigned long flags);
Packit c4476c
Packit c4476c
=head1 DESCRIPTION
Packit c4476c
Packit c4476c
The function CONF_modules_load_file() configures OpenSSL using file
Packit c4476c
B<filename> and application name B<appname>. If B<filename> is NULL
Packit c4476c
the standard OpenSSL configuration file is used. If B<appname> is
Packit c4476c
NULL the standard OpenSSL application name B<openssl_conf> is used.
Packit c4476c
The behaviour can be customized using B<flags>.
Packit c4476c
Packit c4476c
CONF_modules_load() is identical to CONF_modules_load_file() except it
Packit c4476c
reads configuration information from B<cnf>.
Packit c4476c
Packit c4476c
=head1 NOTES
Packit c4476c
Packit c4476c
The following B<flags> are currently recognized:
Packit c4476c
Packit c4476c
If B<CONF_MFLAGS_IGNORE_ERRORS> is set errors returned by individual
Packit c4476c
configuration modules are ignored. If not set the first module error is
Packit c4476c
considered fatal and no further modules are loaded.
Packit c4476c
Packit c4476c
Normally any modules errors will add error information to the error queue. If
Packit c4476c
B<CONF_MFLAGS_SILENT> is set no error information is added.
Packit c4476c
Packit c4476c
If B<CONF_MFLAGS_IGNORE_RETURN_CODES> is set the function unconditionally
Packit c4476c
returns success.
Packit c4476c
This is used by default in L<OPENSSL_init_crypto(3)> to ignore any errors in
Packit c4476c
the default system-wide configuration file, as having all OpenSSL applications
Packit c4476c
fail to start when there are potentially minor issues in the file is too risky.
Packit c4476c
Applications calling B<CONF_modules_load_file> explicitly should not generally
Packit c4476c
set this flag.
Packit c4476c
Packit c4476c
If B<CONF_MFLAGS_NO_DSO> is set configuration module loading from DSOs is
Packit c4476c
disabled.
Packit c4476c
Packit c4476c
B<CONF_MFLAGS_IGNORE_MISSING_FILE> if set will make CONF_load_modules_file()
Packit c4476c
ignore missing configuration files. Normally a missing configuration file
Packit c4476c
return an error.
Packit c4476c
Packit c4476c
B<CONF_MFLAGS_DEFAULT_SECTION> if set and B<appname> is not NULL will use the
Packit c4476c
default section pointed to by B<openssl_conf> if B<appname> does not exist.
Packit c4476c
Packit c4476c
By using CONF_modules_load_file() with appropriate flags an application can
Packit c4476c
customise application configuration to best suit its needs. In some cases the
Packit c4476c
use of a configuration file is optional and its absence is not an error: in
Packit c4476c
this case B<CONF_MFLAGS_IGNORE_MISSING_FILE> would be set.
Packit c4476c
Packit c4476c
Errors during configuration may also be handled differently by different
Packit c4476c
applications. For example in some cases an error may simply print out a warning
Packit c4476c
message and the application continue. In other cases an application might
Packit c4476c
consider a configuration file error as fatal and exit immediately.
Packit c4476c
Packit c4476c
Applications can use the CONF_modules_load() function if they wish to load a
Packit c4476c
configuration file themselves and have finer control over how errors are
Packit c4476c
treated.
Packit c4476c
Packit c4476c
=head1 RETURN VALUES
Packit c4476c
Packit c4476c
These functions return 1 for success and a zero or negative value for
Packit c4476c
failure. If module errors are not ignored the return code will reflect the
Packit c4476c
return value of the failing module (this will always be zero or negative).
Packit c4476c
Packit c4476c
=head1 EXAMPLES
Packit c4476c
Packit c4476c
Load a configuration file and print out any errors and exit (missing file
Packit c4476c
considered fatal):
Packit c4476c
Packit c4476c
 if (CONF_modules_load_file(NULL, NULL, 0) <= 0) {
Packit c4476c
     fprintf(stderr, "FATAL: error loading configuration file\n");
Packit c4476c
     ERR_print_errors_fp(stderr);
Packit c4476c
     exit(1);
Packit c4476c
 }
Packit c4476c
Packit c4476c
Load default configuration file using the section indicated by "myapp",
Packit c4476c
tolerate missing files, but exit on other errors:
Packit c4476c
Packit c4476c
 if (CONF_modules_load_file(NULL, "myapp",
Packit c4476c
                            CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
Packit c4476c
     fprintf(stderr, "FATAL: error loading configuration file\n");
Packit c4476c
     ERR_print_errors_fp(stderr);
Packit c4476c
     exit(1);
Packit c4476c
 }
Packit c4476c
Packit c4476c
Load custom configuration file and section, only print warnings on error,
Packit c4476c
missing configuration file ignored:
Packit c4476c
Packit c4476c
 if (CONF_modules_load_file("/something/app.cnf", "myapp",
Packit c4476c
                            CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
Packit c4476c
     fprintf(stderr, "WARNING: error loading configuration file\n");
Packit c4476c
     ERR_print_errors_fp(stderr);
Packit c4476c
 }
Packit c4476c
Packit c4476c
Load and parse configuration file manually, custom error handling:
Packit c4476c
Packit c4476c
 FILE *fp;
Packit c4476c
 CONF *cnf = NULL;
Packit c4476c
 long eline;
Packit c4476c
Packit c4476c
 fp = fopen("/somepath/app.cnf", "r");
Packit c4476c
 if (fp == NULL) {
Packit c4476c
     fprintf(stderr, "Error opening configuration file\n");
Packit c4476c
     /* Other missing configuration file behaviour */
Packit c4476c
 } else {
Packit c4476c
     cnf = NCONF_new(NULL);
Packit c4476c
     if (NCONF_load_fp(cnf, fp, &eline) == 0) {
Packit c4476c
         fprintf(stderr, "Error on line %ld of configuration file\n", eline);
Packit c4476c
         ERR_print_errors_fp(stderr);
Packit c4476c
         /* Other malformed configuration file behaviour */
Packit c4476c
     } else if (CONF_modules_load(cnf, "appname", 0) <= 0) {
Packit c4476c
         fprintf(stderr, "Error configuring application\n");
Packit c4476c
         ERR_print_errors_fp(stderr);
Packit c4476c
         /* Other configuration error behaviour */
Packit c4476c
     }
Packit c4476c
     fclose(fp);
Packit c4476c
     NCONF_free(cnf);
Packit c4476c
 }
Packit c4476c
Packit c4476c
=head1 SEE ALSO
Packit c4476c
Packit c4476c
L<config(5)>, L<OPENSSL_config(3)>
Packit c4476c
Packit c4476c
=head1 COPYRIGHT
Packit c4476c
Packit c4476c
Copyright 2004-2019 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
Packit c4476c
Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
this file except in compliance with the License.  You can obtain a copy
Packit c4476c
in the file LICENSE in the source distribution or at
Packit c4476c
L<https://www.openssl.org/source/license.html>.
Packit c4476c
Packit c4476c
=cut