svn commit: samba r3703 - in trunk/source/passdb: .

vlendec at samba.org vlendec at samba.org
Fri Nov 12 15:30:31 GMT 2004


Author: vlendec
Date: 2004-11-12 15:30:31 +0000 (Fri, 12 Nov 2004)
New Revision: 3703

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

Log:
Implement a cache get saves the result of a pdb_getsampwnam for later
retrieval by pdb_getsampwsid. This solves our problem that we do lots of calls
to LDAP during a typical XP login. XP does a lookupnames, then an openuser and
some queryinfo stuff. Lookupnames triggers the initial getsampwnam, and all
the subsequent ones make us call getsampwsid. This patch gets this down to one
call to LDAP.

Yes, a more "correct" way would be to stick the information to the open user
handle, but this one is simpler and saves the LDAP roundtrip for the openuser
call.

Volker

Modified:
   trunk/source/passdb/pdb_interface.c


Changeset:
Modified: trunk/source/passdb/pdb_interface.c
===================================================================
--- trunk/source/passdb/pdb_interface.c	2004-11-12 15:01:40 UTC (rev 3702)
+++ trunk/source/passdb/pdb_interface.c	2004-11-12 15:30:31 UTC (rev 3703)
@@ -1176,6 +1176,8 @@
 	return NT_STATUS_IS_OK(pdb_context->pdb_getsampwent(pdb_context, user));
 }
 
+static SAM_ACCOUNT *sam_account_cache = NULL;
+
 BOOL pdb_getsampwnam(SAM_ACCOUNT *sam_acct, const char *username) 
 {
 	struct pdb_context *pdb_context = pdb_get_static_context(False);
@@ -1184,7 +1186,17 @@
 		return False;
 	}
 
-	return NT_STATUS_IS_OK(pdb_context->pdb_getsampwnam(pdb_context, sam_acct, username));
+	if (!NT_STATUS_IS_OK(pdb_context->pdb_getsampwnam(pdb_context,
+							  sam_acct, username)))
+		return False;
+
+	if (sam_account_cache != NULL) {
+		pdb_free_sam(&sam_account_cache);
+		sam_account_cache = NULL;
+	}
+
+	pdb_copy_sam_account(sam_acct, &sam_account_cache);
+	return True;
 }
 
 BOOL pdb_getsampwsid(SAM_ACCOUNT *sam_acct, const DOM_SID *sid) 
@@ -1195,6 +1207,10 @@
 		return False;
 	}
 
+	if ((sam_account_cache != NULL) &&
+	    (sid_equal(sid, pdb_get_user_sid(sam_account_cache))))
+		return pdb_copy_sam_account(sam_account_cache, &sam_acct);
+
 	return NT_STATUS_IS_OK(pdb_context->pdb_getsampwsid(pdb_context, sam_acct, sid));
 }
 
@@ -1243,6 +1259,11 @@
 		pdb_set_acct_ctrl( sam_acct, acb_flags, PDB_CHANGED );
 	}
 
+	if (sam_account_cache != NULL) {
+		pdb_free_sam(&sam_account_cache);
+		sam_account_cache = NULL;
+	}
+
 	return NT_STATUS_IS_OK(pdb_context->pdb_update_sam_account(pdb_context, sam_acct));
 }
 
@@ -1254,6 +1275,11 @@
 		return False;
 	}
 
+	if (sam_account_cache != NULL) {
+		pdb_free_sam(&sam_account_cache);
+		sam_account_cache = NULL;
+	}
+
 	return NT_STATUS_IS_OK(pdb_context->pdb_delete_sam_account(pdb_context, sam_acct));
 }
 



More information about the samba-cvs mailing list