Skip to content

Commit

Permalink
Merge pull request #54 from CobblePot59/patch-1
Browse files Browse the repository at this point in the history
Update connection.py
  • Loading branch information
skelsec authored Nov 29, 2024
2 parents a20d0ca + de14d57 commit 056cd4e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions msldap/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ async def bind(self):
:return: A tuple of (True, None) on success or (False, Exception) on error.
:rtype: (:class:`bool`, :class:`Exception`)
"""
if self.status != MSLDAPClientStatus.CONNECTED:
raise Exception("Connect to the LDAP server before binding.")
logger.debug('BIND in progress...')
try:
if self.credential.protocol == asyauthProtocol.SICILY:
Expand Down Expand Up @@ -647,7 +649,7 @@ async def delete(self, entry:str):
except Exception as e:
return False, e

async def search(self, base:str, query:str, attributes:List[str], search_scope:int = 2, size_limit:int = 1000, types_only:bool = False, derefAliases:int = 0, timeLimit:int = None, controls:List[Control] = None, return_done:bool = False):
async def search(self, base:str, query:str, attributes:List[bytes], search_scope:int = 2, size_limit:int = 1000, types_only:bool = False, derefAliases:int = 0, timeLimit:int = None, controls:List[Control] = None, return_done:bool = False):
"""
Performs the search operation.
Expand All @@ -656,7 +658,7 @@ async def search(self, base:str, query:str, attributes:List[str], search_scope:i
:param query: filter query that defines what should be searched for
:type query: str
:param attributes: a list of attributes to be included in the response
:type attributes: List[str]
:type attributes: List[bytes]
:param search_scope: Specifies the search operation's scope. Default: 2 (Subtree)
:type search_scope: int
:param types_only: indicates whether the entries returned should include attribute types only or both types and values. Default: False (both)
Expand All @@ -675,7 +677,10 @@ async def search(self, base:str, query:str, attributes:List[str], search_scope:i
:return: Async generator which yields (`LDAPMessage`, None) tuple on success or (None, `Exception`) on error
:rtype: Iterator[(:class:`LDAPMessage`, :class:`Exception`)]
"""
if self.status not in [MSLDAPClientStatus.CONNECTED, MSLDAPClientStatus.RUNNING]:
if self.status == MSLDAPClientStatus.CONNECTED:
yield None, Exception('Connected, but not bound.')
return
if self.status != MSLDAPClientStatus.RUNNING:
yield None, Exception('Connection not running! Probably encountered an error')
return
try:
Expand Down Expand Up @@ -728,7 +733,7 @@ async def search(self, base:str, query:str, attributes:List[str], search_scope:i
except Exception as e:
yield (None, e)

async def pagedsearch(self, base:str, query:str, attributes:List[str], search_scope:int = 2, size_limit:int = 1000, typesOnly:bool = False, derefAliases:bool = 0, timeLimit:int = None, controls:List[Control] = None, rate_limit:int = 0):
async def pagedsearch(self, base:str, query:str, attributes:List[bytes], search_scope:int = 2, size_limit:int = 1000, typesOnly:bool = False, derefAliases:bool = 0, timeLimit:int = None, controls:List[Control] = None, rate_limit:int = 0):
"""
Paged search is the same as the search operation and uses it under the hood. Adds automatic control to read all results in a paged manner.
Expand All @@ -737,7 +742,7 @@ async def pagedsearch(self, base:str, query:str, attributes:List[str], search_sc
:param query: filter query that defines what should be searched for
:type query: str
:param attributes: a list of attributes to be included in the response
:type attributes: List[str]
:type attributes: List[bytes]
:param search_scope: Specifies the search operation's scope. Default: 2 (Subtree)
:type search_scope: int
:param types_only: indicates whether the entries returned should include attribute types only or both types and values. Default: False (both)
Expand All @@ -756,6 +761,9 @@ async def pagedsearch(self, base:str, query:str, attributes:List[str], search_sc
:rtype: Iterator[(:class:`dict`, :class:`Exception`)]
"""

if self.status == MSLDAPClientStatus.CONNECTED:
yield None, Exception('Connected, but not bound.')
return
if self.status != MSLDAPClientStatus.RUNNING:
yield None, Exception('Connection not running! Probably encountered an error')
return
Expand Down

0 comments on commit 056cd4e

Please sign in to comment.