diff options
-rw-r--r-- | ext/ldap/ldap.c | 45 | ||||
-rw-r--r-- | ext/ldap/php_ldap.h | 3 |
2 files changed, 48 insertions, 0 deletions
diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index 4946b6f6cd..78c4f12d1d 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -90,6 +90,7 @@ function_entry ldap_functions[] = { PHP_FE(ldap_errno, NULL) PHP_FE(ldap_err2str, NULL) PHP_FE(ldap_error, NULL) + PHP_FE(ldap_compare, NULL) {NULL, NULL, NULL} }; @@ -1367,3 +1368,47 @@ PHP_FUNCTION(ldap_error) { RETURN_STRING(ldap_err2string(ld_errno), 1); } /* }}} */ + + +/* {{{ proto int ldap_compare(int link, string dn, string attr, string value) + Determine if an entry has a specific value for one of its attributes. */ +PHP_FUNCTION(ldap_compare) { + pval **link, **dn, **attr, **value; + char *ldap_dn, *ldap_attr, *ldap_value; + LDAP *ldap; + int errno; + + if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &link, &dn, &attr, &value) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_string_ex(link); + ldap = _get_ldap_link(link); + if (ldap == NULL) RETURN_LONG(-1); + + convert_to_string_ex(dn); + convert_to_string_ex(attr); + convert_to_string_ex(value); + + ldap_dn = (*dn)->value.str.val; + ldap_attr = (*attr)->value.str.val; + ldap_value = (*value)->value.str.val; + + errno = ldap_compare_s(ldap, ldap_dn, ldap_attr, ldap_value); + + switch(errno) { + case LDAP_COMPARE_TRUE : + RETURN_TRUE; + break; + + case LDAP_COMPARE_FALSE : + RETURN_FALSE; + break; + } + + php_error(E_WARNING, "LDAP: Compare operation could not be completed: %s", ldap_err2string(errno)); + RETURN_LONG(-1); + +} +/* }}} */ + diff --git a/ext/ldap/php_ldap.h b/ext/ldap/php_ldap.h index a2f941838c..8ede7263eb 100644 --- a/ext/ldap/php_ldap.h +++ b/ext/ldap/php_ldap.h @@ -14,6 +14,7 @@ +----------------------------------------------------------------------+ | Authors: Amitay Isaacs <amitay@w-o-i.com> | | Eric Warnke <ericw@albany.edu> | + | Jani Taskinen <sniper@iki.fi> | +----------------------------------------------------------------------+ */ @@ -76,6 +77,8 @@ PHP_FUNCTION(ldap_errno); PHP_FUNCTION(ldap_err2str); PHP_FUNCTION(ldap_error); +PHP_FUNCTION(ldap_compare); + ZEND_BEGIN_MODULE_GLOBALS(ldap) long default_link; long num_links, max_links; |