Make rescan_trusted_domains a timed event
authorVolker Lendecke <vl@samba.org>
Mon, 25 May 2009 20:34:48 +0000 (22:34 +0200)
committerVolker Lendecke <vl@samba.org>
Sun, 14 Jun 2009 09:25:48 +0000 (11:25 +0200)
source3/winbindd/winbindd.c
source3/winbindd/winbindd_proto.h
source3/winbindd/winbindd_util.c

index 65c52e4292367329447c1aefb2dfbc6061f49118..fd467e2f135b85a63d27980312a4ba7cd514d51c 100644 (file)
@@ -1014,6 +1014,7 @@ int main(int argc, char **argv, char **envp)
        poptContext pc;
        int opt;
        TALLOC_CTX *frame = talloc_stackframe();
+       struct tevent_timer *te;
 
        /* glibc (?) likes to print "User defined signal 1" and exit if a
           SIGUSR[12] is received before a handler is installed */
@@ -1260,15 +1261,18 @@ int main(int argc, char **argv, char **envp)
                exit(1);
        }
 
+       te = tevent_add_timer(winbind_event_context(), NULL, timeval_zero(),
+                             rescan_trusted_domains, NULL);
+       if (te == NULL) {
+               DEBUG(0, ("Could not trigger rescan_trusted_domains()\n"));
+               exit(1);
+       }
+
        TALLOC_FREE(frame);
        /* Loop waiting for requests */
        while (1) {
                frame = talloc_stackframe();
 
-               /* refresh the trusted domain cache */
-
-               rescan_trusted_domains();
-
                process_loop();
 
                TALLOC_FREE(frame);
index ac0f71e148fdce8340f01828dd852a4f15dcc179..35863e930e579367d389aa334d7658df3f15b292 100644 (file)
@@ -506,7 +506,8 @@ void winbindd_list_users(struct winbindd_cli_state *state);
 
 struct winbindd_domain *domain_list(void);
 void free_domain_list(void);
-void rescan_trusted_domains( void );
+void rescan_trusted_domains(struct tevent_context *ev, struct tevent_timer *te,
+                           struct timeval now, void *private_data);
 enum winbindd_result winbindd_dual_init_connection(struct winbindd_domain *domain,
                                                   struct winbindd_cli_state *state);
 bool init_domain_list(void);
index 7aceca39c48aa30a2179d3940a269627db4db807..8302ec752b26173e5efe8a4ca1e4375efa791ef7 100644 (file)
@@ -45,14 +45,6 @@ extern struct winbindd_methods sam_passdb_methods;
 
 static struct winbindd_domain *_domain_list = NULL;
 
-/**
-   When was the last scan of trusted domains done?
-
-   0 == not ever
-*/
-
-static time_t last_trustdom_scan;
-
 struct winbindd_domain *domain_list(void)
 {
        /* Initialise list */
@@ -535,19 +527,10 @@ static void rescan_forest_trusts( void )
  (c) ask the a DC in any Win2003 trusted forests
 *********************************************************************/
 
-void rescan_trusted_domains( void )
+void rescan_trusted_domains(struct tevent_context *ev, struct tevent_timer *te,
+                           struct timeval now, void *private_data)
 {
-       time_t now = time(NULL);
-
-       /* Check that we allow trusted domains at all */
-       if (!lp_allow_trusted_domains())
-               return;
-
-       /* see if the time has come... */
-
-       if ((now >= last_trustdom_scan) &&
-           ((now-last_trustdom_scan) < WINBINDD_RESCAN_FREQ) )
-               return;
+       TALLOC_FREE(te);
 
        /* I use to clear the cache here and start over but that
           caused problems in child processes that needed the
@@ -562,7 +545,13 @@ void rescan_trusted_domains( void )
 
        add_trusted_domains( find_our_domain() );
 
-       last_trustdom_scan = now;
+       te = tevent_add_timer(
+               ev, NULL, timeval_current_ofs(WINBINDD_RESCAN_FREQ, 0),
+               rescan_trusted_domains, NULL);
+       /*
+        * If te == NULL, there's not much we can do here. Don't fail, the
+        * only thing we miss is new trusted domains.
+        */
 
        return;
 }