@@ -385,6 +385,23 @@ static int _get_lderrno(LDAP *ldap)
385
385
}
386
386
/* }}} */
387
387
388
+ /* {{{ _set_lderrno
389
+ */
390
+ static void _set_lderrno (LDAP * ldap , int lderr )
391
+ {
392
+ #if !HAVE_NSLDAP
393
+ #if LDAP_API_VERSION > 2000 || HAVE_ORALDAP
394
+ /* New versions of OpenLDAP do it this way */
395
+ ldap_set_option (ldap , LDAP_OPT_ERROR_NUMBER , & lderr );
396
+ #else
397
+ ldap -> ld_errno = lderr ;
398
+ #endif
399
+ #else
400
+ ldap_set_lderrno (ldap , lderr , NULL , NULL );
401
+ #endif
402
+ }
403
+ /* }}} */
404
+
388
405
/* {{{ proto bool ldap_bind(resource link [, string dn [, string password]])
389
406
Bind to LDAP directory */
390
407
PHP_FUNCTION (ldap_bind )
@@ -399,18 +416,20 @@ PHP_FUNCTION(ldap_bind)
399
416
RETURN_FALSE ;
400
417
}
401
418
419
+ ZEND_FETCH_RESOURCE (ld , ldap_linkdata * , & link , -1 , "ldap link" , le_link );
420
+
402
421
if (ldap_bind_dn != NULL && memchr (ldap_bind_dn , '\0' , ldap_bind_dnlen ) != NULL ) {
422
+ _set_lderrno (ld -> link , LDAP_INVALID_CREDENTIALS );
403
423
php_error_docref (NULL TSRMLS_CC , E_WARNING , "DN contains a null byte" );
404
424
RETURN_FALSE ;
405
425
}
406
426
407
427
if (ldap_bind_pw != NULL && memchr (ldap_bind_pw , '\0' , ldap_bind_pwlen ) != NULL ) {
428
+ _set_lderrno (ld -> link , LDAP_INVALID_CREDENTIALS );
408
429
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Password contains a null byte" );
409
430
RETURN_FALSE ;
410
431
}
411
432
412
- ZEND_FETCH_RESOURCE (ld , ldap_linkdata * , & link , -1 , "ldap link" , le_link );
413
-
414
433
if ((rc = ldap_bind_s (ld -> link , ldap_bind_dn , ldap_bind_pw , LDAP_AUTH_SIMPLE )) != LDAP_SUCCESS ) {
415
434
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Unable to bind to server: %s" , ldap_err2string (rc ));
416
435
RETURN_FALSE ;
0 commit comments