summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2003-03-18 01:29:58 +0000
committerTim Potter <tpot@samba.org>2003-03-18 01:29:58 +0000
commit07fcc940e631c6eef32a02350c7d31c03445cc7c (patch)
tree39e86a0ee3f02f45560877184fea51c3c9c13455
parent210f24c6b0080f872b260bee51716a65830e449b (diff)
downloadsamba-07fcc940e631c6eef32a02350c7d31c03445cc7c.tar.gz
samba-07fcc940e631c6eef32a02350c7d31c03445cc7c.tar.xz
samba-07fcc940e631c6eef32a02350c7d31c03445cc7c.zip
Clear U/<DOMAIN>/<RID> and UG/<DOMAIN>/<RID> entries from winbindd.cache
so cached errors are not returned on getpwnam and usergroups. Added helper function to test for presence of cached info3 data for a particular rid. Reviewed by jerry. No CR number.
-rw-r--r--source/libsmb/samlogon_cache.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/source/libsmb/samlogon_cache.c b/source/libsmb/samlogon_cache.c
index d233cdddd61..0b49bf354af 100644
--- a/source/libsmb/samlogon_cache.c
+++ b/source/libsmb/samlogon_cache.c
@@ -52,6 +52,56 @@ BOOL netsamlogon_cache_shutdown(void)
}
/***********************************************************************
+ Clear cache getpwnam and getgroups entries from the winbindd cache
+***********************************************************************/
+void netsamlogon_clear_cached_user(TDB_CONTEXT *tdb, NET_USER_INFO_3 *user)
+{
+ fstring domain;
+ TDB_DATA key;
+ BOOL got_tdb = False;
+
+ /* We may need to call this function from smbd which will not have
+ winbindd_cache.tdb open. Open the tdb if a NULL is passed. */
+
+ if (!tdb) {
+ tdb = tdb_open_log(lock_path("winbindd_cache.tdb"), 5000,
+ TDB_DEFAULT, O_RDWR, 0600);
+ if (!tdb) {
+ DEBUG(5, ("netsamlogon_clear_cached_user: failed to open cache\n"));
+ return;
+ }
+ got_tdb = True;
+ }
+
+ unistr2_to_unix(domain, &user->uni_logon_dom, sizeof(domain) - 1);
+
+ /* Clear U/DOMAIN/RID cache entry */
+
+ asprintf(&key.dptr, "U/%s/%d", domain, user->user_rid);
+ key.dsize = strlen(key.dptr) - 1; /* keys are not NULL terminated */
+
+ DEBUG(10, ("netsamlogon_clear_cached_user: clearing %s\n", key.dptr));
+
+ tdb_delete(tdb, key);
+
+ SAFE_FREE(key.dptr);
+
+ /* Clear UG/DOMAIN/RID cache entry */
+
+ asprintf(&key.dptr, "UG/%s/%d", domain, user->user_rid);
+ key.dsize = strlen(key.dptr) - 1; /* keys are not NULL terminated */
+
+ DEBUG(10, ("netsamlogon_clear_cached_user: clearing %s\n", key.dptr));
+
+ tdb_delete(tdb, key);
+
+ SAFE_FREE(key.dptr);
+
+ if (got_tdb)
+ tdb_close(tdb);
+}
+
+/***********************************************************************
Store a NET_USER_INFO_3 structure in a tdb for later user
***********************************************************************/
@@ -132,4 +182,21 @@ NET_USER_INFO_3* netsamlogon_cache_get( TALLOC_CTX *mem_ctx, DOM_SID *dom_sid, u
return user;
}
+BOOL netsamlogon_cache_have(DOM_SID *dom_sid, uint32 rid)
+{
+ TALLOC_CTX *mem_ctx = talloc_init_named("netsamlogon_cache_have");
+ NET_USER_INFO_3 *user = NULL;
+ BOOL result;
+ if (!mem_ctx)
+ return False;
+
+ user = netsamlogon_cache_get(mem_ctx, dom_sid, rid);
+
+ result = (user != NULL);
+
+ talloc_destroy(mem_ctx);
+ SAFE_FREE(user);
+
+ return result;
+}