Python implements group (user) functionality in LDAP __python

Source: Internet
Author: User
Tags ldap

Since no group emptied the user's function, the first function to write is three parameters: Group identity, add user, delete user. Feel the interface is not good to use, then found the combination can be, the code is as follows:

    #清除, insert all users in Def update_users (self, groupname, users=[]): "" ":p Aram GroupName: Group name, string type such as" Groupna
        Me "; :p Aram Users: User list, such as addusers [' User1 ', ' User2 ']: return: Note the parameters defined in the function modlist can accept multiple argument lists, where: Mod_add: If the
         Sex exists, this attribute can have multiple values, then the new value is added, the old value is retained Mod_delete: If the value of the property exists, the value will be deleted mod_replace: This attribute all the old values will be deleted, this value is added to the example: [(LDAP. Mod_add, ' memberuid ', ' User1 '), (LDAP. Mod_delete, ' memberuid ', ' User3 ')] "" "modlist = [] If len (users) = 0:modlist.append (LDAP. Mod_replace, ' Memberuid ', "")) for index in range (len (users)): If index = = 0:modlist. Append (LDAP. Mod_replace, ' Memberuid ', str (Users[index])) else:modlist.append (LDAP. Mod_add, ' Memberuid ', str (Users[index])) Try:obj = Self.ldapconn Obj.protocal_version = Ldap. VERSION3 modifyDN = "cn=%s,ou=group,%s"% (GroupnamE, self.base_dn) obj.modify_s (modifyDN, Modlist) obj.unbind_s () return True ex Cept LDAP. Ldaperror, E:print ("%s Update users Failed,reason:%s"% (groupname, str (e))) return False


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.