[SCM] Samba Shared Repository - branch master updated

Stefan Metzmacher metze at samba.org
Mon Dec 7 11:59:07 MST 2009


The branch, master has been updated
       via  909cd26... s3: let gencache_init() use tdb_check()
       via  8f19c08... s3: let netsamlogon_cache_init() use tdb_check()
       via  6f6608c... s3: let tdb_validate_child() use tdb_check()
       via  886fe5b... s3: require tdb 1.1.7 with tdb_check()
      from  5055ba1... s3:docs: Document "directory name cache size".

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 909cd2617fa1c170183664af1fc4253af2dc2f21
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Dec 4 16:46:34 2009 +0100

    s3: let gencache_init() use tdb_check()
    
    If the check fails we try to clear the tdb and start
    with an empty cache.
    
    metze

commit 8f19c08072a7a6036d59cf6c2ca6ce17c74b7635
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Dec 4 16:34:08 2009 +0100

    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

commit 6f6608c2aa6122c87ea1e8a937708d08e6c5785e
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Dec 4 16:32:42 2009 +0100

    s3: let tdb_validate_child() use tdb_check()
    
    metze

commit 886fe5b92082c2d18f97ff0bdcced52d38f344ca
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Dec 4 16:59:39 2009 +0100

    s3: require tdb 1.1.7 with tdb_check()
    
    metze

-----------------------------------------------------------------------

Summary of changes:
 source3/configure.in            |    2 +-
 source3/lib/gencache.c          |   25 +++++++++++++++++++++
 source3/lib/tdb_validate.c      |   11 +++++++++
 source3/libsmb/samlogon_cache.c |   46 +++++++++++++++++++++++++++++++++++---
 4 files changed, 79 insertions(+), 5 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/configure.in b/source3/configure.in
index 169e01d..c9bfaee 100644
--- a/source3/configure.in
+++ b/source3/configure.in
@@ -1971,7 +1971,7 @@ AC_ARG_ENABLE(external_libtdb,
 
 if test "x$enable_external_libtdb" != xno
 then
-	PKG_CHECK_MODULES(LIBTDB, tdb >= 1.1.4,
+	PKG_CHECK_MODULES(LIBTDB, tdb >= 1.1.7,
 		[ enable_external_libtdb=yes ],
 		[
 		if test x$enable_external_libtdb = xyes; then
diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c
index 4889d7c..9a4cbc2 100644
--- a/source3/lib/gencache.c
+++ b/source3/lib/gencache.c
@@ -55,6 +55,7 @@ static bool gencache_init(void)
 {
 	char* cache_fname = NULL;
 	int open_flags = O_RDWR|O_CREAT;
+	bool first_try = true;
 
 	/* skip file open if it's already opened */
 	if (cache) return True;
@@ -63,7 +64,30 @@ static bool gencache_init(void)
 
 	DEBUG(5, ("Opening cache file at %s\n", cache_fname));
 
+again:
 	cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT, open_flags, 0644);
+	if (cache) {
+		int ret;
+		ret = tdb_check(cache, NULL, NULL);
+		if (ret != 0) {
+			tdb_close(cache);
+			cache = NULL;
+			if (!first_try) {
+				DEBUG(0, ("gencache_init: tdb_check(%s) failed\n",
+					  cache_fname));
+				return false;
+			}
+			first_try = false;
+			DEBUG(0, ("gencache_init: tdb_check(%s) failed - retry after CLEAR_IF_FIRST\n",
+				  cache_fname));
+			cache = tdb_open_log(cache_fname, 0, TDB_CLEAR_IF_FIRST, open_flags, 0644);
+			if (cache) {
+				tdb_close(cache);
+				cache = NULL;
+				goto again;
+			}
+		}
+	}
 
 	if (!cache && (errno == EACCES)) {
 		open_flags = O_RDONLY;
@@ -89,6 +113,7 @@ static bool gencache_init(void)
 		DEBUG(5, ("Opening %s failed: %s\n", cache_fname,
 			  strerror(errno)));
 		tdb_close(cache);
+		cache = NULL;
 		return false;
 	}
 
diff --git a/source3/lib/tdb_validate.c b/source3/lib/tdb_validate.c
index 092546e..a1fb185 100644
--- a/source3/lib/tdb_validate.c
+++ b/source3/lib/tdb_validate.c
@@ -44,6 +44,17 @@ static int tdb_validate_child(struct tdb_context *tdb,
 		goto out;
 	}
 
+	/*
+	 * we can simplify this by passing a check function,
+	 * but I don't want to change all the callers...
+	 */
+	ret = tdb_check(tdb, NULL, NULL);
+	if (ret == -1) {
+		v_status.tdb_error = True;
+		v_status.success = False;
+		goto out;
+	}
+
 	/* Check if the tdb's freelist is good. */
 	if (tdb_validate_freelist(tdb, &num_entries) == -1) {
 		v_status.bad_freelist = True;
diff --git a/source3/libsmb/samlogon_cache.c b/source3/libsmb/samlogon_cache.c
index c96f5da..1290182 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;
 }
 
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list