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, 15 insertions, 40 deletions
diff --git a/source3/nsswitch/winbindd_cache.c b/source3/nsswitch/winbindd_cache.c
index a607727867..9bd95fdd86 100644
--- a/source3/nsswitch/winbindd_cache.c
+++ b/source3/nsswitch/winbindd_cache.c
@@ -22,9 +22,6 @@
#include "winbindd.h"
-#undef DBGC_CLASS
-#define DBGC_CLASS DBGC_WINBIND
-
struct winbind_cache {
struct winbindd_methods *backend;
TDB_CONTEXT *tdb;
@@ -54,7 +51,7 @@ void wcache_flush_cache(void)
if (opt_nocache) return;
wcache->tdb = tdb_open_log(lock_path("winbindd_cache.tdb"), 5000,
- TDB_CLEAR_IF_FIRST, O_RDWR|O_CREAT, 0600);
+ TDB_DEFAULT, O_RDWR | O_CREAT | O_TRUNC, 0600);
if (!wcache->tdb) {
DEBUG(0,("Failed to open winbindd_cache.tdb!\n"));
@@ -208,17 +205,11 @@ 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 < cache_time)) {
+ if (!force && (time_diff < lp_winbind_cache_time())) {
return;
}
@@ -298,15 +289,8 @@ static struct cache_entry *wcache_fetch(struct winbind_cache *cache,
centry->sequence_number = centry_uint32(centry);
if (centry_expired(domain, centry)) {
- extern BOOL opt_dual_daemon;
-
- if (opt_dual_daemon) {
- extern BOOL backgroud_process;
- backgroud_process = True;
- } else {
- centry_free(centry);
- return NULL;
- }
+ centry_free(centry);
+ return NULL;
}
return centry;
@@ -426,7 +410,6 @@ 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;
@@ -435,9 +418,7 @@ 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;
- fstrcpy(uname, name);
- strupper(uname);
- centry_end(centry, "NS/%s/%s", domain->name, uname);
+ centry_end(centry, "NS/%s/%s", domain->name, name);
centry_free(centry);
}
@@ -467,7 +448,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/%d", domain->name, info->user_rid);
+ centry_end(centry, "U/%s/%x", domain->name, info->user_rid);
centry_free(centry);
}
@@ -616,13 +597,10 @@ 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;
- fstrcpy(uname, name);
- strupper(uname);
- centry = wcache_fetch(cache, domain, "NS/%s/%s", domain->name, uname);
+ centry = wcache_fetch(cache, domain, "NS/%s/%s", domain->name, name);
if (!centry) goto do_query;
*type = centry_uint32(centry);
sid_parse(centry->data + centry->ofs, centry->len - centry->ofs, sid);
@@ -642,9 +620,6 @@ 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;
}
@@ -661,8 +636,7 @@ static NTSTATUS sid_to_name(struct winbindd_domain *domain,
NTSTATUS status;
uint32 rid = 0;
- if (!sid_peek_check_rid(&domain->sid, sid, &rid))
- return NT_STATUS_INVALID_PARAMETER;
+ sid_peek_rid(sid, &rid);
if (!cache->tdb) goto do_query;
@@ -687,7 +661,6 @@ 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;
}
@@ -705,7 +678,7 @@ static NTSTATUS query_user(struct winbindd_domain *domain,
if (!cache->tdb) goto do_query;
- centry = wcache_fetch(cache, domain, "U/%s/%d", domain->name, user_rid);
+ centry = wcache_fetch(cache, domain, "U/%s/%x", domain->name, user_rid);
if (!centry) goto do_query;
info->acct_name = centry_string(centry, mem_ctx);
@@ -746,7 +719,7 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
if (!cache->tdb) goto do_query;
- centry = wcache_fetch(cache, domain, "UG/%s/%d", domain->name, user_rid);
+ centry = wcache_fetch(cache, domain, "UG/%s/%x", domain->name, user_rid);
if (!centry) goto do_query;
*num_groups = centry_uint32(centry);
@@ -781,7 +754,7 @@ do_query:
for (i=0; i<(*num_groups); i++) {
centry_put_uint32(centry, (*user_gids)[i]);
}
- centry_end(centry, "UG/%s/%d", domain->name, user_rid);
+ centry_end(centry, "UG/%s/%x", domain->name, user_rid);
centry_free(centry);
skip_save:
@@ -802,7 +775,7 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
if (!cache->tdb) goto do_query;
- centry = wcache_fetch(cache, domain, "GM/%s/%d", domain->name, group_rid);
+ centry = wcache_fetch(cache, domain, "GM/%s/%x", domain->name, group_rid);
if (!centry) goto do_query;
*num_names = centry_uint32(centry);
@@ -851,7 +824,7 @@ do_query:
centry_put_string(centry, (*names)[i]);
centry_put_uint32(centry, (*name_types)[i]);
}
- centry_end(centry, "GM/%s/%d", domain->name, group_rid);
+ centry_end(centry, "GM/%s/%x", domain->name, group_rid);
centry_free(centry);
skip_save:
@@ -905,3 +878,5 @@ struct winbindd_methods cache_methods = {
trusted_domains,
domain_sid
};
+
+