diff --git a/src/confdb/confdb.c b/src/confdb/confdb.c index 21e96634e61..252c557ce9a 100644 --- a/src/confdb/confdb.c +++ b/src/confdb/confdb.c @@ -650,6 +650,11 @@ int confdb_init(TALLOC_CTX *mem_ctx, int ret = EOK; mode_t old_umask; + if (cdb_ctx == NULL) { + DEBUG(SSSDBG_FATAL_FAILURE, "Bad argument\n"); + return EFAULT; + } + cdb = talloc_zero(mem_ctx, struct confdb_ctx); if (!cdb) return ENOMEM; diff --git a/src/tools/common/sss_tools.c b/src/tools/common/sss_tools.c index b7200554c26..7c0a2d3a5a9 100644 --- a/src/tools/common/sss_tools.c +++ b/src/tools/common/sss_tools.c @@ -87,19 +87,12 @@ static void sss_tool_common_opts(struct sss_tool_ctx *tool_ctx, poptFreeContext(pc); } -static errno_t sss_tool_confdb_init(TALLOC_CTX *mem_ctx, - struct confdb_ctx **_confdb) +errno_t sss_tool_confdb_init(TALLOC_CTX *mem_ctx, struct confdb_ctx **_confdb) { - struct confdb_ctx *confdb; - char *path; + static const char *path = DB_PATH"/"CONFDB_FILE; errno_t ret; struct stat statbuf; - path = talloc_asprintf(mem_ctx, "%s/%s", DB_PATH, CONFDB_FILE); - if (path == NULL) { - return ENOMEM; - } - ret = stat(path, &statbuf); if (ret != 0) { ret = errno; @@ -108,18 +101,13 @@ static errno_t sss_tool_confdb_init(TALLOC_CTX *mem_ctx, return ret; } - ret = confdb_init(mem_ctx, &confdb, path); - talloc_zfree(path); + ret = confdb_init(mem_ctx, _confdb, path); if (ret != EOK) { DEBUG(SSSDBG_FATAL_FAILURE, "Unable to connect to config DB [%d]: %s\n", ret, sss_strerror(ret)); return ret; } - if (_confdb != NULL) { - *_confdb = confdb; - } - return EOK; } @@ -599,25 +587,3 @@ errno_t sss_tool_parse_name(TALLOC_CTX *mem_ctx, return ret; } - -errno_t sss_tool_connect_to_confdb(TALLOC_CTX *ctx, struct confdb_ctx **cdb_ctx) -{ - int ret; - char *confdb_path = NULL; - - confdb_path = talloc_asprintf(ctx, "%s/%s", DB_PATH, CONFDB_FILE); - if (confdb_path == NULL) { - DEBUG(SSSDBG_CRIT_FAILURE, - "Could not allocate memory for confdb path\n"); - return ENOMEM; - } - - ret = confdb_init(ctx, cdb_ctx, confdb_path); - if (ret != EOK) { - DEBUG(SSSDBG_CRIT_FAILURE, - "Could not initialize connection to the confdb\n"); - } - - talloc_free(confdb_path); - return ret; -} diff --git a/src/tools/common/sss_tools.h b/src/tools/common/sss_tools.h index 69d35bde0c6..45526e4fe81 100644 --- a/src/tools/common/sss_tools.h +++ b/src/tools/common/sss_tools.h @@ -101,6 +101,6 @@ errno_t sss_tool_parse_name(TALLOC_CTX *mem_ctx, struct sss_domain_info **_domain); -errno_t sss_tool_connect_to_confdb(TALLOC_CTX *ctx, struct confdb_ctx **cdb_ctx); +errno_t sss_tool_confdb_init(TALLOC_CTX *mem_ctx, struct confdb_ctx **_confdb); #endif /* SRC_TOOLS_COMMON_SSS_TOOLS_H_ */ diff --git a/src/tools/sss_cache.c b/src/tools/sss_cache.c index 79de13ac872..75daddddbb8 100644 --- a/src/tools/sss_cache.c +++ b/src/tools/sss_cache.c @@ -27,6 +27,7 @@ #include "util/util.h" #include "tools/tools_util.h" +#include "tools/common/sss_tools.h" #include "db/sysdb.h" #include "db/sysdb_services.h" #include "db/sysdb_autofs.h" @@ -661,22 +662,13 @@ static errno_t invalidate_entry(TALLOC_CTX *ctx, static errno_t init_domains(struct cache_tool_ctx *ctx, const char *domain) { - char *confdb_path; int ret; struct sss_domain_info *dinfo; - confdb_path = talloc_asprintf(ctx, "%s/%s", DB_PATH, CONFDB_FILE); - if (confdb_path == NULL) { - return ENOMEM; - } - - /* Connect to the conf db */ - ret = confdb_init(ctx, &ctx->confdb, confdb_path); - talloc_free(confdb_path); + ret = sss_tool_confdb_init(ctx, &ctx->confdb); if (ret != EOK) { - DEBUG(SSSDBG_CRIT_FAILURE, - "Could not initialize connection to the confdb\n"); - return ret; + ERROR("Can't find configuration db, was SSSD configured and run?\n"); + return ERR_NO_DOMAIN_ENABLED; } if (domain) { diff --git a/src/tools/sss_seed.c b/src/tools/sss_seed.c index 07327da67db..b1c30bebc1d 100644 --- a/src/tools/sss_seed.c +++ b/src/tools/sss_seed.c @@ -33,6 +33,7 @@ #include "util/util.h" #include "db/sysdb.h" #include "tools/tools_util.h" +#include "tools/common/sss_tools.h" #include "confdb/confdb.h" #ifndef BUFSIZE @@ -628,7 +629,6 @@ static int seed_init_db(TALLOC_CTX *mem_ctx, struct sysdb_ctx **_sysdb) { TALLOC_CTX *tmp_ctx = NULL; - char *confdb_path = NULL; struct confdb_ctx *confdb = NULL; struct sss_domain_info *domain = NULL; int ret = EOK; @@ -639,14 +639,7 @@ static int seed_init_db(TALLOC_CTX *mem_ctx, goto done; } - /* setup confdb */ - confdb_path = talloc_asprintf(tmp_ctx, "%s/%s", DB_PATH, CONFDB_FILE); - if (confdb_path == NULL) { - ret = ENOMEM; - goto done; - } - - ret = confdb_init(tmp_ctx, &confdb, confdb_path); + ret = sss_tool_confdb_init(tmp_ctx, &confdb); if (ret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, "Could not initialize connection to the confdb\n"); diff --git a/src/tools/sssctl/sssctl_data.c b/src/tools/sssctl/sssctl_data.c index beeb6361cac..43bfd73fc86 100644 --- a/src/tools/sssctl/sssctl_data.c +++ b/src/tools/sssctl/sssctl_data.c @@ -362,7 +362,7 @@ static errno_t sssctl_cache_index_action(enum sysdb_index_actions action, if (domains == NULL) { /* If the user selected no domain, act on all of them */ - ret = sss_tool_connect_to_confdb(tmp_ctx, &confdb); + ret = sss_tool_confdb_init(tmp_ctx, &confdb); if (ret != EOK) { DEBUG(SSSDBG_OP_FAILURE, "Could not connect to configuration database.\n"); diff --git a/src/tools/sssctl/sssctl_logs.c b/src/tools/sssctl/sssctl_logs.c index 75e855bb901..c719dcbf0b2 100644 --- a/src/tools/sssctl/sssctl_logs.c +++ b/src/tools/sssctl/sssctl_logs.c @@ -567,7 +567,7 @@ errno_t sssctl_debug_level(struct sss_cmdline *cmdline, targets = get_targets(ctx, pc_services, pc_domains); CHECK(targets == NULL, fini, "Could not allocate memory."); - ret = sss_tool_connect_to_confdb(ctx, &ctx->confdb); + ret = sss_tool_confdb_init(ctx, &ctx->confdb); CHECK(ret != EOK, fini, "Could not connect to configuration database."); ret = get_confdb_sections(ctx, ctx->confdb, &ctx->sections);