예제 #1
0
    def process(self) -> int:
        """ The only public method of this class, call straight after construction, returns an integer that
            can/should be used for the process exit value
        """
        self._check_bind_creds()
        log_item("Connecting to LDAP Server", self.ldap_host_port)

        if self.ldap_log:
            logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
            set_library_log_activation_level(EXTENDED)
            set_library_log_detail_level(EXTENDED)

        set_config_parameter('RESPONSE_WAITING_TIMEOUT', self.ldap_timeout)
        set_config_parameter('IGNORE_MALFORMED_SCHEMA', True)

        server = ldap3.Server(self.ldap_host,
                              port=self.ldap_port,
                              connect_timeout=self.ldap_timeout,
                              get_info=ldap3.ALL,
                              use_ssl=False,
                              tls=None,
                              mode=ldap3.IP_V4_ONLY)

        start = time.time()

        rc = 0
        try:
            rc = self._process_connection(server)
        except LDAPBindError:
            log_error(
                f"Unable to bind using dn: {self.bind_dn} and the given password"
            )
            rc = 3
        except LDAPResponseTimeoutError:
            log_error("Server timed out")
            rc = 4
        except LDAPSocketOpenError:
            log_error(f"Could not connect with {self.ldap_host_port}")
            rc = 5
        except PyAsn1Error as e:
            log_error(f"Could not connect with {self.ldap_host_port}: {e}")
            rc = 6
        except LDAPSocketReceiveError as e:
            log_error(f"LDAP Socket Receive Error: {e}")
            rc = 7

        log_item('Seconds', time.time() - start)
        # activity_iri = self.prov_activity_start(xlsx_iri)
        # self.prov_activity_end(activity_iri)
        log_item("Return Code", rc)
        return rc
예제 #2
0
 def __init__(
     self,
     server_name: str,
     manager_distinguished_name: str,
     manager_password: str,
     suffix: str,
     secure: bool = False,
 ) -> None:
     set_library_log_activation_level(INFO)
     set_library_log_detail_level(EXTENDED)
     self.server_name = server_name
     self.manager_distinguished_name = manager_distinguished_name
     self.manager_password = manager_password
     self.suffix = suffix
     self.secure = secure
     self.connection = None
예제 #3
0
def app_logging_config(app):
    with app.app_context():
        logging.basicConfig(
            level=logging.WARNING,
            format='%(asctime)s - %(name)s - %(levelname)s - %(message).4096s',
            datefmt='%m-%d %H:%M')
        console = logging.StreamHandler(sys.stdout)
        console.setLevel(logging.INFO)
        formatter = logging.Formatter(
            '%(name)-12s: %(levelname)-8s %(message).1028s')
        console.setFormatter(formatter)
        logging.getLogger('').addHandler(console)
        app.logger.setLevel(logging.INFO)

        # ldap3 will emit its log only when you set level=logging.CRITICAL in your log configuration
        set_library_log_activation_level(logging.CRITICAL)
        # set_library_log_detail_level(NETWORK)
        set_library_log_detail_level(OFF)
예제 #4
0
파일: config.py 프로젝트: s0undt3ch/ldap3
    test_ntlm_user = test_domain_name.split('.')[0] + '\\Administrator'
    test_ntlm_password = '******'
    test_logging_filename = join(gettempdir(), 'ldap3.log')
    test_valid_names = ['10.160.201.232']
else:
    raise Exception('testing location ' + location + ' is not valid')

if test_logging:
    try:
        remove(test_logging_filename)
    except OSError:
        pass

    import logging
    logging.basicConfig(filename=test_logging_filename, level=logging.DEBUG)
    set_library_log_activation_level(logging.DEBUG)
    set_library_log_detail_level(test_log_detail)

print('Testing location:', location, ' - Test server:', test_server)
print('Python version:', version, ' - ldap3 version:', ldap3_version)
print('Strategy:', test_strategy, '- Lazy:', test_lazy_connection,
      '- Check names:', test_check_names, '- Collect usage:', test_usage,
      ' - pool size:', test_pool_size)
print('Default client encoding:',
      get_config_parameter('DEFAULT_CLIENT_ENCODING'),
      ' - Default server encoding:',
      get_config_parameter('DEFAULT_SERVER_ENCODING'), '- Source encoding:',
      getdefaultencoding(), '- File encoding:', getfilesystemencoding(),
      ' - Additional server encodings:',
      ', '.join(get_config_parameter('ADDITIONAL_SERVER_ENCODINGS')))
print('Logging:', 'False' if not test_logging else test_logging_filename,
예제 #5
0
'''
Created on Feb 11, 2018

@author: smckinney
@copyright: 2018 - Symas Corporation
'''

from util import Config
import logging
from util.logger import logger
import ldap3
from ldap import LdapException
from ldap3.utils.log import set_library_log_activation_level
set_library_log_activation_level(logging.CRITICAL)
from ldap3.utils.log import set_library_log_detail_level, OFF, ERROR, BASIC, PROTOCOL, NETWORK, EXTENDED


# Open a connection for a particular user:
def open_user(user_dn, password):
    c = _open_user(user_dn, password)
    return c


# Open a connection from the pool with service accounts:
def open():
    c = _open_admin()
    if (_ldap_debug):
        logger.debug(c.usage)
    return c

예제 #6
0
class ADUserAlreadyExists(Exception):
    pass

class ADEmailAlreadyExists(Exception):
    pass

class ADAddFailed(Exception):
    pass

import logging
from ldap3.utils.log import set_library_log_activation_level, set_library_log_detail_level, ERROR, DEBUG, EXTENDED

if app.config['DEBUG']:
    logging.basicConfig(level=logging.DEBUG)
    set_library_log_detail_level(EXTENDED)
    set_library_log_activation_level(logging.DEBUG)
else:
    logging.basicConfig(level=logging.INFO)
    set_library_log_detail_level(ERROR)

# need a better name for this shit
class ActiveDirectoryClient(object):
    def __init__(self):
        self.server_pool = ldap3.ServerPool(
            servers=[ldap3.Server(s, use_ssl=AD_USE_TLS) for s in SERVER_LIST],
            pool_strategy=ldap3.POOLING_STRATEGY_FIRST,
            active=True)
        self.connection = ldap3.Connection(
            self.server_pool,
            user=AD_USER,
            password=AD_PASSWD,