Skip to content

Commit

Permalink
CONFDB: Allow loading an empty configuration
Browse files Browse the repository at this point in the history
Function confdb_setup() returns an error if the configuration file(s)
is(are) missing. In some cases it can be acceptable to have an empty
configuration and use the default values.

We are adding a parameter to confdb_setup() to allow empty files.
  • Loading branch information
aplopez committed Oct 6, 2023
1 parent 1de7758 commit 2e2f571
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
21 changes: 15 additions & 6 deletions src/confdb/confdb_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ static int confdb_write_ldif(struct confdb_ctx *cdb,
static int confdb_init_db(const char *config_file,
const char *config_dir,
const char *only_section,
struct confdb_ctx *cdb)
struct confdb_ctx *cdb,
bool allow_missing_file)
{
TALLOC_CTX *tmp_ctx;
int ret;
Expand Down Expand Up @@ -189,10 +190,16 @@ static int confdb_init_db(const char *config_file,
init_data,
&config_ldif);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE,
"Cannot convert INI to LDIF [%d]: [%s]\n",
ret, sss_strerror(ret));
goto done;
if (ret == ERR_INI_EMPTY_CONFIG && allow_missing_file) {
DEBUG(SSSDBG_TRACE_FUNC, "Empty configuration. Using the defaults.\n");
ret = EOK;
goto done;
} else {
DEBUG(SSSDBG_CRIT_FAILURE,
"Cannot convert INI to LDIF [%d]: [%s]\n",
ret, sss_strerror(ret));
goto done;
}
}

DEBUG(SSSDBG_CONF_SETTINGS, "LDIF file to import: \n%s\n", config_ldif);
Expand Down Expand Up @@ -251,6 +258,7 @@ errno_t confdb_setup(TALLOC_CTX *mem_ctx,
const char *config_file,
const char *config_dir,
const char *only_section,
bool allow_missing_file,
struct confdb_ctx **_cdb)
{
TALLOC_CTX *tmp_ctx;
Expand Down Expand Up @@ -295,7 +303,8 @@ errno_t confdb_setup(TALLOC_CTX *mem_ctx,
}

/* Initialize the CDB from the configuration file */
ret = confdb_init_db(config_file, config_dir, only_section, cdb);
ret = confdb_init_db(config_file, config_dir, only_section, cdb,
allow_missing_file);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE, "ConfDB initialization has failed "
"[%d]: %s\n", ret, sss_strerror(ret));
Expand Down
3 changes: 3 additions & 0 deletions src/confdb/confdb_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef CONFDB_SETUP_H_
#define CONFDB_SETUP_H_

#include <stdbool.h>

#define CONFDB_BASE_LDIF \
"dn: @ATTRIBUTES\n" \
"cn: CASE_INSENSITIVE\n" \
Expand All @@ -42,6 +44,7 @@ errno_t confdb_setup(TALLOC_CTX *mem_ctx,
const char *config_file,
const char *config_dir,
const char *only_section,
bool allow_missing_file,
struct confdb_ctx **_cdb);

#endif /* CONFDB_SETUP_H_ */
2 changes: 1 addition & 1 deletion src/monitor/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ errno_t load_configuration(TALLOC_CTX *mem_ctx,
}

ret = confdb_setup(ctx, cdb_file, config_file, config_dir, only_section,
&ctx->cdb);
false, &ctx->cdb);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE, "Unable to setup ConfDB [%d]: %s\n",
ret, sss_strerror(ret));
Expand Down
3 changes: 1 addition & 2 deletions src/tools/common/sss_tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ static errno_t sss_tool_confdb_init(TALLOC_CTX *mem_ctx,

ret = confdb_setup(mem_ctx, path,
SSSD_CONFIG_FILE, CONFDB_DEFAULT_CONFIG_DIR,
NULL,
&confdb);
NULL, false, &confdb);
talloc_zfree(path);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE, "Unable to setup ConfDB [%d]: %s\n",
Expand Down

0 comments on commit 2e2f571

Please sign in to comment.