Skip to content

simple_bind() accept None for who and cred #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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