Skip to content

Commit

Permalink
SYSDB: only monitor should create cache files
Browse files Browse the repository at this point in the history
Everything else (providers, responders, tools) should only connect to.
  • Loading branch information
alexey-tikhonov committed Sep 4, 2024
1 parent 1d09350 commit bb54213
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/db/sysdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ struct sysdb_upgrade_ctx {

int sysdb_init_ext(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domains,
bool dont_create_cache,
struct sysdb_upgrade_ctx *upgrade_ctx);

/* used to initialize only one domain database.
Expand Down
14 changes: 11 additions & 3 deletions src/db/sysdb_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,10 +776,12 @@ static int sysdb_timestamp_cache_connect(struct sysdb_ctx *sysdb,
static int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
const char *db_path,
bool dont_create_cache,
struct sysdb_dom_upgrade_ctx *upgrade_ctx,
struct sysdb_ctx **_ctx)
{
TALLOC_CTX *tmp_ctx = NULL;
bool ldb_file_missing;
struct sysdb_ctx *sysdb;
int ret;

Expand All @@ -799,6 +801,11 @@ static int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx,
if (ret != EOK) {
goto done;
}
ldb_file_missing = (access(sysdb->ldb_file, F_OK) == -1 && errno == ENOENT);
if (ldb_file_missing && dont_create_cache) {
ret = ENOENT;
goto done;
}
DEBUG(SSSDBG_FUNC_DATA,
"DB File for %s: %s\n", domain->name, sysdb->ldb_file);
if (sysdb->ldb_ts_file) {
Expand Down Expand Up @@ -833,11 +840,12 @@ static int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx,
int sysdb_init(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domains)
{
return sysdb_init_ext(mem_ctx, domains, NULL);
return sysdb_init_ext(mem_ctx, domains, true, NULL);
}

int sysdb_init_ext(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domains,
bool dont_create_cache,
struct sysdb_upgrade_ctx *upgrade_ctx)
{
struct sss_domain_info *dom;
Expand Down Expand Up @@ -868,7 +876,7 @@ int sysdb_init_ext(TALLOC_CTX *mem_ctx,
dom_upgrade_ctx = NULL;
}

ret = sysdb_domain_init_internal(tmp_ctx, dom, DB_PATH,
ret = sysdb_domain_init_internal(tmp_ctx, dom, DB_PATH, dont_create_cache,
dom_upgrade_ctx, &sysdb);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE,
Expand All @@ -892,5 +900,5 @@ int sysdb_domain_init(TALLOC_CTX *mem_ctx,
struct sysdb_ctx **_ctx)
{
return sysdb_domain_init_internal(mem_ctx, domain,
db_path, NULL, _ctx);
db_path, true, NULL, _ctx);
}
2 changes: 1 addition & 1 deletion src/monitor/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ static int monitor_process_init(struct mt_ctx *ctx)
}

db_up_ctx.cdb = ctx->cdb;
ret = sysdb_init_ext(tmp_ctx, ctx->domains, &db_up_ctx);
ret = sysdb_init_ext(tmp_ctx, ctx->domains, false, &db_up_ctx);
if (ret != EOK) {
DEBUG(SSSDBG_TRACE_FUNC,
"sysdb_init_ext() failed: '%s'\n", sss_strerror(ret));
Expand Down

0 comments on commit bb54213

Please sign in to comment.