Trusted domain names cache on top of gencache.
Copyright (C) Rafal Szczesniak 2002
-
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
+#include "../libcli/security/security.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_ALL /* there's no proper class yet */
* list of trusted domains
**/
-
/**
* Initialise trustdom name caching system. Call gencache
* initialisation routine to perform necessary activities.
* @return true upon successful cache initialisation or
* false if cache init failed
**/
-
+
bool trustdom_cache_enable(void)
{
- /* Init trustdom cache by calling gencache initialisation */
- if (!gencache_init()) {
- DEBUG(2, ("trustdomcache_enable: Couldn't initialise trustdom cache on top of gencache.\n"));
- return False;
- }
-
return True;
}
* @return true upon successful cache close or
* false if it failed
**/
-
+
bool trustdom_cache_shutdown(void)
{
- /* Close trustdom cache by calling gencache shutdown */
- if (!gencache_shutdown()) {
- DEBUG(2, ("trustdomcache_shutdown: Couldn't shutdown trustdom cache on top of gencache.\n"));
- return False;
- }
-
return True;
}
{
char* keystr = NULL;
asprintf_strupper_m(&keystr, TDOMKEY_FMT, name);
-
+
return keystr;
}
* false if store attempt failed
**/
-bool trustdom_cache_store(char* name, char* alt_name, const DOM_SID *sid,
+bool trustdom_cache_store(char* name, char* alt_name, const struct dom_sid *sid,
time_t timeout)
{
char *key, *alt_key;
fstring sid_string;
bool ret;
- /*
- * we use gecache call to avoid annoying debug messages
- * about initialised trustdom
- */
- if (!gencache_init())
- return False;
-
DEBUG(5, ("trustdom_store: storing SID %s of domain %s\n",
sid_string_dbg(sid), name));
* @return true if entry is found or
* false if has expired/doesn't exist
**/
-
-bool trustdom_cache_fetch(const char* name, DOM_SID* sid)
+
+bool trustdom_cache_fetch(const char* name, struct dom_sid* sid)
{
char *key = NULL, *value = NULL;
+ time_t timeout;
- /* init the cache */
- if (!gencache_init())
- return False;
-
/* exit now if null pointers were passed as they're required further */
if (!sid)
return False;
key = trustdom_cache_key(name);
if (!key)
return False;
-
- if (!gencache_get(key, &value, NULL)) {
+
+ if (!gencache_get(key, &value, &timeout)) {
DEBUG(5, ("no entry for trusted domain %s found.\n", name));
SAFE_FREE(key);
return False;
DEBUG(5, ("trusted domain %s found (%s)\n", name, value));
}
- /* convert sid string representation into DOM_SID structure */
+ /* convert sid string representation into struct dom_sid structure */
if(! string_to_sid(sid, value)) {
sid = NULL;
SAFE_FREE(value);
return False;
}
-
+
SAFE_FREE(value);
return True;
}
uint32 trustdom_cache_fetch_timestamp( void )
{
char *value = NULL;
+ time_t timeout;
uint32 timestamp;
- /* init the cache */
- if (!gencache_init())
- return False;
-
- if (!gencache_get(TDOMTSKEY, &value, NULL)) {
+ if (!gencache_get(TDOMTSKEY, &value, &timeout)) {
DEBUG(5, ("no timestamp for trusted domain cache located.\n"));
SAFE_FREE(value);
return 0;
}
timestamp = atoi(value);
-
+
SAFE_FREE(value);
return timestamp;
}
{
fstring value;
- /* init the cache */
- if (!gencache_init())
- return False;
-
fstr_sprintf(value, "%d", t );
-
+
if (!gencache_set(TDOMTSKEY, value, timeout)) {
DEBUG(5, ("failed to set timestamp for trustdom_cache\n"));
return False;
void trustdom_cache_flush(void)
{
- if (!gencache_init())
- return;
-
/*
* iterate through each TDOM cache's entry and flush it
* by flush_trustdom_name function
void update_trustdom_cache( void )
{
char **domain_names;
- DOM_SID *dom_sids;
+ struct dom_sid *dom_sids;
uint32 num_domains;
uint32 last_check;
int time_diff;
TALLOC_CTX *mem_ctx = NULL;
time_t now = time(NULL);
int i;
-
+
/* get the timestamp. We have to initialise it if the last timestamp == 0 */
if ( (last_check = trustdom_cache_fetch_timestamp()) == 0 )
trustdom_cache_store_timestamp(0, now+TRUSTDOM_UPDATE_INTERVAL);
time_diff = (int) (now - last_check);
-
+
if ( (time_diff > 0) && (time_diff < TRUSTDOM_UPDATE_INTERVAL) ) {
DEBUG(10,("update_trustdom_cache: not time to update trustdom_cache yet\n"));
return;
smbd from blocking all other smbd daemons while we
enumerate the trusted domains */
trustdom_cache_store_timestamp(now, now+TRUSTDOM_UPDATE_INTERVAL);
-
+
if ( !(mem_ctx = talloc_init("update_trustdom_cache")) ) {
DEBUG(0,("update_trustdom_cache: talloc_init() failed!\n"));
goto done;
}
/* get the domains and store them */
-
+
if ( enumerate_domain_trusts(mem_ctx, lp_workgroup(), &domain_names,
&num_domains, &dom_sids)) {
for ( i=0; i<num_domains; i++ ) {
done:
talloc_destroy( mem_ctx );
-
+
return;
}