Hi, I just created a patch for a customer who needed ldap_set_rebind_proc for named rebinding on a sun ldap server.
The #if statements are a bit dirty, but i did not manage to find the correct ifdef condition. Maybe someone can use it or even integrate it into cvs. If you have any questions regarding this patch, do not hesitate to contact me. Greetings Matthias Lange -- Matthias Lange, Dipl.-Ing. (FH) NetUSE AG Dr.-Hell-Straße Fon: +49 431 38643500 http://www.netuse.de/ D-24107 Kiel, Germany Fax: +49 431 38643599 Infos über den neuen NetUSE Workflow Manager: http://workflow.NetUSE.de
*** ldap.c.original Thu Jan 30 17:38:28 2003 --- ldap.c Thu Feb 13 16:11:51 2003 *************** *** 61,67 **** typedef struct { LDAP *link; ! #if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC) zval *rebindproc; #endif } ldap_linkdata; --- 61,67 ---- typedef struct { LDAP *link; ! #if 1 || defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC) zval *rebindproc; #endif } ldap_linkdata; *************** *** 121,127 **** PHP_FE(ldap_compare, NULL) PHP_FE(ldap_sort, NULL) ! #if ( LDAP_API_VERSION > 2000 ) || HAVE_NSLDAP PHP_FE(ldap_get_option, third_argument_force_ref) PHP_FE(ldap_set_option, NULL) PHP_FE(ldap_parse_result, arg3to6of6_force_ref) --- 121,127 ---- PHP_FE(ldap_compare, NULL) PHP_FE(ldap_sort, NULL) ! #if 1 || ( LDAP_API_VERSION > 2000 ) || HAVE_NSLDAP PHP_FE(ldap_get_option, third_argument_force_ref) PHP_FE(ldap_set_option, NULL) PHP_FE(ldap_parse_result, arg3to6of6_force_ref) *************** *** 136,142 **** #endif #endif ! #if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC) PHP_FE(ldap_set_rebind_proc, NULL) #endif --- 136,142 ---- #endif #endif ! #if 1 || defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC) PHP_FE(ldap_set_rebind_proc, NULL) #endif *************** *** 173,179 **** ldap_linkdata *ld = (ldap_linkdata *)rsrc->ptr; ldap_unbind_s(ld->link); ! #if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC) if (ld->rebindproc != NULL) { zval_dtor(ld->rebindproc); FREE_ZVAL(ld->rebindproc); --- 173,179 ---- ldap_linkdata *ld = (ldap_linkdata *)rsrc->ptr; ldap_unbind_s(ld->link); ! #if 1 || defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC) if (ld->rebindproc != NULL) { zval_dtor(ld->rebindproc); FREE_ZVAL(ld->rebindproc); *************** *** 508,514 **** /* deref */ if (deref > -1) { ! #if ( LDAP_API_VERSION >= 2004 ) || HAVE_NSLDAP ldap_set_option(ldap, LDAP_OPT_DEREF, &deref); #else ldap->ld_deref = deref; --- 508,514 ---- /* deref */ if (deref > -1) { ! #if 1 || ( LDAP_API_VERSION >= 2004 ) || HAVE_NSLDAP ldap_set_option(ldap, LDAP_OPT_DEREF, &deref); #else ldap->ld_deref = deref; *************** *** 2003,2010 **** #endif /* ( LDAP_API_VERSION > 2000 ) || HAVE_NSLDAP */ #if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC) ! int _ldap_rebind_proc(LDAP *ldap, const char *url, ber_tag_t req, ber_int_t msgid, void *params) { ldap_linkdata *ld; int retval; zval *cb_url; --- 2003,2013 ---- #endif /* ( LDAP_API_VERSION > 2000 ) || HAVE_NSLDAP */ + #if (LDAP_API_VERSION >= 2004) || HAVE_NSLDAP || +defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC) + + int _ldap_rebind_proc #if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC) ! (LDAP *ldap, const char *url, ber_tag_t req, ber_int_t msgid, void *params) { ldap_linkdata *ld; int retval; zval *cb_url; *************** *** 2037,2045 **** zval_dtor(cb_url); FREE_ZVAL(cb_url); return retval; ! } /* {{{ proto bool ldap_set_rebind_proc(resource link, string callback) Set a callback function to do re-binds on referral chasing. */ PHP_FUNCTION(ldap_set_rebind_proc) --- 2040,2129 ---- zval_dtor(cb_url); FREE_ZVAL(cb_url); return retval; ! #else ! /** ! * 2003-02-13 Matthias Lange <[EMAIL PROTECTED]> ! */ ! (LDAP *ldap, char **dn, char **passwd, int *authmethod, int freeit, void *extraArg) { ! ldap_linkdata *ld; ! zval *cb_retval; ! zval **ret_code, **ret_dn, **ret_passwd; ! zval *cb_link = (zval *) extraArg; + if(freeit) { + free(*dn); + free(*passwd); + return LDAP_SUCCESS; + } + *authmethod = LDAP_AUTH_SIMPLE; + + TSRMLS_FETCH(); + + ld = (ldap_linkdata *) zend_fetch_resource(&cb_link TSRMLS_C, -1, "ldap +link", NULL, 1, le_link); + + /** link exists and callback set? */ + if (ld == NULL || ld->rebindproc == NULL) { + php_error(E_WARNING, "%s(): Link not found or no callback set", + get_active_function_name(TSRMLS_C)); + return LDAP_OTHER; + } + + /* execute callback function */ + if ( call_user_function_ex(EG(function_table), NULL, ld->rebindproc, + &cb_retval, 0, 0, 0, NULL TSRMLS_CC) + == SUCCESS + && cb_retval) { + if (Z_TYPE_P(cb_retval) != IS_ARRAY) { + php_error(E_WARNING, "%s(): Callback did not return an +array",get_active_function_name(TSRMLS_C)); + return LDAP_OTHER; + } + if(3 != zend_hash_num_elements(Z_ARRVAL_P(cb_retval))) { + php_error(E_WARNING, "%s(): Callback array did not have three +elements",get_active_function_name(TSRMLS_C)); + return LDAP_OTHER; + } + + zend_hash_internal_pointer_reset(Z_ARRVAL_P(cb_retval)); + zend_hash_get_current_data(Z_ARRVAL_P(cb_retval), (void **)&ret_code); + zend_hash_move_forward(Z_ARRVAL_P(cb_retval)); + zend_hash_get_current_data(Z_ARRVAL_P(cb_retval), (void **)&ret_dn); + zend_hash_move_forward(Z_ARRVAL_P(cb_retval)); + zend_hash_get_current_data(Z_ARRVAL_P(cb_retval), (void **)&ret_passwd); + + if(Z_TYPE_PP(ret_code) != IS_LONG ) { + php_error(E_WARNING, "%s(): Element 1 is not an +int",get_active_function_name(TSRMLS_C)); + return LDAP_OTHER; + } + if(LDAP_SUCCESS != Z_LVAL_PP(ret_code)) { + php_error(E_WARNING, "%s(): Ldap Error: Return Code %d", + get_active_function_name(TSRMLS_C), Z_LVAL_PP(ret_code)); + return Z_LVAL_PP(ret_code); + } + if(Z_TYPE_PP(ret_dn) != IS_STRING) { + php_error(E_WARNING, "%s(): Element 2 is not a +string",get_active_function_name(TSRMLS_C)); + return LDAP_OTHER; + } + if(Z_TYPE_PP(ret_passwd) != IS_STRING) { + php_error(E_WARNING, "%s(): Element 3 is not a +string",get_active_function_name(TSRMLS_C)); + return LDAP_OTHER; + } + + *dn = calloc(sizeof(char), Z_STRLEN_PP(ret_dn)+1); + strncpy(*dn,Z_STRVAL_PP(ret_dn),Z_STRLEN_PP(ret_dn)); + dn[Z_STRLEN_PP(ret_dn)+1] = 0; + + *passwd = calloc(sizeof(char), Z_STRLEN_PP(ret_passwd)+1); + strncpy(*passwd,Z_STRVAL_PP(ret_passwd),Z_STRLEN_PP(ret_passwd)); + passwd[Z_STRLEN_PP(ret_passwd)+1] = 0; + + return LDAP_SUCCESS; + } + php_error(E_WARNING, "%s(): rebind_proc PHP callback failed", +get_active_function_name(TSRMLS_C)); + return LDAP_OTHER; + + #endif + } + /* {{{ proto bool ldap_set_rebind_proc(resource link, string callback) Set a callback function to do re-binds on referral chasing. */ PHP_FUNCTION(ldap_set_rebind_proc)
*** php_ldap.h Thu Feb 13 15:44:24 2003 --- /var/tmp/php-4.3.0/ext/ldap/php_ldap.h Fri Jan 4 21:56:03 2002 *************** *** 93,99 **** PHP_FUNCTION(ldap_start_tls); #endif ! #if 1 || defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC) PHP_FUNCTION(ldap_set_rebind_proc); #endif --- 93,99 ---- PHP_FUNCTION(ldap_start_tls); #endif ! #if defined(LDAP_API_FEATURE_X_OPENLDAP) && defined(HAVE_3ARG_SETREBINDPROC) PHP_FUNCTION(ldap_set_rebind_proc); #endif
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php