From: Günther Deschner Date: Fri, 25 Jul 2025 21:05:39 +0000 (+0200) Subject: s3-winbindd: provide one wcache_open() function for all tdb opens X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7136a6ba39ddf025e85c639f3e53f53f8ff46cb5;p=thirdparty%2Fsamba.git s3-winbindd: provide one wcache_open() function for all tdb opens Guenther BUG: https://bugzilla.samba.org/show_bug.cgi?id=15963 Signed-off-by: Guenther Deschner Reviewed-by: Andreas Schneider --- diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c index f67492b8408..4deb998f63c 100644 --- a/source3/winbindd/winbindd_cache.c +++ b/source3/winbindd/winbindd_cache.c @@ -3167,10 +3167,33 @@ bool wcache_invalidate_cache_noinit(void) return true; } -static bool init_wcache(void) +static TDB_CONTEXT *wcache_open(void) { char *db_path; + TDB_CONTEXT *tdb = NULL; + + db_path = wcache_path(); + if (db_path == NULL) { + return NULL; + } + + /* when working offline we must not clear the cache on restart */ + tdb = tdb_open_log(db_path, + WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE, + TDB_INCOMPATIBLE_HASH | + (lp_winbind_offline_logon() + ? TDB_DEFAULT + : (TDB_DEFAULT | + TDB_CLEAR_IF_FIRST)), + O_RDWR | O_CREAT, + 0600); + TALLOC_FREE(db_path); + return tdb; +} + +static bool init_wcache(void) +{ if (wcache == NULL) { wcache = SMB_XMALLOC_P(struct winbind_cache); ZERO_STRUCTP(wcache); @@ -3179,18 +3202,7 @@ static bool init_wcache(void) if (wcache->tdb != NULL) return true; - db_path = wcache_path(); - if (db_path == NULL) { - return false; - } - - /* when working offline we must not clear the cache on restart */ - wcache->tdb = tdb_open_log(db_path, - WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE, - TDB_INCOMPATIBLE_HASH | - (lp_winbind_offline_logon() ? TDB_DEFAULT : (TDB_DEFAULT | TDB_CLEAR_IF_FIRST)), - O_RDWR|O_CREAT, 0600); - TALLOC_FREE(db_path); + wcache->tdb = wcache_open(); if (wcache->tdb == NULL) { DBG_ERR("Failed to open winbindd_cache.tdb!\n"); return false; @@ -3397,8 +3409,6 @@ static int traverse_fn_cleanup(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, /* flush the cache */ static void wcache_flush_cache(void) { - char *db_path; - if (!wcache) return; if (wcache->tdb) { @@ -3409,18 +3419,7 @@ static void wcache_flush_cache(void) return; } - db_path = wcache_path(); - if (db_path == NULL) { - return; - } - - /* when working offline we must not clear the cache on restart */ - wcache->tdb = tdb_open_log(db_path, - WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE, - TDB_INCOMPATIBLE_HASH | - (lp_winbind_offline_logon() ? TDB_DEFAULT : (TDB_DEFAULT | TDB_CLEAR_IF_FIRST)), - O_RDWR|O_CREAT, 0600); - TALLOC_FREE(db_path); + wcache->tdb = wcache_open(); if (!wcache->tdb) { DBG_ERR("Failed to open winbindd_cache.tdb!\n"); return; @@ -4244,14 +4243,7 @@ int winbindd_validate_cache(void) goto done; } - tdb = tdb_open_log(tdb_path, - WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE, - TDB_INCOMPATIBLE_HASH | - ( lp_winbind_offline_logon() - ? TDB_DEFAULT - : TDB_DEFAULT | TDB_CLEAR_IF_FIRST ), - O_RDWR|O_CREAT, - 0600); + tdb = wcache_open(); if (!tdb) { DBG_ERR("winbindd_validate_cache: " "error opening/initializing tdb\n");