DirectoryTree / LdapRecord

A fully-featured LDAP framework.
https://ldaprecord.com
MIT License
519 stars 45 forks source link

ErrorException: ldap_read(): Search: Critical extension is unavailable #125

Closed BARNZ closed 4 years ago

BARNZ commented 4 years ago

ErrorException: ldap_read(): Search: Critical extension is unavailable in C:\laragon\www\project-hub\vendor\directorytree\ldaprecord\src\Ldap.php:538

Describe the bug After upgrading this package from v1.2.x to the latest version I am getting the above error when searching for a user in my Active Directory (but it doesnt seem to happen in all cases). I have tested rolling back through the recent versions and it appears as through this bug was introduced in v1.5.1 (v1.5.0 works fine)

I'm unsure what could be causing this, but some change introduced in 1.5.1 is triggering it

Stack trace:

   LdapRecord\LdapRecordException 

  ErrorException: ldap_read(): Search: Critical extension is unavailable in C:\laragon\www\project-hub\vendor\directorytree\ldaprecord\src\Ldap.php:541
Stack trace:
#0 [internal function]: LdapRecord\Ldap->LdapRecord\{closure}(2, 'ldap_read(): Se...', 'C:\\laragon\\www\\...', 541, Array)
#1 C:\laragon\www\project-hub\vendor\directorytree\ldaprecord\src\Ldap.php(541): ldap_read(Resource id #485, 'CN=Harrod\\, Amy...', '(&(objectclass=...', Array, false, 1, 0, NULL)
#2 C:\laragon\www\project-hub\vendor\directorytree\ldaprecord\src\Ldap.php(892): LdapRecord\Ldap->LdapRecord\{closure}()
#3 C:\laragon\www\project-hub\vendor\directorytree\ldaprecord\src\Ldap.php(542): LdapRecord\Ldap->executeFailableOperation(Object(Closure))
#4 C:\laragon\www\project-hub\vendor\directorytree\ldaprecord\src\Query\Builder.php(531): LdapRecord\Ldap->read('CN=Harrod\\, Amy...', '(&(objectclass=...', Array, false, 1)
#5 C:\laragon\www\project-hub\vendor\directorytree\ldaprecord\src\Connection.php(280): LdapRecord\Query\Builder->LdapRecord\Query\{closure}(Object(LdapRecord\Ldap))
#6 C:\laragon\www\project-hub\vendor\directorytree\ldaprecord\src\Connection.php(262): LdapRecord\Connection->runOperationCallback(Object(Closure))
#7 C:\laragon\www\project-hub\vendor\directorytree\ldaprecord\src\Query\Builder.php(533): LdapRecord\Connection->run(Object(Closure))
#8 C:\laragon\www\project-hub\vendor\directorytree\ldaprecord\src\Query\Builder.php(398): LdapRecord\Query\Builder->run('(&(objectclass=...')
#9 C:\laragon\www\project-hub\vendor\directorytree\ldaprecord\src\Query\Builder.php(503): LdapRecord\Query\Builder->LdapRecord\Query\{closure}()
#10 C:\laragon\www\project-hub\vendor\directorytree\ldaprecord\src\Query\Builder.php(401): LdapRecord\Query\Builder->getCachedResponse('(&(objectclass=...', Object(Closure))
#11 C:\laragon\www\project-hub\vendor\directorytree\ldaprecord\src\Query\Builder.php(224): LdapRecord\Query\Builder->query('(&(objectclass=...')
#12 C:\laragon\www\project-hub\vendor\directorytree\ldaprecord\src\Query\Builder.php(246): LdapRecord\Query\Builder->LdapRecord\Query\{closure}()
#13 C:\laragon\www\project-hub\vendor\directorytree\ldaprecord\src\Query\Builder.php(225): LdapRecord\Query\Builder->onceWithColumns(Array, Object(Closure))
#14 C:\laragon\www\project-hub\vendor\directorytree\ldaprecord\src\Query\Builder.php(699): LdapRecord\Query\Builder->get(Array)
#15 C:\laragon\www\project-hub\vendor\directorytree\ldaprecord\src\Query\Builder.php(717): LdapRecord\Query\Builder->first(Array)
#16 C:\laragon\www\project-hub\vendor\directorytree\ldaprecord\src\Query\Builder.php(816): LdapRecord\Query\Builder->firstOrFail(Array)
#17 C:\laragon\www\project-hub\vendor\directorytree\ldaprecord\src\Query\Builder.php(793): LdapRecord\Query\Builder->findOrFail('CN=Harrod\\, Amy...', Array)
#18 C:\laragon\www\project-hub\vendor\wsp-nz-packages\active-directory\src\Models\User.php(51): LdapRecord\Query\Builder->find('CN=Harrod\\, Amy...')
...

I'm fetching a user from AD and in the asPlainObject function of my User model (which extends the standard BaseUser) im firing another call to User::find to get their manager based on the users retrieved manager dn. Highlighted below:

image

The highlighted section triggers the above stack trace resulting in the exception being thrown.

Expected behavior No exception to be thrown

Environment (please complete the following information):

stevebauman commented 4 years ago

Ah thanks @BARNZ! I know exactly what it is -- v1.5.1 introduced a patch to fix this issue: https://github.com/DirectoryTree/LdapRecord/issues/116

However, this may be a bug with the PHP version itself that the dev was using... Give me a couple minutes to do some testing and I'll have a patch out, thanks!

stevebauman commented 4 years ago

Okay rolled the change back. I'm dubbing the original cause of #116 as a PHP bug, as I have not experienced it using PHP 7.2, 7.3 or 7.4 on my own installations.

Run composer update and you're good to go!

BARNZ commented 4 years ago

Yep confirmed working with the latest version. Thanks for the quick turnaround Steve!

stevebauman commented 4 years ago

Perfect, great to hear @BARNZ, glad I could help! 👍