diff options
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/module.c | 85 | ||||
-rw-r--r-- | source3/lib/smbldap.c | 47 |
2 files changed, 34 insertions, 98 deletions
diff --git a/source3/lib/module.c b/source3/lib/module.c index 092a68cd68..96a37ae6b5 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -150,88 +150,3 @@ void init_modules(void) if(lp_preload_modules()) smb_load_modules(lp_preload_modules()); } - - -/*************************************************************************** - * This Function registers a idle event - * - * the registered funtions are run periodically - * and maybe shutdown idle connections (e.g. to an LDAP server) - ***************************************************************************/ -static smb_event_id_t smb_idle_event_id = 1; - -struct smb_idle_list_ent { - struct smb_idle_list_ent *prev,*next; - smb_event_id_t id; - smb_idle_event_fn *fn; - void *data; - time_t interval; - time_t lastrun; -}; - -static struct smb_idle_list_ent *smb_idle_event_list = NULL; - -smb_event_id_t smb_register_idle_event(smb_idle_event_fn *fn, void *data, time_t interval) -{ - struct smb_idle_list_ent *event; - - if (!fn) { - return SMB_EVENT_ID_INVALID; - } - - event = SMB_MALLOC_P(struct smb_idle_list_ent); - if (!event) { - DEBUG(0,("malloc() failed!\n")); - return SMB_EVENT_ID_INVALID; - } - event->fn = fn; - event->data = data; - event->interval = interval; - event->lastrun = 0; - event->id = smb_idle_event_id++; - - DLIST_ADD(smb_idle_event_list,event); - - return event->id; -} - -BOOL smb_unregister_idle_event(smb_event_id_t id) -{ - struct smb_idle_list_ent *event = smb_idle_event_list; - - while(event) { - if (event->id == id) { - DLIST_REMOVE(smb_idle_event_list,event); - SAFE_FREE(event); - return True; - } - event = event->next; - } - - return False; -} - -void smb_run_idle_events(time_t now) -{ - struct smb_idle_list_ent *event = smb_idle_event_list; - - while (event) { - struct smb_idle_list_ent *next = event->next; - time_t interval; - - if (event->interval <= 0) { - interval = SMB_IDLE_EVENT_DEFAULT_INTERVAL; - } else if (event->interval >= SMB_IDLE_EVENT_MIN_INTERVAL) { - interval = event->interval; - } else { - interval = SMB_IDLE_EVENT_MIN_INTERVAL; - } - if (now >(event->lastrun+interval)) { - event->lastrun = now; - event->fn(&event->data,&event->interval,now); - } - event = next; - } - - return; -} diff --git a/source3/lib/smbldap.c b/source3/lib/smbldap.c index c102c2185f..5b9ec1d55b 100644 --- a/source3/lib/smbldap.c +++ b/source3/lib/smbldap.c @@ -999,6 +999,11 @@ static int smbldap_connect_system(struct smbldap_state *ldap_state, LDAP * ldap_ return rc; } +static void smbldap_idle_fn(struct event_context *event_ctx, + struct timed_event *te, + const struct timeval *now, + void *private_data); + /********************************************************************** Connect to LDAP server (called before every ldap operation) *********************************************************************/ @@ -1061,6 +1066,16 @@ static int smbldap_open(struct smbldap_state *ldap_state) ldap_state->last_ping = time(NULL); ldap_state->pid = sys_getpid(); + + TALLOC_FREE(ldap_state->idle_event); + + if (ldap_state->event_context != NULL) { + ldap_state->idle_event = event_add_timed( + ldap_state->event_context, NULL, + timeval_current_ofs(SMBLDAP_IDLE_TIME, 0), + "smbldap_idle_fn", smbldap_idle_fn, ldap_state); + } + DEBUG(4,("The LDAP server is succesfully connected\n")); return LDAP_SUCCESS; @@ -1545,17 +1560,28 @@ int smbldap_search_suffix (struct smbldap_state *ldap_state, filter, search_attr, 0, result); } -static void smbldap_idle_fn(void **data, time_t *interval, time_t now) +static void smbldap_idle_fn(struct event_context *event_ctx, + struct timed_event *te, + const struct timeval *now, + void *private_data) { - struct smbldap_state *state = (struct smbldap_state *)(*data); + struct smbldap_state *state = (struct smbldap_state *)private_data; + + TALLOC_FREE(state->idle_event); if (state->ldap_struct == NULL) { DEBUG(10,("ldap connection not connected...\n")); return; } - if ((state->last_use+SMBLDAP_IDLE_TIME) > now) { + if ((state->last_use+SMBLDAP_IDLE_TIME) > now->tv_sec) { DEBUG(10,("ldap connection not idle...\n")); + + state->idle_event = event_add_timed( + event_ctx, NULL, + timeval_current_ofs(SMBLDAP_IDLE_TIME, 0), + "smbldap_idle_fn", smbldap_idle_fn, + private_data); return; } @@ -1578,7 +1604,7 @@ void smbldap_free_struct(struct smbldap_state **ldap_state) SAFE_FREE((*ldap_state)->bind_dn); SAFE_FREE((*ldap_state)->bind_secret); - smb_unregister_idle_event((*ldap_state)->event_id); + TALLOC_FREE((*ldap_state)->idle_event); *ldap_state = NULL; @@ -1590,7 +1616,9 @@ void smbldap_free_struct(struct smbldap_state **ldap_state) Intitalise the 'general' ldap structures, on which ldap operations may be conducted *********************************************************************/ -NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx, const char *location, struct smbldap_state **smbldap_state) +NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx, struct event_context *event_ctx, + const char *location, + struct smbldap_state **smbldap_state) { *smbldap_state = TALLOC_ZERO_P(mem_ctx, struct smbldap_state); if (!*smbldap_state) { @@ -1604,14 +1632,7 @@ NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx, const char *location, struct smbldap_ (*smbldap_state)->uri = "ldap://localhost"; } - (*smbldap_state)->event_id = - smb_register_idle_event(smbldap_idle_fn, (void *)(*smbldap_state), - SMBLDAP_IDLE_TIME); - - if ((*smbldap_state)->event_id == SMB_EVENT_ID_INVALID) { - DEBUG(0,("Failed to register LDAP idle event!\n")); - return NT_STATUS_INVALID_HANDLE; - } + (*smbldap_state)->event_context = event_ctx; return NT_STATUS_OK; } |