noirello / bonsai

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

Process finished with exit code 11 #38

Closed reach4bawer closed 3 years ago

reach4bawer commented 4 years ago

I recently got Macbook system refreshed and I am trying to get bonsai working -

openssl 1.1.1f
openldap 2.4.49
Python 3.7.7
Bonsai 1.2.0
import asyncio
import bonsai
CACERT_FILE = ".//cacerts.pem"
bonsai.set_connect_async(False)
bonsai.set_debug(True, -1)
server_name ="ldaps://server.com"
client = bonsai.LDAPClient(server_name)
client.set_ca_cert(CACERT_FILE)
client.set_credentials("SIMPLE", user=user, password=password)
client.set_auto_page_acquire(True)
base = "x,y,z"
async def get_last_login(search_filter):
    async with client.connect(is_async=True) as conn:
        res = await conn.search(base=base, scope=2, filter_exp=search_filter, attrlist=['*'])
    print(res[0])

if __name__ == '__main__':
    search_filter = "(&(objectClass=group)(samaccountname={}))".format('Test')
    print(search_filter)
    loop = asyncio.get_event_loop()
    loop.run_until_complete(get_last_login(search_filter))

ldap_url_parse_ext(ldap://localhost/) ldap_init: trying /usr/local/etc/openldap/ldap.conf ldap_init: using /usr/local/etc/openldap/ldap.conf ldap_init: HOME env is /Users/MYUSER ldap_init: trying /Users/MYUSER/ldaprc ldap_init: trying /Users/MYUSER/.ldaprc ldap_init: trying ldaprc ldap_init: LDAPCONF env is NULL ldap_init: LDAPRC env is NULL (&(objectClass=group)(samaccountname=Test)) DBG: ldapconnection_new [self:0x10a2a8fa0] DBG: ldapconnection_init (self:0x10a2a8fa0) DBG: ldapconnection_open (self:0x10a2a8fa0) DBG: connecting (self:0x10a2a8fa0) DBG: create_conn_info (mech:SIMPLE, sock:7, creds:0x10a2c2780) DBG: ldapconnectiter_new [self:0x10a2cf4e0] DBG: create_init_thread_data (client:0x1063bba50, sock:7) DBG: create_init_thread (ld:0x7ff42fc02400, info:0x7ff42fc1f290, thread:0) DBG: ldap_init_thread_func (params:0x7ff42fc02400) ldap_create ldap_url_parse_ext(ldaps://server.com:636) DBG: set connecting async: 0 DBG: ldap_init_thread_func [retval:0] DBG: ldapconnection_fileno (self:0x10a2a8fa0)[desc:0, dummy] DBG: ldapconnection_fileno (self:0x10a2a8fa0)[desc:0, dummy] DBG: ldapconnection_fileno (self:0x10a2a8fa0)[desc:0, dummy] DBG: ldapconnection_fileno (self:0x10a2a8fa0)[desc:0, dummy] DBG: ldapconnection_result (self:0x10a2a8fa0, args:0x109e19f10, kwds:0x0)[msgid:8] DBG: LDAPConnection_Result (self:0x10a2a8fa0, msgid:8, millisec:-1) DBG: LDAPConnectIter_Next (self:0x10a2cf4e0, timeout:-1) [tls:0, state:0] DBG: _ldap_finish_init_thread (async:1, thread:123145450450944, timeout:-1, misc:0x7ff42fc02400) DBG: _pthread_mutex_timedlock DBG: set_certificates (self:0x10a2cf4e0)

Process finished with exit code 11

I am not sure if it is version compatibility or something else, is there something that I need to change?

reach4bawer commented 4 years ago

Output for the -

otool -L /usr/local/lib/python3.7/site-packages/bonsai/_bonsai.cpython-37m-darwin.so

/usr/local/lib/python3.7/site-packages/bonsai/_bonsai.cpython-37m-darwin.so:
    @loader_path/.dylibs/libldap-2.4.2.10.11.dylib (compatibility version 13.0.0, current version 13.11.0)
    @loader_path/.dylibs/liblber-2.4.2.10.11.dylib (compatibility version 13.0.0, current version 13.11.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
noirello commented 4 years ago

I had the chance to build the module on a similar environment (macos 10.15.3, openssl 1.1.1f, openldap 2.4.49, python 3.7.7), and your example code (tailored to the test docker ldap server) ran successfully.

Could you simplify the code to a synchronous connection and see that the error is still same?

reach4bawer commented 4 years ago

The synchronous connection didn't work either so I uninstalled the module and had to recompile the code from source to make it work. Every-time there is an update to python or OpenLdap this would break.

I am not sure if it's just my system or if anyone else has faced it. I used brew to manage the packages for both python and the openldap.