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