Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ldap3 search will not return user with one special objectGUID #650

cornelinux opened this issue Jan 22, 2019 · 6 comments


None yet
3 participants
Copy link

commented Jan 22, 2019

We are experiencing problems with an ldap search when running a speical search filter (2.5.1, 2.5.2)
We have a search filter, that looks like this:


which works fine for all the users we have seen so far. Thousands. For years ;-)

But interesting enough we connect to an active directory and this code works for almost all users.
But there is only one single user with this guid


And this search returns nothing! And empty result.
We are running python 2.7.

Please note that the very same searchfilter acutally returns the correct user, when e.g. used in a powershell.
Could it be that there are nasty bytes, which some internals of ldap3 do not like?


This comment has been minimized.

Copy link

commented Jan 29, 2019

Hi Giovanni,

I think we have found the culprit: If we send a SEARCH with the search filter above, Wireshark tells us the following LDAP search request goes over the wire:

Filter: (&(&(sAMAccountName=*)(objectClass=person))(objectGUID=64:93:71:71:ab:8d:a2:b8:37:98:0b:38:f2:88))

These are only 14 Bytes, not 16. Comparing this with the objectGUID from above:

correct objectGUID:       \64\93\71\71\ab\5c\38\44\a2\b8\37\98\0b\38\f2\88
objectGUID actually sent:  64:93:71:71:ab:8d      :a2:b8:37:98:0b:38:f2:88

we see the sent objectGUID misses two bytes in the middle, and also has an incorrect byte 8d instead of 5c. I think the issue is the following line in prepare_filter_for_sending:

if (raw_string[i] == 92 or raw_string[i] == '\\') and i < len(raw_string) - 2: # 92 is backslash

which misinterprets the 5c (= 92 decimal) byte as an escaping backslash and modifies the objectGUID value.

However, I'm not sure how to fix this without breaking other things :-) Do you have any idea? If you need any help, please just let me know.

@cannatag cannatag added the bug label Feb 9, 2019


This comment has been minimized.

Copy link

commented Feb 9, 2019

Hi, this is a bug I already met and tought it was fixed. Can you please try the "test_search_string_guid_with_backslash" test in test/ I have no error either with python 2.7 or 3.7. You must change the test for your environment and GUID.



This comment has been minimized.

Copy link

commented Feb 11, 2019

Hi Giovanni, thank you for your reply! Unfortunately I haven't succeeded in adapting test_search_string_guid_with_backslash to my environment yet. However, I think that testcase matches on the audio attribute, not objectGUID, and doesn't seem to hit the bug above.

I put together a demo script with the MOCK_SYNC strategy and the OFFLINE_AD_2012_R2 offline schema. It uses the same 16 bytes in a filter matching the audio attribute and in a filter matching objectGUID, and prints the decoded request afterwards:

from ldap3 import Server, Connection, MOCK_SYNC, OFFLINE_AD_2012_R2

server = Server('my_fake_server', get_info=OFFLINE_AD_2012_R2)
connection = Connection(server, user='cn=my_user,ou=test,o=lab', password='my_password',

BASE_DN = 'ou=test,o=lab'
# Same representation of bytes, once for ``objectGUID``, once for ``audio``
OBJECTGUID_FILTER = r"(objectGUID=\cc\5c\63\0a\27\4f\3a\42\b1\a7\c2\9f\29\f5\91\68)"
AUDIO_FILTER =           r"(audio=\cc\5c\63\0a\27\4f\3a\42\b1\a7\c2\9f\29\f5\91\68)", OBJECTGUID_FILTER)
decoded_objectguid_filter = connection.request['filter']
print('Decoded filter for objectGUID: {}'.format(decoded_objectguid_filter)), AUDIO_FILTER)
decoded_audio_filter = connection.request['filter']
print('Decoded filter for audio:           {}'.format(decoded_audio_filter))

On current dev (b39b0f9), it gives the same result under both Python 2.7 and 3.7:

Decoded filter for objectGUID: (objectGUID=\cc\0c\27\4f\3a\42\b1\a7\c2\9f\29\f5\91\68)
Decoded filter for audio:           (audio=\cc\5c\63\0a\27\4f\3a\42\b1\a7\c2\9f\29\f5\91\68)

So I think the filter is only mangled for the objectGUID attribute. Also, the bug disappears if I remove the get_info=OFFLINE_AD_2012_R2, so I guess it only occurs in combination with AD.

As always, just let me know if I can be of any help :-)


This comment has been minimized.

Copy link

commented Mar 16, 2019

Hi, can you check the code in dev? It should work now.



This comment has been minimized.

Copy link

commented Mar 22, 2019

Hi Giovanni, thanks a lot for looking into this!

I can confirm that the current dev (3b928eb) solves the problem for us. Also, I realized this is a duplicate of #589, apologies for that :)

Best Wishes



This comment has been minimized.

Copy link

commented Mar 24, 2019

Fixed in version 2.6

@cannatag cannatag closed this Mar 24, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.