[PHP-CVS] cvs: php4 /ext/ldap config.m4 ldap.c php_ldap.h

2003-06-13 Thread Jani Taskinen
sniper  Fri Jun 13 09:30:46 2003 EDT

  Modified files:  
/php4/ext/ldap  config.m4 ldap.c php_ldap.h 
  Log:
  Fixed the SASL config check.
  
Index: php4/ext/ldap/config.m4
diff -u php4/ext/ldap/config.m4:1.32 php4/ext/ldap/config.m4:1.33
--- php4/ext/ldap/config.m4:1.32Sun Jun  8 19:44:01 2003
+++ php4/ext/ldap/config.m4 Fri Jun 13 09:30:46 2003
@@ -1,5 +1,5 @@
 dnl
-dnl $Id: config.m4,v 1.32 2003/06/08 23:44:01 sniper Exp $
+dnl $Id: config.m4,v 1.33 2003/06/13 13:30:46 sniper Exp $
 dnl
 
 AC_DEFUN(PHP_LDAP_CHECKS, [
@@ -18,9 +18,56 @@
   fi
 ])
 
+AC_DEFUN(PHP_LDAP_SASL_CHECKS, [
+  if test $1 = yes; then
+SEARCH_DIRS=/usr/local /usr
+  else
+SEARCH_DIRS=$1
+  fi
+
+  for i in $SEARCH_DIRS; do
+if test -f $i/include/sasl/sasl.h; then
+  LDAP_SASL_DIR=$i
+  AC_DEFINE(HAVE_LDAP_SASL_SASL_H,1,[ ])
+  break
+elif test -f $i/include/sasl.h; then
+  LDAP_SASL_DIR=$i
+  AC_DEFINE(HAVE_LDAP_SASL_H,1,[ ])
+  break
+fi
+  done
+  
+  if test $LDAP_SASL_DIR; then
+LDAP_SASL_INCDIR=$LDAP_SASL_DIR/include
+LDAP_SASL_LIBDIR=$LDAP_SASL_DIR/lib
+  else
+AC_MSG_ERROR([sasl.h not found!])
+  fi
+
+  if test $PHP_LDAP_SASL = yes; then
+SASL_LIB=-lsasl2
+  else
+SASL_LIB=-L$LDAP_SASL_LIBDIR -lsasl2
+  fi
+  
+  PHP_CHECK_LIBRARY(ldap, sasl_version,
+  [
+PHP_ADD_INCLUDE($LDAP_SASL_INCDIR)
+PHP_ADD_LIBRARY_WITH_PATH(sasl2, $LDAP_SASL_LIBDIR, LDAP_SHARED_LIBADD)
+AC_DEFINE(HAVE_LDAP_SASL, 1, [LDAP SASL support])
+  ], [
+AC_MSG_ERROR([LDAP SASL check failed. Please check config.log for more 
information.])
+  ], [
+$LDAP_SHARED_LIBADD $SASL_LIB
+  ])
+])
+
 PHP_ARG_WITH(ldap,for LDAP support,
 [  --with-ldap[=DIR]   Include LDAP support.])
 
+PHP_ARG_WITH(ldap-sasl,for LDAP Cyrus SASL support,
+[  --with-ldap-sasl[=DIR]LDAP: Include Cyrus SASL support.], no, no)
+
 if test $PHP_LDAP != no; then
 
   PHP_NEW_EXTENSION(ldap, ldap.c, $ext_shared)
@@ -121,5 +168,19 @@
 
   dnl Solaris 2.8 claims to be 2004 API, but doesn't have
   dnl ldap_parse_reference() nor ldap_start_tls_s()
-  AC_CHECK_FUNCS([ldap_parse_reference ldap_start_tls_s ldap_sasl_interactive_bind_s])
+  AC_CHECK_FUNCS([ldap_parse_reference ldap_start_tls_s])
+
+  dnl
+  dnl SASL check
+  dnl
+  if test $PHP_LDAP_SASL != no; then
+PHP_LDAP_SASL_CHECKS([$PHP_LDAP_SASL])
+  fi
+
+  dnl
+  dnl Sanity check
+  dnl 
+  AC_CHECK_FUNC(ldap_bind_s, [], [
+AC_MSG_ERROR([LDAP build check failed. Please check config.log for more 
information.]) 
+  ])
 fi 
Index: php4/ext/ldap/ldap.c
diff -u php4/ext/ldap/ldap.c:1.141 php4/ext/ldap/ldap.c:1.142
--- php4/ext/ldap/ldap.c:1.141  Tue Jun 10 16:03:31 2003
+++ php4/ext/ldap/ldap.cFri Jun 13 09:30:46 2003
@@ -22,7 +22,7 @@
+--+
  */
  
-/* $Id: ldap.c,v 1.141 2003/06/10 20:03:31 imajes Exp $ */
+/* $Id: ldap.c,v 1.142 2003/06/13 13:30:46 sniper Exp $ */
 #define IS_EXT_MODULE
 
 #ifdef HAVE_CONFIG_H
@@ -59,6 +59,12 @@
 #include ext/standard/php_string.h
 #include ext/standard/info.h
 
+#ifdef HAVE_LDAP_SASL_H
+#include sasl.h
+#elif defined(HAVE_LDAP_SASL_SASL_H)
+#include sasl/sasl.h
+#endif
+
 typedef struct {
LDAP *link;
 #if defined(LDAP_API_FEATURE_X_OPENLDAP)  defined(HAVE_3ARG_SETREBINDPROC)
@@ -88,7 +94,7 @@
PHP_FE(ldap_connect,   
 NULL)
PHP_FALIAS(ldap_close,  ldap_unbind,NULL)
PHP_FE(ldap_bind,  
 NULL)
-#ifdef HAVE_LDAP_SASL_INTERACTIVE_BIND_S
+#ifdef HAVE_LDAP_SASL
PHP_FE(ldap_sasl_bind, 
 NULL)
 #endif
PHP_FE(ldap_unbind,
 NULL)
@@ -286,7 +292,7 @@
 
php_info_print_table_start();
php_info_print_table_row(2, LDAP Support, enabled);
-   php_info_print_table_row(2, RCS Version, $Id: ldap.c,v 1.141 2003/06/10 
20:03:31 imajes Exp $);
+   php_info_print_table_row(2, RCS Version, $Id: ldap.c,v 1.142 2003/06/13 
13:30:46 sniper Exp $);
 
if (LDAPG(max_links) == -1) {
snprintf(tmp, 31, %ld/unlimited, LDAPG(num_links));
@@ -335,6 +341,10 @@
php_info_print_table_row(2, Level of Encryption, tmp);
 #endif
 
+#ifdef HAVE_LDAP_SASL
+   php_info_print_table_row(2, SASL Support, Enabled);
+#endif
+
php_info_print_table_end();
 }
 /* }}} */
@@ -466,7 +476,7 @@
 }
 /* }}} */
 
-#ifdef HAVE_LDAP_SASL_INTERACTIVE_BIND_S
+#ifdef HAVE_LDAP_SASL
 /* {{{ _php_sasl_interact
Interact function for SASL */
 static int _php_sasl_interact(LDAP *ld, unsigned flags, void *defaults, void *in)
@@ -505,7 +515,7 @@
}
 }
 /* }}} */
-#endif /* HAVE_LDAP_SASL_INTERACTIVE_BIND_S */
+#endif /* HAVE_LDAP_SASL */
 
 /* {{{ proto bool 

[PHP-CVS] cvs: php4 /ext/ldap config.m4 ldap.c php_ldap.h

2003-06-08 Thread Jani Taskinen
sniper  Sun Jun  8 19:44:01 2003 EDT

  Modified files:  
/php4/ext/ldap  config.m4 ldap.c php_ldap.h 
  Log:
  - Added ldap_sasl_bind(). (Jani, [EMAIL PROTECTED])
  
Index: php4/ext/ldap/config.m4
diff -u php4/ext/ldap/config.m4:1.31 php4/ext/ldap/config.m4:1.32
--- php4/ext/ldap/config.m4:1.31Sun Mar  2 13:52:29 2003
+++ php4/ext/ldap/config.m4 Sun Jun  8 19:44:01 2003
@@ -1,5 +1,5 @@
 dnl
-dnl $Id: config.m4,v 1.31 2003/03/02 18:52:29 sniper Exp $
+dnl $Id: config.m4,v 1.32 2003/06/08 23:44:01 sniper Exp $
 dnl
 
 AC_DEFUN(PHP_LDAP_CHECKS, [
@@ -121,5 +121,5 @@
 
   dnl Solaris 2.8 claims to be 2004 API, but doesn't have
   dnl ldap_parse_reference() nor ldap_start_tls_s()
-  AC_CHECK_FUNCS([ldap_parse_reference ldap_start_tls_s])
+  AC_CHECK_FUNCS([ldap_parse_reference ldap_start_tls_s ldap_sasl_interactive_bind_s])
 fi 
Index: php4/ext/ldap/ldap.c
diff -u php4/ext/ldap/ldap.c:1.139 php4/ext/ldap/ldap.c:1.140
--- php4/ext/ldap/ldap.c:1.139  Sun Jun  8 19:34:51 2003
+++ php4/ext/ldap/ldap.cSun Jun  8 19:44:01 2003
@@ -22,7 +22,7 @@
+--+
  */
  
-/* $Id: ldap.c,v 1.139 2003/06/08 23:34:51 sniper Exp $ */
+/* $Id: ldap.c,v 1.140 2003/06/08 23:44:01 sniper Exp $ */
 #define IS_EXT_MODULE
 
 #ifdef HAVE_CONFIG_H
@@ -88,6 +88,9 @@
PHP_FE(ldap_connect,   
 NULL)
PHP_FALIAS(ldap_close,  ldap_unbind,NULL)
PHP_FE(ldap_bind,  
 NULL)
+#ifdef HAVE_LDAP_SASL_INTERACTIVE_BIND_S
+   PHP_FE(ldap_sasl_bind, 
 NULL)
+#endif
PHP_FE(ldap_unbind,
 NULL)
PHP_FE(ldap_read,  
 NULL)
PHP_FE(ldap_list,  
 NULL)
@@ -283,7 +286,7 @@
 
php_info_print_table_start();
php_info_print_table_row(2, LDAP Support, enabled);
-   php_info_print_table_row(2, RCS Version, $Id: ldap.c,v 1.139 2003/06/08 
23:34:51 sniper Exp $);
+   php_info_print_table_row(2, RCS Version, $Id: ldap.c,v 1.140 2003/06/08 
23:44:01 sniper Exp $);
 
if (LDAPG(max_links) == -1) {
snprintf(tmp, 31, %ld/unlimited, LDAPG(num_links));
@@ -462,6 +465,47 @@
}
 }
 /* }}} */
+
+#ifdef HAVE_LDAP_SASL_INTERACTIVE_BIND_S
+/* {{{ _php_sasl_interact
+   Interact function for SASL */
+static int _php_sasl_interact(LDAP *ld, unsigned flags, void *defaults, void *in)
+{
+   sasl_interact_t *interact = in;
+
+   while (interact-id != SASL_CB_LIST_END) {
+   const char *dflt = interact-defresult;
+
+   interact-result = strdup((dflt  *dflt) ? dflt : );
+   interact-len = interact-result ? strlen(interact-result) : 0;
+   interact++;
+   };
+   return LDAP_SUCCESS;
+}
+
+/* {{{ proto bool ldap_sasl_bind(resource link)
+   Bind to LDAP directory using SASL */
+PHP_FUNCTION(ldap_sasl_bind)
+{
+   zval *link;
+   ldap_linkdata *ld;
+   int rc;
+
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, r, link) == FAILURE) {
+   RETURN_FALSE;
+   }
+
+   ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, link, -1, ldap link, le_link);
+
+   if ((rc = ldap_sasl_interactive_bind_s(ld-link, NULL, NULL, NULL, NULL, 
LDAP_SASL_QUIET, _php_sasl_interact, NULL)) != LDAP_SUCCESS) {
+   php_error_docref(NULL TSRMLS_CC, E_WARNING, Unable to bind to server: 
%s, ldap_err2string(rc));
+   RETURN_FALSE;
+   } else {
+   RETURN_TRUE;
+   }
+}
+/* }}} */
+#endif /* HAVE_LDAP_SASL_INTERACTIVE_BIND_S */
 
 /* {{{ proto bool ldap_unbind(resource link)
Unbind from LDAP directory */
Index: php4/ext/ldap/php_ldap.h
diff -u php4/ext/ldap/php_ldap.h:1.26 php4/ext/ldap/php_ldap.h:1.27
--- php4/ext/ldap/php_ldap.h:1.26   Tue Dec 31 11:06:51 2002
+++ php4/ext/ldap/php_ldap.hSun Jun  8 19:44:01 2003
@@ -18,7 +18,7 @@
+--+
 */
 
-/* $Id: php_ldap.h,v 1.26 2002/12/31 16:06:51 sebastian Exp $ */
+/* $Id: php_ldap.h,v 1.27 2003/06/08 23:44:01 sniper Exp $ */
 
 #ifndef PHP_LDAP_H
 #define PHP_LDAP_H
@@ -34,52 +34,43 @@
 /* LDAP functions */
 PHP_MINIT_FUNCTION(ldap);
 PHP_MSHUTDOWN_FUNCTION(ldap);
-
 PHP_MINFO_FUNCTION(ldap);
 
 PHP_FUNCTION(ldap_connect);
-
 PHP_FUNCTION(ldap_bind);
+#ifdef HAVE_LDAP_SASL_INTERACTIVE_BIND_S
+PHP_FUNCTION(ldap_sasl_bind);
+#endif
 PHP_FUNCTION(ldap_unbind);
-
 PHP_FUNCTION(ldap_read);
 PHP_FUNCTION(ldap_list);
 PHP_FUNCTION(ldap_search);
-
 PHP_FUNCTION(ldap_free_result);
 PHP_FUNCTION(ldap_count_entries);
-