From mg at max.gautier.name Sat Jul 2 07:01:35 2022 From: mg at max.gautier.name (Max Gautier) Date: Sat, 2 Jul 2022 13:01:35 +0200 Subject: [python-ldap] Processing query in spans of time with timeout and resuming Message-ID: Hi everyone, I'm trying to use python-ldap to write a vim completion plugin (more specically, a completion source for vim-asyncomplete[1]), and I'm not sure if what I want is possible. Basically, I'd like to do launch a LDAP query, and return results either: 1. When the query is finished 2. After a soft timeout With the possibility in the second case to re-loop and each time get the results up to now. I was trying to use the ldap.resiter.ResultProcessor as the docs seems to recommend that, but I think I would need to wrap it in something else to obtain the desired behaviour. I thought about doing it this way: --- class LdapSoftTimeout(ldap.ldapobject.LDAPObject, ldap.resiter.ResultProcessor): pass con = ldap.initialize("ldaps://myuri") con.sasl_gssapi_bind_s() msg_id = con.search('ou=users,dc=mycompany,dc=com', ldap.SCOPE_SUBTREE, '(cn=*Go*)', ['cn', 'mail']) # Keep that whole context somehow, then do a function returning partial # results each time it's called, something like : partial_results = list() now = time.time() timeout = 0.1 for r in con.allresults(msgid=search): if time.time() > now + timeout break list.append(some_processing(r)) return partial_results --- However this does not seem very efficient to me. Does someone have encountered that kind of usecase and would have a better idea ? I'm not a very experienced pythonista, so I might have missed something obvious, but my search on google on this mailing list were not fruitful, so don't hesitate to point me to the obvious solution if there is one. Thanks a lot :) -- Max Gautier From william at blackhats.net.au Mon Jul 4 21:08:47 2022 From: william at blackhats.net.au (William Brown) Date: Tue, 5 Jul 2022 11:08:47 +1000 Subject: [python-ldap] Processing query in spans of time with timeout and resuming In-Reply-To: References: Message-ID: > On 2 Jul 2022, at 21:01, Max Gautier wrote: > > Hi everyone, > > I'm trying to use python-ldap to write a vim completion plugin > (more specically, a completion source for vim-asyncomplete[1]), and I'm not sure if > what I want is possible. > > Basically, I'd like to do launch a LDAP query, and return results either: > 1. When the query is finished > 2. After a soft timeout > With the possibility in the second case to re-loop and each time get the > results up to now. > > I was trying to use the ldap.resiter.ResultProcessor as the docs seems > to recommend that, but I think I would need to wrap it in something else > to obtain the desired behaviour. > > I thought about doing it this way: > > --- > class LdapSoftTimeout(ldap.ldapobject.LDAPObject, ldap.resiter.ResultProcessor): > pass > > con = ldap.initialize("ldaps://myuri") > con.sasl_gssapi_bind_s() > msg_id = con.search('ou=users,dc=mycompany,dc=com', ldap.SCOPE_SUBTREE, '(cn=*Go*)', ['cn', 'mail']) > > # Keep that whole context somehow, then do a function returning partial > # results each time it's called, something like : > > partial_results = list() > now = time.time() > timeout = 0.1 > for r in con.allresults(msgid=search): > if time.time() > now + timeout > break > list.append(some_processing(r)) > > return partial_results > --- > > However this does not seem very efficient to me. > Does someone have encountered that kind of usecase and would have a > better idea ? > I'm not a very experienced pythonista, so I might have missed something > obvious, but my search on google on this mailing list were not fruitful, > so don't hesitate to point me to the obvious solution if there is one. You can create a thread that does the con.results() call, and then queue the results in memory for the main thread to dequeue and read from. I think thatd be your best bet. > > Thanks a lot :) > > -- > Max Gautier > _______________________________________________ > python-ldap mailing list > python-ldap at python.org > https://mail.python.org/mailman/listinfo/python-ldap -- Sincerely, William From ondra at mistotebe.net Tue Jul 5 07:18:08 2022 From: ondra at mistotebe.net (=?utf-8?B?T25kxZllaiBLdXpuw61r?=) Date: Tue, 5 Jul 2022 13:18:08 +0200 Subject: [python-ldap] Processing query in spans of time with timeout and resuming In-Reply-To: References: Message-ID: <20220705111808.GA1087@mistotebe.net> On Sat, Jul 02, 2022 at 01:01:35PM +0200, Max Gautier wrote: > Hi everyone, > > I'm trying to use python-ldap to write a vim completion plugin > (more specically, a completion source for vim-asyncomplete[1]), and I'm not sure if > what I want is possible. > > Basically, I'd like to do launch a LDAP query, and return results either: > 1. When the query is finished > 2. After a soft timeout > With the possibility in the second case to re-loop and each time get the > results up to now. > > [...] > > I'm not a very experienced pythonista, so I might have missed something > obvious, but my search on google on this mailing list were not fruitful, > so don't hesitate to point me to the obvious solution if there is one. I guess timelimit is not working for you? Haven't written any vim plugins, but looking around I don't think you have much asynchronous capability inside vim. If were your own process, you could follow the lines of my asyncio wrapper[0] around python-ldap or extract the fd and do select/pselect() with a timeout you manage. Regards, Ondrej [0]. https://git.openldap.org/openldap/syncmonitor/-/blob/master/syncmonitor/ldap_wrapper.py From ondra at mistotebe.net Wed Jul 6 15:27:52 2022 From: ondra at mistotebe.net (=?utf-8?B?T25kxZllaiBLdXpuw61r?=) Date: Wed, 6 Jul 2022 21:27:52 +0200 Subject: [python-ldap] ANN: python-ldap 3.4.2 Message-ID: <20220706192752.GC1087@mistotebe.net> You can find a new release of python-ldap here: https://pypi.python.org/pypi/python-ldap/3.4.2 See below for changes in this release. If you find any issues, please report them either on this mailing list or on the GitHub tracker: https://github.com/python-ldap/python-ldap/issues Git tag hash for the release: python-ldap-3.4.2 b80e8135785ef80a40a52eb61033a54dfd70266e The tag is signed by my GPG key with fingerprint: 4657 9513 A0E1 B929 334F 3AF6 F465 B179 E1FE 717B -------- About the project: python-ldap provides an object-oriented API to access LDAP directory servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for that purpose. Additionally it contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAP URLs and LDAPv3 schema). Project's web site: https://www.python-ldap.org/ ---------------------------------------------------------------- Released 3.4.2 2022-07-06 This is a minor release to provide out-of-the-box compatibility with the merge of libldap and libldap_r that happened with OpenLDAP's 2.5 release. The following undocumented functions are deprecated and scheduled for removal: - ``ldap.cidict.strlist_intersection`` - ``ldap.cidict.strlist_minus`` - ``ldap.cidict.strlist_union`` The following deprecated option has been removed: - ``OPT_X_TLS`` Doc/ * SASL option usage has been clarified Lib/ * ppolicy control definition has been updated to match Behera draft 11 Modules/ * By default, compile against libldap, checking whether it provides a threadsafe implementation at runtime * When decoding controls, the module can now distinguish between no value (now exposed as ``None``) and an empty value (exposed as ``b''``) * Several new OpenLDAP options are now supported: * ``OPT_SOCKET_BIND_ADDRESSES`` * ``OPT_TCP_USER_TIMEOUT`` * ``OPT_X_SASL_MAXBUFSIZE`` * ``OPT_X_SASL_SECPROPS`` * ``OPT_X_TLS_ECNAME`` * ``OPT_X_TLS_PEERCERT`` * ``OPT_X_TLS_PROTOCOL``-related options and constants Fixes: * Encoding/decoding of boolean controls has been corrected * ldap.schema.models.Entry is now usable * ``method`` keyword to ReconnectLDAPObject.bind_s is now usable From simon.pichugin at gmail.com Wed Sep 28 22:12:18 2022 From: simon.pichugin at gmail.com (Simon Pichugin) Date: Wed, 28 Sep 2022 19:12:18 -0700 Subject: [python-ldap] ANN: python-ldap 3.4.3 Message-ID: You can find a new release of python-ldap here: https://pypi.python.org/pypi/python-ldap/3.4.3 See below for changes in this release. If you find any issues, please report them either on this mailing list or on the GitHub tracker: https://github.com/python-ldap/python-ldap/issues Git tag hash for the release: python-ldap-3.4.3 9dd59a9cefdf8980beca5d75ac5983fdde7f0d79 The tag is signed by GitHub GPG key with a fingerprint: 5DE3 E050 9C47 EA3C F04A 42D3 4AEE 18F8 3AFD EB23 -------- About the project: python-ldap provides an object-oriented API to access LDAP directory servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for that purpose. Additionally, it contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAP URLs and LDAPv3 schema). Project's website: https://www.python-ldap.org/ ---------------------------------------------------------------- Released 3.4.3 2022-09-15 This is a minor release to bring back the removed OPT_X_TLS option. Please note, it's still a deprecated option and it will be removed in 3.5.0. The following deprecated option has been brought back: - ``OPT_X_TLS`` Fixes: * Sphinx documentation is now successfully built * pypy3 tests stability was improved * setup.py deprecation warning is now resolved ---------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From chris.paul at rexconsulting.net Thu Sep 15 13:55:44 2022 From: chris.paul at rexconsulting.net (Christopher Paul) Date: Thu, 15 Sep 2022 17:55:44 -0000 Subject: [python-ldap] dirSync control, no Cookie Message-ID: Hello Python-LDAP, I am trying to use python-ldap to LDAPSearch w/the MS DirSync control '1.2.840.113556.1.4.841'. My ldap.controls.LDAPControl ends up looking like this: >>> dirSync.ctrl1.controlType '1.2.840.113556.1.4.841' >>> dirSync.ctrl1.criticality True >>> dirSync.ctrl1.encodedControlValue b'0\x08\x02\x01\x00\x02\x01\x00\x04\x00' This sets flags: 0, maxBytes: 0, with a null Cookie. I get a result using "result4": adldapconn.result4(msgid=ldap.RES_ANY, all=1, add_ctrls=1, add_intermediates=1, add_extop=1, timeout=30) It seems to work in as much as it was able to submit the control and control value to AD (though null cookie), and AD returns the answer with cookie value. The problem is that the result4 contains "None, None" for the 3rd and 4th fields, so I cannot get the cookie. >>> res=dirSync.dirSync() result is (101, [('CN=Jed Tanner,CN=Users,DC=adlab,DC=rexconsulting,DC=net', {'objectGUID': [b't\xfafq\xa6\xa7\xdcI\x8e\xd7\xfe\xde\xdb\xab\xfaa'], 'description': [b'Most Awesome Test User'], 'instanceType': [b'4']}, [])], 2, [], None, None) I tried LDAPObject.extop_result too and get (None, None). So with no cookie, I cannot make my next control value, though I do see it in tcpdump/wireshark, so know that AD is sending it back. Is this a problem with python-ldap or am I doing something wrong? Many thanks, Chris Paul