Skip to content

Commit

Permalink
simple_bind() accept None for who and cred
Browse files Browse the repository at this point in the history
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 <cheimes@redhat.com>
  • Loading branch information
Christian Heimes committed Jan 10, 2018
1 parent 91438fd commit 9369294
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
9 changes: 7 additions & 2 deletions Doc/reference/ldap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Lib/ldap/ldapobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -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
"""
Expand Down Expand Up @@ -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"""
Expand Down
2 changes: 1 addition & 1 deletion Modules/LDAPObject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions Tests/t_ldapobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9369294

Please sign in to comment.