2025-12-25 upload
This commit is contained in:
146
venv/Lib/site-packages/ldap3/extend/standard/PagedSearch.py
Normal file
146
venv/Lib/site-packages/ldap3/extend/standard/PagedSearch.py
Normal file
@@ -0,0 +1,146 @@
|
||||
"""
|
||||
"""
|
||||
|
||||
# Created on 2014.07.08
|
||||
#
|
||||
# Author: Giovanni Cannata
|
||||
#
|
||||
# Copyright 2014 - 2020 Giovanni Cannata
|
||||
#
|
||||
# This file is part of ldap3.
|
||||
#
|
||||
# ldap3 is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# ldap3 is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with ldap3 in the COPYING and COPYING.LESSER files.
|
||||
# If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from ... import SUBTREE, DEREF_ALWAYS
|
||||
from ...utils.dn import safe_dn
|
||||
from ...core.results import DO_NOT_RAISE_EXCEPTIONS, RESULT_SIZE_LIMIT_EXCEEDED
|
||||
from ...core.exceptions import LDAPOperationResult
|
||||
from ...utils.log import log, log_enabled, ERROR, BASIC, PROTOCOL, NETWORK, EXTENDED
|
||||
|
||||
|
||||
def paged_search_generator(connection,
|
||||
search_base,
|
||||
search_filter,
|
||||
search_scope=SUBTREE,
|
||||
dereference_aliases=DEREF_ALWAYS,
|
||||
attributes=None,
|
||||
size_limit=0,
|
||||
time_limit=0,
|
||||
types_only=False,
|
||||
get_operational_attributes=False,
|
||||
controls=None,
|
||||
paged_size=100,
|
||||
paged_criticality=False):
|
||||
if connection.check_names and search_base:
|
||||
search_base = safe_dn(search_base)
|
||||
|
||||
responses = []
|
||||
original_connection = None
|
||||
original_auto_referrals = connection.auto_referrals
|
||||
connection.auto_referrals = False # disable auto referrals because it cannot handle paged searches
|
||||
cookie = True # performs search operation at least one time
|
||||
cachekey = None # for referrals cache
|
||||
while cookie:
|
||||
result = connection.search(search_base,
|
||||
search_filter,
|
||||
search_scope,
|
||||
dereference_aliases,
|
||||
attributes,
|
||||
size_limit,
|
||||
time_limit,
|
||||
types_only,
|
||||
get_operational_attributes,
|
||||
controls,
|
||||
paged_size,
|
||||
paged_criticality,
|
||||
None if cookie is True else cookie)
|
||||
|
||||
if not connection.strategy.sync:
|
||||
response, result = connection.get_response(result)
|
||||
else:
|
||||
if connection.strategy.thread_safe:
|
||||
_, result, response, _ = result
|
||||
else:
|
||||
response = connection.response
|
||||
result = connection.result
|
||||
|
||||
if result['referrals'] and original_auto_referrals: # if rererrals are returned start over the loop with a new connection to the referral
|
||||
if not original_connection:
|
||||
original_connection = connection
|
||||
_, connection, cachekey = connection.strategy.create_referral_connection(result['referrals']) # change connection to a valid referrals
|
||||
continue
|
||||
|
||||
responses.extend(response)
|
||||
try:
|
||||
cookie = result['controls']['1.2.840.113556.1.4.319']['value']['cookie']
|
||||
except KeyError:
|
||||
cookie = None
|
||||
|
||||
if connection.raise_exceptions and result and result['result'] not in DO_NOT_RAISE_EXCEPTIONS:
|
||||
if log_enabled(PROTOCOL):
|
||||
log(PROTOCOL, 'paged search operation result <%s> for <%s>', result, connection)
|
||||
if result['result'] == RESULT_SIZE_LIMIT_EXCEEDED:
|
||||
while responses:
|
||||
yield responses.pop()
|
||||
raise LDAPOperationResult(result=result['result'], description=result['description'], dn=result['dn'], message=result['message'], response_type=result['type'])
|
||||
|
||||
while responses:
|
||||
yield responses.pop()
|
||||
|
||||
if original_connection:
|
||||
connection = original_connection
|
||||
if connection.use_referral_cache and cachekey:
|
||||
connection.strategy.referral_cache[cachekey] = connection
|
||||
else:
|
||||
connection.unbind()
|
||||
|
||||
connection.auto_referrals = original_auto_referrals
|
||||
connection.response = None
|
||||
|
||||
|
||||
def paged_search_accumulator(connection,
|
||||
search_base,
|
||||
search_filter,
|
||||
search_scope=SUBTREE,
|
||||
dereference_aliases=DEREF_ALWAYS,
|
||||
attributes=None,
|
||||
size_limit=0,
|
||||
time_limit=0,
|
||||
types_only=False,
|
||||
get_operational_attributes=False,
|
||||
controls=None,
|
||||
paged_size=100,
|
||||
paged_criticality=False):
|
||||
if connection.check_names and search_base:
|
||||
search_base = safe_dn(search_base)
|
||||
|
||||
responses = []
|
||||
for response in paged_search_generator(connection,
|
||||
search_base,
|
||||
search_filter,
|
||||
search_scope,
|
||||
dereference_aliases,
|
||||
attributes,
|
||||
size_limit,
|
||||
time_limit,
|
||||
types_only,
|
||||
get_operational_attributes,
|
||||
controls,
|
||||
paged_size,
|
||||
paged_criticality):
|
||||
responses.append(response)
|
||||
|
||||
connection.response = responses
|
||||
return responses
|
||||
137
venv/Lib/site-packages/ldap3/extend/standard/PersistentSearch.py
Normal file
137
venv/Lib/site-packages/ldap3/extend/standard/PersistentSearch.py
Normal file
@@ -0,0 +1,137 @@
|
||||
"""
|
||||
"""
|
||||
|
||||
# Created on 2016.07.08
|
||||
#
|
||||
# Author: Giovanni Cannata
|
||||
#
|
||||
# Copyright 2016 - 2020 Giovanni Cannata
|
||||
#
|
||||
# This file is part of ldap3.
|
||||
#
|
||||
# ldap3 is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# ldap3 is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with ldap3 in the COPYING and COPYING.LESSER files.
|
||||
# If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
try:
|
||||
from queue import Empty
|
||||
except ImportError: # Python 2
|
||||
# noinspection PyUnresolvedReferences
|
||||
from Queue import Empty
|
||||
|
||||
from ...core.exceptions import LDAPExtensionError
|
||||
from ...protocol.persistentSearch import persistent_search_control
|
||||
from ... import SEQUENCE_TYPES
|
||||
from ...utils.dn import safe_dn
|
||||
|
||||
|
||||
class PersistentSearch(object):
|
||||
def __init__(self,
|
||||
connection,
|
||||
search_base,
|
||||
search_filter,
|
||||
search_scope,
|
||||
dereference_aliases,
|
||||
attributes,
|
||||
size_limit,
|
||||
time_limit,
|
||||
controls,
|
||||
changes_only,
|
||||
events_type,
|
||||
notifications,
|
||||
streaming,
|
||||
callback
|
||||
):
|
||||
if connection.strategy.sync:
|
||||
raise LDAPExtensionError('Persistent Search needs an asynchronous streaming connection')
|
||||
|
||||
if connection.check_names and search_base:
|
||||
search_base = safe_dn(search_base)
|
||||
|
||||
self.connection = connection
|
||||
self.changes_only = changes_only
|
||||
self.notifications = notifications
|
||||
self.message_id = None
|
||||
self.base = search_base
|
||||
self.filter = search_filter
|
||||
self.scope = search_scope
|
||||
self.dereference_aliases = dereference_aliases
|
||||
self.attributes = attributes
|
||||
self.size_limit = size_limit
|
||||
self.time_limit = time_limit
|
||||
self.connection.strategy.streaming = streaming
|
||||
if callback and callable(callback):
|
||||
self.connection.strategy.callback = callback
|
||||
elif callback:
|
||||
raise LDAPExtensionError('callback is not callable')
|
||||
|
||||
if not isinstance(controls, SEQUENCE_TYPES):
|
||||
self.controls = []
|
||||
else:
|
||||
self.controls = controls
|
||||
|
||||
if events_type and changes_only and notifications:
|
||||
self.controls.append(persistent_search_control(events_type, changes_only, notifications))
|
||||
self.start()
|
||||
|
||||
def start(self):
|
||||
if self.message_id: # persistent search already started
|
||||
return
|
||||
|
||||
if not self.connection.bound:
|
||||
self.connection.bind()
|
||||
|
||||
with self.connection.strategy.async_lock:
|
||||
self.message_id = self.connection.search(search_base=self.base,
|
||||
search_filter=self.filter,
|
||||
search_scope=self.scope,
|
||||
dereference_aliases=self.dereference_aliases,
|
||||
attributes=self.attributes,
|
||||
size_limit=self.size_limit,
|
||||
time_limit=self.time_limit,
|
||||
controls=self.controls)
|
||||
self.connection.strategy.persistent_search_message_id = self.message_id
|
||||
|
||||
def stop(self, unbind=True):
|
||||
self.connection.abandon(self.message_id)
|
||||
if unbind:
|
||||
self.connection.unbind()
|
||||
if self.message_id in self.connection.strategy._responses:
|
||||
del self.connection.strategy._responses[self.message_id]
|
||||
if hasattr(self.connection.strategy, '_requests') and self.message_id in self.connection.strategy._requests: # asynchronous strategy has a dict of request that could be returned by get_response()
|
||||
del self.connection.strategy._requests[self.message_id]
|
||||
self.connection.strategy.persistent_search_message_id = None
|
||||
self.message_id = None
|
||||
|
||||
def next(self, block=False, timeout=None):
|
||||
if not self.connection.strategy.streaming and not self.connection.strategy.callback:
|
||||
try:
|
||||
return self.connection.strategy.events.get(block, timeout)
|
||||
except Empty:
|
||||
return None
|
||||
|
||||
raise LDAPExtensionError('Persistent search is not accumulating events in queue')
|
||||
|
||||
def funnel(self, block=False, timeout=None):
|
||||
done = False
|
||||
while not done:
|
||||
try:
|
||||
entry = self.connection.strategy.events.get(block, timeout)
|
||||
except Empty:
|
||||
yield None
|
||||
if entry['type'] == 'searchResEntry':
|
||||
yield entry
|
||||
else:
|
||||
done = True
|
||||
|
||||
yield entry
|
||||
@@ -0,0 +1,72 @@
|
||||
"""
|
||||
"""
|
||||
|
||||
# Created on 2014.04.30
|
||||
#
|
||||
# Author: Giovanni Cannata
|
||||
#
|
||||
# Copyright 2014 - 2020 Giovanni Cannata
|
||||
#
|
||||
# This file is part of ldap3.
|
||||
#
|
||||
# ldap3 is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# ldap3 is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with ldap3 in the COPYING and COPYING.LESSER files.
|
||||
# If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from ... import HASHED_NONE
|
||||
from ...extend.operation import ExtendedOperation
|
||||
from ...protocol.rfc3062 import PasswdModifyRequestValue, PasswdModifyResponseValue
|
||||
from ...utils.hashed import hashed
|
||||
from ...protocol.sasl.sasl import validate_simple_password
|
||||
from ...utils.dn import safe_dn
|
||||
from ...core.results import RESULT_SUCCESS
|
||||
|
||||
# implements RFC3062
|
||||
|
||||
|
||||
class ModifyPassword(ExtendedOperation):
|
||||
def config(self):
|
||||
self.request_name = '1.3.6.1.4.1.4203.1.11.1'
|
||||
self.request_value = PasswdModifyRequestValue()
|
||||
self.asn1_spec = PasswdModifyResponseValue()
|
||||
self.response_attribute = 'new_password'
|
||||
|
||||
def __init__(self, connection, user=None, old_password=None, new_password=None, hash_algorithm=None, salt=None, controls=None):
|
||||
ExtendedOperation.__init__(self, connection, controls) # calls super __init__()
|
||||
if user:
|
||||
if connection.check_names:
|
||||
user = safe_dn(user)
|
||||
self.request_value['userIdentity'] = user
|
||||
if old_password:
|
||||
if not isinstance(old_password, bytes): # bytes are returned raw, as per RFC (4.2)
|
||||
old_password = validate_simple_password(old_password, True)
|
||||
self.request_value['oldPasswd'] = old_password
|
||||
if new_password:
|
||||
if not isinstance(new_password, bytes): # bytes are returned raw, as per RFC (4.2)
|
||||
new_password = validate_simple_password(new_password, True)
|
||||
if hash_algorithm is None or hash_algorithm == HASHED_NONE:
|
||||
self.request_value['newPasswd'] = new_password
|
||||
else:
|
||||
self.request_value['newPasswd'] = hashed(hash_algorithm, new_password, salt)
|
||||
|
||||
def populate_result(self):
|
||||
try:
|
||||
self.result[self.response_attribute] = str(self.decoded_response['genPasswd'])
|
||||
except TypeError: # optional field can be absent, so returns True if operation is successful else False
|
||||
if self.result['result'] == RESULT_SUCCESS:
|
||||
self.result[self.response_attribute] = True
|
||||
else: # change was not successful, raises exception if raise_exception = True in connection or returns the operation result, error code is in result['result']
|
||||
self.result[self.response_attribute] = False
|
||||
if self.connection.raise_exceptions:
|
||||
from ...core.exceptions import LDAPOperationResult
|
||||
raise LDAPOperationResult(result=self.result['result'], description=self.result['description'], dn=self.result['dn'], message=self.result['message'], response_type=self.result['type'])
|
||||
40
venv/Lib/site-packages/ldap3/extend/standard/whoAmI.py
Normal file
40
venv/Lib/site-packages/ldap3/extend/standard/whoAmI.py
Normal file
@@ -0,0 +1,40 @@
|
||||
"""
|
||||
"""
|
||||
|
||||
# Created on 2014.04.30
|
||||
#
|
||||
# Author: Giovanni Cannata
|
||||
#
|
||||
# Copyright 2014 - 2020 Giovanni Cannata
|
||||
#
|
||||
# This file is part of ldap3.
|
||||
#
|
||||
# ldap3 is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# ldap3 is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with ldap3 in the COPYING and COPYING.LESSER files.
|
||||
# If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# implements RFC4532
|
||||
from ...extend.operation import ExtendedOperation
|
||||
from ...utils.conv import to_unicode
|
||||
|
||||
|
||||
class WhoAmI(ExtendedOperation):
|
||||
def config(self):
|
||||
self.request_name = '1.3.6.1.4.1.4203.1.11.3'
|
||||
self.response_attribute = 'authzid'
|
||||
|
||||
def populate_result(self):
|
||||
try:
|
||||
self.result['authzid'] = to_unicode(self.decoded_response) if self.decoded_response else None
|
||||
except TypeError:
|
||||
self.result['authzid'] = self.decoded_response if self.decoded_response else None
|
||||
Reference in New Issue
Block a user