当前位置: 首页>>代码示例>>Python>>正文


Python ldap.SCOPE_BASE属性代码示例

本文整理汇总了Python中ldap.SCOPE_BASE属性的典型用法代码示例。如果您正苦于以下问题:Python ldap.SCOPE_BASE属性的具体用法?Python ldap.SCOPE_BASE怎么用?Python ldap.SCOPE_BASE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在ldap的用法示例。


在下文中一共展示了ldap.SCOPE_BASE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: exact

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def exact(self):
        try:
            results = self.connection.search_s(
                self.dn, ldap.SCOPE_BASE, attrlist=[self.name])
        except ldap.LDAPError:
            e = get_exception()
            self.module.fail_json(
                msg="Cannot search for attribute %s" % self.name,
                details=str(e))

        current = results[0][1].get(self.name, [])
        modlist = []

        if frozenset(self.values) != frozenset(current):
            if len(current) == 0:
                modlist = [(ldap.MOD_ADD, self.name, self.values)]
            elif len(self.values) == 0:
                modlist = [(ldap.MOD_DELETE, self.name, None)]
            else:
                modlist = [(ldap.MOD_REPLACE, self.name, self.values)]

        return modlist 
开发者ID:IBM-Security,项目名称:isam-ansible-roles,代码行数:24,代码来源:ldap_attr.py

示例2: getDefaultNamingContext

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def getDefaultNamingContext(self):
        try:
            newCon = ldap.initialize('ldap://{}'.format(self.dc_ip))
            newCon.simple_bind_s('', '')
            res = newCon.search_s("", ldap.SCOPE_BASE, '(objectClass=*)')
            rootDSE = res[0][1]
        except ldap.LDAPError as e:
            print("[!] Error retrieving the root DSE")
            print("[!] {}".format(e))
            sys.exit(1)

        if 'defaultNamingContext' not in rootDSE:
            print("[!] No defaultNamingContext found!")
            sys.exit(1)

        defaultNamingContext = rootDSE['defaultNamingContext'][0].decode()

        self.domainBase = defaultNamingContext
        newCon.unbind()
        return defaultNamingContext 
开发者ID:ropnop,项目名称:windapsearch,代码行数:22,代码来源:windapsearch.py

示例3: _ldap_user_search_with_rdn

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def _ldap_user_search_with_rdn(self, conn, username_or_email, user_search_dn, suffix=""):
        query = "(|({0}={2}{3})({1}={2}{3}))".format(
            self._uid_attr, self._email_attr, escape_filter_chars(username_or_email), suffix
        )
        query = self._add_user_filter(query)

        logger.debug("Conducting user search: %s under %s", query, user_search_dn)
        try:
            return (conn.search_s(user_search_dn, ldap.SCOPE_SUBTREE, query), None)
        except ldap.REFERRAL as re:
            referral_dn = self._get_ldap_referral_dn(re)
            if not referral_dn:
                return (None, "Failed to follow referral when looking up username")

            try:
                subquery = "(%s=%s)" % (self._uid_attr, username_or_email)
                subquery = self._add_user_filter(subquery)
                return (conn.search_s(referral_dn, ldap.SCOPE_BASE, subquery), None)
            except ldap.LDAPError:
                logger.debug("LDAP referral search exception")
                return (None, "Username not found")

        except ldap.LDAPError:
            logger.debug("LDAP search exception")
            return (None, "Username not found") 
开发者ID:quay,项目名称:quay,代码行数:27,代码来源:externalldap.py

示例4: _get_fqdn

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def _get_fqdn(self):
        self._log.debug('Grabbing FQDN from LDAP')
        results = self._search(
            'cn=config',
            '(objectClass=*)',
            ['nsslapd-localhost'],
            scope=ldap.SCOPE_BASE
        )

        if not results and type(results) is not list:
            r = None
        else:
            dn, attrs = results[0]
            r = attrs['nsslapd-localhost'][0].decode('utf-8')

        self._log.debug(r)
        return r 
开发者ID:peterpakos,项目名称:checkipaconsistency,代码行数:19,代码来源:freeipaserver.py

示例5: _get_context

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def _get_context(self):
        self._log.debug('Grabbing default context from LDAP')
        results = self._search(
            'cn=config',
            '(objectClass=*)',
            ['nsslapd-defaultnamingcontext'],
            scope=ldap.SCOPE_BASE
        )

        if not results and type(results) is not list:
            r = None
        else:
            dn, attrs = results[0]
            r = attrs['nsslapd-defaultnamingcontext'][0].decode('utf-8')

        self._log.debug(r)
        return r 
开发者ID:peterpakos,项目名称:checkipaconsistency,代码行数:19,代码来源:freeipaserver.py

示例6: _count_users

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def _count_users(self, user_base):
        self._log.debug('Counting %s users...' % user_base)
        results = self._search(
            getattr(self, '_%s_user_base' % user_base),
            '(objectClass=*)',
            ['numSubordinates'],
            scope=ldap.SCOPE_BASE
        )

        if not results and type(results) is not list:
            r = 0
        else:
            dn, attrs = results[0]
            r = attrs['numSubordinates'][0].decode('utf-8')

        self._log.debug(r)
        return r 
开发者ID:peterpakos,项目名称:checkipaconsistency,代码行数:19,代码来源:freeipaserver.py

示例7: _anon_bind

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def _anon_bind(self):
        self._log.debug('Checking for anonymous bind...')
        results = self._search(
            'cn=config',
            '(objectClass=*)',
            ['nsslapd-allow-anonymous-access'],
            scope=ldap.SCOPE_BASE
        )
        dn, attrs = results[0]
        state = attrs['nsslapd-allow-anonymous-access'][0].decode('utf-8')

        if state in ['on', 'off', 'rootdse']:
            r = str(state).upper()
        else:
            r = 'ERROR'

        self._log.debug(r)
        return r 
开发者ID:peterpakos,项目名称:checkipaconsistency,代码行数:20,代码来源:freeipaserver.py

示例8: _load_user_attrs

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def _load_user_attrs(self):
        if self.dn is not None:
            search = LDAPSearch(
                self.dn, ldap.SCOPE_BASE, attrlist=self.settings.USER_ATTRLIST
            )
            results = search.execute(self.connection)

            if results is not None and len(results) > 0:
                self._user_attrs = results[0][1] 
开发者ID:django-auth-ldap,项目名称:django-auth-ldap,代码行数:11,代码来源:backend.py

示例9: test_populate_with_attrlist

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def test_populate_with_attrlist(self, mock):
        self._init_settings(
            USER_DN_TEMPLATE="uid=%(user)s,ou=people,o=test",
            USER_ATTR_MAP={"first_name": "givenName", "last_name": "sn"},
            USER_ATTRLIST=["*", "+"],
        )

        user = authenticate(username="alice", password="password")

        self.assertEqual(user.username, "alice")

        # lookup user attrs
        mock.assert_called_once_with(
            "uid=alice,ou=people,o=test", ldap.SCOPE_BASE, "(objectClass=*)", ["*", "+"]
        ) 
开发者ID:django-auth-ldap,项目名称:django-auth-ldap,代码行数:17,代码来源:tests.py

示例10: _scope_to_ldap_option

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def _scope_to_ldap_option(self, scope):
        """
        Transform scope string into ldap module constant.
        """
        if 'base' in scope.lower():
            opt = ldap.SCOPE_BASE
        elif 'onelevel' in scope.lower():
            opt = ldap.SCOPE_ONELEVEL
        else:
            opt = ldap.SCOPE_SUBTREE
        return opt 
开发者ID:StackStorm,项目名称:st2-auth-backend-ldap,代码行数:13,代码来源:ldap_backend.py

示例11: get_profile

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def get_profile(self, uid, password):
        c = self.connect()
        ldap_result = c.search_s(self.get_user_dn(uid), ldap.SCOPE_BASE)[0][1]
        profile = {}
        profile['uid'] = ldap_result['uid'][0]
        profile['name'] = ldap_result['displayName'][0].decode('utf-8')
        profile['email'] = ldap_result['mail'][0]
        profile['picture'] = ldap_result['jpegPhoto'][0] if ('jpegPhoto' in ldap_result and
                                                             ldap_result['jpegPhoto']) else None
        c.unbind()
        return profile 
开发者ID:Net-ng,项目名称:kansha,代码行数:13,代码来源:ldap_auth.py

示例12: getDefaultNamingContext

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def getDefaultNamingContext(self):
		try:
			newCon = ldap.initialize('ldap://{}'.format(self.dc_ip))
			newCon.simple_bind_s('','')
			res = newCon.search_s("", ldap.SCOPE_BASE, '(objectClass=*)')
			rootDSE = res[0][1]
		except ldap.LDAPError, e:
			print "[!] Error retrieving the root DSE"
			print "[!] {}".format(e)
			sys.exit(1) 
开发者ID:ropnop,项目名称:windapsearch,代码行数:12,代码来源:windapsearch_py2.py

示例13: getFunctionalityLevel

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def getFunctionalityLevel(self):
		objectFilter = '(objectclass=*)'
		attrs = ['domainFunctionality', 'forestFunctionality', 'domainControllerFunctionality']
		try:
			# rawFunctionality = self.do_ldap_query('', ldap.SCOPE_BASE, objectFilter, attrs)
			rawData = self.con.search_s('', ldap.SCOPE_BASE, "(objectclass=*)", attrs)
			functionalityLevels = rawData[0][1]
		except Error, e:
			print "[!] Error retrieving functionality level"
			print "[!] {}".format(e)
			sys.exit(1) 
开发者ID:ropnop,项目名称:windapsearch,代码行数:13,代码来源:windapsearch_py2.py

示例14: getFunctionalityLevel

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def getFunctionalityLevel(self):
        objectFilter = '(objectclass=*)'
        attrs = ['domainFunctionality', 'forestFunctionality', 'domainControllerFunctionality']
        try:
            # rawFunctionality = self.do_ldap_query('', ldap.SCOPE_BASE, objectFilter, attrs)
            rawData = self.con.search_s('', ldap.SCOPE_BASE, "(objectclass=*)", attrs)
            functionalityLevels = rawData[0][1]
        except Error as e:
            print("[!] Error retrieving functionality level")
            print("[!] {}".format(e))
            sys.exit(1)

        return functionalityLevels 
开发者ID:ropnop,项目名称:windapsearch,代码行数:15,代码来源:windapsearch.py

示例15: _find_pubkeys

# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_BASE [as 别名]
def _find_pubkeys(self, dn):
        conf = self.conf
        result = self._conn.search_s(
            dn, ldap.SCOPE_BASE, attrlist=[conf.pubkey_attr])

        return map(_decode, result[0][1].get(conf.pubkey_attr, [])) 
开发者ID:jirutka,项目名称:ssh-ldap-pubkey,代码行数:8,代码来源:__init__.py


注:本文中的ldap.SCOPE_BASE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。