Python ldap 模块,MOD_DELETE 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用ldap.MOD_DELETE

项目:isam-ansible-roles    作者:IBM-Security    | 项目源码 | 文件源码
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
项目:auth-tool    作者:luciddg    | 项目源码 | 文件源码
def delete_sshpubkey(self, username, sshpubkey):
        """
        Add an sshPublicKey attribute to the user's dn
        """
        dn = 'uid={0},{1}'.format(username, self.base_dn)

        try:
            with self._ldap_connection() as ldap_cxn:
                ldap_cxn.simple_bind_s(self.bind_dn, self.bind_pw)
                mod_list = [(ldap.MOD_DELETE, 'sshPublicKey', str(sshpubkey))]
                ldap_cxn.modify_s(dn, mod_list)

        except (ldap.INVALID_CREDENTIALS, ldap.INSUFFICIENT_ACCESS, ldap.LDAPError) as e:
            self.bus.log('LDAP Error: {0}'.format(e.message['desc'] if 'desc' in e.message else str(e)),
                         level=40,
                         traceback=True)
            raise
项目:Trusted-Platform-Module-nova    作者:BU-NU-CLOUD-SP16    | 项目源码 | 文件源码
def remove_name(self, name):
        names = self.ldap_tuple[1]['associatedDomain']
        if not names:
            raise exception.NotFound()
        if len(names) > 1:
            # We just have to remove the requested domain.
            self.lobj.modify_s(self.dn, [(ldap.MOD_DELETE, 'associatedDomain',
                                        self._qualify(utils.utf8(name)))])
            if (self.rdn[1] == name):
                # We just removed the rdn, so we need to move this entry.
                names.remove(self._qualify(name))
                newrdn = 'dc=%s' % self._dequalify(names[0])
                self.lobj.modrdn_s(self.dn, [newrdn])
        else:
            # We should delete the entire record.
            self.lobj.delete_s(self.dn)
项目:pizza-auth    作者:xxpizzaxx    | 项目源码 | 文件源码
def groupapprove(id, group):
    if ("admin" not in current_user.get_authgroups()) and ("admin-%s" % group not in current_user.get_authgroups()):
        flash("You do not have the right to do that.", "danger")
        return redirect("/groups/admin")
    try:
        id = str(id)
        group = str(group)
        ldaptools.modgroup(id, MOD_DELETE, group+"-pending")
        ldaptools.modgroup(id, MOD_ADD, group)
        flash("Membership of %s approved for %s" % (group, id), "success")
        return redirect("/groups/admin")
    except:
        flash("Membership application not found", "danger")
        return redirect("/groups/admin")
项目:pizza-auth    作者:xxpizzaxx    | 项目源码 | 文件源码
def groupdeny(id, group):
    if ("admin" not in current_user.get_authgroups()) and ("admin-%s" % group not in current_user.get_authgroups()):
        flash("You do not have the right to do that.", "danger")
        return redirect("/groups/admin")
    try:
        id = str(id)
        group = str(group)
        ldaptools.modgroup(id, MOD_DELETE, group+"-pending")
        flash("Membership of %s denied for %s" % (group, id), "success")
        return redirect("/groups/admin")
    except:
        flash("Membership application not found", "danger")
        return redirect("/groups/admin")
项目:pizza-auth    作者:xxpizzaxx    | 项目源码 | 文件源码
def groupremove(id, group):
    if ("admin" not in current_user.get_authgroups()) and ("admin-%s" % group not in current_user.get_authgroups()):
        flash("You do not have the right to do that.", "danger")
        return redirect("/groups/admin")
    id = str(id)
    group = str(group)
    ldaptools.modgroup(id, MOD_DELETE, group)
    flash("Membership of %s removed for %s" % (group, id), "success")
    return redirect("/groups/list/"+group)
项目:pizza-auth    作者:xxpizzaxx    | 项目源码 | 文件源码
def group_remove(group):
    group = str(group)
    ldaptools.modgroup(current_user.get_id() , MOD_DELETE, group)
    flash("Removed %s group" % group, "success")
    return redirect("/groups")
项目:pizza-auth    作者:xxpizzaxx    | 项目源码 | 文件源码
def delete_ts3id(id):
    id = str(id)
    ts3manager.modpermissions(id, remove=True, groupid=app.config["ts3"]["servergroups"]["full"])
    ts3manager.modpermissions(id, remove=True, groupid=app.config["ts3"]["servergroups"]["ally"])
    ldaptools.modts3id(current_user.get_id() , MOD_DELETE, id)
    return redirect("/services")
项目:isam-ansible-roles    作者:IBM-Security    | 项目源码 | 文件源码
def delete(self):
        values_to_delete = filter(self._is_value_present, self.values)

        if len(values_to_delete) > 0:
            modlist = [(ldap.MOD_DELETE, self.name, values_to_delete)]
        else:
            modlist = []

        return modlist