CONF_MODULES_LOAD_FILE(3ossl)
π CONF_MODULES_LOAD_FILE(3ossl) π
okay bestie, welcome to the OpenSSL manual page for CONF_MODULES_LOAD_FILE(3ossl) β that's the title, and 3ossl is the manual name. we're about to make OpenSSL configuration loading make sense, fr fr. π«Ά
β¨ NAME β¨
This page covers CONF_get1_default_config_file, CONF_modules_load_file_ex, CONF_modules_load_file, and CONF_modules_load β the OpenSSL configuration functions. πΈ
π¦ SYNOPSIS π¦
#include <openssl/conf.h>
char *CONF_get1_default_config_file(void);
int CONF_modules_load_file_ex(OSSL_LIB_CTX *libctx, const char *filename,
const char *appname, unsigned long flags);
int CONF_modules_load_file(const char *filename, const char *appname,
unsigned long flags);
int CONF_modules_load(const CONF *cnf, const char *appname,
unsigned long flags);
π DESCRIPTION π
okay so CONF_get1_default_config_file() determines the default configuration file pathname like this: if the OPENSSL_CONF environment variable is set, its value is returned. Else the function returns the path obtained using X509_get_default_cert_area(3) with the filename "openssl.cnf" appended. The caller is responsible for freeing any string returned. don't ghost that free, bestie π
CONF_modules_load_file_ex() configures OpenSSL using library context libctx, file filename, and application name appname. If filename is NULL, the standard OpenSSL configuration file is used as determined by calling CONF_get1_default_config_file(). If appname is NULL, the standard OpenSSL application name openssl_conf is used. The behaviour can be customized using flags. Note that the error suppressing can be overridden by config_diagnostics as described in config(5). π
CONF_modules_load_file() is the same as CONF_modules_load_file_ex() but has a NULL library context.
CONF_modules_load() is identical to CONF_modules_load_file() except it reads configuration information from cnf.
π© NOTES π©
The following flags are currently recognized:
CONF_MFLAGS_IGNORE_ERRORSβ if set, errors returned by individual configuration modules are ignored. If not set, the first module error is considered fatal and no further modules are loaded. πCONF_MFLAGS_SILENTβ normally any modules errors will add error information to the error queue. IfCONF_MFLAGS_SILENTis set, no error information is added. π€«CONF_MFLAGS_IGNORE_RETURN_CODESβ if set, the function unconditionally returns success. This is used by default inOPENSSL_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. Applications callingCONF_modules_load_file_exexplicitly should not generally set this flag. π¨CONF_MFLAGS_NO_DSOβ if set, configuration module loading from DSOs is disabled. π«CONF_MFLAGS_IGNORE_MISSING_FILEβ if set, will makeCONF_load_modules_file()ignore missing configuration files. Normally a missing configuration file return an error. πCONF_MFLAGS_DEFAULT_SECTIONβ if set andappnameis notNULL, will use the default section pointed to byopenssl_confifappnamedoes not exist. π
By using CONF_modules_load_file_ex() with appropriate flags an 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 CONF_MFLAGS_IGNORE_MISSING_FILE would be set.
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. π
π 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). π
π₯ EXAMPLES π₯
Load a configuration file and print out any errors and exit (missing file considered fatal):
if (CONF_modules_load_file_ex(libctx, NULL, NULL, 0) <= 0) {
fprintf(stderr, "FATAL: error loading configuration file\n");
ERR_print_errors_fp(stderr);
exit(1);
}
Load default configuration file using the section indicated by "myapp", tolerate missing files, but exit on other errors:
if (CONF_modules_load_file_ex(NULL, NULL, "myapp",
CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
fprintf(stderr, "FATAL: error loading configuration file\n");
ERR_print_errors_fp(stderr);
exit(1);
}
Load custom configuration file and section, only print warnings on error, missing configuration file ignored:
if (CONF_modules_load_file_ex(NULL, "/something/app.cnf", "myapp",
CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) {
fprintf(stderr, "WARNING: error loading configuration file\n");
ERR_print_errors_fp(stderr);
}
Load and parse configuration file manually, custom error handling:
FILE *fp;
CONF *cnf = NULL;
long eline;
fp = fopen("/somepath/app.cnf", "r");
if (fp == NULL) {
fprintf(stderr, "Error opening configuration file\n");
/* Other missing configuration file behaviour */
} else {
cnf = NCONF_new_ex(libctx, NULL);
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);
}
π SEE ALSO π
π COPYRIGHT π
Copyright 2004-2022 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>. π
π«Ά that's the whole page, bestie. this iconic manual page is from OpenSSL 3.5.0, dated 2026-09-25 β periodt. π β¨
π¦ where this page comes from
- opensuse-leap 16.0: openssl-3-doc 3.5.0-160000.11.1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms