Skip to content

Commit b69e8ad

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 158594f commit b69e8ad

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
@@ -12118,13 +12118,17 @@ fi
1211812118
if test "$with_ldap" = yes ; then
1211912119
_LIBS="$LIBS"
1212012120
if test "$PORTNAME" != "win32"; then
12121-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ldap_bind in -lldap" >&5
12122-
$as_echo_n "checking for ldap_bind in -lldap... " >&6; }
12123-
if ${ac_cv_lib_ldap_ldap_bind+:} false; then :
12121+
if test "$enable_thread_safety" = yes; then
12122+
# Use ldap_r for FE if available, else assume ldap is thread-safe.
12123+
# If ldap_r does exist, assume without checking that ldap does too.
12124+
# on some platforms ldap_r fails to link without PTHREAD_LIBS
12125+
LIBS=""
12126+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing ldap_bind" >&5
12127+
$as_echo_n "checking for library containing ldap_bind... " >&6; }
12128+
if ${ac_cv_search_ldap_bind+:} false; then :
1212412129
$as_echo_n "(cached) " >&6
1212512130
else
12126-
ac_check_lib_save_LIBS=$LIBS
12127-
LIBS="-lldap $EXTRA_LDAP_LIBS $LIBS"
12131+
ac_func_search_save_LIBS=$LIBS
1212812132
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1212912133
/* end confdefs.h. */
1213012134

@@ -12143,38 +12147,50 @@ return ldap_bind ();
1214312147
return 0;
1214412148
}
1214512149
_ACEOF
12146-
if ac_fn_c_try_link "$LINENO"; then :
12147-
ac_cv_lib_ldap_ldap_bind=yes
12148-
else
12149-
ac_cv_lib_ldap_ldap_bind=no
12150+
for ac_lib in '' ldap_r ldap; do
12151+
if test -z "$ac_lib"; then
12152+
ac_res="none required"
12153+
else
12154+
ac_res=-l$ac_lib
12155+
LIBS="-l$ac_lib $PTHREAD_CFLAGS $PTHREAD_LIBS $EXTRA_LDAP_LIBS $ac_func_search_save_LIBS"
12156+
fi
12157+
if ac_fn_c_try_link "$LINENO"; then :
12158+
ac_cv_search_ldap_bind=$ac_res
1215012159
fi
1215112160
rm -f core conftest.err conftest.$ac_objext \
12152-
conftest$ac_exeext conftest.$ac_ext
12153-
LIBS=$ac_check_lib_save_LIBS
12161+
conftest$ac_exeext
12162+
if ${ac_cv_search_ldap_bind+:} false; then :
12163+
break
1215412164
fi
12155-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ldap_ldap_bind" >&5
12156-
$as_echo "$ac_cv_lib_ldap_ldap_bind" >&6; }
12157-
if test "x$ac_cv_lib_ldap_ldap_bind" = xyes; then :
12158-
cat >>confdefs.h <<_ACEOF
12159-
#define HAVE_LIBLDAP 1
12160-
_ACEOF
12165+
done
12166+
if ${ac_cv_search_ldap_bind+:} false; then :
1216112167

12162-
LIBS="-lldap $LIBS"
12168+
else
12169+
ac_cv_search_ldap_bind=no
12170+
fi
12171+
rm conftest.$ac_ext
12172+
LIBS=$ac_func_search_save_LIBS
12173+
fi
12174+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_ldap_bind" >&5
12175+
$as_echo "$ac_cv_search_ldap_bind" >&6; }
12176+
ac_res=$ac_cv_search_ldap_bind
12177+
if test "$ac_res" != no; then :
12178+
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
1216312179

1216412180
else
1216512181
as_fn_error $? "library 'ldap' is required for LDAP" "$LINENO" 5
1216612182
fi
1216712183

12168-
LDAP_LIBS_BE="-lldap $EXTRA_LDAP_LIBS"
12169-
if test "$enable_thread_safety" = yes; then
12170-
# on some platforms ldap_r fails to link without PTHREAD_LIBS
12171-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ldap_simple_bind in -lldap_r" >&5
12172-
$as_echo_n "checking for ldap_simple_bind in -lldap_r... " >&6; }
12173-
if ${ac_cv_lib_ldap_r_ldap_simple_bind+:} false; then :
12184+
LDAP_LIBS_FE="$LIBS $EXTRA_LDAP_LIBS"
12185+
LDAP_LIBS_BE="-lldap $EXTRA_LDAP_LIBS"
12186+
else
12187+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ldap_bind in -lldap" >&5
12188+
$as_echo_n "checking for ldap_bind in -lldap... " >&6; }
12189+
if ${ac_cv_lib_ldap_ldap_bind+:} false; then :
1217412190
$as_echo_n "(cached) " >&6
1217512191
else
1217612192
ac_check_lib_save_LIBS=$LIBS
12177-
LIBS="-lldap_r $PTHREAD_CFLAGS $PTHREAD_LIBS $EXTRA_LDAP_LIBS $LIBS"
12193+
LIBS="-lldap $EXTRA_LDAP_LIBS $LIBS"
1217812194
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1217912195
/* end confdefs.h. */
1218012196

@@ -12184,40 +12200,39 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1218412200
#ifdef __cplusplus
1218512201
extern "C"
1218612202
#endif
12187-
char ldap_simple_bind ();
12203+
char ldap_bind ();
1218812204
int
1218912205
main ()
1219012206
{
12191-
return ldap_simple_bind ();
12207+
return ldap_bind ();
1219212208
;
1219312209
return 0;
1219412210
}
1219512211
_ACEOF
1219612212
if ac_fn_c_try_link "$LINENO"; then :
12197-
ac_cv_lib_ldap_r_ldap_simple_bind=yes
12213+
ac_cv_lib_ldap_ldap_bind=yes
1219812214
else
12199-
ac_cv_lib_ldap_r_ldap_simple_bind=no
12215+
ac_cv_lib_ldap_ldap_bind=no
1220012216
fi
1220112217
rm -f core conftest.err conftest.$ac_objext \
1220212218
conftest$ac_exeext conftest.$ac_ext
1220312219
LIBS=$ac_check_lib_save_LIBS
1220412220
fi
12205-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ldap_r_ldap_simple_bind" >&5
12206-
$as_echo "$ac_cv_lib_ldap_r_ldap_simple_bind" >&6; }
12207-
if test "x$ac_cv_lib_ldap_r_ldap_simple_bind" = xyes; then :
12221+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ldap_ldap_bind" >&5
12222+
$as_echo "$ac_cv_lib_ldap_ldap_bind" >&6; }
12223+
if test "x$ac_cv_lib_ldap_ldap_bind" = xyes; then :
1220812224
cat >>confdefs.h <<_ACEOF
12209-
#define HAVE_LIBLDAP_R 1
12225+
#define HAVE_LIBLDAP 1
1221012226
_ACEOF
1221112227

12212-
LIBS="-lldap_r $LIBS"
12228+
LIBS="-lldap $LIBS"
1221312229

1221412230
else
12215-
as_fn_error $? "library 'ldap_r' is required for LDAP" "$LINENO" 5
12231+
as_fn_error $? "library 'ldap' is required for LDAP" "$LINENO" 5
1221612232
fi
1221712233

12218-
LDAP_LIBS_FE="-lldap_r $EXTRA_LDAP_LIBS"
12219-
else
1222012234
LDAP_LIBS_FE="-lldap $EXTRA_LDAP_LIBS"
12235+
LDAP_LIBS_BE="-lldap $EXTRA_LDAP_LIBS"
1222112236
fi
1222212237
for ac_func in ldap_initialize
1222312238
do :

configure.in

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,18 +1265,22 @@ fi
12651265
if test "$with_ldap" = yes ; then
12661266
_LIBS="$LIBS"
12671267
if test "$PORTNAME" != "win32"; then
1268-
AC_CHECK_LIB(ldap, ldap_bind, [],
1269-
[AC_MSG_ERROR([library 'ldap' is required for LDAP])],
1270-
[$EXTRA_LDAP_LIBS])
1271-
LDAP_LIBS_BE="-lldap $EXTRA_LDAP_LIBS"
12721268
if test "$enable_thread_safety" = yes; then
1269+
# Use ldap_r for FE if available, else assume ldap is thread-safe.
1270+
# If ldap_r does exist, assume without checking that ldap does too.
12731271
# on some platforms ldap_r fails to link without PTHREAD_LIBS
1274-
AC_CHECK_LIB(ldap_r, ldap_simple_bind, [],
1275-
[AC_MSG_ERROR([library 'ldap_r' is required for LDAP])],
1276-
[$PTHREAD_CFLAGS $PTHREAD_LIBS $EXTRA_LDAP_LIBS])
1277-
LDAP_LIBS_FE="-lldap_r $EXTRA_LDAP_LIBS"
1272+
LIBS=""
1273+
AC_SEARCH_LIBS(ldap_bind, [ldap_r ldap], [],
1274+
[AC_MSG_ERROR([library 'ldap' is required for LDAP])],
1275+
[$PTHREAD_CFLAGS $PTHREAD_LIBS $EXTRA_LDAP_LIBS])
1276+
LDAP_LIBS_FE="$LIBS $EXTRA_LDAP_LIBS"
1277+
LDAP_LIBS_BE="-lldap $EXTRA_LDAP_LIBS"
12781278
else
1279+
AC_CHECK_LIB(ldap, ldap_bind, [],
1280+
[AC_MSG_ERROR([library 'ldap' is required for LDAP])],
1281+
[$EXTRA_LDAP_LIBS])
12791282
LDAP_LIBS_FE="-lldap $EXTRA_LDAP_LIBS"
1283+
LDAP_LIBS_BE="-lldap $EXTRA_LDAP_LIBS"
12801284
fi
12811285
AC_CHECK_FUNCS([ldap_initialize])
12821286
else

src/include/pg_config.h.in

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

347-
/* Define to 1 if you have the `ldap_r' library (-lldap_r). */
348-
#undef HAVE_LIBLDAP_R
349-
350347
/* Define to 1 if you have the `m' library (-lm). */
351348
#undef HAVE_LIBM
352349

0 commit comments

Comments
 (0)