#define WINBINDD_CACHE_VERSION_KEYSTR "WINBINDD_CACHE_VERSION"
extern struct winbindd_methods reconnect_methods;
-extern BOOL opt_nocache;
+extern bool opt_nocache;
#ifdef HAVE_ADS
extern struct winbindd_methods ads_methods;
#endif
Is this key a non-centry type ?
************************************************************************/
-static BOOL is_non_centry_key(TDB_DATA kbuf)
+static bool is_non_centry_key(TDB_DATA kbuf)
{
int i;
and sets this to true if the first query fails and there's an entry in
the cache tdb telling us to stay offline. */
-static BOOL global_winbindd_offline_state;
+static bool global_winbindd_offline_state;
struct winbind_cache {
TDB_CONTEXT *tdb;
free(centry);
}
-static BOOL centry_check_bytes(struct cache_entry *centry, size_t nbytes)
+static bool centry_check_bytes(struct cache_entry *centry, size_t nbytes)
{
if (centry->len - centry->ofs < nbytes) {
DEBUG(0,("centry corruption? needed %u bytes, have %d\n",
/* pull a sid from a cache entry, using the supplied
talloc context
*/
-static BOOL centry_sid(struct cache_entry *centry, TALLOC_CTX *mem_ctx, DOM_SID *sid)
+static bool centry_sid(struct cache_entry *centry, TALLOC_CTX *mem_ctx, DOM_SID *sid)
{
char *sid_string;
sid_string = centry_string(centry, mem_ctx);
/* the server is considered down if it can't give us a sequence number */
-static BOOL wcache_server_down(struct winbindd_domain *domain)
+static bool wcache_server_down(struct winbindd_domain *domain)
{
- BOOL ret;
+ bool ret;
if (!wcache->tdb)
return False;
then always refresh it, no matter how recently we fetched it
*/
-static void refresh_sequence_number(struct winbindd_domain *domain, BOOL force)
+static void refresh_sequence_number(struct winbindd_domain *domain, bool force)
{
NTSTATUS status;
unsigned time_diff;
/*
decide if a cache entry has expired
*/
-static BOOL centry_expired(struct winbindd_domain *domain, const char *keystr, struct cache_entry *centry)
+static bool centry_expired(struct winbindd_domain *domain, const char *keystr, struct cache_entry *centry)
{
/* If we've been told to be offline - stay in that state... */
if (lp_winbind_offline_logon() && global_winbindd_offline_state) {
static void centry_put_sid(struct cache_entry *centry, const DOM_SID *sid)
{
fstring sid_string;
- centry_put_string(centry, sid_to_string(sid_string, sid));
+ centry_put_string(centry, sid_to_fstring(sid_string, sid));
}
fstrcpy(uname, name);
strupper_m(uname);
centry_end(centry, "NS/%s/%s", domain_name, uname);
- DEBUG(10,("wcache_save_name_to_sid: %s\\%s -> %s (%s)\n", domain_name, uname,
- sid_string_static(sid), nt_errstr(status)));
+ DEBUG(10,("wcache_save_name_to_sid: %s\\%s -> %s (%s)\n", domain_name,
+ uname, sid_string_dbg(sid), nt_errstr(status)));
centry_free(centry);
}
centry_put_string(centry, name);
}
- centry_end(centry, "SN/%s", sid_to_string(sid_string, sid));
+ centry_end(centry, "SN/%s", sid_to_fstring(sid_string, sid));
DEBUG(10,("wcache_save_sid_to_name: %s -> %s (%s)\n", sid_string,
name, nt_errstr(status)));
centry_free(centry);
centry_put_uint32(centry, info->primary_gid);
centry_put_sid(centry, &info->user_sid);
centry_put_sid(centry, &info->group_sid);
- centry_end(centry, "U/%s", sid_to_string(sid_string, &info->user_sid));
+ centry_end(centry, "U/%s", sid_to_fstring(sid_string,
+ &info->user_sid));
DEBUG(10,("wcache_save_user: %s (acct_name %s)\n", sid_string, info->acct_name));
centry_free(centry);
}
{
struct winbind_cache *cache = get_cache(domain);
TDB_DATA data;
- fstring key_str;
+ fstring key_str, tmp;
uint32 rid;
if (!cache->tdb) {
return NT_STATUS_INVALID_SID;
}
- fstr_sprintf(key_str, "CRED/%s", sid_string_static(sid));
+ fstr_sprintf(key_str, "CRED/%s", sid_to_fstring(tmp, sid));
data = tdb_fetch(cache->tdb, string_tdb_data(key_str));
if (!data.dptr) {
NTSTATUS status;
time_t t;
uint32 rid;
+ fstring tmp;
if (!cache->tdb) {
return NT_STATUS_INTERNAL_DB_ERROR;
/* Try and get a salted cred first. If we can't
fall back to an unsalted cred. */
- centry = wcache_fetch(cache, domain, "CRED/%s", sid_string_static(sid));
+ centry = wcache_fetch(cache, domain, "CRED/%s",
+ sid_to_fstring(tmp, sid));
if (!centry) {
DEBUG(10,("wcache_get_creds: entry for [CRED/%s] not found\n",
- sid_string_static(sid)));
+ sid_string_dbg(sid)));
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
*cached_nt_pass = (const uint8 *)centry_hash16(centry, mem_ctx);
if (*cached_nt_pass == NULL) {
- const char *sidstr = sid_string_static(sid);
+ fstring sidstr;
+
+ sid_to_fstring(sidstr, sid);
/* Bad (old) cred cache. Delete and pretend we
don't have it. */
status = centry->status;
DEBUG(10,("wcache_get_creds: [Cached] - cached creds for user %s status: %s\n",
- sid_string_static(sid), nt_errstr(status) ));
+ sid_string_dbg(sid), nt_errstr(status) ));
centry_free(centry);
return status;
centry_put_hash16(centry, salted_hash);
centry_put_hash16(centry, cred_salt);
- centry_end(centry, "CRED/%s", sid_to_string(sid_string, sid));
+ centry_end(centry, "CRED/%s", sid_to_fstring(sid_string, sid));
DEBUG(10,("wcache_save_creds: %s\n", sid_string));
if (!cache->tdb)
goto do_query;
- centry = wcache_fetch(cache, domain, "SN/%s", sid_to_string(sid_string, sid));
+ centry = wcache_fetch(cache, domain, "SN/%s",
+ sid_to_fstring(sid_string, sid));
if (!centry)
goto do_query;
struct winbind_cache *cache = get_cache(domain);
size_t i;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- BOOL have_mapped;
- BOOL have_unmapped;
+ bool have_mapped;
+ bool have_unmapped;
*domain_name = NULL;
*names = NULL;
for (i=0; i<num_rids; i++) {
DOM_SID sid;
struct cache_entry *centry;
+ fstring tmp;
if (!sid_compose(&sid, domain_sid, rids[i])) {
result = NT_STATUS_INTERNAL_ERROR;
}
centry = wcache_fetch(cache, domain, "SN/%s",
- sid_string_static(&sid));
+ sid_to_fstring(tmp, &sid));
if (!centry) {
goto do_query;
}
struct winbind_cache *cache = get_cache(domain);
struct cache_entry *centry = NULL;
NTSTATUS status;
+ fstring tmp;
if (!cache->tdb)
goto do_query;
- centry = wcache_fetch(cache, domain, "U/%s", sid_string_static(user_sid));
+ centry = wcache_fetch(cache, domain, "U/%s",
+ sid_to_fstring(tmp, user_sid));
/* If we have an access denied cache entry and a cached info3 in the
samlogon cache then do a query. This will force the rpc back end
if (!cache->tdb)
goto do_query;
- centry = wcache_fetch(cache, domain, "UG/%s", sid_to_string(sid_string, user_sid));
+ centry = wcache_fetch(cache, domain, "UG/%s",
+ sid_to_fstring(sid_string, user_sid));
/* If we have an access denied cache entry and a cached info3 in the
samlogon cache then do a query. This will force the rpc back end
centry_put_sid(centry, &(*user_gids)[i]);
}
- centry_end(centry, "UG/%s", sid_to_string(sid_string, user_sid));
+ centry_end(centry, "UG/%s", sid_to_fstring(sid_string, user_sid));
centry_free(centry);
skip_save:
* resulting might come from any of the SIDs. */
for (i=0; i<num_sids; i++) {
+ fstring tmp;
sidlist = talloc_asprintf(mem_ctx, "%s/%s", sidlist,
- sid_string_static(&sids[i]));
+ sid_to_fstring(tmp, &sids[i]));
if (sidlist == NULL)
return NT_STATUS_NO_MEMORY;
}
if (!cache->tdb)
goto do_query;
- centry = wcache_fetch(cache, domain, "GM/%s", sid_to_string(sid_string, group_sid));
+ centry = wcache_fetch(cache, domain, "GM/%s",
+ sid_to_fstring(sid_string, group_sid));
if (!centry)
goto do_query;
centry_put_string(centry, (*names)[i]);
centry_put_uint32(centry, (*name_types)[i]);
}
- centry_end(centry, "GM/%s", sid_to_string(sid_string, group_sid));
+ centry_end(centry, "GM/%s", sid_to_fstring(sid_string, group_sid));
centry_free(centry);
skip_save:
netsamlogon_clear_cached_user(cache->tdb, info3);
}
-void wcache_invalidate_cache(void)
+int wcache_invalidate_cache(void)
{
struct winbindd_domain *domain;
DEBUG(10, ("wcache_invalidate_cache: invalidating cache "
"entries for %s\n", domain->name));
- if (cache)
- tdb_traverse(cache->tdb, traverse_fn, NULL);
+ if (cache) {
+ if (cache->tdb) {
+ tdb_traverse(cache->tdb, traverse_fn, NULL);
+ } else {
+ return -1;
+ }
+ }
}
+ return 0;
}
-BOOL init_wcache(void)
+bool init_wcache(void)
{
if (wcache == NULL) {
wcache = SMB_XMALLOC_P(struct winbind_cache);
only opener.
************************************************************************/
-BOOL initialize_winbindd_cache(void)
+bool initialize_winbindd_cache(void)
{
- BOOL cache_bad = True;
+ bool cache_bad = True;
uint32 vers;
if (!init_wcache()) {
return True;
}
+void close_winbindd_cache()
+{
+ if (!wcache) {
+ return;
+ }
+ if (wcache->tdb) {
+ tdb_close(wcache->tdb);
+ wcache->tdb = NULL;
+ }
+}
+
void cache_store_response(pid_t pid, struct winbindd_response *response)
{
fstring key_str;
return;
}
-BOOL cache_retrieve_response(pid_t pid, struct winbindd_response * response)
+bool cache_retrieve_response(pid_t pid, struct winbindd_response * response)
{
TDB_DATA data;
fstring key_str;
}
-BOOL lookup_cached_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
+bool lookup_cached_sid(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
char **domain_name, char **name,
enum lsa_SidType *type)
{
struct winbind_cache *cache;
struct cache_entry *centry = NULL;
NTSTATUS status;
+ fstring tmp;
domain = find_lookup_domain_from_sid(sid);
if (domain == NULL) {
return False;
}
- centry = wcache_fetch(cache, domain, "SN/%s", sid_string_static(sid));
+ centry = wcache_fetch(cache, domain, "SN/%s",
+ sid_to_fstring(tmp, sid));
if (centry == NULL) {
return False;
}
return NT_STATUS_IS_OK(status);
}
-BOOL lookup_cached_name(TALLOC_CTX *mem_ctx,
+bool lookup_cached_name(TALLOC_CTX *mem_ctx,
const char *domain_name,
const char *name,
DOM_SID *sid,
struct cache_entry *centry = NULL;
NTSTATUS status;
fstring uname;
- BOOL original_online_state;
+ bool original_online_state;
domain = find_lookup_domain_from_name(domain_name);
if (domain == NULL) {
/* we possibly already have an entry */
if (sid && NT_STATUS_IS_OK(wcache_cached_creds_exist(domain, sid))) {
- fstring key_str;
+ fstring key_str, tmp;
DEBUG(11,("we already have an entry, deleting that\n"));
- fstr_sprintf(key_str, "CRED/%s", sid_string_static(sid));
+ fstr_sprintf(key_str, "CRED/%s", sid_to_fstring(tmp, sid));
tdb_delete(cache->tdb, string_tdb_data(key_str));
}
/* Change the global online/offline state. */
-BOOL set_global_winbindd_state_offline(void)
+bool set_global_winbindd_state_offline(void)
{
TDB_DATA data;
tdb_delete_bystring(wcache->tdb, "WINBINDD_OFFLINE");
}
-BOOL get_global_winbindd_state_offline(void)
+bool get_global_winbindd_state_offline(void)
{
return global_winbindd_offline_state;
}
/***********************************************************************
Try and validate every entry in the winbindd cache. If we fail here,
- delete the cache tdb and return non-zero - the caller (main winbindd
- function) will restart us as we don't know if we crashed or not.
+ delete the cache tdb and return non-zero.
***********************************************************************/
int winbindd_validate_cache(void)
/*********************************************************************
********************************************************************/
-static BOOL add_wbdomain_to_tdc_array( struct winbindd_domain *new_dom,
+static bool add_wbdomain_to_tdc_array( struct winbindd_domain *new_dom,
struct winbindd_tdc_domain **domains,
size_t *num_domains )
{
struct winbindd_tdc_domain *list = NULL;
size_t idx;
int i;
- BOOL set_only = False;
+ bool set_only = False;
/* don't allow duplicates */
/* now pack each domain trust record */
for ( i=0; i<num_domains; i++ ) {
+ fstring tmp;
+
if ( buflen > 0 ) {
DEBUG(10,("pack_tdc_domains: Packing domain %s (%s)\n",
domains[i].domain_name,
len += tdb_pack( buffer+len, buflen-len, "fffddd",
domains[i].domain_name,
domains[i].dns_name,
- sid_string_static(&domains[i].sid),
+ sid_to_fstring(tmp, &domains[i].sid),
domains[i].trust_flags,
domains[i].trust_attribs,
domains[i].trust_type );
/*********************************************************************
********************************************************************/
-static BOOL wcache_tdc_store_list( struct winbindd_tdc_domain *domains, size_t num_domains )
+static bool wcache_tdc_store_list( struct winbindd_tdc_domain *domains, size_t num_domains )
{
TDB_DATA key = make_tdc_key( lp_workgroup() );
TDB_DATA data = { NULL, 0 };
/*********************************************************************
********************************************************************/
-BOOL wcache_tdc_fetch_list( struct winbindd_tdc_domain **domains, size_t *num_domains )
+bool wcache_tdc_fetch_list( struct winbindd_tdc_domain **domains, size_t *num_domains )
{
TDB_DATA key = make_tdc_key( lp_workgroup() );
TDB_DATA data = { NULL, 0 };
/*********************************************************************
********************************************************************/
-BOOL wcache_tdc_add_domain( struct winbindd_domain *domain )
+bool wcache_tdc_add_domain( struct winbindd_domain *domain )
{
struct winbindd_tdc_domain *dom_list = NULL;
size_t num_domains = 0;
- BOOL ret = False;
+ bool ret = False;
DEBUG(10,("wcache_tdc_add_domain: Adding domain %s (%s), SID %s, "
"flags = 0x%x, attributes = 0x%x, type = 0x%x\n",
domain->name, domain->alt_name,
- sid_string_static(&domain->sid),
+ sid_string_dbg(&domain->sid),
domain->domain_flags,
domain->domain_trust_attribs,
domain->domain_type));
uint32 gid)
{
struct cache_entry *centry;
+ fstring tmp;
if ( (centry = centry_start(domain, status)) == NULL )
return;
centry_put_string( centry, gecos );
centry_put_uint32( centry, gid );
- centry_end(centry, "NSS/PWINFO/%s", sid_string_static(user_sid) );
+ centry_end(centry, "NSS/PWINFO/%s", sid_to_fstring(tmp, user_sid) );
- DEBUG(10,("wcache_save_user_pwinfo: %s\n", sid_string_static(user_sid) ));
+ DEBUG(10,("wcache_save_user_pwinfo: %s\n", sid_string_dbg(user_sid) ));
centry_free(centry);
}
struct winbind_cache *cache = get_cache(domain);
struct cache_entry *centry = NULL;
NTSTATUS nt_status;
+ fstring tmp;
if (!cache->tdb)
goto do_query;
- centry = wcache_fetch(cache, domain, "NSS/PWINFO/%s", sid_string_static(user_sid));
+ centry = wcache_fetch(cache, domain, "NSS/PWINFO/%s",
+ sid_to_fstring(tmp, user_sid));
if (!centry)
goto do_query;
centry_free(centry);
DEBUG(10,("nss_get_info_cached: [Cached] - user_sid %s\n",
- sid_string_static(user_sid)));
+ sid_string_dbg(user_sid)));
return NT_STATUS_OK;