com php-src: Set an LDAP error code when failing ldap_bind due to null bytes: ext/ldap/ldap.c
| From: | Stanislav Malyshev | Date: | Sun, 28 Sep 2014 19:23:52 +0000 |
| Subject: | com php-src: Set an LDAP error code when failing ldap_bind due to null bytes: ext/ldap/ldap.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-81999@lists.php.net to get a copy of this message | ||
Commit: fcbe20d3577ad261f4b8a77714a2fb6facc85dbd
Author: Matthew Daley <mattd@bugfuzz.com> Sun, 28 Sep 2014 17:49:35 +1300
Committer: Stanislav Malyshev <stas@php.net> Sun, 28 Sep 2014 12:23:52 -0700
Parents: 2711948d14cbcd5ababf82cae55ef25f3f870e1f
Branches: PHP-5.4 PHP-5.5 PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=fcbe20d3577ad261f4b8a77714a2fb6facc85dbd
Log:
Set an LDAP error code when failing ldap_bind due to null bytes
Some applications check a LDAP link's error code after seeing ldap_bind
fail due to a null byte bind attempt and hence incorrectly receive the
last set error code.
Fix by setting an LDAP error code before returning in this case.
Changed paths:
M ext/ldap/ldap.c
Diff:
diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c
index 9fe48a0..2dabc34 100644
--- a/ext/ldap/ldap.c
+++ b/ext/ldap/ldap.c
@@ -385,6 +385,23 @@ static int _get_lderrno(LDAP *ldap)
}
/* }}} */
+/* {{{ _set_lderrno
+ */
+static void _set_lderrno(LDAP *ldap, int lderr)
+{
+#if !HAVE_NSLDAP
+#if LDAP_API_VERSION > 2000 || HAVE_ORALDAP
+ /* New versions of OpenLDAP do it this way */
+ ldap_set_option(ldap, LDAP_OPT_ERROR_NUMBER, &lderr);
+#else
+ ldap->ld_errno = lderr;
+#endif
+#else
+ ldap_set_lderrno(ldap, lderr, NULL, NULL);
+#endif
+}
+/* }}} */
+
/* {{{ proto bool ldap_bind(resource link [, string dn [, string password]])
Bind to LDAP directory */
PHP_FUNCTION(ldap_bind)
@@ -399,18 +416,20 @@ PHP_FUNCTION(ldap_bind)
RETURN_FALSE;
}
+ ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
+
if (ldap_bind_dn != NULL && memchr(ldap_bind_dn, '\0', ldap_bind_dnlen) != NULL)
{
+ _set_lderrno(ld->link, LDAP_INVALID_CREDENTIALS);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "DN contains a null byte");
RETURN_FALSE;
}
if (ldap_bind_pw != NULL && memchr(ldap_bind_pw, '\0', ldap_bind_pwlen) != NULL)
{
+ _set_lderrno(ld->link, LDAP_INVALID_CREDENTIALS);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Password contains a null byte");
RETURN_FALSE;
}
- ZEND_FETCH_RESOURCE(ld, ldap_linkdata *, &link, -1, "ldap link", le_link);
-
if ((rc = ldap_bind_s(ld->link, ldap_bind_dn, ldap_bind_pw, LDAP_AUTH_SIMPLE)) != LDAP_SUCCESS)
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to bind to server: %s",
ldap_err2string(rc));
RETURN_FALSE;