[SCM] Samba Shared Repository - branch v3-2-test updated - initial-v3-2-unstable-864-g4baf367

Volker Lendecke vl at samba.org
Sun Dec 23 11:40:31 GMT 2007


The branch, v3-2-test has been updated
       via  4baf36784f6496121a6863af0283821785eb0cf1 (commit)
      from  0e7f215f54c68b2d40f65f90ed11c41e1a7ef5ed (commit)

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


- Log -----------------------------------------------------------------
commit 4baf36784f6496121a6863af0283821785eb0cf1
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Dec 22 14:52:34 2007 +0100

    Convert the [gu]id_sid cache to memcache

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

Summary of changes:
 source/passdb/lookup_sid.c |  196 ++++++++++++++------------------------------
 1 files changed, 62 insertions(+), 134 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/passdb/lookup_sid.c b/source/passdb/lookup_sid.c
index f5b03ff..55dd654 100644
--- a/source/passdb/lookup_sid.c
+++ b/source/passdb/lookup_sid.c
@@ -971,184 +971,112 @@ bool lookup_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
  modified to use linked lists by jra.
 *****************************************************************/  
 
-#define MAX_UID_SID_CACHE_SIZE 100
-#define TURNOVER_UID_SID_CACHE_SIZE 10
-#define MAX_GID_SID_CACHE_SIZE 100
-#define TURNOVER_GID_SID_CACHE_SIZE 10
-
-static size_t n_uid_sid_cache = 0;
-static size_t n_gid_sid_cache = 0;
-
-static struct uid_sid_cache {
-	struct uid_sid_cache *next, *prev;
-	uid_t uid;
-	DOM_SID sid;
-	enum lsa_SidType sidtype;
-} *uid_sid_cache_head;
-
-static struct gid_sid_cache {
-	struct gid_sid_cache *next, *prev;
-	gid_t gid;
-	DOM_SID sid;
-	enum lsa_SidType sidtype;
-} *gid_sid_cache_head;
-
 /*****************************************************************
   Find a SID given a uid.
-*****************************************************************/  
+*****************************************************************/
 
 static bool fetch_sid_from_uid_cache(DOM_SID *psid, uid_t uid)
 {
-	struct uid_sid_cache *pc;
-
-	for (pc = uid_sid_cache_head; pc; pc = pc->next) {
-		if (pc->uid == uid) {
-			*psid = pc->sid;
-			DEBUG(3,("fetch sid from uid cache %u -> %s\n",
-				 (unsigned int)uid, sid_string_dbg(psid)));
-			DLIST_PROMOTE(uid_sid_cache_head, pc);
-			return true;
-		}
+	DATA_BLOB cache_value;
+
+	if (!memcache_lookup(NULL, UID_SID_CACHE,
+			     data_blob_const(&uid, sizeof(uid)),
+			     &cache_value)) {
+		return false;
 	}
-	return false;
+
+	SMB_ASSERT(cache_value.length == sizeof(*psid));
+	memcpy(psid, cache_value.data, sizeof(*psid));
+
+	return true;
 }
 
 /*****************************************************************
   Find a uid given a SID.
-*****************************************************************/  
+*****************************************************************/
 
 static bool fetch_uid_from_cache( uid_t *puid, const DOM_SID *psid )
 {
-	struct uid_sid_cache *pc;
-
-	for (pc = uid_sid_cache_head; pc; pc = pc->next) {
-		if (sid_compare(&pc->sid, psid) == 0) {
-			*puid = pc->uid;
-			DEBUG(3,("fetch uid from cache %u -> %s\n",
-				 (unsigned int)*puid, sid_string_dbg(psid)));
-			DLIST_PROMOTE(uid_sid_cache_head, pc);
-			return true;
-		}
+	DATA_BLOB cache_value;
+
+	if (!memcache_lookup(NULL, SID_UID_CACHE,
+			     data_blob_const(psid, sizeof(*psid)),
+			     &cache_value)) {
+		return false;
 	}
-	return false;
+
+	SMB_ASSERT(cache_value.length == sizeof(*puid));
+	memcpy(puid, cache_value.data, sizeof(*puid));
+
+	return true;
 }
 
 /*****************************************************************
  Store uid to SID mapping in cache.
-*****************************************************************/  
+*****************************************************************/
 
 void store_uid_sid_cache(const DOM_SID *psid, uid_t uid)
 {
-	struct uid_sid_cache *pc;
-
-	/* do not store SIDs in the "Unix Group" domain */
-	
-	if ( sid_check_is_in_unix_users( psid ) )
-		return;
-
-	if (n_uid_sid_cache >= MAX_UID_SID_CACHE_SIZE && n_uid_sid_cache > TURNOVER_UID_SID_CACHE_SIZE) {
-		/* Delete the last TURNOVER_UID_SID_CACHE_SIZE entries. */
-		struct uid_sid_cache *pc_next;
-		size_t i;
-
-		for (i = 0, pc = uid_sid_cache_head; i < (n_uid_sid_cache - TURNOVER_UID_SID_CACHE_SIZE); i++, pc = pc->next)
-			;
-		for(; pc; pc = pc_next) {
-			pc_next = pc->next;
-			DLIST_REMOVE(uid_sid_cache_head,pc);
-			SAFE_FREE(pc);
-			n_uid_sid_cache--;
-		}
-	}
-
-	pc = SMB_MALLOC_P(struct uid_sid_cache);
-	if (!pc)
-		return;
-	pc->uid = uid;
-	sid_copy(&pc->sid, psid);
-	DLIST_ADD(uid_sid_cache_head, pc);
-	n_uid_sid_cache++;
+	memcache_add(NULL, SID_UID_CACHE,
+		     data_blob_const(psid, sizeof(*psid)),
+		     data_blob_const(&uid, sizeof(uid)));
+	memcache_add(NULL, UID_SID_CACHE,
+		     data_blob_const(&uid, sizeof(uid)),
+		     data_blob_const(psid, sizeof(*psid)));
 }
 
 /*****************************************************************
   Find a SID given a gid.
-*****************************************************************/  
+*****************************************************************/
 
 static bool fetch_sid_from_gid_cache(DOM_SID *psid, gid_t gid)
 {
-	struct gid_sid_cache *pc;
-
-	for (pc = gid_sid_cache_head; pc; pc = pc->next) {
-		if (pc->gid == gid) {
-			*psid = pc->sid;
-			DEBUG(3,("fetch sid from gid cache %u -> %s\n",
-				 (unsigned int)gid, sid_string_dbg(psid)));
-			DLIST_PROMOTE(gid_sid_cache_head, pc);
-			return true;
-		}
+	DATA_BLOB cache_value;
+
+	if (!memcache_lookup(NULL, GID_SID_CACHE,
+			     data_blob_const(&gid, sizeof(gid)),
+			     &cache_value)) {
+		return false;
 	}
-	return false;
+
+	SMB_ASSERT(cache_value.length == sizeof(*psid));
+	memcpy(psid, cache_value.data, sizeof(*psid));
+
+	return true;
 }
 
 /*****************************************************************
   Find a gid given a SID.
-*****************************************************************/  
+*****************************************************************/
 
 static bool fetch_gid_from_cache(gid_t *pgid, const DOM_SID *psid)
 {
-	struct gid_sid_cache *pc;
-
-	for (pc = gid_sid_cache_head; pc; pc = pc->next) {
-		if (sid_compare(&pc->sid, psid) == 0) {
-			*pgid = pc->gid;
-			DEBUG(3,("fetch gid from cache %u -> %s\n",
-				 (unsigned int)*pgid, sid_string_dbg(psid)));
-			DLIST_PROMOTE(gid_sid_cache_head, pc);
-			return true;
-		}
+	DATA_BLOB cache_value;
+
+	if (!memcache_lookup(NULL, SID_UID_CACHE,
+			     data_blob_const(psid, sizeof(*psid)),
+			     &cache_value)) {
+		return false;
 	}
-	return false;
+
+	SMB_ASSERT(cache_value.length == sizeof(*pgid));
+	memcpy(pgid, cache_value.data, sizeof(*pgid));
+
+	return true;
 }
 
 /*****************************************************************
  Store gid to SID mapping in cache.
-*****************************************************************/  
+*****************************************************************/
 
 void store_gid_sid_cache(const DOM_SID *psid, gid_t gid)
 {
-	struct gid_sid_cache *pc;
-	
-	/* do not store SIDs in the "Unix Group" domain */
-	
-	if ( sid_check_is_in_unix_groups( psid ) )
-		return;
-
-	if (n_gid_sid_cache >= MAX_GID_SID_CACHE_SIZE && n_gid_sid_cache > TURNOVER_GID_SID_CACHE_SIZE) {
-		/* Delete the last TURNOVER_GID_SID_CACHE_SIZE entries. */
-		struct gid_sid_cache *pc_next;
-		size_t i;
-
-		for (i = 0, pc = gid_sid_cache_head; i < (n_gid_sid_cache - TURNOVER_GID_SID_CACHE_SIZE); i++, pc = pc->next)
-			;
-		for(; pc; pc = pc_next) {
-			pc_next = pc->next;
-			DLIST_REMOVE(gid_sid_cache_head,pc);
-			SAFE_FREE(pc);
-			n_gid_sid_cache--;
-		}
-	}
-
-	pc = SMB_MALLOC_P(struct gid_sid_cache);
-	if (!pc)
-		return;
-	pc->gid = gid;
-	sid_copy(&pc->sid, psid);
-	DLIST_ADD(gid_sid_cache_head, pc);
-
-	DEBUG(3,("store_gid_sid_cache: gid %u in cache -> %s\n",
-		 (unsigned int)gid, sid_string_dbg(psid)));
-
-	n_gid_sid_cache++;
+	memcache_add(NULL, SID_GID_CACHE,
+		     data_blob_const(psid, sizeof(*psid)),
+		     data_blob_const(&gid, sizeof(gid)));
+	memcache_add(NULL, GID_SID_CACHE,
+		     data_blob_const(&gid, sizeof(gid)),
+		     data_blob_const(psid, sizeof(*psid)));
 }
 
 /*****************************************************************


-- 
Samba Shared Repository


More information about the samba-cvs mailing list