Skip to content

Commit 9369294

Browse files
committed
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: #147 Signed-off-by: Christian Heimes <cheimes@redhat.com>
1 parent 91438fd commit 9369294

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

Doc/reference/ldap.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,9 +1000,9 @@ and wait for and return with the server's result, or with
10001000
*serverctrls* and *clientctrls* like described in section :ref:`ldap-controls`.
10011001

10021002

1003-
.. py:method:: LDAPObject.simple_bind([who='' [, cred='' [, serverctrls=None [, clientctrls=None]]]]) -> int
1003+
.. py:method:: LDAPObject.simple_bind([who=None [, cred=None [, serverctrls=None [, clientctrls=None]]]]) -> int
10041004
1005-
.. py:method:: LDAPObject.simple_bind_s([who='' [, cred='' [, serverctrls=None [, clientctrls=None]]]]) -> None
1005+
.. py:method:: LDAPObject.simple_bind_s([who=None [, cred=None [, serverctrls=None [, clientctrls=None]]]]) -> None
10061006
10071007
After an LDAP object is created, and before any other operations can be
10081008
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
10151015

10161016
*serverctrls* and *clientctrls* like described in section :ref:`ldap-controls`.
10171017

1018+
.. versionchanged:: 3.0
1019+
1020+
:meth:`~LDAPObject.simple_bind` and :meth:`~LDAPObject.simple_bind_s`
1021+
now accept `None` for who and cred, too.
1022+
10181023

10191024
.. py:method:: LDAPObject.search(base, scope [,filterstr='(objectClass=*)' [, attrlist=None [, attrsonly=0]]]) ->int
10201025

Lib/ldap/ldapobject.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def add(self,dn,modlist):
406406
def add_s(self,dn,modlist):
407407
return self.add_ext_s(dn,modlist,None,None)
408408

409-
def simple_bind(self,who='',cred='',serverctrls=None,clientctrls=None):
409+
def simple_bind(self,who=None,cred=None,serverctrls=None,clientctrls=None):
410410
"""
411411
simple_bind([who='' [,cred='']]) -> int
412412
"""
@@ -415,7 +415,7 @@ def simple_bind(self,who='',cred='',serverctrls=None,clientctrls=None):
415415
cred = self._bytesify_input('cred', cred)
416416
return self._ldap_call(self._l.simple_bind,who,cred,RequestControlTuples(serverctrls),RequestControlTuples(clientctrls))
417417

418-
def simple_bind_s(self,who='',cred='',serverctrls=None,clientctrls=None):
418+
def simple_bind_s(self,who=None,cred=None,serverctrls=None,clientctrls=None):
419419
"""
420420
simple_bind_s([who='' [,cred='']]) -> 4-tuple
421421
"""
@@ -1107,7 +1107,7 @@ def _apply_last_bind(self):
11071107
func(self,*args,**kwargs)
11081108
else:
11091109
# Send explicit anon simple bind request to provoke ldap.SERVER_DOWN in method reconnect()
1110-
SimpleLDAPObject.simple_bind_s(self,'','')
1110+
SimpleLDAPObject.simple_bind_s(self, None, None)
11111111

11121112
def _restore_options(self):
11131113
"""Restore all recorded options"""

Modules/LDAPObject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ l_ldap_simple_bind( LDAPObject* self, PyObject* args )
499499
LDAPControl** client_ldcs = NULL;
500500
struct berval cred;
501501

502-
if (!PyArg_ParseTuple( args, "ss#|OO", &who, &cred.bv_val, &cred_len, &serverctrls, &clientctrls )) return NULL;
502+
if (!PyArg_ParseTuple( args, "zz#|OO", &who, &cred.bv_val, &cred_len, &serverctrls, &clientctrls )) return NULL;
503503
cred.bv_len = (ber_len_t) cred_len;
504504

505505
if (not_valid(self)) return NULL;

Tests/t_ldapobject.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,14 @@ def assertIsSubclass(self, cls, other):
401401
cls.__mro__
402402
)
403403

404+
def test_simple_bind_noarg(self):
405+
l = self.ldap_object_class(self.server.ldap_uri)
406+
l.simple_bind_s()
407+
self.assertEqual(l.whoami_s(), u'')
408+
l = self.ldap_object_class(self.server.ldap_uri)
409+
l.simple_bind_s(None, None)
410+
self.assertEqual(l.whoami_s(), u'')
411+
404412
@unittest.skipUnless(PY2, "no bytes_mode under Py3")
405413
def test_ldapbyteswarning(self):
406414
self.assertIsSubclass(ldap.LDAPBytesWarning, BytesWarning)

0 commit comments

Comments
 (0)
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