Skip to content

Allow uri and base to be taken from system/user LDAP configuration #164

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions Lib/ldap/asyncsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def __init__(self,l):

def startSearch(
self,
searchRoot,
searchScope,
filterStr,
searchRoot=None,
searchScope=None,
filterStr=None,
attrList=None,
attrsOnly=0,
timeout=-1,
Expand Down
2 changes: 1 addition & 1 deletion Lib/ldap/controls/openldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SearchNoOpMixIn:
for easily using the no-op search control.
"""

def noop_search_st(self,base,scope=ldap.SCOPE_SUBTREE,filterstr='(objectClass=*)',timeout=-1):
def noop_search_st(self,base=None,scope=ldap.SCOPE_SUBTREE,filterstr='(objectClass=*)',timeout=-1):
try:
msg_id = self.search_ext(
base,
Expand Down
5 changes: 3 additions & 2 deletions Lib/ldap/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ def _ldap_function_call(lock,func,*args,**kwargs):
return result


def initialize(uri,trace_level=0,trace_file=sys.stdout,trace_stack_limit=None, bytes_mode=None):
def initialize(uri=None,trace_level=0,trace_file=sys.stdout,trace_stack_limit=None, bytes_mode=None):
"""
Return LDAPObject instance by opening LDAP connection to
LDAP host specified by LDAP URL
LDAP host specified by LDAP URL. If uri is None, use the value
from ldap.conf/.ldaprc.

Parameters:
uri
Expand Down
28 changes: 14 additions & 14 deletions Lib/ldap/ldapobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class SimpleLDAPObject:
}

def __init__(
self,uri,
self,uri=None,
trace_level=0,trace_file=None,trace_stack_limit=5,bytes_mode=None,
bytes_strictness=None,
):
Expand Down Expand Up @@ -769,13 +769,13 @@ def result4(self,msgid=ldap.RES_ANY,all=1,timeout=None,add_ctrls=0,add_intermedi
resp_data = self._bytesify_results(resp_data, with_ctrls=add_ctrls)
return resp_type, resp_data, resp_msgid, decoded_resp_ctrls, resp_name, resp_value

def search_ext(self,base,scope,filterstr=None,attrlist=None,attrsonly=0,serverctrls=None,clientctrls=None,timeout=-1,sizelimit=0):
def search_ext(self,base=None,scope=ldap.SCOPE_SUBTREE,filterstr=None,attrlist=None,attrsonly=0,serverctrls=None,clientctrls=None,timeout=-1,sizelimit=0):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you decide to use subtree here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the more general (for searches) and is more common in examples.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The chief example of an interface with a default for scope is ldapsearch and it picks -s sub, so this is being consistent.

"""
search(base, scope [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0]]]) -> int
search_s(base, scope [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0]]])
search_st(base, scope [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,timeout=-1]]]])
search_ext(base,scope,[,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,serverctrls=None [,clientctrls=None [,timeout=-1 [,sizelimit=0]]]]]]])
search_ext_s(base,scope,[,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,serverctrls=None [,clientctrls=None [,timeout=-1 [,sizelimit=0]]]]]]])
search([base=None, [scope=ldap.SCOPE_SUBTREE, [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0]]]]]) -> int
search_s([base=None, [scope=ldap.SCOPE_SUBTREE, [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0]]]]])
search_st([base=None, [scope=ldap.SCOPE_SUBTREE, [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,timeout=-1]]]]]])
search_ext([base=None, [scope=ldap.SCOPE_SUBTREE, [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,serverctrls=None [,clientctrls=None [,timeout=-1 [,sizelimit=0]]]]]]]]])
search_ext_s([base=None, [scope=ldap.SCOPE_SUBTREE, [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,serverctrls=None [,clientctrls=None [,timeout=-1 [,sizelimit=0]]]]]]]]])

Perform an LDAP search operation, with base as the DN of
the entry at which to start the search, scope being one of
Expand Down Expand Up @@ -841,17 +841,17 @@ def search_ext(self,base,scope,filterstr=None,attrlist=None,attrsonly=0,serverct
timeout,sizelimit,
)

def search_ext_s(self,base,scope,filterstr=None,attrlist=None,attrsonly=0,serverctrls=None,clientctrls=None,timeout=-1,sizelimit=0):
def search_ext_s(self,base=None,scope=ldap.SCOPE_SUBTREE,filterstr=None,attrlist=None,attrsonly=0,serverctrls=None,clientctrls=None,timeout=-1,sizelimit=0):
msgid = self.search_ext(base,scope,filterstr,attrlist,attrsonly,serverctrls,clientctrls,timeout,sizelimit)
return self.result(msgid,all=1,timeout=timeout)[1]

def search(self,base,scope,filterstr=None,attrlist=None,attrsonly=0):
def search(self,base=None,scope=ldap.SCOPE_SUBTREE,filterstr=None,attrlist=None,attrsonly=0):
return self.search_ext(base,scope,filterstr,attrlist,attrsonly,None,None)

def search_s(self,base,scope,filterstr=None,attrlist=None,attrsonly=0):
def search_s(self,base=None,scope=ldap.SCOPE_SUBTREE,filterstr=None,attrlist=None,attrsonly=0):
return self.search_ext_s(base,scope,filterstr,attrlist,attrsonly,None,None,timeout=self.timeout)

def search_st(self,base,scope,filterstr=None,attrlist=None,attrsonly=0,timeout=-1):
def search_st(self,base=None,scope=ldap.SCOPE_SUBTREE,filterstr=None,attrlist=None,attrsonly=0,timeout=-1):
return self.search_ext_s(base,scope,filterstr,attrlist,attrsonly,None,None,timeout)

def start_tls_s(self):
Expand Down Expand Up @@ -962,7 +962,7 @@ def search_subschemasubentry_s(self,dn=None):
except IndexError:
return None

def read_s(self,dn,filterstr=None,attrlist=None,serverctrls=None,clientctrls=None,timeout=-1):
def read_s(self,dn=None,filterstr=None,attrlist=None,serverctrls=None,clientctrls=None,timeout=-1):
"""
Reads and returns a single entry specified by `dn'.

Expand Down Expand Up @@ -1005,7 +1005,7 @@ def read_subschemasubentry_s(self,subschemasubentry_dn,attrs=None):
else:
return subschemasubentry

def find_unique_entry(self,base,scope=ldap.SCOPE_SUBTREE,filterstr=None,attrlist=None,attrsonly=0,serverctrls=None,clientctrls=None,timeout=-1):
def find_unique_entry(self,base=None,scope=ldap.SCOPE_SUBTREE,filterstr=None,attrlist=None,attrsonly=0,serverctrls=None,clientctrls=None,timeout=-1):
"""
Returns a unique entry, raises exception if not unique
"""
Expand Down Expand Up @@ -1077,7 +1077,7 @@ class ReconnectLDAPObject(SimpleLDAPObject):
}

def __init__(
self,uri,
self,uri=None,
trace_level=0,trace_file=None,trace_stack_limit=5,bytes_mode=None,
bytes_strictness=None, retry_max=1, retry_delay=60.0
):
Expand Down
2 changes: 1 addition & 1 deletion Lib/ldap/syncrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ class SyncreplConsumer:
SyncreplConsumer - LDAP syncrepl consumer object.
"""

def syncrepl_search(self, base, scope, mode='refreshOnly', cookie=None, **search_args):
def syncrepl_search(self, base=None, scope=None, mode='refreshOnly', cookie=None, **search_args):
"""
Starts syncrepl search operation.

Expand Down
2 changes: 1 addition & 1 deletion Modules/LDAPObject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ l_ldap_search_ext(LDAPObject *self, PyObject *args)
int msgid;
int ldaperror;

if (!PyArg_ParseTuple(args, "sis|OiOOdi:search_ext",
if (!PyArg_ParseTuple(args, "zis|OiOOdi:search_ext",
&base, &scope, &filter, &attrlist, &attrsonly,
&serverctrls, &clientctrls, &timeout, &sizelimit))
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion Modules/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ l_ldap_initialize(PyObject *unused, PyObject *args)
LDAP *ld = NULL;
int ret;

if (!PyArg_ParseTuple(args, "s:initialize", &uri))
if (!PyArg_ParseTuple(args, "z:initialize", &uri))
return NULL;

Py_BEGIN_ALLOW_THREADS ret = ldap_initialize(&ld, uri);
Expand Down
2 changes: 1 addition & 1 deletion Tests/t_ldapobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_reject_bytes_base(self):
elif sys.version_info >= (3, 5, 0):
# Python 3.4.x does not include 'search_ext()' in message
self.assertEqual(
"search_ext() argument 1 must be str, not bytes",
"search_ext() argument 1 must be str or None, not bytes",
text_type(e.exception)
)

Expand Down