summaryrefslogtreecommitdiff
path: root/source3/lib/smbldap.c
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2007-03-11 16:49:16 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:18:33 -0500
commit0d91334fe799f6b50a8265f9dc097411c3a29e18 (patch)
treec86395688b41edd01055a2a75ac0ba7f6113ad18 /source3/lib/smbldap.c
parent5214cb6782b1ac01b4b23d53478fa11ad00915fe (diff)
downloadsamba-0d91334fe799f6b50a8265f9dc097411c3a29e18.tar.gz
samba-0d91334fe799f6b50a8265f9dc097411c3a29e18.tar.bz2
samba-0d91334fe799f6b50a8265f9dc097411c3a29e18.zip
r21784: Replace smb_register_idle_event() with event_add_timed(). This fixes winbind
who did not run the idle events to drop ldap connections. Volker (This used to be commit af3308ce5a21220ff4c510de356dbaa6cf9ff997)
Diffstat (limited to 'source3/lib/smbldap.c')
-rw-r--r--source3/lib/smbldap.c47
1 files changed, 34 insertions, 13 deletions
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;
}