How to use the ldap3.utils.log.ERROR function in ldap3

To help you get started, we’ve selected a few ldap3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cannatag / ldap3 / ldap3 / strategy / base.py View on Github external
self.connection.server.update_availability(candidate_address, True)
                        break
                    except Exception as e:
                        self.connection.server.update_availability(candidate_address, False)
                        # exception_history.append((datetime.now(), exc_type, exc_value, candidate_address[4]))
                        exception_history.append((type(e)(str(e)), candidate_address[4]))
                if not self.connection.server.current_address and exception_history:
                    # if len(exception_history) == 1:  # only one exception, reraise
                    #     if log_enabled(ERROR):
                    #         log(ERROR, '<%s> for <%s>', exception_history[0][1](exception_history[0][2]), self.connection)
                    #     raise exception_history[0][1](exception_history[0][2])
                    # else:
                    #     if log_enabled(ERROR):
                    #         log(ERROR, 'unable to open socket for <%s>', self.connection)
                    #     raise LDAPSocketOpenError('unable to open socket', exception_history)
                    if log_enabled(ERROR):
                        log(ERROR, 'unable to open socket for <%s>', self.connection)
                    raise LDAPSocketOpenError('unable to open socket', exception_history)
                elif not self.connection.server.current_address:
                    if log_enabled(ERROR):
                        log(ERROR, 'invalid server address for <%s>', self.connection)
                    raise LDAPSocketOpenError('invalid server address')

            self.connection._deferred_open = False
            self._start_listen()
            # self.connection.do_auto_bind()
            if log_enabled(NETWORK):
                log(NETWORK, 'connection open for <%s>', self.connection)
github cannatag / ldap3 / ldap3 / core / pooling.py View on Github external
continue
                    if log_enabled(NETWORK):
                            log(NETWORK, 'server <%s> reinserted in pool', server_state.server)
                server_state.last_checked_time = datetime.now()
                if log_enabled(NETWORK):
                    log(NETWORK, 'checking server <%s> for availability', server_state.server)
                if server_state.server.check_availability():
                    # returns a random active server in the pool
                    server_state.available = True
                    return self.server_states.index(server_state)
                else:
                    server_state.available = False
            if not isinstance(self.server_pool.active, bool):
                counter -= 1
        if log_enabled(ERROR):
            log(ERROR, 'no random active server available in Server Pool <%s> after maximum number of tries', self)
        raise LDAPServerPoolExhaustedError('no random active server available in server pool after maximum number of tries')
github cannatag / ldap3 / ldap3 / abstract / cursor.py View on Github external
if isinstance(object_def, (STRING_TYPES, SEQUENCE_TYPES)):
            object_def = ObjectDef(object_def, connection.server.schema, auxiliary_class=auxiliary_class)
        self.definition = object_def
        if attributes:  # checks if requested attributes are defined in ObjectDef
            not_defined_attributes = []
            if isinstance(attributes, STRING_TYPES):
                attributes = [attributes]

            for attribute in attributes:
                if attribute not in self.definition._attributes and attribute.lower() not in conf_attributes_excluded_from_object_def:
                    not_defined_attributes.append(attribute)

            if not_defined_attributes:
                error_message = 'Attributes \'%s\' non in definition' % ', '.join(not_defined_attributes)
                if log_enabled(ERROR):
                    log(ERROR, '%s for <%s>', error_message, self)
                raise LDAPCursorError(error_message)

        self.attributes = set(attributes) if attributes else set([attr.name for attr in self.definition])
        self.controls = controls
        self.execution_time = None
        self.entries = []
        self.schema = self.connection.server.schema
        self._do_not_reset = False  # used for refreshing entry in entry_refresh() without removing all entries from the Cursor
        self._operation_history = list()  # a list storing all the requests, results and responses for the last cursor operation
github cannatag / ldap3 / ldap3 / strategy / MockBase.py View on Github external
def entries_from_json(self, json_entry_file):
        target = open(json_entry_file, 'r')
        definition = json.load(target, object_hook=json_hook)
        if 'entries' not in definition:
            self.connection.last_error = 'invalid JSON definition, missing "entries" section'
            if log_enabled(ERROR):
                log(ERROR, '<%s> for <%s>', self.connection.last_error, self.connection)
            raise LDAPDefinitionError(self.connection.last_error)
        if not self.entries:
            self.entries = CaseInsensitiveDict()
        for entry in definition['entries']:
            if 'raw' not in entry:
                self.connection.last_error = 'invalid JSON definition, missing "raw" section'
                if log_enabled(ERROR):
                    log(ERROR, '<%s> for <%s>', self.connection.last_error, self.connection)
                raise LDAPDefinitionError(self.connection.last_error)
            if 'dn' not in entry:
                self.connection.last_error = 'invalid JSON definition, missing "dn" section'
                if log_enabled(ERROR):
                    log(ERROR, '<%s> for <%s>', self.connection.last_error, self.connection)
                raise LDAPDefinitionError(self.connection.last_error)
            self.add_entry(entry['dn'], entry['raw'])
github cannatag / ldap3 / ldap3 / strategy / reusable.py View on Github external
def __init__(self, ldap_connection):
        BaseStrategy.__init__(self, ldap_connection)
        self.sync = False
        self.no_real_dsa = False
        self.pooled = True
        self.can_stream = False
        if hasattr(ldap_connection, 'pool_name') and ldap_connection.pool_name:
            self.pool = ReusableStrategy.ConnectionPool(ldap_connection)
        else:
            if log_enabled(ERROR):
                log(ERROR, 'reusable connection must have a pool_name')
            raise LDAPConnectionPoolNameIsMandatoryError('reusable connection must have a pool_name')
github cannatag / ldap3 / ldap3 / strategy / reusable.py View on Github external
def __init__(self, ldap_connection):
        BaseStrategy.__init__(self, ldap_connection)
        self.sync = False
        self.no_real_dsa = False
        self.pooled = True
        self.can_stream = False
        if hasattr(ldap_connection, 'pool_name') and ldap_connection.pool_name:
            self.pool = ReusableStrategy.ConnectionPool(ldap_connection)
        else:
            if log_enabled(ERROR):
                log(ERROR, 'reusable connection must have a pool_name')
            raise LDAPConnectionPoolNameIsMandatoryError('reusable connection must have a pool_name')
github cannatag / ldap3 / ldap3 / core / tls.py View on Github external
continue
        elif host_name == '*':
            if log_enabled(NETWORK):
                log(NETWORK, 'certificate matches * wildcard')
            return  # valid

        try:
            match_hostname(server_certificate, host_name)  # raise CertificateError if certificate doesn't match server name
            if log_enabled(NETWORK):
                log(NETWORK, 'certificate matches host name <%s>', host_name)
            return  # valid
        except CertificateError as e:
            if log_enabled(NETWORK):
                log(NETWORK, str(e))

    if log_enabled(ERROR):
        log(ERROR, "hostname doesn't match certificate")
    raise LDAPCertificateError("certificate %s doesn't match any name in %s " % (server_certificate, str(host_names)))
github cannatag / ldap3 / ldap3 / core / server.py View on Github external
temp_socket.shutdown(socket.SHUT_RDWR)
                    except socket.error:
                        available = False
                    finally:
                        temp_socket.close()
            except socket.gaierror:
                available = False

            if available:
                if log_enabled(BASIC):
                    log(BASIC, 'server <%s> available at <%r>', self, address)
                self.update_availability(address, True)
                break  # if an available address is found exits immediately
            else:
                self.update_availability(address, False)
                if log_enabled(ERROR):
                    log(ERROR, 'server <%s> not available at <%r>', self, address)

        return available
github cannatag / ldap3 / ldap3 / strategy / restartable.py View on Github external
try:  # reissuing same operation
                    if self.connection.server_pool:
                        new_server = self.connection.server_pool.get_server(self.connection)  # get a server from the server_pool if available
                        if self.connection.server != new_server:
                            self.connection.server = new_server
                            if self.connection.usage:
                                self.connection._usage.servers_from_pool += 1
                    SyncStrategy._open_socket(self, address, use_ssl, unix_socket)  # calls super (not restartable) _open_socket()
                    if self.connection.usage:
                        self.connection._usage.restartable_successes += 1
                    self.connection.closed = False
                    self._restarting = False
                    self._reset_exception_history()
                    return
                except Exception as e:
                    if log_enabled(ERROR):
                        log(ERROR, '<%s> while restarting <%s>', e, self.connection)
                    self._add_exception_to_history(type(e)(str(e)))
                    if self.connection.usage:
                        self.connection._usage.restartable_failures += 1
                if not isinstance(self.restartable_tries, bool):
                    counter -= 1
            self._restarting = False
            self.connection.last_error = 'restartable connection strategy failed while opening socket'
            if log_enabled(ERROR):
                log(ERROR, '<%s> for <%s>', self.connection.last_error, self.connection)
            raise LDAPMaximumRetriesError(self.connection.last_error, self.exception_history, self.restartable_tries)