Skip to content

Commit bb37952

Browse files
author
foobar
committed
Fixed the SASL config check.
1 parent f25ff93 commit bb37952

File tree

3 files changed

+76
-5
lines changed

3 files changed

+76
-5
lines changed

ext/ldap/config.m4

+62-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,56 @@ AC_DEFUN(PHP_LDAP_CHECKS, [
1818
fi
1919
])
2020

21+
AC_DEFUN(PHP_LDAP_SASL_CHECKS, [
22+
if test "$1" = "yes"; then
23+
SEARCH_DIRS="/usr/local /usr"
24+
else
25+
SEARCH_DIRS=$1
26+
fi
27+
28+
for i in $SEARCH_DIRS; do
29+
if test -f $i/include/sasl/sasl.h; then
30+
LDAP_SASL_DIR=$i
31+
AC_DEFINE(HAVE_LDAP_SASL_SASL_H,1,[ ])
32+
break
33+
elif test -f $i/include/sasl.h; then
34+
LDAP_SASL_DIR=$i
35+
AC_DEFINE(HAVE_LDAP_SASL_H,1,[ ])
36+
break
37+
fi
38+
done
39+
40+
if test "$LDAP_SASL_DIR"; then
41+
LDAP_SASL_INCDIR=$LDAP_SASL_DIR/include
42+
LDAP_SASL_LIBDIR=$LDAP_SASL_DIR/lib
43+
else
44+
AC_MSG_ERROR([sasl.h not found!])
45+
fi
46+
47+
if test "$PHP_LDAP_SASL" = "yes"; then
48+
SASL_LIB="-lsasl2"
49+
else
50+
SASL_LIB="-L$LDAP_SASL_LIBDIR -lsasl2"
51+
fi
52+
53+
PHP_CHECK_LIBRARY(ldap, sasl_version,
54+
[
55+
PHP_ADD_INCLUDE($LDAP_SASL_INCDIR)
56+
PHP_ADD_LIBRARY_WITH_PATH(sasl2, $LDAP_SASL_LIBDIR, LDAP_SHARED_LIBADD)
57+
AC_DEFINE(HAVE_LDAP_SASL, 1, [LDAP SASL support])
58+
], [
59+
AC_MSG_ERROR([LDAP SASL check failed. Please check config.log for more information.])
60+
], [
61+
$LDAP_SHARED_LIBADD $SASL_LIB
62+
])
63+
])
64+
2165
PHP_ARG_WITH(ldap,for LDAP support,
2266
[ --with-ldap[=DIR] Include LDAP support.])
2367

68+
PHP_ARG_WITH(ldap-sasl,for LDAP Cyrus SASL support,
69+
[ --with-ldap-sasl[=DIR] LDAP: Include Cyrus SASL support.], no, no)
70+
2471
if test "$PHP_LDAP" != "no"; then
2572

2673
PHP_NEW_EXTENSION(ldap, ldap.c, $ext_shared)
@@ -121,5 +168,19 @@ if test "$PHP_LDAP" != "no"; then
121168

122169
dnl Solaris 2.8 claims to be 2004 API, but doesn't have
123170
dnl ldap_parse_reference() nor ldap_start_tls_s()
124-
AC_CHECK_FUNCS([ldap_parse_reference ldap_start_tls_s ldap_sasl_interactive_bind_s])
171+
AC_CHECK_FUNCS([ldap_parse_reference ldap_start_tls_s])
172+
173+
dnl
174+
dnl SASL check
175+
dnl
176+
if test "$PHP_LDAP_SASL" != "no"; then
177+
PHP_LDAP_SASL_CHECKS([$PHP_LDAP_SASL])
178+
fi
179+
180+
dnl
181+
dnl Sanity check
182+
dnl
183+
AC_CHECK_FUNC(ldap_bind_s, [], [
184+
AC_MSG_ERROR([LDAP build check failed. Please check config.log for more information.])
185+
])
125186
fi

ext/ldap/ldap.c

+13-3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@
5959
#include "ext/standard/php_string.h"
6060
#include "ext/standard/info.h"
6161

62+
#ifdef HAVE_LDAP_SASL_H
63+
#include <sasl.h>
64+
#elif defined(HAVE_LDAP_SASL_SASL_H)
65+
#include <sasl/sasl.h>
66+
#endif
67+
6268
typedef struct {
6369
LDAP *link;
6470
#if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC)
@@ -88,7 +94,7 @@ function_entry ldap_functions[] = {
8894
PHP_FE(ldap_connect, NULL)
8995
PHP_FALIAS(ldap_close, ldap_unbind, NULL)
9096
PHP_FE(ldap_bind, NULL)
91-
#ifdef HAVE_LDAP_SASL_INTERACTIVE_BIND_S
97+
#ifdef HAVE_LDAP_SASL
9298
PHP_FE(ldap_sasl_bind, NULL)
9399
#endif
94100
PHP_FE(ldap_unbind, NULL)
@@ -335,6 +341,10 @@ PHP_MINFO_FUNCTION(ldap)
335341
php_info_print_table_row(2, "Level of Encryption", tmp);
336342
#endif
337343

344+
#ifdef HAVE_LDAP_SASL
345+
php_info_print_table_row(2, "SASL Support", "Enabled");
346+
#endif
347+
338348
php_info_print_table_end();
339349
}
340350
/* }}} */
@@ -466,7 +476,7 @@ PHP_FUNCTION(ldap_bind)
466476
}
467477
/* }}} */
468478

469-
#ifdef HAVE_LDAP_SASL_INTERACTIVE_BIND_S
479+
#ifdef HAVE_LDAP_SASL
470480
/* {{{ _php_sasl_interact
471481
Interact function for SASL */
472482
static int _php_sasl_interact(LDAP *ld, unsigned flags, void *defaults, void *in)
@@ -505,7 +515,7 @@ PHP_FUNCTION(ldap_sasl_bind)
505515
}
506516
}
507517
/* }}} */
508-
#endif /* HAVE_LDAP_SASL_INTERACTIVE_BIND_S */
518+
#endif /* HAVE_LDAP_SASL */
509519

510520
/* {{{ proto bool ldap_unbind(resource link)
511521
Unbind from LDAP directory */

ext/ldap/php_ldap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ PHP_MINFO_FUNCTION(ldap);
3838

3939
PHP_FUNCTION(ldap_connect);
4040
PHP_FUNCTION(ldap_bind);
41-
#ifdef HAVE_LDAP_SASL_INTERACTIVE_BIND_S
41+
#ifdef HAVE_LDAP_SASL
4242
PHP_FUNCTION(ldap_sasl_bind);
4343
#endif
4444
PHP_FUNCTION(ldap_unbind);

0 commit comments

Comments
 (0)