From 9369294db7a8d39f6416b74de61e1596cd309b88 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Wed, 10 Jan 2018 12:09:05 +0100 Subject: [PATCH 1/2] simple_bind() accept None for who and cred sasl_bind_s() has accepted None for who and cred for a long time. Now simple_bind() and simple_bind_s() default to and accept None, too. See: https://github.com/python-ldap/python-ldap/issues/147 Signed-off-by: Christian Heimes --- Doc/reference/ldap.rst | 9 +++++++-- Lib/ldap/ldapobject.py | 6 +++--- Modules/LDAPObject.c | 2 +- Tests/t_ldapobject.py | 8 ++++++++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Doc/reference/ldap.rst b/Doc/reference/ldap.rst index fdd5d356..66434b54 100644 --- a/Doc/reference/ldap.rst +++ b/Doc/reference/ldap.rst @@ -1000,9 +1000,9 @@ and wait for and return with the server's result, or with *serverctrls* and *clientctrls* like described in section :ref:`ldap-controls`. -.. py:method:: LDAPObject.simple_bind([who='' [, cred='' [, serverctrls=None [, clientctrls=None]]]]) -> int +.. py:method:: LDAPObject.simple_bind([who=None [, cred=None [, serverctrls=None [, clientctrls=None]]]]) -> int -.. py:method:: LDAPObject.simple_bind_s([who='' [, cred='' [, serverctrls=None [, clientctrls=None]]]]) -> None +.. py:method:: LDAPObject.simple_bind_s([who=None [, cred=None [, serverctrls=None [, clientctrls=None]]]]) -> None After an LDAP object is created, and before any other operations can be attempted over the connection, a bind operation must be performed. @@ -1015,6 +1015,11 @@ and wait for and return with the server's result, or with *serverctrls* and *clientctrls* like described in section :ref:`ldap-controls`. + .. versionchanged:: 3.0 + + :meth:`~LDAPObject.simple_bind` and :meth:`~LDAPObject.simple_bind_s` + now accept `None` for who and cred, too. + .. py:method:: LDAPObject.search(base, scope [,filterstr='(objectClass=*)' [, attrlist=None [, attrsonly=0]]]) ->int diff --git a/Lib/ldap/ldapobject.py b/Lib/ldap/ldapobject.py index 69431eff..5a80bff7 100644 --- a/Lib/ldap/ldapobject.py +++ b/Lib/ldap/ldapobject.py @@ -406,7 +406,7 @@ def add(self,dn,modlist): def add_s(self,dn,modlist): return self.add_ext_s(dn,modlist,None,None) - def simple_bind(self,who='',cred='',serverctrls=None,clientctrls=None): + def simple_bind(self,who=None,cred=None,serverctrls=None,clientctrls=None): """ simple_bind([who='' [,cred='']]) -> int """ @@ -415,7 +415,7 @@ def simple_bind(self,who='',cred='',serverctrls=None,clientctrls=None): cred = self._bytesify_input('cred', cred) return self._ldap_call(self._l.simple_bind,who,cred,RequestControlTuples(serverctrls),RequestControlTuples(clientctrls)) - def simple_bind_s(self,who='',cred='',serverctrls=None,clientctrls=None): + def simple_bind_s(self,who=None,cred=None,serverctrls=None,clientctrls=None): """ simple_bind_s([who='' [,cred='']]) -> 4-tuple """ @@ -1107,7 +1107,7 @@ def _apply_last_bind(self): func(self,*args,**kwargs) else: # Send explicit anon simple bind request to provoke ldap.SERVER_DOWN in method reconnect() - SimpleLDAPObject.simple_bind_s(self,'','') + SimpleLDAPObject.simple_bind_s(self, None, None) def _restore_options(self): """Restore all recorded options""" diff --git a/Modules/LDAPObject.c b/Modules/LDAPObject.c index addbe961..f8720fa4 100644 --- a/Modules/LDAPObject.c +++ b/Modules/LDAPObject.c @@ -499,7 +499,7 @@ l_ldap_simple_bind( LDAPObject* self, PyObject* args ) LDAPControl** client_ldcs = NULL; struct berval cred; - if (!PyArg_ParseTuple( args, "ss#|OO", &who, &cred.bv_val, &cred_len, &serverctrls, &clientctrls )) return NULL; + if (!PyArg_ParseTuple( args, "zz#|OO", &who, &cred.bv_val, &cred_len, &serverctrls, &clientctrls )) return NULL; cred.bv_len = (ber_len_t) cred_len; if (not_valid(self)) return NULL; diff --git a/Tests/t_ldapobject.py b/Tests/t_ldapobject.py index 243cd86d..27deadcd 100644 --- a/Tests/t_ldapobject.py +++ b/Tests/t_ldapobject.py @@ -401,6 +401,14 @@ def assertIsSubclass(self, cls, other): cls.__mro__ ) + def test_simple_bind_noarg(self): + l = self.ldap_object_class(self.server.ldap_uri) + l.simple_bind_s() + self.assertEqual(l.whoami_s(), u'') + l = self.ldap_object_class(self.server.ldap_uri) + l.simple_bind_s(None, None) + self.assertEqual(l.whoami_s(), u'') + @unittest.skipUnless(PY2, "no bytes_mode under Py3") def test_ldapbyteswarning(self): self.assertIsSubclass(ldap.LDAPBytesWarning, BytesWarning) From a144e3d0b51a5622a228b682d9b9109005c9ecfc Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 10 Jan 2018 12:21:59 +0100 Subject: [PATCH 2/2] ReST syntax fix --- Doc/reference/ldap.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/ldap.rst b/Doc/reference/ldap.rst index 66434b54..9cb1d520 100644 --- a/Doc/reference/ldap.rst +++ b/Doc/reference/ldap.rst @@ -1018,7 +1018,7 @@ and wait for and return with the server's result, or with .. versionchanged:: 3.0 :meth:`~LDAPObject.simple_bind` and :meth:`~LDAPObject.simple_bind_s` - now accept `None` for who and cred, too. + now accept ``None`` for *who* and *cred*, too. .. py:method:: LDAPObject.search(base, scope [,filterstr='(objectClass=*)' [, attrlist=None [, attrsonly=0]]]) ->int pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy