@@ -748,7 +748,7 @@ def result4(self,msgid=ldap.RES_ANY,all=1,timeout=None,add_ctrls=0,add_intermedi
748
748
resp_data = self ._bytesify_results (resp_data , with_ctrls = add_ctrls )
749
749
return resp_type , resp_data , resp_msgid , decoded_resp_ctrls , resp_name , resp_value
750
750
751
- def search_ext (self ,base ,scope ,filterstr = '(objectClass=*)' ,attrlist = None ,attrsonly = 0 ,serverctrls = None ,clientctrls = None ,timeout = - 1 ,sizelimit = 0 ):
751
+ def search_ext (self ,base ,scope ,filterstr = None ,attrlist = None ,attrsonly = 0 ,serverctrls = None ,clientctrls = None ,timeout = - 1 ,sizelimit = 0 ):
752
752
"""
753
753
search(base, scope [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0]]]) -> int
754
754
search_s(base, scope [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0]]])
@@ -793,12 +793,24 @@ def search_ext(self,base,scope,filterstr='(objectClass=*)',attrlist=None,attrson
793
793
The amount of search results retrieved can be limited with the
794
794
sizelimit parameter if non-zero.
795
795
"""
796
+
796
797
if PY2 :
797
798
base = self ._bytesify_input ('base' , base )
798
- filterstr = self ._bytesify_input ('filterstr' , filterstr )
799
+ if filterstr is None :
800
+ # workaround for default argument,
801
+ # see https://github.com/python-ldap/python-ldap/issues/147
802
+ if self .bytes_mode :
803
+ filterstr = b'(objectClass=*)'
804
+ else :
805
+ filterstr = u'(objectClass=*)'
806
+ else :
807
+ filterstr = self ._bytesify_input ('filterstr' , filterstr )
799
808
if attrlist is not None :
800
809
attrlist = tuple (self ._bytesify_input ('attrlist' , a )
801
810
for a in attrlist )
811
+ else :
812
+ if filterstr is None :
813
+ filterstr = '(objectClass=*)'
802
814
return self ._ldap_call (
803
815
self ._l .search_ext ,
804
816
base ,scope ,filterstr ,
@@ -808,17 +820,17 @@ def search_ext(self,base,scope,filterstr='(objectClass=*)',attrlist=None,attrson
808
820
timeout ,sizelimit ,
809
821
)
810
822
811
- def search_ext_s (self ,base ,scope ,filterstr = '(objectClass=*)' ,attrlist = None ,attrsonly = 0 ,serverctrls = None ,clientctrls = None ,timeout = - 1 ,sizelimit = 0 ):
823
+ def search_ext_s (self ,base ,scope ,filterstr = None ,attrlist = None ,attrsonly = 0 ,serverctrls = None ,clientctrls = None ,timeout = - 1 ,sizelimit = 0 ):
812
824
msgid = self .search_ext (base ,scope ,filterstr ,attrlist ,attrsonly ,serverctrls ,clientctrls ,timeout ,sizelimit )
813
825
return self .result (msgid ,all = 1 ,timeout = timeout )[1 ]
814
826
815
- def search (self ,base ,scope ,filterstr = '(objectClass=*)' ,attrlist = None ,attrsonly = 0 ):
827
+ def search (self ,base ,scope ,filterstr = None ,attrlist = None ,attrsonly = 0 ):
816
828
return self .search_ext (base ,scope ,filterstr ,attrlist ,attrsonly ,None ,None )
817
829
818
- def search_s (self ,base ,scope ,filterstr = '(objectClass=*)' ,attrlist = None ,attrsonly = 0 ):
830
+ def search_s (self ,base ,scope ,filterstr = None ,attrlist = None ,attrsonly = 0 ):
819
831
return self .search_ext_s (base ,scope ,filterstr ,attrlist ,attrsonly ,None ,None ,timeout = self .timeout )
820
832
821
- def search_st (self ,base ,scope ,filterstr = '(objectClass=*)' ,attrlist = None ,attrsonly = 0 ,timeout = - 1 ):
833
+ def search_st (self ,base ,scope ,filterstr = None ,attrlist = None ,attrsonly = 0 ,timeout = - 1 ):
822
834
return self .search_ext_s (base ,scope ,filterstr ,attrlist ,attrsonly ,None ,None ,timeout )
823
835
824
836
def start_tls_s (self ):
@@ -885,7 +897,7 @@ def set_option(self,option,invalue):
885
897
invalue = RequestControlTuples (invalue )
886
898
return self ._ldap_call (self ._l .set_option ,option ,invalue )
887
899
888
- def search_subschemasubentry_s (self ,dn = '' ):
900
+ def search_subschemasubentry_s (self ,dn = None ):
889
901
"""
890
902
Returns the distinguished name of the sub schema sub entry
891
903
for a part of a DIT specified by dn.
@@ -895,9 +907,17 @@ def search_subschemasubentry_s(self,dn=''):
895
907
896
908
Returns: None or text/bytes depending on bytes_mode.
897
909
"""
910
+ if self .bytes_mode :
911
+ empty_dn = b''
912
+ attrname = b'subschemaSubentry'
913
+ else :
914
+ empty_dn = u''
915
+ attrname = u'subschemaSubentry'
916
+ if dn is None :
917
+ dn = empty_dn
898
918
try :
899
919
r = self .search_s (
900
- dn ,ldap .SCOPE_BASE ,'(objectClass=*)' ,[ 'subschemaSubentry' ]
920
+ dn ,ldap .SCOPE_BASE ,None ,[ attrname ]
901
921
)
902
922
except (ldap .NO_SUCH_OBJECT ,ldap .NO_SUCH_ATTRIBUTE ,ldap .INSUFFICIENT_ACCESS ):
903
923
r = []
@@ -906,11 +926,11 @@ def search_subschemasubentry_s(self,dn=''):
906
926
try :
907
927
if r :
908
928
e = ldap .cidict .cidict (r [0 ][1 ])
909
- search_subschemasubentry_dn = e .get ('subschemaSubentry' ,[None ])[0 ]
929
+ search_subschemasubentry_dn = e .get (attrname ,[None ])[0 ]
910
930
if search_subschemasubentry_dn is None :
911
931
if dn :
912
932
# Try to find sub schema sub entry in root DSE
913
- return self .search_subschemasubentry_s (dn = '' )
933
+ return self .search_subschemasubentry_s (dn = empty_dn )
914
934
else :
915
935
# If dn was already root DSE we can return here
916
936
return None
@@ -930,7 +950,7 @@ def read_s(self,dn,filterstr=None,attrlist=None,serverctrls=None,clientctrls=Non
930
950
r = self .search_ext_s (
931
951
dn ,
932
952
ldap .SCOPE_BASE ,
933
- filterstr or '(objectClass=*)' ,
953
+ filterstr ,
934
954
attrlist = attrlist ,
935
955
serverctrls = serverctrls ,
936
956
clientctrls = clientctrls ,
@@ -945,26 +965,34 @@ def read_subschemasubentry_s(self,subschemasubentry_dn,attrs=None):
945
965
"""
946
966
Returns the sub schema sub entry's data
947
967
"""
968
+ if self .bytes_mode :
969
+ filterstr = b'(objectClass=subschema)'
970
+ if attrs is None :
971
+ attrs = [attr .encode ('utf-8' ) for attr in SCHEMA_ATTRS ]
972
+ else :
973
+ filterstr = u'(objectClass=subschema)'
974
+ if attrs is None :
975
+ attrs = SCHEMA_ATTRS
948
976
try :
949
977
subschemasubentry = self .read_s (
950
978
subschemasubentry_dn ,
951
- filterstr = '(objectClass=subschema)' ,
952
- attrlist = attrs or SCHEMA_ATTRS
979
+ filterstr = filterstr ,
980
+ attrlist = attrs
953
981
)
954
982
except ldap .NO_SUCH_OBJECT :
955
983
return None
956
984
else :
957
985
return subschemasubentry
958
986
959
- def find_unique_entry (self ,base ,scope = ldap .SCOPE_SUBTREE ,filterstr = '(objectClass=*)' ,attrlist = None ,attrsonly = 0 ,serverctrls = None ,clientctrls = None ,timeout = - 1 ):
987
+ def find_unique_entry (self ,base ,scope = ldap .SCOPE_SUBTREE ,filterstr = None ,attrlist = None ,attrsonly = 0 ,serverctrls = None ,clientctrls = None ,timeout = - 1 ):
960
988
"""
961
989
Returns a unique entry, raises exception if not unique
962
990
"""
963
991
r = self .search_ext_s (
964
992
base ,
965
993
scope ,
966
994
filterstr ,
967
- attrlist = attrlist or [ '*' ] ,
995
+ attrlist = attrlist ,
968
996
attrsonly = attrsonly ,
969
997
serverctrls = serverctrls ,
970
998
clientctrls = clientctrls ,
@@ -975,14 +1003,20 @@ def find_unique_entry(self,base,scope=ldap.SCOPE_SUBTREE,filterstr='(objectClass
975
1003
raise NO_UNIQUE_ENTRY ('No or non-unique search result for %s' % (repr (filterstr )))
976
1004
return r [0 ]
977
1005
978
- def read_rootdse_s (self , filterstr = '(objectClass=*)' , attrlist = None ):
1006
+ def read_rootdse_s (self , filterstr = None , attrlist = None ):
979
1007
"""
980
1008
convenience wrapper around read_s() for reading rootDSE
981
1009
"""
1010
+ if self .bytes_mode :
1011
+ base = b''
1012
+ attrlist = attrlist or [b'*' , b'+' ]
1013
+ else :
1014
+ base = u''
1015
+ attrlist = attrlist or [u'*' , u'+' ]
982
1016
ldap_rootdse = self .read_s (
983
- '' ,
1017
+ base ,
984
1018
filterstr = filterstr ,
985
- attrlist = attrlist or [ '*' , '+' ] ,
1019
+ attrlist = attrlist ,
986
1020
)
987
1021
return ldap_rootdse # read_rootdse_s()
988
1022
@@ -991,9 +1025,13 @@ def get_naming_contexts(self):
991
1025
returns all attribute values of namingContexts in rootDSE
992
1026
if namingContexts is not present (not readable) then empty list is returned
993
1027
"""
1028
+ if self .bytes_mode :
1029
+ name = b'namingContexts'
1030
+ else :
1031
+ name = u'namingContexts'
994
1032
return self .read_rootdse_s (
995
- attrlist = ['namingContexts' ]
996
- ).get ('namingContexts' , [])
1033
+ attrlist = [name ]
1034
+ ).get (name , [])
997
1035
998
1036
999
1037
class ReconnectLDAPObject (SimpleLDAPObject ):
0 commit comments