svn commit: samba r19974 - in branches/SAMBA_3_0/source: . nsswitch

jra at samba.org jra at samba.org
Fri Dec 1 00:06:37 GMT 2006


Author: jra
Date: 2006-12-01 00:06:35 +0000 (Fri, 01 Dec 2006)
New Revision: 19974

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=19974

Log:
Add freelist check for cache. Fix testing of entry
names (all except SEQNUM are *not* null terminated
strings).
Jeremy.

Modified:
   branches/SAMBA_3_0/source/Makefile.in
   branches/SAMBA_3_0/source/nsswitch/winbindd_cache.c


Changeset:
Modified: branches/SAMBA_3_0/source/Makefile.in
===================================================================
--- branches/SAMBA_3_0/source/Makefile.in	2006-11-30 23:49:27 UTC (rev 19973)
+++ branches/SAMBA_3_0/source/Makefile.in	2006-12-01 00:06:35 UTC (rev 19974)
@@ -188,7 +188,7 @@
 ######################################################################
 
 TDBBASE_OBJ = tdb/common/tdb.o tdb/common/dump.o tdb/common/error.o \
-	tdb/common/freelist.o tdb/common/io.o tdb/common/lock.o \
+	tdb/common/freelist.o tdb/common/freelistcheck.o tdb/common/io.o tdb/common/lock.o \
 	tdb/common/open.o tdb/common/transaction.o tdb/common/traverse.o
 
 TDB_OBJ = $(TDBBASE_OBJ) lib/util_tdb.o tdb/common/tdbback.o

Modified: branches/SAMBA_3_0/source/nsswitch/winbindd_cache.c
===================================================================
--- branches/SAMBA_3_0/source/nsswitch/winbindd_cache.c	2006-11-30 23:49:27 UTC (rev 19973)
+++ branches/SAMBA_3_0/source/nsswitch/winbindd_cache.c	2006-12-01 00:06:35 UTC (rev 19974)
@@ -372,7 +372,7 @@
 
 static NTSTATUS store_cache_seqnum( struct winbindd_domain *domain )
 {
-	TDB_DATA data, key;
+	TDB_DATA data;
 	fstring key_str;
 	char buf[8];
 	
@@ -382,15 +382,13 @@
 	}
 		
 	fstr_sprintf( key_str, "SEQNUM/%s", domain->name );
-	key.dptr = key_str;
-	key.dsize = strlen(key_str)+1;
 	
 	SIVAL(buf, 0, domain->sequence_number);
 	SIVAL(buf, 4, domain->last_seq_check);
 	data.dptr = buf;
 	data.dsize = 8;
 	
-	if ( tdb_store( wcache->tdb, key, data, TDB_REPLACE) == -1 ) {
+	if ( tdb_store_bystring( wcache->tdb, key_str, data, TDB_REPLACE) == -1 ) {
 		DEBUG(10,("store_cache_seqnum: tdb_store fail key [%s]\n", key_str ));
 		return NT_STATUS_UNSUCCESSFUL;
 	}
@@ -2703,23 +2701,14 @@
 {
 	int i;
 
-	/* Ensure key is valid. */
-	if (kbuf.dsize < 3) {
-		return 1; /* terminate. */
-	}
-	/* Ensure key is a string. */
-	if (kbuf.dptr[kbuf.dsize] != '\0') {
-		return 1; /* terminate. */
-	}
-
 	for (i = 0; key_val[i].keyname; i++) {
-		if (strncmp(key_val[i].keyname, kbuf.dptr, strlen(key_val[i].keyname)) == 0) {
-			if (key_val[i].validate_data_fn(kbuf, dbuf)) {
-				return 1; /* terminate. */
-			}
+		size_t namelen = strlen(key_val[i].keyname);
+		if (kbuf.dsize >= namelen && (
+				strncmp(key_val[i].keyname, kbuf.dptr, namelen)) == 0) {
+			return key_val[i].validate_data_fn(kbuf, dbuf);
 		}
 	}
-	return 0;
+	return 1; /* terminate. */
 }
 
 /* Handle any signals generated when validating a possibly
@@ -2758,6 +2747,7 @@
 {
 	BOOL ret = -1;
 	int fd = -1;
+	int num_entries = 0;
 	TDB_CONTEXT *tdb = NULL;
 	const char *cache_path = lock_path("winbindd_cache.tdb");
 
@@ -2792,12 +2782,22 @@
 
 	fd = tdb_fd(tdb);
 
+	/* Check the cache freelist is good. */
+	if (tdb_validate_freelist(tdb, &num_entries) == -1) {
+		DEBUG(0,("winbindd_validate_cache: bad freelist in cache %s\n",
+			cache_path));
+		goto out;
+	}
+
 	/* Now traverse the cache to validate it. */
 	if (tdb_traverse(tdb, cache_traverse_validate_fn, NULL)) {
+		DEBUG(0,("winbindd_validate_cache: cache %s traverse failed\n",
+			cache_path));
 		goto out;
 	}
 
-	DEBUG(10,("winbindd_validate_cache: cache %s is good\n", cache_path));
+	DEBUG(10,("winbindd_validate_cache: cache %s is good "
+		"freelist has %d entries\n", cache_path, num_entries));
 	ret = 0; /* Cache is good. */
 
   out:



More information about the samba-cvs mailing list