Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
__init__.py335 linesDownload Raw Back to extend
1"""2"""3 4# Created on 2014.04.285#6# Author: Giovanni Cannata7#8# Copyright 2014 - 2020 Giovanni Cannata9#10# This file is part of ldap3.11#12# ldap3 is free software: you can redistribute it and/or modify13# it under the terms of the GNU Lesser General Public License as published14# by the Free Software Foundation, either version 3 of the License, or15# (at your option) any later version.16#17# ldap3 is distributed in the hope that it will be useful,18# but WITHOUT ANY WARRANTY; without even the implied warranty of19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the20# GNU Lesser General Public License for more details.21#22# You should have received a copy of the GNU Lesser General Public License23# along with ldap3 in the COPYING and COPYING.LESSER files.24# If not, see <http://www.gnu.org/licenses/>.25 26from os import linesep27 28from .. import SUBTREE, DEREF_ALWAYS, ALL_ATTRIBUTES, DEREF_NEVER29from .microsoft.dirSync import DirSync30from .microsoft.modifyPassword import ad_modify_password31from .microsoft.unlockAccount import ad_unlock_account32from .microsoft.addMembersToGroups import ad_add_members_to_groups33from .microsoft.removeMembersFromGroups import ad_remove_members_from_groups34from .microsoft.persistentSearch import ADPersistentSearch35from .novell.partition_entry_count import PartitionEntryCount36from .novell.replicaInfo import ReplicaInfo37from .novell.listReplicas import ListReplicas38from .novell.getBindDn import GetBindDn39from .novell.nmasGetUniversalPassword import NmasGetUniversalPassword40from .novell.nmasSetUniversalPassword import NmasSetUniversalPassword41from .novell.startTransaction import StartTransaction42from .novell.endTransaction import EndTransaction43from .novell.addMembersToGroups import edir_add_members_to_groups44from .novell.removeMembersFromGroups import edir_remove_members_from_groups45from .novell.checkGroupsMemberships import edir_check_groups_memberships46from .standard.whoAmI import WhoAmI47from .standard.modifyPassword import ModifyPassword48from .standard.PagedSearch import paged_search_generator, paged_search_accumulator49from .standard.PersistentSearch import PersistentSearch50 51 52class ExtendedOperationContainer(object):53    def __init__(self, connection):54        self._connection = connection55 56    def __repr__(self):57        return linesep.join(['  ' + element for element in dir(self) if element[0] != '_'])58 59    def __str__(self):60        return self.__repr__()61 62 63class StandardExtendedOperations(ExtendedOperationContainer):64    def who_am_i(self, controls=None):65        return WhoAmI(self._connection,66                      controls).send()67 68    def modify_password(self,69                        user=None,70                        old_password=None,71                        new_password=None,72                        hash_algorithm=None,73                        salt=None,74                        controls=None):75 76        return ModifyPassword(self._connection,77                              user,78                              old_password,79                              new_password,80                              hash_algorithm,81                              salt,82                              controls).send()83 84    def paged_search(self,85                     search_base,86                     search_filter,87                     search_scope=SUBTREE,88                     dereference_aliases=DEREF_ALWAYS,89                     attributes=None,90                     size_limit=0,91                     time_limit=0,92                     types_only=False,93                     get_operational_attributes=False,94                     controls=None,95                     paged_size=100,96                     paged_criticality=False,97                     generator=True):98 99        if generator:100            return paged_search_generator(self._connection,101                                          search_base,102                                          search_filter,103                                          search_scope,104                                          dereference_aliases,105                                          attributes,106                                          size_limit,107                                          time_limit,108                                          types_only,109                                          get_operational_attributes,110                                          controls,111                                          paged_size,112                                          paged_criticality)113        else:114            return paged_search_accumulator(self._connection,115                                            search_base,116                                            search_filter,117                                            search_scope,118                                            dereference_aliases,119                                            attributes,120                                            size_limit,121                                            time_limit,122                                            types_only,123                                            get_operational_attributes,124                                            controls,125                                            paged_size,126                                            paged_criticality)127 128    def persistent_search(self,129                          search_base='',130                          search_filter='(objectclass=*)',131                          search_scope=SUBTREE,132                          dereference_aliases=DEREF_NEVER,133                          attributes=ALL_ATTRIBUTES,134                          size_limit=0,135                          time_limit=0,136                          controls=None,137                          changes_only=True,138                          show_additions=True,139                          show_deletions=True,140                          show_modifications=True,141                          show_dn_modifications=True,142                          notifications=True,143                          streaming=True,144                          callback=None145                          ):146        events_type = 0147        if show_additions:148            events_type += 1149        if show_deletions:150            events_type += 2151        if show_modifications:152            events_type += 4153        if show_dn_modifications:154            events_type += 8155 156        if callback:157            streaming = False158        return PersistentSearch(self._connection,159                                search_base,160                                search_filter,161                                search_scope,162                                dereference_aliases,163                                attributes,164                                size_limit,165                                time_limit,166                                controls,167                                changes_only,168                                events_type,169                                notifications,170                                streaming,171                                callback)172 173    def funnel_search(self,174                      search_base='',175                      search_filter='',176                      search_scope=SUBTREE,177                      dereference_aliases=DEREF_NEVER,178                      attributes=ALL_ATTRIBUTES,179                      size_limit=0,180                      time_limit=0,181                      controls=None,182                      streaming=False,183                      callback=None184                      ):185        return PersistentSearch(self._connection,186                                search_base,187                                search_filter,188                                search_scope,189                                dereference_aliases,190                                attributes,191                                size_limit,192                                time_limit,193                                controls,194                                None,195                                None,196                                None,197                                streaming,198                                callback)199 200 201class NovellExtendedOperations(ExtendedOperationContainer):202    def get_bind_dn(self, controls=None):203        return GetBindDn(self._connection,204                         controls).send()205 206    def get_universal_password(self, user, controls=None):207        return NmasGetUniversalPassword(self._connection,208                                        user,209                                        controls).send()210 211    def set_universal_password(self, user, new_password=None, controls=None):212        return NmasSetUniversalPassword(self._connection,213                                        user,214                                        new_password,215                                        controls).send()216 217    def list_replicas(self, server_dn, controls=None):218        return ListReplicas(self._connection,219                            server_dn,220                            controls).send()221 222    def partition_entry_count(self, partition_dn, controls=None):223        return PartitionEntryCount(self._connection,224                                   partition_dn,225                                   controls).send()226 227    def replica_info(self, server_dn, partition_dn, controls=None):228        return ReplicaInfo(self._connection,229                           server_dn,230                           partition_dn,231                           controls).send()232 233    def start_transaction(self, controls=None):234        return StartTransaction(self._connection,235                                controls).send()236 237    def end_transaction(self, commit=True, controls=None):  # attach the groupingControl to commit, None to abort transaction238        return EndTransaction(self._connection,239                              commit,240                              controls).send()241 242    def add_members_to_groups(self, members, groups, fix=True, transaction=True):243        return edir_add_members_to_groups(self._connection,244                                          members_dn=members,245                                          groups_dn=groups,246                                          fix=fix,247                                          transaction=transaction)248 249    def remove_members_from_groups(self, members, groups, fix=True, transaction=True):250        return edir_remove_members_from_groups(self._connection,251                                               members_dn=members,252                                               groups_dn=groups,253                                               fix=fix,254                                               transaction=transaction)255 256    def check_groups_memberships(self, members, groups, fix=False, transaction=True):257        return edir_check_groups_memberships(self._connection,258                                             members_dn=members,259                                             groups_dn=groups,260                                             fix=fix,261                                             transaction=transaction)262 263 264class MicrosoftExtendedOperations(ExtendedOperationContainer):265    def dir_sync(self,266                 sync_base,267                 sync_filter='(objectclass=*)',268                 attributes=ALL_ATTRIBUTES,269                 cookie=None,270                 object_security=False,271                 ancestors_first=True,272                 public_data_only=False,273                 incremental_values=True,274                 max_length=2147483647,275                 hex_guid=False):276        return DirSync(self._connection,277                       sync_base=sync_base,278                       sync_filter=sync_filter,279                       attributes=attributes,280                       cookie=cookie,281                       object_security=object_security,282                       ancestors_first=ancestors_first,283                       public_data_only=public_data_only,284                       incremental_values=incremental_values,285                       max_length=max_length,286                       hex_guid=hex_guid)287 288    def modify_password(self, user, new_password, old_password=None, controls=None):289        return ad_modify_password(self._connection,290                                  user,291                                  new_password,292                                  old_password,293                                  controls)294 295    def unlock_account(self, user):296        return ad_unlock_account(self._connection,297                                 user)298 299    def add_members_to_groups(self, members, groups, fix=True):300        return ad_add_members_to_groups(self._connection,301                                        members_dn=members,302                                        groups_dn=groups,303                                        fix=fix)304 305    def remove_members_from_groups(self, members, groups, fix=True):306        return ad_remove_members_from_groups(self._connection,307                                             members_dn=members,308                                             groups_dn=groups,309                                             fix=fix)310 311    def persistent_search(self,312                          search_base='',313                          search_scope=SUBTREE,314                          attributes=ALL_ATTRIBUTES,315                          streaming=True,316                          callback=None317                          ):318 319        if callback:320            streaming = False321        return ADPersistentSearch(self._connection,322                                  search_base,323                                  search_scope,324                                  attributes,325                                  streaming,326                                  callback)327 328 329class ExtendedOperationsRoot(ExtendedOperationContainer):330    def __init__(self, connection):331        ExtendedOperationContainer.__init__(self, connection)  # calls super332        self.standard = StandardExtendedOperations(self._connection)333        self.novell = NovellExtendedOperations(self._connection)334        self.microsoft = MicrosoftExtendedOperations(self._connection)335 
codekingpro/portable-devtools · Team Ai