multiple server ldap patch.
authorChristos Zoulas <christos@zoulas.com>
Wed, 3 Dec 2008 18:17:20 +0000 (18:17 +0000)
committerChristos Zoulas <christos@zoulas.com>
Wed, 3 Dec 2008 18:17:20 +0000 (18:17 +0000)
ChangeLog
amd/info_ldap.c

index c9db510271c70513410837168d56b5002810d461..15317a9771c04744f059c4cd04553b0736cd4a42 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-12-03  Christos Zoulas <christos@zoulas.com>
+
+       * 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 <christos@zoulas.com>
 
        * the auth_create gid on NetBSD is int
index 4ac61c8bee375366abc4fec50ab4a18bf4bc8bcc..ea3fe78bbf468aaede617536688bf3562f737341 100644 (file)
@@ -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)