當前位置: 首頁>>代碼示例>>Python>>正文


Python ldap.NO_SUCH_ATTRIBUTE屬性代碼示例

本文整理匯總了Python中ldap.NO_SUCH_ATTRIBUTE屬性的典型用法代碼示例。如果您正苦於以下問題:Python ldap.NO_SUCH_ATTRIBUTE屬性的具體用法?Python ldap.NO_SUCH_ATTRIBUTE怎麽用?Python ldap.NO_SUCH_ATTRIBUTE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在ldap的用法示例。


在下文中一共展示了ldap.NO_SUCH_ATTRIBUTE屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _remove_pubkey

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import NO_SUCH_ATTRIBUTE [as 別名]
def _remove_pubkey(self, dn, pubkey):
        conf = self.conf

        modlist = [(ldap.MOD_DELETE, conf.pubkey_attr, _encode(pubkey))]
        try:
            self._conn.modify_s(dn, modlist)

        except ldap.OBJECT_CLASS_VIOLATION:
            modlist += [(ldap.MOD_DELETE, 'objectClass', _encode(conf.pubkey_class))]
            self._conn.modify_s(dn, modlist)

        except ldap.NO_SUCH_ATTRIBUTE:
            raise NoPubKeyFoundError("No such public key exists: %s." % keyname(pubkey), 1)

        except ldap.INSUFFICIENT_ACCESS:
            raise InsufficientAccessError("No rights to remove key for %s " % dn, 2) 
開發者ID:jirutka,項目名稱:ssh-ldap-pubkey,代碼行數:18,代碼來源:__init__.py

示例2: is_member

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import NO_SUCH_ATTRIBUTE [as 別名]
def is_member(self, ldap_user, group_dn):
        """
        Returns True if the group is the user's primary group or if the user is
        listed in the group's memberUid attribute.
        """
        try:
            user_uid = ldap_user.attrs["uid"][0]

            try:
                is_member = ldap_user.connection.compare_s(
                    group_dn, "memberUid", user_uid.encode()
                )
            except (ldap.UNDEFINED_TYPE, ldap.NO_SUCH_ATTRIBUTE):
                is_member = False

            if not is_member:
                try:
                    user_gid = ldap_user.attrs["gidNumber"][0]
                    is_member = ldap_user.connection.compare_s(
                        group_dn, "gidNumber", user_gid.encode()
                    )
                except (ldap.UNDEFINED_TYPE, ldap.NO_SUCH_ATTRIBUTE):
                    is_member = False
        except (KeyError, IndexError):
            is_member = False

        return is_member 
開發者ID:django-auth-ldap,項目名稱:django-auth-ldap,代碼行數:29,代碼來源:config.py

示例3: _is_value_present

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import NO_SUCH_ATTRIBUTE [as 別名]
def _is_value_present(self, value):
        """ True if the target attribute has the given value. """
        try:
            is_present = bool(
                self.connection.compare_s(self.dn, self.name, value))
        except ldap.NO_SUCH_ATTRIBUTE:
            is_present = False

        return is_present 
開發者ID:IBM-Security,項目名稱:isam-ansible-roles,代碼行數:11,代碼來源:ldap_attr.py

示例4: del_from_groups

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import NO_SUCH_ATTRIBUTE [as 別名]
def del_from_groups(self, username, groups):
        """Delete user from groups"""
        # it follows the same logic than add_to_groups
        # but with MOD_DELETE
        ldap_client = self._bind()
        tmp = self._get_user(self._byte_p2(username), ALL_ATTRS)
        if tmp is None:
            raise UserDoesntExist(username, self.backend_name)
        dn = tmp[0]
        attrs = tmp[1]
        attrs['dn'] = dn
        self._normalize_group_attrs(attrs)
        dn = self._byte_p2(tmp[0])
        for group in groups:
            group = self._byte_p2(group)
            for attr in self.group_attrs:
                content = self._byte_p2(self.group_attrs[attr] % attrs)
                ldif = [(ldap.MOD_DELETE, attr, self._byte_p3(content))]
                try:
                    ldap_client.modify_s(group, ldif)
                except ldap.NO_SUCH_ATTRIBUTE as e:
                    self._logger(
                        severity=logging.INFO,
                        msg="%(backend)s: user '%(user)s'"
                        " wasn't member of group '%(group)s'"
                        " (attribute '%(attr)s')" % {
                            'user': username,
                            'group': self._uni(group),
                            'attr': attr,
                            'backend': self.backend_name
                            }
                    )
                except Exception as e:
                    ldap_client.unbind_s()
                    self._exception_handler(e)
        ldap_client.unbind_s() 
開發者ID:kakwa,項目名稱:ldapcherry,代碼行數:38,代碼來源:backendLdap.py

示例5: increment_attr

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import NO_SUCH_ATTRIBUTE [as 別名]
def increment_attr(self, dn, attr, incr=1, use_increment=True):
        import random
        import time

        if use_increment and \
           self.has_control(OID_LDAP_CONTROL_POSTREAD) and \
           self.has_feature(OID_LDAP_FEATURE_MODIFY_INCREMENT):
            incr = str(incr).encode()
            ctrl = ldap.controls.readentry.PostReadControl(attrList=[attr])
            res = self.conn.modify_ext_s(dn,
                                         [(ldap.MOD_INCREMENT, attr, incr)],
                                         serverctrls=[ctrl])
            for outctrl in res[3]:
                if outctrl.controlType == ctrl.controlType:
                    values = CaseInsensitiveDict(outctrl.entry)[attr]
                    return int(values[0])

        wait = 0
        while True:
            old_val = self.read_attr(dn, attr, raw=True)[0]
            new_val = str(int(old_val) + incr).encode()
            try:
                self.conn.modify_s(dn,
                                   [(ldap.MOD_DELETE, attr, old_val),
                                    (ldap.MOD_ADD, attr, new_val)])
                done = True
            except ldap.NO_SUCH_ATTRIBUTE as e:
                Core.debug("swap (%r, %r) failed: %r", old_val, new_val, e)
                wait += 1
                time.sleep(0.05 * 2**random.randint(0, wait))
            else:
                break
        return int(new_val) 
開發者ID:grawity,項目名稱:code,代碼行數:35,代碼來源:client_libldap.py


注:本文中的ldap.NO_SUCH_ATTRIBUTE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。