當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。