Skip to content

Commit 55cccdf

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 6edccac commit 55cccdf

File tree

4 files changed

+64
-49
lines changed

4 files changed

+64
-49
lines changed

configure

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12495,13 +12495,17 @@ fi
1249512495
if test "$with_ldap" = yes ; then
1249612496
_LIBS="$LIBS"
1249712497
if test "$PORTNAME" != "win32"; then
12498-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ldap_bind in -lldap" >&5
12499-
$as_echo_n "checking for ldap_bind in -lldap... " >&6; }
12500-
if ${ac_cv_lib_ldap_ldap_bind+:} false; then :
12498+
if test "$enable_thread_safety" = yes; then
12499+
# Use ldap_r for FE if available, else assume ldap is thread-safe.
12500+
# If ldap_r does exist, assume without checking that ldap does too.
12501+
# on some platforms ldap_r fails to link without PTHREAD_LIBS
12502+
LIBS=""
12503+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing ldap_bind" >&5
12504+
$as_echo_n "checking for library containing ldap_bind... " >&6; }
12505+
if ${ac_cv_search_ldap_bind+:} false; then :
1250112506
$as_echo_n "(cached) " >&6
1250212507
else
12503-
ac_check_lib_save_LIBS=$LIBS
12504-
LIBS="-lldap $EXTRA_LDAP_LIBS $LIBS"
12508+
ac_func_search_save_LIBS=$LIBS
1250512509
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1250612510
/* end confdefs.h. */
1250712511

@@ -12520,38 +12524,50 @@ return ldap_bind ();
1252012524
return 0;
1252112525
}
1252212526
_ACEOF
12523-
if ac_fn_c_try_link "$LINENO"; then :
12524-
ac_cv_lib_ldap_ldap_bind=yes
12525-
else
12526-
ac_cv_lib_ldap_ldap_bind=no
12527+
for ac_lib in '' ldap_r ldap; do
12528+
if test -z "$ac_lib"; then
12529+
ac_res="none required"
12530+
else
12531+
ac_res=-l$ac_lib
12532+
LIBS="-l$ac_lib $PTHREAD_CFLAGS $PTHREAD_LIBS $EXTRA_LDAP_LIBS $ac_func_search_save_LIBS"
12533+
fi
12534+
if ac_fn_c_try_link "$LINENO"; then :
12535+
ac_cv_search_ldap_bind=$ac_res
1252712536
fi
1252812537
rm -f core conftest.err conftest.$ac_objext \
12529-
conftest$ac_exeext conftest.$ac_ext
12530-
LIBS=$ac_check_lib_save_LIBS
12538+
conftest$ac_exeext
12539+
if ${ac_cv_search_ldap_bind+:} false; then :
12540+
break
1253112541
fi
12532-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ldap_ldap_bind" >&5
12533-
$as_echo "$ac_cv_lib_ldap_ldap_bind" >&6; }
12534-
if test "x$ac_cv_lib_ldap_ldap_bind" = xyes; then :
12535-
cat >>confdefs.h <<_ACEOF
12536-
#define HAVE_LIBLDAP 1
12537-
_ACEOF
12542+
done
12543+
if ${ac_cv_search_ldap_bind+:} false; then :
1253812544

12539-
LIBS="-lldap $LIBS"
12545+
else
12546+
ac_cv_search_ldap_bind=no
12547+
fi
12548+
rm conftest.$ac_ext
12549+
LIBS=$ac_func_search_save_LIBS
12550+
fi
12551+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_ldap_bind" >&5
12552+
$as_echo "$ac_cv_search_ldap_bind" >&6; }
12553+
ac_res=$ac_cv_search_ldap_bind
12554+
if test "$ac_res" != no; then :
12555+
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
1254012556

1254112557
else
1254212558
as_fn_error $? "library 'ldap' is required for LDAP" "$LINENO" 5
1254312559
fi
1254412560

12545-
LDAP_LIBS_BE="-lldap $EXTRA_LDAP_LIBS"
12546-
if test "$enable_thread_safety" = yes; then
12547-
# on some platforms ldap_r fails to link without PTHREAD_LIBS
12548-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ldap_simple_bind in -lldap_r" >&5
12549-
$as_echo_n "checking for ldap_simple_bind in -lldap_r... " >&6; }
12550-
if ${ac_cv_lib_ldap_r_ldap_simple_bind+:} false; then :
12561+
LDAP_LIBS_FE="$LIBS $EXTRA_LDAP_LIBS"
12562+
LDAP_LIBS_BE="-lldap $EXTRA_LDAP_LIBS"
12563+
else
12564+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ldap_bind in -lldap" >&5
12565+
$as_echo_n "checking for ldap_bind in -lldap... " >&6; }
12566+
if ${ac_cv_lib_ldap_ldap_bind+:} false; then :
1255112567
$as_echo_n "(cached) " >&6
1255212568
else
1255312569
ac_check_lib_save_LIBS=$LIBS
12554-
LIBS="-lldap_r $PTHREAD_CFLAGS $PTHREAD_LIBS $EXTRA_LDAP_LIBS $LIBS"
12570+
LIBS="-lldap $EXTRA_LDAP_LIBS $LIBS"
1255512571
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1255612572
/* end confdefs.h. */
1255712573

@@ -12561,40 +12577,39 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1256112577
#ifdef __cplusplus
1256212578
extern "C"
1256312579
#endif
12564-
char ldap_simple_bind ();
12580+
char ldap_bind ();
1256512581
int
1256612582
main ()
1256712583
{
12568-
return ldap_simple_bind ();
12584+
return ldap_bind ();
1256912585
;
1257012586
return 0;
1257112587
}
1257212588
_ACEOF
1257312589
if ac_fn_c_try_link "$LINENO"; then :
12574-
ac_cv_lib_ldap_r_ldap_simple_bind=yes
12590+
ac_cv_lib_ldap_ldap_bind=yes
1257512591
else
12576-
ac_cv_lib_ldap_r_ldap_simple_bind=no
12592+
ac_cv_lib_ldap_ldap_bind=no
1257712593
fi
1257812594
rm -f core conftest.err conftest.$ac_objext \
1257912595
conftest$ac_exeext conftest.$ac_ext
1258012596
LIBS=$ac_check_lib_save_LIBS
1258112597
fi
12582-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ldap_r_ldap_simple_bind" >&5
12583-
$as_echo "$ac_cv_lib_ldap_r_ldap_simple_bind" >&6; }
12584-
if test "x$ac_cv_lib_ldap_r_ldap_simple_bind" = xyes; then :
12598+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ldap_ldap_bind" >&5
12599+
$as_echo "$ac_cv_lib_ldap_ldap_bind" >&6; }
12600+
if test "x$ac_cv_lib_ldap_ldap_bind" = xyes; then :
1258512601
cat >>confdefs.h <<_ACEOF
12586-
#define HAVE_LIBLDAP_R 1
12602+
#define HAVE_LIBLDAP 1
1258712603
_ACEOF
1258812604

12589-
LIBS="-lldap_r $LIBS"
12605+
LIBS="-lldap $LIBS"
1259012606

1259112607
else
12592-
as_fn_error $? "library 'ldap_r' is required for LDAP" "$LINENO" 5
12608+
as_fn_error $? "library 'ldap' is required for LDAP" "$LINENO" 5
1259312609
fi
1259412610

12595-
LDAP_LIBS_FE="-lldap_r $EXTRA_LDAP_LIBS"
12596-
else
1259712611
LDAP_LIBS_FE="-lldap $EXTRA_LDAP_LIBS"
12612+
LDAP_LIBS_BE="-lldap $EXTRA_LDAP_LIBS"
1259812613
fi
1259912614
for ac_func in ldap_initialize
1260012615
do :

configure.in

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,18 +1241,22 @@ fi
12411241
if test "$with_ldap" = yes ; then
12421242
_LIBS="$LIBS"
12431243
if test "$PORTNAME" != "win32"; then
1244-
AC_CHECK_LIB(ldap, ldap_bind, [],
1245-
[AC_MSG_ERROR([library 'ldap' is required for LDAP])],
1246-
[$EXTRA_LDAP_LIBS])
1247-
LDAP_LIBS_BE="-lldap $EXTRA_LDAP_LIBS"
12481244
if test "$enable_thread_safety" = yes; then
1245+
# Use ldap_r for FE if available, else assume ldap is thread-safe.
1246+
# If ldap_r does exist, assume without checking that ldap does too.
12491247
# on some platforms ldap_r fails to link without PTHREAD_LIBS
1250-
AC_CHECK_LIB(ldap_r, ldap_simple_bind, [],
1251-
[AC_MSG_ERROR([library 'ldap_r' is required for LDAP])],
1252-
[$PTHREAD_CFLAGS $PTHREAD_LIBS $EXTRA_LDAP_LIBS])
1253-
LDAP_LIBS_FE="-lldap_r $EXTRA_LDAP_LIBS"
1248+
LIBS=""
1249+
AC_SEARCH_LIBS(ldap_bind, [ldap_r ldap], [],
1250+
[AC_MSG_ERROR([library 'ldap' is required for LDAP])],
1251+
[$PTHREAD_CFLAGS $PTHREAD_LIBS $EXTRA_LDAP_LIBS])
1252+
LDAP_LIBS_FE="$LIBS $EXTRA_LDAP_LIBS"
1253+
LDAP_LIBS_BE="-lldap $EXTRA_LDAP_LIBS"
12541254
else
1255+
AC_CHECK_LIB(ldap, ldap_bind, [],
1256+
[AC_MSG_ERROR([library 'ldap' is required for LDAP])],
1257+
[$EXTRA_LDAP_LIBS])
12551258
LDAP_LIBS_FE="-lldap $EXTRA_LDAP_LIBS"
1259+
LDAP_LIBS_BE="-lldap $EXTRA_LDAP_LIBS"
12561260
fi
12571261
AC_CHECK_FUNCS([ldap_initialize])
12581262
else

src/include/pg_config.h.in

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

319-
/* Define to 1 if you have the `ldap_r' library (-lldap_r). */
320-
#undef HAVE_LIBLDAP_R
321-
322319
/* Define to 1 if you have the `m' library (-lm). */
323320
#undef HAVE_LIBM
324321

src/tools/msvc/Solution.pm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ sub GenerateFiles
290290
HAVE_LDAP_INITIALIZE => undef,
291291
HAVE_LIBCRYPTO => undef,
292292
HAVE_LIBLDAP => undef,
293-
HAVE_LIBLDAP_R => undef,
294293
HAVE_LIBM => undef,
295294
HAVE_LIBPAM => undef,
296295
HAVE_LIBREADLINE => undef,

0 commit comments

Comments
 (0)