diff options
author | Stefan Metzmacher <metze@samba.org> | 2009-12-04 16:34:08 +0100 |
---|---|---|
committer | Karolin Seeger <kseeger@samba.org> | 2009-12-08 09:15:41 +0100 |
commit | 05927ff692edbac6b35dda175f702b72a38def8b (patch) | |
tree | 09ad7a17b706b8fb12146ea94757834852ea815a | |
parent | 830f18c5f4fc85a1dc49198365ed6ed7061e5dee (diff) | |
download | samba-05927ff692edbac6b35dda175f702b72a38def8b.tar.gz samba-05927ff692edbac6b35dda175f702b72a38def8b.tar.xz samba-05927ff692edbac6b35dda175f702b72a38def8b.zip |
s3: let netsamlogon_cache_init() use tdb_check()
If the check fails we try to unlink the old file and
start with an empty cache.
metze
(cherry picked from commit 8f19c08072a7a6036d59cf6c2ca6ce17c74b7635)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
(cherry picked from commit 8f737c3cd154f394f821b0e34ced3f84ff8773c4)
-rw-r--r-- | source3/libsmb/samlogon_cache.c | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/source3/libsmb/samlogon_cache.c b/source3/libsmb/samlogon_cache.c index c96f5dad831..12901826eee 100644 --- a/source3/libsmb/samlogon_cache.c +++ b/source3/libsmb/samlogon_cache.c @@ -34,12 +34,50 @@ static TDB_CONTEXT *netsamlogon_tdb = NULL; bool netsamlogon_cache_init(void) { - if (!netsamlogon_tdb) { - netsamlogon_tdb = tdb_open_log(cache_path(NETSAMLOGON_TDB), 0, - TDB_DEFAULT, O_RDWR | O_CREAT, 0600); + bool first_try = true; + const char *path = NULL; + int ret; + struct tdb_context *tdb; + + if (netsamlogon_tdb) { + return true; + } + + path = cache_path(NETSAMLOGON_TDB); +again: + tdb = tdb_open_log(path, 0, TDB_DEFAULT, + O_RDWR | O_CREAT, 0600); + if (tdb == NULL) { + DEBUG(0,("tdb_open_log('%s') - failed\n", path)); + goto clear; + } + + ret = tdb_check(tdb, NULL, NULL); + if (ret != 0) { + tdb_close(tdb); + DEBUG(0,("tdb_check('%s') - failed\n", path)); + goto clear; + } + + netsamlogon_tdb = tdb; + return true; + +clear: + if (!first_try) { + return false; + } + first_try = false; + + DEBUG(0,("retry after CLEAR_IF_FIRST for '%s'\n", path)); + tdb = tdb_open_log(path, 0, TDB_CLEAR_IF_FIRST, + O_RDWR | O_CREAT, 0600); + if (tdb) { + tdb_close(tdb); + goto again; } + DEBUG(0,("tdb_open_log(%s) with CLEAR_IF_FIRST - failed\n", path)); - return (netsamlogon_tdb != NULL); + return false; } |