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 2 of the License, or
+ 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,
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, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
* false if cache init failed
**/
-BOOL trustdom_cache_enable(void)
+bool trustdom_cache_enable(void)
{
/* Init trustdom cache by calling gencache initialisation */
if (!gencache_init()) {
* false if it failed
**/
-BOOL trustdom_cache_shutdown(void)
+bool trustdom_cache_shutdown(void)
{
/* Close trustdom cache by calling gencache shutdown */
if (!gencache_shutdown()) {
static char* trustdom_cache_key(const char* name)
{
char* keystr = NULL;
- asprintf(&keystr, TDOMKEY_FMT, strupper_static(name));
+ asprintf_strupper_m(&keystr, TDOMKEY_FMT, name);
return keystr;
}
/**
* Store trusted domain in gencache as the domain name (key)
- * and ip address of domain controller (value)
+ * and trusted domain's SID (value)
*
* @param name trusted domain name
* @param alt_name alternative trusted domain name (used in ADS domains)
* 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 DOM_SID *sid,
time_t timeout)
{
char *key, *alt_key;
fstring sid_string;
- BOOL ret;
+ bool ret;
/*
* we use gecache call to avoid annoying debug messages
return False;
DEBUG(5, ("trustdom_store: storing SID %s of domain %s\n",
- sid_string_static(sid), name));
+ sid_string_dbg(sid), name));
key = trustdom_cache_key(name);
alt_key = alt_name ? trustdom_cache_key(alt_name) : NULL;
/**
- * Fetch trusted domain's dc from the gencache.
+ * Fetch trusted domain's SID from the gencache.
* This routine can also be used to check whether given
* domain is currently trusted one.
*
* false if has expired/doesn't exist
**/
-BOOL trustdom_cache_fetch(const char* name, DOM_SID* sid)
+bool trustdom_cache_fetch(const char* name, DOM_SID* sid)
{
char *key = NULL, *value = NULL;
time_t timeout;
if (!gencache_get(key, &value, &timeout)) {
DEBUG(5, ("no entry for trusted domain %s found.\n", name));
SAFE_FREE(key);
- SAFE_FREE(value);
return False;
} else {
SAFE_FREE(key);
DEBUG(5, ("trusted domain %s found (%s)\n", name, value));
}
- /* convert ip string representation into in_addr structure */
+ /* convert sid string representation into DOM_SID structure */
if(! string_to_sid(sid, value)) {
sid = NULL;
SAFE_FREE(value);
store the timestamp from the last update
*******************************************************************/
-BOOL trustdom_cache_store_timestamp( uint32 t, time_t timeout )
+bool trustdom_cache_store_timestamp( uint32 t, time_t timeout )
{
fstring value;
}
-/*******************************************************************
- lock the timestamp entry in the trustdom_cache
-*******************************************************************/
-
-BOOL trustdom_cache_lock_timestamp( void )
-{
- return gencache_lock_entry( TDOMTSKEY ) != -1;
-}
-
-/*******************************************************************
- unlock the timestamp entry in the trustdom_cache
-*******************************************************************/
-
-void trustdom_cache_unlock_timestamp( void )
-{
- gencache_unlock_entry( TDOMTSKEY );
-}
-
/**
* Delete single trustdom entry. Look at the
* gencache_iterate definition.
time_t now = time(NULL);
int i;
- /* get the timestamp. We have to initialise it if the last timestamp == 0 */
-
+ /* 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);
DEBUG(10,("update_trustdom_cache: not time to update trustdom_cache yet\n"));
return;
}
+
+ /* note that we don't lock the timestamp. This prevents this
+ smbd from blocking all other smbd daemons while we
+ enumerate the trusted domains */
+ trustdom_cache_store_timestamp(now, now+TRUSTDOM_UPDATE_INTERVAL);
- /* lock the timestamp */
- if ( !trustdom_cache_lock_timestamp() )
- return;
-
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) )
- {
+ &num_domains, &dom_sids)) {
for ( i=0; i<num_domains; i++ ) {
trustdom_cache_store( domain_names[i], NULL, &dom_sids[i],
now+TRUSTDOM_UPDATE_INTERVAL);
- }
-
- trustdom_cache_store_timestamp( now, now+TRUSTDOM_UPDATE_INTERVAL );
+ }
+ } else {
+ /* we failed to fetch the list of trusted domains - restore the old
+ timestamp */
+ trustdom_cache_store_timestamp(last_check,
+ last_check+TRUSTDOM_UPDATE_INTERVAL);
}
done:
- /* unlock and we're done */
- trustdom_cache_unlock_timestamp();
-
talloc_destroy( mem_ctx );
return;