summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2007-12-28 13:13:29 +0100
committerVolker Lendecke <vl@samba.org>2007-12-28 13:13:29 +0100
commit3c99b7773ef62d13a7e3611be0603a5807315d9d (patch)
tree0624d567fee62faf96eeaeb18a702fe2d8e8473e /source3
parentc2b5cf58f598e0c4018fac639007e8b4306db8d6 (diff)
downloadsamba-3c99b7773ef62d13a7e3611be0603a5807315d9d.tar.gz
samba-3c99b7773ef62d13a7e3611be0603a5807315d9d.tar.bz2
samba-3c99b7773ef62d13a7e3611be0603a5807315d9d.zip
Convert csamuser to memcache
(This used to be commit 476d3abf9c6142d99822212141fc3d843aca4798)
Diffstat (limited to 'source3')
-rw-r--r--source3/include/memcache.h1
-rw-r--r--source3/lib/memcache.c1
-rw-r--r--source3/passdb/pdb_interface.c53
3 files changed, 28 insertions, 27 deletions
diff --git a/source3/include/memcache.h b/source3/include/memcache.h
index c4a2974b62..c615efa695 100644
--- a/source3/include/memcache.h
+++ b/source3/include/memcache.h
@@ -33,6 +33,7 @@ enum memcache_number {
GETWD_CACHE,
GETPWNAM_CACHE, /* talloc */
MANGLE_HASH2_CACHE,
+ PDB_GETPWSID_CACHE, /* talloc */
SINGLETON_CACHE
};
diff --git a/source3/lib/memcache.c b/source3/lib/memcache.c
index 457586bd68..c06e7ceacc 100644
--- a/source3/lib/memcache.c
+++ b/source3/lib/memcache.c
@@ -46,6 +46,7 @@ static bool memcache_is_talloc(enum memcache_number n)
switch (n) {
case GETPWNAM_CACHE:
+ case PDB_GETPWSID_CACHE:
result = true;
break;
default:
diff --git a/source3/passdb/pdb_interface.c b/source3/passdb/pdb_interface.c
index 2102b579ec..0ab45bafc3 100644
--- a/source3/passdb/pdb_interface.c
+++ b/source3/passdb/pdb_interface.c
@@ -25,10 +25,6 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_PASSDB
-/* Cache of latest SAM lookup query */
-
-static struct samu *csamuser = NULL;
-
static_decl_pdb;
static struct pdb_init_function_entry *backends = NULL;
@@ -211,25 +207,29 @@ static struct pdb_methods *pdb_get_methods(void)
bool pdb_getsampwnam(struct samu *sam_acct, const char *username)
{
struct pdb_methods *pdb = pdb_get_methods();
+ struct samu *cache_copy;
+ const struct dom_sid *user_sid;
if (!NT_STATUS_IS_OK(pdb->getsampwnam(pdb, sam_acct, username))) {
return False;
}
- if ( csamuser ) {
- TALLOC_FREE(csamuser);
- }
-
- csamuser = samu_new( NULL );
- if (!csamuser) {
+ cache_copy = samu_new(NULL);
+ if (cache_copy == NULL) {
return False;
}
- if (!pdb_copy_sam_account(csamuser, sam_acct)) {
- TALLOC_FREE(csamuser);
+ if (!pdb_copy_sam_account(cache_copy, sam_acct)) {
+ TALLOC_FREE(cache_copy);
return False;
}
+ user_sid = pdb_get_user_sid(cache_copy);
+
+ memcache_add_talloc(NULL, PDB_GETPWSID_CACHE,
+ data_blob_const(user_sid, sizeof(*user_sid)),
+ cache_copy);
+
return True;
}
@@ -262,6 +262,7 @@ bool pdb_getsampwsid(struct samu *sam_acct, const DOM_SID *sid)
{
struct pdb_methods *pdb = pdb_get_methods();
uint32 rid;
+ void *cache_data;
/* hard code the Guest RID of 501 */
@@ -274,9 +275,16 @@ bool pdb_getsampwsid(struct samu *sam_acct, const DOM_SID *sid)
}
/* check the cache first */
-
- if ( csamuser && sid_equal(sid, pdb_get_user_sid(csamuser) ) )
- return pdb_copy_sam_account(sam_acct, csamuser);
+
+ cache_data = memcache_lookup_talloc(
+ NULL, PDB_GETPWSID_CACHE, data_blob_const(sid, sizeof(*sid)));
+
+ if (cache_data != NULL) {
+ struct samu *cache_copy = talloc_get_type_abort(
+ cache_data, struct samu);
+
+ return pdb_copy_sam_account(sam_acct, cache_copy);
+ }
return NT_STATUS_IS_OK(pdb->getsampwsid(pdb, sam_acct, sid));
}
@@ -471,10 +479,7 @@ NTSTATUS pdb_update_sam_account(struct samu *sam_acct)
{
struct pdb_methods *pdb = pdb_get_methods();
- if (csamuser != NULL) {
- TALLOC_FREE(csamuser);
- csamuser = NULL;
- }
+ memcache_flush(NULL, PDB_GETPWSID_CACHE);
return pdb->update_sam_account(pdb, sam_acct);
}
@@ -483,10 +488,7 @@ NTSTATUS pdb_delete_sam_account(struct samu *sam_acct)
{
struct pdb_methods *pdb = pdb_get_methods();
- if (csamuser != NULL) {
- TALLOC_FREE(csamuser);
- csamuser = NULL;
- }
+ memcache_flush(NULL, PDB_GETPWSID_CACHE);
return pdb->delete_sam_account(pdb, sam_acct);
}
@@ -497,10 +499,7 @@ NTSTATUS pdb_rename_sam_account(struct samu *oldname, const char *newname)
uid_t uid;
NTSTATUS status;
- if (csamuser != NULL) {
- TALLOC_FREE(csamuser);
- csamuser = NULL;
- }
+ memcache_flush(NULL, PDB_GETPWSID_CACHE);
/* sanity check to make sure we don't rename root */