1AC_DEFUN([PHP_LDAP_CHECKS], [
2  if test -f $1/include/ldap.h; then
3    LDAP_DIR=$1
4    LDAP_INCDIR=$1/include
5    LDAP_LIBDIR=$1/$PHP_LIBDIR
6  elif test -f $1/ldap/public/ldap.h; then
7    LDAP_DIR=$1
8    LDAP_INCDIR=$1/ldap/public
9    LDAP_LIBDIR=$1/$PHP_LIBDIR
10  else
11
12    dnl Find Oracle Instant Client RPM header location corresponding to the
13    dnl given lib path e.g. for --with-ldap=/usr/lib/oracle/12.1/client64/lib
14    AC_CHECK_SIZEOF([long])
15    AC_MSG_CHECKING([if we're at 64-bit platform])
16    AS_IF([test "$ac_cv_sizeof_long" -eq 4],[
17      AC_MSG_RESULT([no])
18      PHP_OCI8_IC_LIBDIR_SUFFIX=""
19    ],[
20      AC_MSG_RESULT([yes])
21      PHP_OCI8_IC_LIBDIR_SUFFIX=64
22    ])
23
24    OCISDKRPMINC=`echo "$1" | $SED -e 's!^/usr/lib/oracle/\(.*\)/client\('${PHP_OCI8_IC_LIBDIR_SUFFIX}'\)*/lib[/]*$!/usr/include/oracle/\1/client\2!'`
25
26    dnl Check for Oracle Instant Client RPM install
27    if test -f $OCISDKRPMINC/ldap.h; then
28      LDAP_DIR=$1
29      LDAP_INCDIR=$OCISDKRPMINC
30      LDAP_LIBDIR=$1
31    dnl Check for Oracle Instant Client ZIP install
32    elif test -f $1/sdk/include/ldap.h; then
33      LDAP_DIR=$1
34      LDAP_INCDIR=$1/sdk/include
35      LDAP_LIBDIR=$1
36    fi
37  fi
38])
39
40PHP_ARG_WITH([ldap],
41  [for LDAP support],
42  [AS_HELP_STRING([[--with-ldap[=DIR]]],
43    [Include LDAP support])])
44
45PHP_ARG_WITH([ldap-sasl],
46  [whether to build with LDAP Cyrus SASL support],
47  [AS_HELP_STRING([--with-ldap-sasl],
48    [LDAP: Build with Cyrus SASL support])],
49  [no],
50  [no])
51
52if test "$PHP_LDAP" != "no"; then
53
54  PHP_NEW_EXTENSION(ldap, ldap.c, $ext_shared,,-DLDAP_DEPRECATED=1 -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
55
56  if test "$PHP_LDAP" = "yes"; then
57    for i in /usr/local /usr; do
58      PHP_LDAP_CHECKS($i)
59    done
60  else
61    PHP_LDAP_CHECKS($PHP_LDAP)
62  fi
63
64  if test -z "$LDAP_DIR"; then
65    AC_MSG_ERROR(Cannot find ldap.h)
66  fi
67
68  dnl -pc removal is a hack for clang
69  MACHINE_INCLUDES=$($CC -dumpmachine | $SED 's/-pc//')
70
71  if test -f $LDAP_LIBDIR/liblber.a || test -f $LDAP_LIBDIR/liblber.$SHLIB_SUFFIX_NAME || test -f $LDAP_LIBDIR/$MACHINE_INCLUDES/liblber.a || test -f $LDAP_LIBDIR/$MACHINE_INCLUDES/liblber.$SHLIB_SUFFIX_NAME; then
72    PHP_ADD_LIBRARY_WITH_PATH(lber, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
73    PHP_ADD_LIBRARY_WITH_PATH(ldap, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
74
75  elif test -f $LDAP_LIBDIR/libldap.$SHLIB_SUFFIX_NAME || test -f $LDAP_LIBDIR/libldap.$SHLIB_SUFFIX_NAME.3 || test -f $LDAP_LIBDIR/$MACHINE_INCLUDES/libldap.$SHLIB_SUFFIX_NAME || test -f $LDAP_LIBDIR/$MACHINE_INCLUDES/libldap.$SHLIB_SUFFIX_NAME.3 || test -f $LDAP_LIBDIR/libldap.3.dylib; then
76    PHP_ADD_LIBRARY_WITH_PATH(ldap, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
77
78  elif test -f $LDAP_LIBDIR/libclntsh.$SHLIB_SUFFIX_NAME.12.1 || test -f $LDAP_LIBDIR/$MACHINE_INCLUDES/libclntsh.$SHLIB_SUFFIX_NAME.12.1; then
79    PHP_ADD_LIBRARY_WITH_PATH(clntsh, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
80    AC_DEFINE(HAVE_ORALDAP,1,[ ])
81
82  elif test -f $LDAP_LIBDIR/libclntsh.$SHLIB_SUFFIX_NAME.11.1 || test -f $LDAP_LIBDIR/$MACHINE_INCLUDES/libclntsh.$SHLIB_SUFFIX_NAME.11.1; then
83    PHP_ADD_LIBRARY_WITH_PATH(clntsh, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
84    AC_DEFINE(HAVE_ORALDAP,1,[ ])
85
86  elif test -f $LDAP_LIBDIR/libclntsh.$SHLIB_SUFFIX_NAME || test -f $LDAP_LIBDIR/$MACHINE_INCLUDES/libclntsh.$SHLIB_SUFFIX_NAME; then
87     PHP_ADD_LIBRARY_WITH_PATH(clntsh, $LDAP_LIBDIR, LDAP_SHARED_LIBADD)
88     AC_DEFINE(HAVE_ORALDAP,1,[ ])
89
90  else
91    AC_MSG_ERROR(Cannot find ldap libraries in $LDAP_LIBDIR.)
92  fi
93
94  PHP_ADD_INCLUDE($LDAP_INCDIR)
95  PHP_SUBST(LDAP_SHARED_LIBADD)
96  AC_DEFINE(HAVE_LDAP,1,[ ])
97
98  dnl Save original values
99  _SAVE_CPPFLAGS=$CPPFLAGS
100  _SAVE_LIBS=$LIBS
101  CPPFLAGS="$CPPFLAGS -I$LDAP_INCDIR"
102  LIBS="$LIBS $LDAP_SHARED_LIBADD"
103
104  dnl Check for 3 arg ldap_set_rebind_proc
105  AC_CACHE_CHECK([for 3 arg ldap_set_rebind_proc], ac_cv_3arg_setrebindproc,
106  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <ldap.h>]], [[ldap_set_rebind_proc(0,0,0)]])],
107  [ac_cv_3arg_setrebindproc=yes], [ac_cv_3arg_setrebindproc=no])])
108  if test "$ac_cv_3arg_setrebindproc" = yes; then
109    AC_DEFINE(HAVE_3ARG_SETREBINDPROC,1,[Whether 3 arg set_rebind_proc()])
110  fi
111
112  dnl Solaris 2.8 claims to be 2004 API, but doesn't have ldap_parse_reference()
113  dnl nor ldap_start_tls_s()
114  AC_CHECK_FUNCS([ldap_parse_result ldap_parse_reference ldap_start_tls_s ldap_control_find ldap_parse_extended_result ldap_extended_operation ldap_extended_operation_s ldap_passwd ldap_whoami_s ldap_refresh_s])
115
116  dnl SASL check
117  if test "$PHP_LDAP_SASL" != "no"; then
118    PKG_CHECK_MODULES([SASL], [libsasl2])
119
120    PHP_EVAL_INCLINE($SASL_CFLAGS)
121    PHP_EVAL_LIBLINE($SASL_LIBS, LDAP_SHARED_LIBADD)
122
123    AC_DEFINE(HAVE_LDAP_SASL, 1, [LDAP SASL support])
124  fi
125
126  dnl Sanity check
127  AC_CHECK_FUNC(ldap_bind_s, [], [
128    AC_MSG_ERROR([LDAP build check failed. Please check config.log for more information.])
129  ])
130
131  dnl Restore original values
132  CPPFLAGS=$_SAVE_CPPFLAGS
133  LIBS=$_SAVE_LIBS
134fi
135