]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ldap: initial support for --with-ldap option
authorMax Dymond <cmeister2@gmail.com>
Thu, 10 Jul 2025 18:31:15 +0000 (19:31 +0100)
committerMax Dymond <cmeister2@gmail.com>
Tue, 15 Jul 2025 13:54:44 +0000 (14:54 +0100)
Add the --with-ldap option so we can specify an include and library path for LDAP.

configure.ac

index 785069a46ca787d8d1d74b78466f8ea13246c086..a0e63d5dc37a922078e30bdac6761fda6297fb52 100644 (file)
@@ -1615,7 +1615,47 @@ AC_ARG_WITH(lber-lib,
 AS_HELP_STRING([--with-lber-lib=libname],[Specify name of lber lib file]),
   [LBERLIBNAME="$withval"])
 
-if test x$CURL_DISABLE_LDAP != x1; then
+dnl Handle argument to --with-ldap.
+clean_LDAP_CPPFLAGS=$CPPFLAGS
+clean_LDAP_LDFLAGS=$LDFLAGS
+clean_LDAP_LIBS=$LIBS
+OPT_LDAP=off
+AC_ARG_WITH(ldap,
+AS_HELP_STRING([--with-ldap=PATH],[Where to look for LDAP, PATH points to the LDAP installation; when possible, set the PKG_CONFIG_PATH environment variable instead of using this option])
+AS_HELP_STRING([--without-ldap], [disable LDAP]),
+  OPT_LDAP=$withval)
+
+case "$OPT_LDAP" in
+  no)
+    dnl --without-ldap option used
+    want_ldap="no"
+    ;;
+  yes)
+    dnl --with-ldap option used without path
+    want_ldap="yes"
+    ;;
+  off)
+    dnl no --with-ldap option given, don't change anything
+    want_ldap="default"
+    ;;
+  *)
+    dnl --with-ldap option used with path
+    want_ldap="yes"
+    if test -d "$OPT_LDAP/lib$libsuff"; then
+      LDFLAGS="$LDFLAGS -L$OPT_LDAP/lib$libsuff"
+      DIR_LDAP="$OPT_LDAP/lib$libsuff"
+    elif test -d "$OPT_LDAP/lib"; then
+      LDFLAGS="$LDFLAGS -L$OPT_LDAP/lib"
+      DIR_LDAP="$OPT_LDAP/lib"
+    fi
+    if test -d "$OPT_LDAP/include"; then
+      CPPFLAGS="$CPPFLAGS -I$OPT_LDAP/include"
+    fi
+    ldap_askedfor="yes"
+    ;;
+esac
+
+if test x$CURL_DISABLE_LDAP != x1 && test "$want_ldap" != "no"; then
 
   CURL_CHECK_HEADER_LBER
   CURL_CHECK_HEADER_LDAP
@@ -1630,7 +1670,24 @@ if test x$CURL_DISABLE_LDAP != x1; then
   fi
 
   if test "$LDAPLIBNAME"; then
-    AC_CHECK_LIB("$LDAPLIBNAME", ldap_init,, [
+    dnl If we have both LDAP and LBER library names, check if we need both
+    if test "$LBERLIBNAME" -a "$LBERLIBNAME" != "no"; then
+      dnl Try LDAP first, then with LBER if needed
+      AC_CHECK_LIB("$LDAPLIBNAME", ldap_init, [ldap_lib_ok=yes], [ldap_lib_ok=no])
+      if test "$ldap_lib_ok" = "no"; then
+        dnl LDAP alone failed, try with LBER
+        AC_CHECK_LIB("$LDAPLIBNAME", ldap_init, [ldap_lib_ok=yes], [ldap_lib_ok=no], [-l$LBERLIBNAME])
+        if test "$ldap_lib_ok" = "yes"; then
+          dnl We need both libraries
+          LIBS="-l$LDAPLIBNAME -l$LBERLIBNAME $LIBS"
+        fi
+      fi
+    else
+      dnl Only check LDAP library
+      AC_CHECK_LIB("$LDAPLIBNAME", ldap_init, [ldap_lib_ok=yes], [ldap_lib_ok=no])
+    fi
+
+    if test "$ldap_lib_ok" = "no"; then
       if test -n "$ldap_askedfor"; then
         AC_MSG_ERROR([couldn't detect the LDAP libraries])
       fi
@@ -1639,8 +1696,11 @@ if test x$CURL_DISABLE_LDAP != x1; then
       CURL_DISABLE_LDAP=1
       AC_DEFINE(CURL_DISABLE_LDAPS, 1, [to disable LDAPS])
       CURL_DISABLE_LDAPS=1
-      ]
-    )
+      dnl restore original flags
+      CPPFLAGS=$clean_LDAP_CPPFLAGS
+      LDFLAGS=$clean_LDAP_LDFLAGS
+      LIBS=$clean_LDAP_LIBS
+    fi
   else
     dnl Try to find the right ldap libraries for this system
     CURL_CHECK_LIBS_LDAP
@@ -1654,23 +1714,45 @@ if test x$CURL_DISABLE_LDAP != x1; then
         CURL_DISABLE_LDAP=1
         AC_DEFINE(CURL_DISABLE_LDAPS, 1, [to disable LDAPS])
         CURL_DISABLE_LDAPS=1
+        dnl restore original flags
+        CPPFLAGS=$clean_LDAP_CPPFLAGS
+        LDFLAGS=$clean_LDAP_LDFLAGS
+        LIBS=$clean_LDAP_LIBS
         ;;
     esac
   fi
 fi
 
 if test x$CURL_DISABLE_LDAP != x1; then
+  dnl Add to library path if needed
+  if test -n "$DIR_LDAP"; then
+    dnl when the ldap shared lib were found in a path that the run-time
+    dnl linker doesn't search through, we need to add it to
+    dnl CURL_LIBRARY_PATH to prevent further configure tests to fail due to
+    dnl this
+
+    if test "x$cross_compiling" != "xyes"; then
+      CURL_LIBRARY_PATH="$CURL_LIBRARY_PATH:$DIR_LDAP"
+      export CURL_LIBRARY_PATH
+      AC_MSG_NOTICE([Added $DIR_LDAP to CURL_LIBRARY_PATH])
+    fi
+  fi
 
   if test "$LBERLIBNAME"; then
     dnl If name is "no" then don't define this library at all
     dnl (it's only needed if libldap.so's dependencies are broken).
-    if test "$LBERLIBNAME" != "no"; then
+    dnl Skip this check if we already determined we need both libraries above
+    if test "$LBERLIBNAME" != "no" -a "$ldap_lib_ok" != "yes"; then
       AC_CHECK_LIB("$LBERLIBNAME", ber_free,, [
         AC_MSG_WARN(["$LBERLIBNAME" is not an LBER library: LDAP disabled])
         AC_DEFINE(CURL_DISABLE_LDAP, 1, [to disable LDAP])
         CURL_DISABLE_LDAP=1
         AC_DEFINE(CURL_DISABLE_LDAPS, 1, [to disable LDAPS])
         CURL_DISABLE_LDAPS=1
+        dnl restore original flags
+        CPPFLAGS=$clean_LDAP_CPPFLAGS
+        LDFLAGS=$clean_LDAP_LDFLAGS
+        LIBS=$clean_LDAP_LIBS
         ]
       )
     fi