当前位置: 首页>>代码示例>>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;未经允许,请勿转载。