noirello / bonsai

Simple Python 3 module for LDAP, using libldap2 and winldap C libraries.
MIT License
117 stars 33 forks source link

It does not work LDAP PING #7

Closed vm86 closed 7 years ago

vm86 commented 7 years ago

https://msdn.microsoft.com/en-us/library/cc223811.aspx Ntver option is a byte string. When searching for the form: conn.search(base='', scope=bonsai.LDAPSearchScope.BASE, filter='(&(DnsDomain=EKB2003.LOCAL)(NtVer=\00\00\00\01))', attrlist=['NETLOGON'])

I get the error:

TypeError: Wrong parameters (base<str|LDAPDN>, scope<int>, filter<str>, attrlist<List>, timeout<float>, attrsonly<bool>, sort_order<List>, page_size<int>, offset<int>, before_count<int>, after_count<int>, est_list_count<int>, attrvalue<object>).

How to fix it?

vm86 commented 7 years ago

i am sorry,fixed

filter='(&(DnsDomain=EKB2003.LOCAL)(NtVer=\\00\\00\\00\\01))

noirello commented 7 years ago

Actually, this issue might be considered as a bug (but at least a wrong reaction). Every parameter has the right type, clearly. The problem surfaces in the Python/C API side of the type-checking, where the argument parsing function doesn't like strings with null characters inside, thus returns with error.

Nonetheless, the thrown exception is entirely misleading. If the argument parser accepted byte-likes object along with str and None, then the search method would throw an LDAPError with bad search filter message, which would help you far more where to look for the original error.

I'm going to change the parser's parameters in the next release, hoping that being more permissive doesn't lead to bigger problems.