def ldap_search(self, filter, attributes):
        """
        Query the configured LDAP server with the provided search
        filter and attribute list. Returns a list of the results
        returned.
        """
        uri = getattr(settings, 'LDAP_SYNC_URI', None)
        if not uri:
            error_msg = ("LDAP_SYNC_URI must be specified in your Django "
                         "settings file")
            raise ImproperlyConfigured(error_msg)

        base_user = getattr(settings, 'LDAP_SYNC_BASE_USER', None)
        if not base_user:
            error_msg = ("LDAP_SYNC_BASE_USER must be specified in your "
                         "Django settings file")
            raise ImproperlyConfigured(error_msg)

        base_pass = getattr(settings, 'LDAP_SYNC_BASE_PASS', None)
        if not base_pass:
            error_msg = ("LDAP_SYNC_BASE_PASS must be specified in your "
                         "Django settings file")
            raise ImproperlyConfigured(error_msg)

        base = getattr(settings, 'LDAP_SYNC_BASE', None)
        if not base:
            error_msg = ("LDAP_SYNC_BASE must be specified in your Django "
                         "settings file")
            raise ImproperlyConfigured(error_msg)

        ldap.set_option(ldap.OPT_REFERRALS, 0)
        l = PagedLDAPObject(uri)
        l.protocol_version = 3
        try:
            l.simple_bind_s(base_user, base_pass)
        except ldap.LDAPError:
            logger.error("Error connecting to LDAP server %s" % uri)
            raise

        results = l.paged_search_ext_s(base,
                                       ldap.SCOPE_SUBTREE,
                                       filter,
                                       attrlist=attributes,
                                       serverctrls=None)
        l.unbind_s()
        return results
dataset/ETHPy150Open jbittel/django-ldap-sync/ldap_sync/management/commands/syncldap.py/Command.ldap_search/original