[Exim] ldap and openldap-2.0.6

Top Page
Delete this message
Reply to this message
Author: Brian Candler
Date:  
To: exim-users
Subject: [Exim] ldap and openldap-2.0.6
Minor patches to allow exim-3.16 to compile against openldap-2.0.6

In openldap2, they have completely hidden the LDAP structure, so you cannot
access its contents directly (e.g. lcp->ld->ld_sizelimit = 0) unless you dig
around for the internal header file libldap/ldap-int.h

So the attached patch uses the Netscape-style API calls.

Other issues have surfaced with openldap-2.0.6 though. When you give a URL
with no hostname (e.g. ldap:///whatever),
- ldap_url_search fails (this has now been fixed in OPENLDAP_REL_ENG_2
by having ldap_url_search ignore the host in the URL and use the one
which was given to ldap_open)
- ldap_url_parse returns an empty string, rather than a null pointer, for
the hostname. Not clear whether that is going to be changed to the old
behaviour.

So I think I'll stick to openldap-1.2.11 for now, but I just thought this
might be useful to anyone playing with ldap.

Regards,

Brian Candler.
--- exim-3.16/src/buildconfig.c.orig    Tue Oct 17 15:22:23 2000
+++ exim-3.16/src/buildconfig.c    Tue Oct 17 15:22:44 2000
@@ -230,6 +230,7 @@
     if (strcmp(name, "LDAP_LIB_TYPE") == 0)
       {
       if (strcmp(value, "NETSCAPE") == 0 ||
+          strcmp(value, "OPENLDAP2") == 0 ||
           strcmp(value, "UMICHIGAN") == 0 ||
           strcmp(value, "SOLARIS7") == 0)
         {
--- exim-3.16/src/lookups/ldap.c.orig    Tue Oct 17 15:21:38 2000
+++ exim-3.16/src/lookups/ldap.c    Tue Oct 17 15:21:20 2000
@@ -243,7 +243,7 @@
 /* Before doing the search, set the time and size limits (if given). Here again
 the different implementations of LDAP have chosen to do things differently. */


-#if defined LDAP_LIB_NETSCAPE
+#if defined LDAP_LIB_NETSCAPE || defined LDAP_LIB_OPENLDAP2
 if (sizelimit > 0)
   ldap_set_option(lcp->ld, LDAP_OPT_SIZELIMIT, (void *)&sizelimit);
 if (timelimit > 0)
@@ -271,6 +271,12 @@
   #elif defined LDAP_LIB_NETSCAPE   /* Netscape SDK */
     (void)ldap_get_lderrno(lcp->ld, &matched, &error);
     *errmsg = string_sprintf("ldap search failed: %s (%s)", error, matched);
+  #elif defined LDAP_LIB_OPENLDAP2  /* OpenLDAP v2.x */
+    ldap_get_option(lcp->ld, LDAP_OPT_MATCHED_DN, &matched);
+    ldap_get_option(lcp->ld, LDAP_OPT_ERROR_STRING, &error);
+    *errmsg = string_sprintf("ldap search failed: %s (%s)", error, matched);
+    free(matched);
+    free(error);    
   #else                             /* UMich LDAP */
     matched = lcp->ld->ld_matched;
     error = lcp->ld->ld_error;
@@ -321,7 +327,7 @@
 entries. */


 for(e = ldap_first_entry(lcp->ld, result);
-    e != NULLMSG;
+    e != (void *)0;
     e = ldap_next_entry(lcp->ld, e))
   {
   BOOL add_comma = FALSE;
@@ -372,7 +378,7 @@
         }
       }


-#ifdef HAVE_NETSCAPE_LDAP_SDK
+#if defined LDAP_LIB_NETSCAPE || defined LDAP_LIB_OPENLDAP2

     /* Netscape LDAP's attr's are dynamically allocated and need to be freed.
     UMich LDAP stores them in static storage and does not require this. */