From ca80787248bfe7fe8dff12486ba32520f6910341 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 26 Feb 2003 12:23:03 +0000 Subject: Netlogon-unigroup changes needed for the winbind RID-to-SID conversion. This changes the cache format, which will simply invalidate existing entries, leaving them dead in the cache. Andrew Bartlett (This used to be commit 3fc179362ea849db23490b971a9f64f943e7f7f8) --- source3/libsmb/netlogon_unigrp.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'source3/libsmb') diff --git a/source3/libsmb/netlogon_unigrp.c b/source3/libsmb/netlogon_unigrp.c index fa2fe32f35..466410d800 100644 --- a/source3/libsmb/netlogon_unigrp.c +++ b/source3/libsmb/netlogon_unigrp.c @@ -22,6 +22,7 @@ */ #include "includes.h" +#define UNIGROUP_PREFIX "UNIGROUP" /* Handle for netlogon_unigrp.tdb database. It is used internally @@ -50,17 +51,22 @@ BOOL uni_group_cache_init(void) BOOL uni_group_cache_store_netlogon(TALLOC_CTX *mem_ctx, NET_USER_INFO_3 *user) { TDB_DATA key,data; - fstring keystr; - int i; + fstring keystr, sid_string; + DOM_SID user_sid; + unsigned int i; if (!uni_group_cache_init()) { DEBUG(0,("uni_group_cache_store_netlogon: cannot open netlogon_unigrp.tdb for write!\n")); return False; } - /* Prepare key as DOMAIN-SID/USER-RID string */ - slprintf(keystr, sizeof(keystr), "%s/%d", - sid_string_static(&user->dom_sid.sid), user->user_rid); + sid_copy(&user_sid, &user->dom_sid.sid); + sid_append_rid(&user_sid, user->user_rid); + + /* Prepare key as USER-SID string */ + slprintf(keystr, sizeof(keystr), "%s/%s", + UNIGROUP_PREFIX, + sid_to_string(sid_string, &user_sid)); key.dptr = keystr; key.dsize = strlen(keystr) + 1; @@ -90,14 +96,15 @@ BOOL uni_group_cache_store_netlogon(TALLOC_CTX *mem_ctx, NET_USER_INFO_3 *user) and elements are array[0] ... array[num_elements-1] */ -uint32* uni_group_cache_fetch(DOM_SID *domain, uint32 user_rid, +DOM_SID **uni_group_cache_fetch(DOM_SID *domain, DOM_SID *user_sid, TALLOC_CTX *mem_ctx, uint32 *num_groups) { TDB_DATA key,data; fstring keystr; - uint32 *groups; + DOM_SID **groups; uint32 i; uint32 group_count; + fstring sid_string; if (!domain) { DEBUG(1,("uni_group_cache_fetch: expected non-null domain sid\n")); @@ -123,8 +130,9 @@ uint32* uni_group_cache_fetch(DOM_SID *domain, uint32 user_rid, *num_groups = 0; /* Fetch universal groups */ - slprintf(keystr, sizeof(keystr), "%s/%d", - sid_string_static(domain), user_rid); + slprintf(keystr, sizeof(keystr), "%s/%s", + UNIGROUP_PREFIX, + sid_to_string(sid_string, user_sid)); key.dptr = keystr; key.dsize = strlen(keystr) + 1; data = tdb_fetch(netlogon_unigrp_tdb, key); @@ -136,12 +144,17 @@ uint32* uni_group_cache_fetch(DOM_SID *domain, uint32 user_rid, /* Transfer data to receiver's memory context */ group_count = IVAL(&((uint32*)data.dptr)[0],0); - groups = talloc(mem_ctx, (group_count)*sizeof(uint32)); + groups = talloc(mem_ctx, (group_count)*sizeof(*groups)); if (groups) { for(i=0; i