summaryrefslogtreecommitdiff
path: root/source3/nsswitch/winbindd_cache.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/nsswitch/winbindd_cache.c')
-rw-r--r--source3/nsswitch/winbindd_cache.c55
1 files changed, 40 insertions, 15 deletions
diff --git a/source3/nsswitch/winbindd_cache.c b/source3/nsswitch/winbindd_cache.c
index 9bd95fdd86..a607727867 100644
--- a/source3/nsswitch/winbindd_cache.c
+++ b/source3/nsswitch/winbindd_cache.c
@@ -22,6 +22,9 @@
#include "winbindd.h"
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_WINBIND
+
struct winbind_cache {
struct winbindd_methods *backend;
TDB_CONTEXT *tdb;
@@ -51,7 +54,7 @@ void wcache_flush_cache(void)
if (opt_nocache) return;
wcache->tdb = tdb_open_log(lock_path("winbindd_cache.tdb"), 5000,
- TDB_DEFAULT, O_RDWR | O_CREAT | O_TRUNC, 0600);
+ TDB_CLEAR_IF_FIRST, O_RDWR|O_CREAT, 0600);
if (!wcache->tdb) {
DEBUG(0,("Failed to open winbindd_cache.tdb!\n"));
@@ -205,11 +208,17 @@ static void refresh_sequence_number(struct winbindd_domain *domain, BOOL force)
{
NTSTATUS status;
unsigned time_diff;
+ unsigned cache_time = lp_winbind_cache_time();
+
+ /* trying to reconnect is expensive, don't do it too often */
+ if (domain->sequence_number == DOM_SEQUENCE_NONE) {
+ cache_time *= 8;
+ }
time_diff = time(NULL) - domain->last_seq_check;
/* see if we have to refetch the domain sequence number */
- if (!force && (time_diff < lp_winbind_cache_time())) {
+ if (!force && (time_diff < cache_time)) {
return;
}
@@ -289,8 +298,15 @@ static struct cache_entry *wcache_fetch(struct winbind_cache *cache,
centry->sequence_number = centry_uint32(centry);
if (centry_expired(domain, centry)) {
- centry_free(centry);
- return NULL;
+ extern BOOL opt_dual_daemon;
+
+ if (opt_dual_daemon) {
+ extern BOOL backgroud_process;
+ backgroud_process = True;
+ } else {
+ centry_free(centry);
+ return NULL;
+ }
}
return centry;
@@ -410,6 +426,7 @@ static void wcache_save_name_to_sid(struct winbindd_domain *domain, NTSTATUS sta
{
struct cache_entry *centry;
uint32 len;
+ fstring uname;
centry = centry_start(domain, status);
if (!centry) return;
@@ -418,7 +435,9 @@ static void wcache_save_name_to_sid(struct winbindd_domain *domain, NTSTATUS sta
centry_put_uint32(centry, type);
sid_linearize(centry->data + centry->ofs, len, sid);
centry->ofs += len;
- centry_end(centry, "NS/%s/%s", domain->name, name);
+ fstrcpy(uname, name);
+ strupper(uname);
+ centry_end(centry, "NS/%s/%s", domain->name, uname);
centry_free(centry);
}
@@ -448,7 +467,7 @@ static void wcache_save_user(struct winbindd_domain *domain, NTSTATUS status, WI
centry_put_string(centry, info->full_name);
centry_put_uint32(centry, info->user_rid);
centry_put_uint32(centry, info->group_rid);
- centry_end(centry, "U/%s/%x", domain->name, info->user_rid);
+ centry_end(centry, "U/%s/%d", domain->name, info->user_rid);
centry_free(centry);
}
@@ -597,10 +616,13 @@ static NTSTATUS name_to_sid(struct winbindd_domain *domain,
struct winbind_cache *cache = get_cache(domain);
struct cache_entry *centry = NULL;
NTSTATUS status;
+ fstring uname;
if (!cache->tdb) goto do_query;
- centry = wcache_fetch(cache, domain, "NS/%s/%s", domain->name, name);
+ fstrcpy(uname, name);
+ strupper(uname);
+ centry = wcache_fetch(cache, domain, "NS/%s/%s", domain->name, uname);
if (!centry) goto do_query;
*type = centry_uint32(centry);
sid_parse(centry->data + centry->ofs, centry->len - centry->ofs, sid);
@@ -620,6 +642,9 @@ do_query:
/* and save it */
wcache_save_name_to_sid(domain, status, name, sid, *type);
+ /* We can't save the sid to name mapping as we don't know the
+ correct case of the name without looking it up */
+
return status;
}
@@ -636,7 +661,8 @@ static NTSTATUS sid_to_name(struct winbindd_domain *domain,
NTSTATUS status;
uint32 rid = 0;
- sid_peek_rid(sid, &rid);
+ if (!sid_peek_check_rid(&domain->sid, sid, &rid))
+ return NT_STATUS_INVALID_PARAMETER;
if (!cache->tdb) goto do_query;
@@ -661,6 +687,7 @@ do_query:
/* and save it */
refresh_sequence_number(domain, True);
wcache_save_sid_to_name(domain, status, sid, *name, *type, rid);
+ wcache_save_name_to_sid(domain, status, *name, sid, *type);
return status;
}
@@ -678,7 +705,7 @@ static NTSTATUS query_user(struct winbindd_domain *domain,
if (!cache->tdb) goto do_query;
- centry = wcache_fetch(cache, domain, "U/%s/%x", domain->name, user_rid);
+ centry = wcache_fetch(cache, domain, "U/%s/%d", domain->name, user_rid);
if (!centry) goto do_query;
info->acct_name = centry_string(centry, mem_ctx);
@@ -719,7 +746,7 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
if (!cache->tdb) goto do_query;
- centry = wcache_fetch(cache, domain, "UG/%s/%x", domain->name, user_rid);
+ centry = wcache_fetch(cache, domain, "UG/%s/%d", domain->name, user_rid);
if (!centry) goto do_query;
*num_groups = centry_uint32(centry);
@@ -754,7 +781,7 @@ do_query:
for (i=0; i<(*num_groups); i++) {
centry_put_uint32(centry, (*user_gids)[i]);
}
- centry_end(centry, "UG/%s/%x", domain->name, user_rid);
+ centry_end(centry, "UG/%s/%d", domain->name, user_rid);
centry_free(centry);
skip_save:
@@ -775,7 +802,7 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
if (!cache->tdb) goto do_query;
- centry = wcache_fetch(cache, domain, "GM/%s/%x", domain->name, group_rid);
+ centry = wcache_fetch(cache, domain, "GM/%s/%d", domain->name, group_rid);
if (!centry) goto do_query;
*num_names = centry_uint32(centry);
@@ -824,7 +851,7 @@ do_query:
centry_put_string(centry, (*names)[i]);
centry_put_uint32(centry, (*name_types)[i]);
}
- centry_end(centry, "GM/%s/%x", domain->name, group_rid);
+ centry_end(centry, "GM/%s/%d", domain->name, group_rid);
centry_free(centry);
skip_save:
@@ -878,5 +905,3 @@ struct winbindd_methods cache_methods = {
trusted_domains,
domain_sid
};
-
-