Skip to content

Commit a5377e7

Browse files
committed
Update configure's probe for libldap to work with OpenLDAP 2.5.
The separate libldap_r is gone and libldap itself is now always thread-safe. Unfortunately there seems no easy way to tell by inspection whether libldap is thread-safe, so we have to take it on faith that libldap is thread-safe if there's no libldap_r. That should be okay, as it appears that libldap_r was a standard part of the installation going back at least 20 years. Report and patch by Adrian Ho. Back-patch to all supported branches, since people might try to build any of them with a newer OpenLDAP. Discussion: https://postgr.es/m/17083-a19190d9591946a7@postgresql.org
1 parent 9c729bd commit a5377e7

File tree

3 files changed

+64
-48
lines changed

3 files changed

+64
-48
lines changed

configure

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12460,13 +12460,17 @@ fi
1246012460
if test "$with_ldap" = yes ; then
1246112461
_LIBS="$LIBS"
1246212462
if test "$PORTNAME" != "win32"; then
12463-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ldap_bind in -lldap" >&5
12464-
$as_echo_n "checking for ldap_bind in -lldap... " >&6; }
12465-
if ${ac_cv_lib_ldap_ldap_bind+:} false; then :
12463+
if test "$enable_thread_safety" = yes; then
12464+
# Use ldap_r for FE if available, else assume ldap is thread-safe.
12465+
# If ldap_r does exist, assume without checking that ldap does too.
12466+
# on some platforms ldap_r fails to link without PTHREAD_LIBS
12467+
LIBS=""
12468+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing ldap_bind" >&5
12469+
$as_echo_n "checking for library containing ldap_bind... " >&6; }
12470+
if ${ac_cv_search_ldap_bind+:} false; then :
1246612471
$as_echo_n "(cached) " >&6
1246712472
else
12468-
ac_check_lib_save_LIBS=$LIBS
12469-
LIBS="-lldap $EXTRA_LDAP_LIBS $LIBS"
12473+
ac_func_search_save_LIBS=$LIBS
1247012474
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1247112475
/* end confdefs.h. */
1247212476

@@ -12485,38 +12489,50 @@ return ldap_bind ();
1248512489
return 0;
1248612490
}
1248712491
_ACEOF
12488-
if ac_fn_c_try_link "$LINENO"; then :
12489-
ac_cv_lib_ldap_ldap_bind=yes
12490-
else
12491-
ac_cv_lib_ldap_ldap_bind=no
12492+
for ac_lib in '' ldap_r ldap; do
12493+
if test -z "$ac_lib"; then
12494+
ac_res="none required"
12495+
else
12496+
ac_res=-l$ac_lib
12497+
LIBS="-l$ac_lib $PTHREAD_CFLAGS $PTHREAD_LIBS $EXTRA_LDAP_LIBS $ac_func_search_save_LIBS"
12498+
fi
12499+
if ac_fn_c_try_link "$LINENO"; then :
12500+
ac_cv_search_ldap_bind=$ac_res
1249212501
fi
1249312502
rm -f core conftest.err conftest.$ac_objext \
12494-
conftest$ac_exeext conftest.$ac_ext
12495-
LIBS=$ac_check_lib_save_LIBS
12503+
conftest$ac_exeext
12504+
if ${ac_cv_search_ldap_bind+:} false; then :
12505+
break
1249612506
fi
12497-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ldap_ldap_bind" >&5
12498-
$as_echo "$ac_cv_lib_ldap_ldap_bind" >&6; }
12499-
if test "x$ac_cv_lib_ldap_ldap_bind" = xyes; then :
12500-
cat >>confdefs.h <<_ACEOF
12501-
#define HAVE_LIBLDAP 1
12502-
_ACEOF
12507+
done
12508+
if ${ac_cv_search_ldap_bind+:} false; then :
1250312509

12504-
LIBS="-lldap $LIBS"
12510+
else
12511+
ac_cv_search_ldap_bind=no
12512+
fi
12513+
rm conftest.$ac_ext
12514+
LIBS=$ac_func_search_save_LIBS
12515+
fi
12516+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_ldap_bind" >&5
12517+
$as_echo "$ac_cv_search_ldap_bind" >&6; }
12518+
ac_res=$ac_cv_search_ldap_bind
12519+
if test "$ac_res" != no; then :
12520+
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
1250512521

1250612522
else
1250712523
as_fn_error $? "library 'ldap' is required for LDAP" "$LINENO" 5
1250812524
fi
1250912525

12510-
LDAP_LIBS_BE="-lldap $EXTRA_LDAP_LIBS"
12511-
if test "$enable_thread_safety" = yes; then
12512-
# on some platforms ldap_r fails to link without PTHREAD_LIBS
12513-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ldap_simple_bind in -lldap_r" >&5
12514-
$as_echo_n "checking for ldap_simple_bind in -lldap_r... " >&6; }
12515-
if ${ac_cv_lib_ldap_r_ldap_simple_bind+:} false; then :
12526+
LDAP_LIBS_FE="$LIBS $EXTRA_LDAP_LIBS"
12527+
LDAP_LIBS_BE="-lldap $EXTRA_LDAP_LIBS"
12528+
else
12529+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ldap_bind in -lldap" >&5
12530+
$as_echo_n "checking for ldap_bind in -lldap... " >&6; }
12531+
if ${ac_cv_lib_ldap_ldap_bind+:} false; then :
1251612532
$as_echo_n "(cached) " >&6
1251712533
else
1251812534
ac_check_lib_save_LIBS=$LIBS
12519-
LIBS="-lldap_r $PTHREAD_CFLAGS $PTHREAD_LIBS $EXTRA_LDAP_LIBS $LIBS"
12535+
LIBS="-lldap $EXTRA_LDAP_LIBS $LIBS"
1252012536
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1252112537
/* end confdefs.h. */
1252212538

@@ -12526,40 +12542,39 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1252612542
#ifdef __cplusplus
1252712543
extern "C"
1252812544
#endif
12529-
char ldap_simple_bind ();
12545+
char ldap_bind ();
1253012546
int
1253112547
main ()
1253212548
{
12533-
return ldap_simple_bind ();
12549+
return ldap_bind ();
1253412550
;
1253512551
return 0;
1253612552
}
1253712553
_ACEOF
1253812554
if ac_fn_c_try_link "$LINENO"; then :
12539-
ac_cv_lib_ldap_r_ldap_simple_bind=yes
12555+
ac_cv_lib_ldap_ldap_bind=yes
1254012556
else
12541-
ac_cv_lib_ldap_r_ldap_simple_bind=no
12557+
ac_cv_lib_ldap_ldap_bind=no
1254212558
fi
1254312559
rm -f core conftest.err conftest.$ac_objext \
1254412560
conftest$ac_exeext conftest.$ac_ext
1254512561
LIBS=$ac_check_lib_save_LIBS
1254612562
fi
12547-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ldap_r_ldap_simple_bind" >&5
12548-
$as_echo "$ac_cv_lib_ldap_r_ldap_simple_bind" >&6; }
12549-
if test "x$ac_cv_lib_ldap_r_ldap_simple_bind" = xyes; then :
12563+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ldap_ldap_bind" >&5
12564+
$as_echo "$ac_cv_lib_ldap_ldap_bind" >&6; }
12565+
if test "x$ac_cv_lib_ldap_ldap_bind" = xyes; then :
1255012566
cat >>confdefs.h <<_ACEOF
12551-
#define HAVE_LIBLDAP_R 1
12567+
#define HAVE_LIBLDAP 1
1255212568
_ACEOF
1255312569

12554-
LIBS="-lldap_r $LIBS"
12570+
LIBS="-lldap $LIBS"
1255512571

1255612572
else
12557-
as_fn_error $? "library 'ldap_r' is required for LDAP" "$LINENO" 5
12573+
as_fn_error $? "library 'ldap' is required for LDAP" "$LINENO" 5
1255812574
fi
1255912575

12560-
LDAP_LIBS_FE="-lldap_r $EXTRA_LDAP_LIBS"
12561-
else
1256212576
LDAP_LIBS_FE="-lldap $EXTRA_LDAP_LIBS"
12577+
LDAP_LIBS_BE="-lldap $EXTRA_LDAP_LIBS"
1256312578
fi
1256412579
for ac_func in ldap_initialize
1256512580
do :

configure.in

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,18 +1270,22 @@ fi
12701270
if test "$with_ldap" = yes ; then
12711271
_LIBS="$LIBS"
12721272
if test "$PORTNAME" != "win32"; then
1273-
AC_CHECK_LIB(ldap, ldap_bind, [],
1274-
[AC_MSG_ERROR([library 'ldap' is required for LDAP])],
1275-
[$EXTRA_LDAP_LIBS])
1276-
LDAP_LIBS_BE="-lldap $EXTRA_LDAP_LIBS"
12771273
if test "$enable_thread_safety" = yes; then
1274+
# Use ldap_r for FE if available, else assume ldap is thread-safe.
1275+
# If ldap_r does exist, assume without checking that ldap does too.
12781276
# on some platforms ldap_r fails to link without PTHREAD_LIBS
1279-
AC_CHECK_LIB(ldap_r, ldap_simple_bind, [],
1280-
[AC_MSG_ERROR([library 'ldap_r' is required for LDAP])],
1281-
[$PTHREAD_CFLAGS $PTHREAD_LIBS $EXTRA_LDAP_LIBS])
1282-
LDAP_LIBS_FE="-lldap_r $EXTRA_LDAP_LIBS"
1277+
LIBS=""
1278+
AC_SEARCH_LIBS(ldap_bind, [ldap_r ldap], [],
1279+
[AC_MSG_ERROR([library 'ldap' is required for LDAP])],
1280+
[$PTHREAD_CFLAGS $PTHREAD_LIBS $EXTRA_LDAP_LIBS])
1281+
LDAP_LIBS_FE="$LIBS $EXTRA_LDAP_LIBS"
1282+
LDAP_LIBS_BE="-lldap $EXTRA_LDAP_LIBS"
12831283
else
1284+
AC_CHECK_LIB(ldap, ldap_bind, [],
1285+
[AC_MSG_ERROR([library 'ldap' is required for LDAP])],
1286+
[$EXTRA_LDAP_LIBS])
12841287
LDAP_LIBS_FE="-lldap $EXTRA_LDAP_LIBS"
1288+
LDAP_LIBS_BE="-lldap $EXTRA_LDAP_LIBS"
12851289
fi
12861290
AC_CHECK_FUNCS([ldap_initialize])
12871291
else

src/include/pg_config.h.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,6 @@
347347
/* Define to 1 if you have the `ldap' library (-lldap). */
348348
#undef HAVE_LIBLDAP
349349

350-
/* Define to 1 if you have the `ldap_r' library (-lldap_r). */
351-
#undef HAVE_LIBLDAP_R
352-
353350
/* Define to 1 if you have the `m' library (-lm). */
354351
#undef HAVE_LIBM
355352

0 commit comments

Comments
 (0)