From 7bfc287b693d3696bd5b3c60bdb7e543eb230f9b Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Mon, 7 Jun 2010 15:59:26 -0400 Subject: Disable connection callbacks when going online Under certain circumstances, the openldap libraries will continue internally trying to reconnect to a connection lost (as during a cable-pull test). We need to drop the reconnection callbacks when marking the backend offline in order to guarantee that they are not called with an invalid sdap_handle. --- src/providers/ldap/ldap_common.c | 10 ++++++++++ src/providers/ldap/sdap_async_private.h | 1 + src/providers/ldap/sdap_fd_events.c | 16 ++++++++++++++++ 3 files changed, 27 insertions(+) (limited to 'src/providers') diff --git a/src/providers/ldap/ldap_common.c b/src/providers/ldap/ldap_common.c index f97267148..4f1dc067a 100644 --- a/src/providers/ldap/ldap_common.c +++ b/src/providers/ldap/ldap_common.c @@ -24,6 +24,7 @@ #include "providers/ldap/ldap_common.h" #include "providers/fail_over.h" +#include "providers/ldap/sdap_async_private.h" #include "util/sss_krb5.h" @@ -359,10 +360,19 @@ bool sdap_connected(struct sdap_id_ctx *ctx) void sdap_mark_offline(struct sdap_id_ctx *ctx) { + int ret; + if (ctx->gsh) { /* make sure we mark the connection as gone when we go offline so that * we do not try to reuse a bad connection by mistale later */ ctx->gsh->connected = false; + ret = remove_ldap_connection_callbacks(ctx->gsh); + if (ret != EOK) { + DEBUG(1, ("Could not clear ldap connection callbacks\n")); + /* Not really anything we can do about this, so proceed + * and hope for the best. + */ + } } be_mark_offline(ctx->be); diff --git a/src/providers/ldap/sdap_async_private.h b/src/providers/ldap/sdap_async_private.h index 727cee2e0..ac91a0105 100644 --- a/src/providers/ldap/sdap_async_private.h +++ b/src/providers/ldap/sdap_async_private.h @@ -33,6 +33,7 @@ void sdap_ldap_result(struct tevent_context *ev, struct tevent_fd *fde, int setup_ldap_connection_callbacks(struct sdap_handle *sh, struct tevent_context *ev); +int remove_ldap_connection_callbacks(struct sdap_handle *sh); int get_fd_from_ldap(LDAP *ldap, int *fd); diff --git a/src/providers/ldap/sdap_fd_events.c b/src/providers/ldap/sdap_fd_events.c index 327829630..f989c2249 100644 --- a/src/providers/ldap/sdap_fd_events.c +++ b/src/providers/ldap/sdap_fd_events.c @@ -47,7 +47,23 @@ int get_fd_from_ldap(LDAP *ldap, int *fd) return EOK; } +int remove_ldap_connection_callbacks(struct sdap_handle *sh) +{ +#ifdef HAVE_LDAP_CONNCB + int ret; + + ret = talloc_free(sh->sdap_fd_events->conncb); + if (ret != 0) { + return EIO; + } + + sh->sdap_fd_events->conncb = NULL; +#endif + return EOK; +} + #ifdef HAVE_LDAP_CONNCB + static int remove_connection_callback(TALLOC_CTX *mem_ctx) { int lret; -- cgit