[SCM] Samba Shared Repository - branch v3-2-test updated - initial-v3-2-unstable-1124-g6f673b7

Michael Adam obnox at samba.org
Mon Jan 7 11:24:04 GMT 2008


The branch, v3-2-test has been updated
       via  6f673b7f10c145d88e6a6d3072b5f8cd98837304 (commit)
       via  62d6d4fff2edcce04e793d2a2f877cb3f4fedbdb (commit)
       via  dba24ceae78ffc49200b647838b6bf3657275add (commit)
       via  66fc1db1d19d11792d9506b06ad914d88b7e0663 (commit)
       via  d0c0f91fb9f3438a18c6f47ed894f525beb75cbf (commit)
      from  d9d6775878f8b3425665c6a45a5ef9cb92932cf8 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit 6f673b7f10c145d88e6a6d3072b5f8cd98837304
Author: Michael Adam <obnox at samba.org>
Date:   Mon Jan 7 11:27:54 2008 +0100

    Use the proper boolean constants.
    
    Michael

commit 62d6d4fff2edcce04e793d2a2f877cb3f4fedbdb
Author: Michael Adam <obnox at samba.org>
Date:   Mon Jan 7 11:19:27 2008 +0100

    Fix a comment.
    
    Michael

commit dba24ceae78ffc49200b647838b6bf3657275add
Author: Michael Adam <obnox at samba.org>
Date:   Mon Jan 7 10:59:14 2008 +0100

    Make wcache_invalidate_cache() return bool, not int.
    
    Michael

commit 66fc1db1d19d11792d9506b06ad914d88b7e0663
Author: Michael Adam <obnox at samba.org>
Date:   Mon Jan 7 10:41:09 2008 +0100

    Add some braces to if statement.
    
    Michael

commit d0c0f91fb9f3438a18c6f47ed894f525beb75cbf
Author: Andreas Schneider <anschneider at suse.de>
Date:   Mon Nov 26 11:44:30 2007 +0100

    Prevent winbindd from segfaulting due to corrupted cache tdb.
    
    If we try to flush the caches and due to a corrupted tdb we and have no tdb
    context close the tdb and validate it. Initialize the cache afterwards again.

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

Summary of changes:
 source/winbindd/winbindd.c       |   19 ++++-
 source/winbindd/winbindd_cache.c |  209 ++++++++++++++++++++-----------------
 2 files changed, 131 insertions(+), 97 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/winbindd/winbindd.c b/source/winbindd/winbindd.c
index 07cf226..5e9900d 100644
--- a/source/winbindd/winbindd.c
+++ b/source/winbindd/winbindd.c
@@ -121,7 +121,24 @@ static void flush_caches(void)
            otherwise cached access denied errors due to restrict anonymous
            hang around until the sequence number changes. */
 
-	wcache_invalidate_cache();
+	if (!wcache_invalidate_cache()) {
+		DEBUG(0, ("invalidating the cache failed; revalidate the cache\n"));
+		/* Close the cache to be able to valdite the cache */
+		close_winbindd_cache();
+		/*
+		 * Ensure all cache and idmap caches are consistent
+		 * before we initialize the cache again.
+		 */
+		if (winbindd_validate_cache() < 0) {
+			DEBUG(0, ("winbindd cache tdb corrupt and no backup "
+				  "could be restore.\n"));
+		}
+
+		/* Initialize cache again. */
+		if (!initialize_winbindd_cache()) {
+			exit(1);
+		}
+	}
 }
 
 /* Handle the signal by unlinking socket and exiting */
diff --git a/source/winbindd/winbindd_cache.c b/source/winbindd/winbindd_cache.c
index f63c7a5..fc71868 100644
--- a/source/winbindd/winbindd_cache.c
+++ b/source/winbindd/winbindd_cache.c
@@ -62,7 +62,7 @@ static bool is_non_centry_key(TDB_DATA kbuf)
 	int i;
 
 	if (kbuf.dptr == NULL || kbuf.dsize == 0) {
-		return False;
+		return false;
 	}
 	for (i = 0; non_centry_keys[i] != NULL; i++) {
 		size_t namelen = strlen(non_centry_keys[i]);
@@ -70,10 +70,10 @@ static bool is_non_centry_key(TDB_DATA kbuf)
 			continue;
 		}
 		if (strncmp(non_centry_keys[i], (const char *)kbuf.dptr, namelen) == 0) {
-			return True;
+			return true;
 		}
 	}
-	return False;
+	return false;
 }
 
 /* Global online/offline state - False when online. winbindd starts up online
@@ -210,9 +210,9 @@ static bool centry_check_bytes(struct cache_entry *centry, size_t nbytes)
 		DEBUG(0,("centry corruption? needed %u bytes, have %d\n", 
 			 (unsigned int)nbytes,
 			 centry->len - centry->ofs));
-		return False;
+		return false;
 	}
-	return True;
+	return true;
 }
 
 /*
@@ -348,9 +348,9 @@ static bool centry_sid(struct cache_entry *centry, TALLOC_CTX *mem_ctx, DOM_SID
 	char *sid_string;
 	sid_string = centry_string(centry, mem_ctx);
 	if ((sid_string == NULL) || (!string_to_sid(sid, sid_string))) {
-		return False;
+		return false;
 	}
-	return True;
+	return true;
 }
 
 
@@ -372,7 +372,7 @@ static bool wcache_server_down(struct winbindd_domain *domain)
 	bool ret;
 
 	if (!wcache->tdb)
-		return False;
+		return false;
 
 	ret = (domain->sequence_number == DOM_SEQUENCE_NONE);
 
@@ -454,7 +454,7 @@ static NTSTATUS store_cache_seqnum( struct winbindd_domain *domain )
 }
 
 /*
-  refresh the domain sequence number. If force is True
+  refresh the domain sequence number. If force is true
   then always refresh it, no matter how recently we fetched it
 */
 
@@ -538,7 +538,7 @@ static bool centry_expired(struct winbindd_domain *domain, const char *keystr, s
 	if (lp_winbind_offline_logon() && global_winbindd_offline_state) {
 		DEBUG(10,("centry_expired: Key %s for domain %s valid as winbindd is globally offline.\n",
 			keystr, domain->name ));
-		return False;
+		return false;
 	}
 
 	/* when the domain is offline return the cached entry.
@@ -547,7 +547,7 @@ static bool centry_expired(struct winbindd_domain *domain, const char *keystr, s
 	if (!domain->online) {
 		DEBUG(10,("centry_expired: Key %s for domain %s valid as domain is offline.\n",
 			keystr, domain->name ));
-		return False;
+		return false;
 	}
 
 	/* if the server is OK and our cache entry came from when it was down then
@@ -556,7 +556,7 @@ static bool centry_expired(struct winbindd_domain *domain, const char *keystr, s
 	    (centry->sequence_number == DOM_SEQUENCE_NONE)) {
 		DEBUG(10,("centry_expired: Key %s for domain %s invalid sequence.\n",
 			keystr, domain->name ));
-		return True;
+		return true;
 	}
 
 	/* if the server is down or the cache entry is not older than the
@@ -565,14 +565,14 @@ static bool centry_expired(struct winbindd_domain *domain, const char *keystr, s
 	    centry->sequence_number == domain->sequence_number) {
 		DEBUG(10,("centry_expired: Key %s for domain %s is good.\n",
 			keystr, domain->name ));
-		return False;
+		return false;
 	}
 
 	DEBUG(10,("centry_expired: Key %s for domain %s expired\n",
 		keystr, domain->name ));
 
 	/* it's expired */
-	return True;
+	return true;
 }
 
 static struct cache_entry *wcache_fetch_raw(char *kstr)
@@ -625,7 +625,7 @@ static struct cache_entry *wcache_fetch(struct winbind_cache *cache,
 		return NULL;
 	}
 
-	refresh_sequence_number(domain, False);
+	refresh_sequence_number(domain, false);
 
 	va_start(ap, format);
 	smb_xvasprintf(&kstr, format, ap);
@@ -1189,7 +1189,7 @@ do_query:
 		 (retry++ < 5));
 
 	/* and save it */
-	refresh_sequence_number(domain, False);
+	refresh_sequence_number(domain, false);
 	centry = centry_start(domain, status);
 	if (!centry)
 		goto skip_save;
@@ -1280,7 +1280,7 @@ do_query:
 	status = domain->backend->enum_dom_groups(domain, mem_ctx, num_entries, info);
 
 	/* and save it */
-	refresh_sequence_number(domain, False);
+	refresh_sequence_number(domain, false);
 	centry = centry_start(domain, status);
 	if (!centry)
 		goto skip_save;
@@ -1364,7 +1364,7 @@ do_query:
 	status = domain->backend->enum_local_groups(domain, mem_ctx, num_entries, info);
 
 	/* and save it */
-	refresh_sequence_number(domain, False);
+	refresh_sequence_number(domain, false);
 	centry = centry_start(domain, status);
 	if (!centry)
 		goto skip_save;
@@ -1437,7 +1437,7 @@ do_query:
 					      domain_name, name, sid, type);
 
 	/* and save it */
-	refresh_sequence_number(domain, False);
+	refresh_sequence_number(domain, false);
 
 	if (domain->online &&
 	    (NT_STATUS_IS_OK(status) || NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED))) {
@@ -1510,7 +1510,7 @@ do_query:
 	status = domain->backend->sid_to_name(domain, mem_ctx, sid, domain_name, name, type);
 
 	/* and save it */
-	refresh_sequence_number(domain, False);
+	refresh_sequence_number(domain, false);
 	wcache_save_sid_to_name(domain, status, sid, *domain_name, *name, *type);
 
 	/* We can't save the name to sid mapping here, as with sid history a
@@ -1554,7 +1554,7 @@ static NTSTATUS rids_to_names(struct winbindd_domain *domain,
 		goto error;
 	}
 
-	have_mapped = have_unmapped = False;
+	have_mapped = have_unmapped = false;
 
 	for (i=0; i<num_rids; i++) {
 		DOM_SID sid;
@@ -1577,7 +1577,7 @@ static NTSTATUS rids_to_names(struct winbindd_domain *domain,
 
 		if (NT_STATUS_IS_OK(centry->status)) {
 			char *dom;
-			have_mapped = True;
+			have_mapped = true;
 			(*types)[i] = (enum lsa_SidType)centry_uint32(centry);
 
 			dom = centry_string(centry, mem_ctx);
@@ -1590,7 +1590,7 @@ static NTSTATUS rids_to_names(struct winbindd_domain *domain,
 			(*names)[i] = centry_string(centry, *names);
 
 		} else if (NT_STATUS_EQUAL(centry->status, NT_STATUS_NONE_MAPPED)) {
-			have_unmapped = True;
+			have_unmapped = true;
 
 		} else {
 			/* something's definitely wrong */
@@ -1647,7 +1647,7 @@ static NTSTATUS rids_to_names(struct winbindd_domain *domain,
 		return result;
 	}
 
-	refresh_sequence_number(domain, False);
+	refresh_sequence_number(domain, false);
 
 	for (i=0; i<num_rids; i++) {
 		DOM_SID sid;
@@ -1739,7 +1739,7 @@ do_query:
 	status = domain->backend->query_user(domain, mem_ctx, user_sid, info);
 
 	/* and save it */
-	refresh_sequence_number(domain, False);
+	refresh_sequence_number(domain, false);
 	wcache_save_user(domain, status, info);
 
 	return status;
@@ -1819,7 +1819,7 @@ do_query:
 		goto skip_save;
 	
 	/* and save it */
-	refresh_sequence_number(domain, False);
+	refresh_sequence_number(domain, false);
 	centry = centry_start(domain, status);
 	if (!centry)
 		goto skip_save;
@@ -1912,7 +1912,7 @@ static NTSTATUS lookup_useraliases(struct winbindd_domain *domain,
 						     num_aliases, alias_rids);
 
 	/* and save it */
-	refresh_sequence_number(domain, False);
+	refresh_sequence_number(domain, false);
 	centry = centry_start(domain, status);
 	if (!centry)
 		goto skip_save;
@@ -1993,7 +1993,7 @@ do_query:
 						  sid_mem, names, name_types);
 
 	/* and save it */
-	refresh_sequence_number(domain, False);
+	refresh_sequence_number(domain, false);
 	centry = centry_start(domain, status);
 	if (!centry)
 		goto skip_save;
@@ -2013,7 +2013,7 @@ skip_save:
 /* find the sequence number for a domain */
 static NTSTATUS sequence_number(struct winbindd_domain *domain, uint32 *seq)
 {
-	refresh_sequence_number(domain, False);
+	refresh_sequence_number(domain, false);
 
 	*seq = domain->sequence_number;
 
@@ -2104,7 +2104,7 @@ do_query:
 	    the main parent and always to make the query.  --jerry */
 
 	/* and save it */
-	refresh_sequence_number(domain, False);
+	refresh_sequence_number(domain, false);
  
  	centry = centry_start(domain, status);
 	if (!centry)
@@ -2170,7 +2170,7 @@ do_query:
 	status = domain->backend->lockout_policy(domain, mem_ctx, policy); 
  
 	/* and save it */
- 	refresh_sequence_number(domain, False);
+ 	refresh_sequence_number(domain, false);
 	wcache_save_lockout_policy(domain, status, policy);
  
  	return status;
@@ -2221,7 +2221,7 @@ do_query:
 	status = domain->backend->password_policy(domain, mem_ctx, policy); 
 
 	/* and save it */
-	refresh_sequence_number(domain, False);
+	refresh_sequence_number(domain, false);
 	wcache_save_password_policy(domain, status, policy);
 
 	return status;
@@ -2261,7 +2261,7 @@ void wcache_invalidate_samlogon(struct winbindd_domain *domain,
 	netsamlogon_clear_cached_user(cache->tdb, info3);
 }
 
-void wcache_invalidate_cache(void)
+bool wcache_invalidate_cache(void)
 {
 	struct winbindd_domain *domain;
 
@@ -2270,9 +2270,15 @@ void wcache_invalidate_cache(void)
 
 		DEBUG(10, ("wcache_invalidate_cache: invalidating cache "
 			   "entries for %s\n", domain->name));
-		if (cache)
-			tdb_traverse(cache->tdb, traverse_fn, NULL);
+		if (cache) {
+			if (cache->tdb) {
+				tdb_traverse(cache->tdb, traverse_fn, NULL);
+			} else {
+				return false;
+			}
+		}
 	}
+	return true;
 }
 
 bool init_wcache(void)
@@ -2283,7 +2289,7 @@ bool init_wcache(void)
 	}
 
 	if (wcache->tdb != NULL)
-		return True;
+		return true;
 
 	/* when working offline we must not clear the cache on restart */
 	wcache->tdb = tdb_open_log(lock_path("winbindd_cache.tdb"),
@@ -2293,10 +2299,10 @@ bool init_wcache(void)
 
 	if (wcache->tdb == NULL) {
 		DEBUG(0,("Failed to open winbindd_cache.tdb!\n"));
-		return False;
+		return false;
 	}
 
-	return True;
+	return true;
 }
 
 /************************************************************************
@@ -2307,18 +2313,18 @@ bool init_wcache(void)
 
 bool initialize_winbindd_cache(void)
 {
-	bool cache_bad = True;
+	bool cache_bad = true;
 	uint32 vers;
 
 	if (!init_wcache()) {
 		DEBUG(0,("initialize_winbindd_cache: init_wcache failed.\n"));
-		return False;
+		return false;
 	}
 
 	/* Check version number. */
 	if (tdb_fetch_uint32(wcache->tdb, WINBINDD_CACHE_VERSION_KEYSTR, &vers) &&
 			vers == WINBINDD_CACHE_VERSION) {
-		cache_bad = False;
+		cache_bad = false;
 	}
 
 	if (cache_bad) {
@@ -2333,25 +2339,36 @@ bool initialize_winbindd_cache(void)
 			DEBUG(0,("initialize_winbindd_cache: unlink %s failed %s ",
 				lock_path("winbindd_cache.tdb"),
 				strerror(errno) ));
-			return False;
+			return false;
 		}
 		if (!init_wcache()) {
 			DEBUG(0,("initialize_winbindd_cache: re-initialization "
 					"init_wcache failed.\n"));
-			return False;
+			return false;
 		}
 
 		/* Write the version. */
 		if (!tdb_store_uint32(wcache->tdb, WINBINDD_CACHE_VERSION_KEYSTR, WINBINDD_CACHE_VERSION)) {
 			DEBUG(0,("initialize_winbindd_cache: version number store failed %s\n",
 				tdb_errorstr(wcache->tdb) ));
-			return False;
+			return false;
 		}
 	}
 
 	tdb_close(wcache->tdb);
 	wcache->tdb = NULL;
-	return True;
+	return true;
+}
+
+void close_winbindd_cache()
+{
+	if (!wcache) {
+		return;
+	}
+	if (wcache->tdb) {
+		tdb_close(wcache->tdb);
+		wcache->tdb = NULL;
+	}
 }
 
 void cache_store_response(pid_t pid, struct winbindd_response *response)
@@ -2400,7 +2417,7 @@ bool cache_retrieve_response(pid_t pid, struct winbindd_response * response)
 	fstring key_str;
 
 	if (!init_wcache())
-		return False;
+		return false;
 
 	DEBUG(10, ("Retrieving response for pid %d\n", pid));
 
@@ -2408,17 +2425,17 @@ bool cache_retrieve_response(pid_t pid, struct winbindd_response * response)
 	data = tdb_fetch(wcache->tdb, string_tdb_data(key_str));
 
 	if (data.dptr == NULL)
-		return False;
+		return false;
 
 	if (data.dsize != sizeof(*response))
-		return False;
+		return false;
 
 	memcpy(response, data.dptr, data.dsize);
 	SAFE_FREE(data.dptr);
 
 	if (response->length == sizeof(*response)) {
 		response->extra_data.data = NULL;
-		return True;
+		return true;
 	}
 
 	/* There's extra data */
@@ -2431,19 +2448,19 @@ bool cache_retrieve_response(pid_t pid, struct winbindd_response * response)
 
 	if (data.dptr == NULL) {
 		DEBUG(0, ("Did not find extra data\n"));
-		return False;
+		return false;
 	}
 
 	if (data.dsize != (response->length - sizeof(*response))) {
 		DEBUG(0, ("Invalid extra data length: %d\n", (int)data.dsize));
 		SAFE_FREE(data.dptr);
-		return False;
+		return false;
 	}
 
 	dump_data(11, (uint8 *)data.dptr, data.dsize);
 
 	response->extra_data.data = data.dptr;
-	return True;
+	return true;
 }
 
 void cache_cleanup_response(pid_t pid)
@@ -2475,19 +2492,19 @@ bool lookup_cached_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
 
 	domain = find_lookup_domain_from_sid(sid);
 	if (domain == NULL) {
-		return False;
+		return false;
 	}
 
 	cache = get_cache(domain);
 
 	if (cache->tdb == NULL) {
-		return False;
+		return false;
 	}
 
 	centry = wcache_fetch(cache, domain, "SN/%s",
 			      sid_to_fstring(tmp, sid));
 	if (centry == NULL) {
-		return False;
+		return false;
 	}
 
 	if (NT_STATUS_IS_OK(centry->status)) {
@@ -2516,13 +2533,13 @@ bool lookup_cached_name(TALLOC_CTX *mem_ctx,
 
 	domain = find_lookup_domain_from_name(domain_name);
 	if (domain == NULL) {
-		return False;
+		return false;
 	}
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list