* set winbind cache time to 5 minutes
authorGerald Carter <jerry@samba.org>
Tue, 3 Jun 2003 16:02:33 +0000 (16:02 +0000)
committerGerald Carter <jerry@samba.org>
Tue, 3 Jun 2003 16:02:33 +0000 (16:02 +0000)
* quit obsessing over the sequence number so much
* share the updated sequence number between parent
  and child winbindd processes in dual mode
(This used to be commit 6f99cafa95b2a9dc98d8272fe6a54e9d37098340)

source3/nsswitch/winbindd_cache.c
source3/nsswitch/winbindd_group.c
source3/nsswitch/winbindd_util.c
source3/param/loadparm.c

index dc40142a771af59506abb5b7b99010596317123d..1b817592ae882f1219f0d533a54a8ae296e25dbd 100644 (file)
@@ -221,15 +221,77 @@ static BOOL wcache_server_down(struct winbindd_domain *domain)
        return (domain->sequence_number == DOM_SEQUENCE_NONE);
 }
 
+static NTSTATUS fetch_cache_seqnum( struct winbindd_domain *domain, time_t now )
+{
+       TDB_DATA data;
+       fstring key;
+       uint32 time_diff;
+       
+       if (!wcache->tdb) 
+               return NT_STATUS_UNSUCCESSFUL;
+               
+       snprintf( key, sizeof(key), "SEQNUM/%s", domain->name );
+       
+       data = tdb_fetch_by_string( wcache->tdb, key );
+       if ( !data.dptr || data.dsize!=8 )
+               return NT_STATUS_UNSUCCESSFUL;
+       
+       domain->sequence_number = IVAL(data.dptr, 0);
+       domain->last_seq_check  = IVAL(data.dptr, 4);
+       
+       /* have we expired? */
+       
+       time_diff = now - domain->last_seq_check;
+       if ( time_diff > lp_winbind_cache_time() )
+               return NT_STATUS_UNSUCCESSFUL;
+
+       DEBUG(10,("fetch_cache_seqnum: success [%s][%u @ %u]\n", 
+               domain->name, domain->sequence_number, 
+               (uint32)domain->last_seq_check));
+
+       return NT_STATUS_OK;
+}
+
+static NTSTATUS store_cache_seqnum( struct winbindd_domain *domain )
+{
+       TDB_DATA data, key;
+       fstring key_str;
+       char buf[8];
+       
+       if (!wcache->tdb) 
+               return NT_STATUS_UNSUCCESSFUL;
+               
+       snprintf( key_str, sizeof(key_str), "SEQNUM/%s", domain->name );
+       key.dptr = key_str;
+       key.dsize = strlen(key_str)+1;
+       
+       SIVAL(buf, 0, domain->sequence_number);
+       SIVAL(buf, 4, domain->last_seq_check);
+       data.dptr = buf;
+       data.dsize = 8;
+       
+       if ( tdb_store( wcache->tdb, key, data, TDB_REPLACE) == -1 )
+               return NT_STATUS_UNSUCCESSFUL;
+
+       DEBUG(10,("store_cache_seqnum: success [%s][%u @ %u]\n", 
+               domain->name, domain->sequence_number, 
+               (uint32)domain->last_seq_check));
+       
+       return NT_STATUS_OK;
+}
+
+
 
 /*
   refresh the domain sequence number. If force is True
   then always refresh it, no matter how recently we fetched it
 */
+
 static void refresh_sequence_number(struct winbindd_domain *domain, BOOL force)
 {
        NTSTATUS status;
        unsigned time_diff;
+       time_t t = time(NULL);
        unsigned cache_time = lp_winbind_cache_time();
 
        /* trying to reconnect is expensive, don't do it too often */
@@ -237,20 +299,36 @@ static void refresh_sequence_number(struct winbindd_domain *domain, BOOL force)
                cache_time *= 8;
        }
 
-       time_diff = time(NULL) - domain->last_seq_check;
+       time_diff = t - domain->last_seq_check;
 
        /* see if we have to refetch the domain sequence number */
        if (!force && (time_diff < cache_time)) {
                return;
        }
+       
+       /* try to get the sequence number from the tdb cache first */
+       /* this will update the timestamp as well */
+       
+       status = fetch_cache_seqnum( domain, t );
+       if ( NT_STATUS_IS_OK(status) )
+               goto done;      
 
        status = wcache->backend->sequence_number(domain, &domain->sequence_number);
 
        if (!NT_STATUS_IS_OK(status)) {
                domain->sequence_number = DOM_SEQUENCE_NONE;
        }
-
+       
        domain->last_seq_check = time(NULL);
+       
+       /* save the new sequence number ni the cache */
+       store_cache_seqnum( domain );
+
+done:
+       DEBUG(10, ("refresh_sequence_number: seq number is now %d\n", 
+                  domain->sequence_number));
+
+       return;
 }
 
 /*
@@ -540,7 +618,7 @@ do_query:
        status = cache->backend->query_user_list(domain, mem_ctx, num_entries, info);
 
        /* and save it */
-       refresh_sequence_number(domain, True);
+       refresh_sequence_number(domain, False);
        centry = centry_start(domain, status);
        if (!centry) goto skip_save;
        centry_put_uint32(centry, *num_entries);
@@ -613,7 +691,7 @@ do_query:
        status = cache->backend->enum_dom_groups(domain, mem_ctx, num_entries, info);
 
        /* and save it */
-       refresh_sequence_number(domain, True);
+       refresh_sequence_number(domain, False);
        centry = centry_start(domain, status);
        if (!centry) goto skip_save;
        centry_put_uint32(centry, *num_entries);
@@ -684,7 +762,7 @@ do_query:
        status = cache->backend->enum_local_groups(domain, mem_ctx, num_entries, info);
 
        /* and save it */
-       refresh_sequence_number(domain, True);
+       refresh_sequence_number(domain, False);
        centry = centry_start(domain, status);
        if (!centry) goto skip_save;
        centry_put_uint32(centry, *num_entries);
@@ -782,7 +860,7 @@ do_query:
        status = cache->backend->sid_to_name(domain, mem_ctx, sid, name, type);
 
        /* and save it */
-       refresh_sequence_number(domain, True);
+       refresh_sequence_number(domain, False);
        wcache_save_sid_to_name(domain, status, sid, *name, *type);
        wcache_save_name_to_sid(domain, status, *name, sid, *type);
 
@@ -824,7 +902,7 @@ do_query:
        status = cache->backend->query_user(domain, mem_ctx, user_sid, info);
 
        /* and save it */
-       refresh_sequence_number(domain, True);
+       refresh_sequence_number(domain, False);
        wcache_save_user(domain, status, info);
 
        return status;
@@ -873,7 +951,7 @@ do_query:
        status = cache->backend->lookup_usergroups(domain, mem_ctx, user_sid, num_groups, user_gids);
 
        /* and save it */
-       refresh_sequence_number(domain, True);
+       refresh_sequence_number(domain, False);
        centry = centry_start(domain, status);
        if (!centry) goto skip_save;
        centry_put_uint32(centry, *num_groups);
@@ -942,7 +1020,7 @@ do_query:
                                                 sid_mem, names, name_types);
 
        /* and save it */
-       refresh_sequence_number(domain, True);
+       refresh_sequence_number(domain, False);
        centry = centry_start(domain, status);
        if (!centry) goto skip_save;
        centry_put_uint32(centry, *num_names);
index 14ebb7846682e2fbeca65c2a6a65f4ecf333bd5e..94b6326b90a86ec52c0dd9f2b271f2577277e991 100644 (file)
@@ -450,10 +450,11 @@ static BOOL get_sam_group_entries(struct getent_state *ent)
        
        ent->num_sam_entries = num_entries;
        
-       /* get the domain local groups if we are a member of 
-          a native win2k domain */
+       /* get the domain local groups if we are a member of a native win2k domain */
           
-       if ( domain->native_mode && domain->methods->enum_local_groups )
+       if ( domain->native_mode 
+               && domain->methods->enum_local_groups 
+               && strequal(lp_workgroup(), domain->name) )
        {
                DEBUG(4,("get_sam_group_entries: Native Mode 2k domain; enumerating local groups as well\n"));
                
index ac0b317b427a6ee633fb713fbe5bf61936b7b8b2..84f5d1956863699d216bd29c689e29c4f89ec2db 100644 (file)
@@ -124,13 +124,11 @@ static struct winbindd_domain *add_trusted_domain(const char *domain_name, const
                sid_copy(&domain->sid, sid);
        }
        
-       /* see if this is a native mode win2k domain, but only for our own domain */
+       /* see if this is a native mode win2k domain */
           
-       if ( strequal( lp_workgroup(), domain_name) )   {
-               domain->native_mode = cm_check_for_native_mode_win2k( domain_name );
-               DEBUG(3,("add_trusted_domain: %s is a %s mode domain\n", domain_name,
-                                       domain->native_mode ? "native" : "mixed" ));
-       }       
+       domain->native_mode = cm_check_for_native_mode_win2k( domain_name );
+       DEBUG(3,("add_trusted_domain: %s is a %s mode domain\n", domain_name,
+               domain->native_mode ? "native" : "mixed (or NT4)" ));
 
        /* Link to domain list */
        DLIST_ADD(_domain_list, domain);
index c70152e6cc5eebae68706421a048bebce1d73e8d..16735673217bf60c52d831f8846b6a3825e59bda 100644 (file)
@@ -1459,7 +1459,7 @@ static void init_globals(void)
        string_set(&Globals.szWinbindSeparator, "\\");
        string_set(&Globals.szAclCompat, "");
 
-       Globals.winbind_cache_time = 120;
+       Globals.winbind_cache_time = 600;       /* 5 minutes */
        Globals.bWinbindEnumUsers = True;
        Globals.bWinbindEnumGroups = True;
        Globals.bWinbindUseDefaultDomain = False;