From 2fc5b06d7231328b9b103606c586ded6269b5846 Mon Sep 17 00:00:00 2001 From: Christos Zoulas Date: Wed, 3 Dec 2008 18:17:20 +0000 Subject: [PATCH] multiple server ldap patch. --- ChangeLog | 8 ++++++++ amd/info_ldap.c | 44 +++++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index c9db510..15317a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-12-03 Christos Zoulas + + * allow ldap queries try a comma-separated list of servers given as: + + ldap_hostports = host1:port1,host2,host3:port3 + + original patch from Florian Geyer + 2008-09-19 Christos Zoulas * the auth_create gid on NetBSD is int diff --git a/amd/info_ldap.c b/amd/info_ldap.c index 4ac61c8..ea3fe78 100644 --- a/amd/info_ldap.c +++ b/amd/info_ldap.c @@ -148,30 +148,32 @@ string2he(char *s_orig) { char *c, *p; char *s; - HE_ENT *new, *old = NULL; + HE_ENT *first = NULL, *cur = NULL; if (NULL == s_orig || NULL == (s = strdup(s_orig))) return NULL; - for (p = s; p; p = strchr(p, ',')) { - if (old != NULL) { - new = ALLOC(HE_ENT); - old->next = new; - old = new; - } else { - old = ALLOC(HE_ENT); - old->next = NULL; - } + for (p = strtok(s, ","); p; p = strtok(NULL, ",")) { + if (cur != NULL) { + cur->next = ALLOC(HE_ENT); + cur = cur->next; + } else + first = cur = ALLOC(HE_ENT); + + cur->next = NULL; c = strchr(p, ':'); if (c) { /* Host and port */ *c++ = '\0'; - old->host = strdup(p); - old->port = atoi(c); - } else - old->host = strdup(p); - + cur->host = strdup(p); + cur->port = atoi(c); + } else { + cur->host = strdup(p); + cur->port = LDAP_PORT; + } + plog(XLOG_USER, "Adding ldap server %s:%d", + cur->host, cur->port); } XFREE(s); - return (old); + return first; } @@ -316,7 +318,7 @@ amu_ldap_rebind(ALD *a) for (h = a->hostent; h != NULL; h = h->next) { if ((ld = ldap_open(h->host, h->port)) == NULL) { plog(XLOG_WARNING, "Unable to ldap_open to %s:%d\n", h->host, h->port); - break; + continue; } #if LDAP_VERSION_MAX > LDAP_VERSION2 /* handle LDAPv3 and heigher, if available and amd.conf-igured */ @@ -325,16 +327,16 @@ amu_ldap_rebind(ALD *a) dlog("amu_ldap_rebind: LDAP protocol version set to %ld\n", gopt.ldap_proto_version); } else { - plog(XLOG_WARNING, "Unable to set ldap protocol version to %ld\n", - gopt.ldap_proto_version); - break; + plog(XLOG_WARNING, "Unable to set ldap protocol version to %ld for " + "%s:%d\n", gopt.ldap_proto_version, h->host, h->port); + continue; } } #endif /* LDAP_VERSION_MAX > LDAP_VERSION2 */ if (ldap_bind_s(ld, c->who, c->pw, c->method) != LDAP_SUCCESS) { plog(XLOG_WARNING, "Unable to ldap_bind to %s:%d as %s\n", h->host, h->port, c->who); - break; + continue; } if (gopt.ldap_cache_seconds > 0) { #if defined(HAVE_LDAP_ENABLE_CACHE) && defined(HAVE_EXTERN_LDAP_ENABLE_CACHE) -- 2.34.1