openldap - adding group using python-ldap -
i need add group several members. use code below
import ldap import ldap.modlist modlist # open connection l = ldap.initialize("ldap://localhost:389/") # bind/authenticate user apropriate rights add objects l.simple_bind_s("cn=manager,dc=maxcrc,dc=com","secret") # dn of our new entry/object dn="cn=semuafk,ou=group,dc=maxcrc,dc=com" # dict build "body" of object attrs = {} attrs['objectclass'] = ['top','groupofnames'] attrs['member'] = 'cn=user1,ou=people,dc=maxcrc,dc=com' attrs['member'] = 'cn=user2,ou=people,dc=maxcrc,dc=com' attrs['description'] = 'ini group untuk semua dosen dokter' # convert our dict nice syntax add-function using modlist-module ldif = modlist.addmodlist(attrs) # actual synchronous add-operation ldapserver l.add_s(dn,ldif) # nice server disconnect , free resources when done l.unbind_s()
adding member group
attrs['member'] = 'cn=user1,ou=people,dc=maxcrc,dc=com' attrs['member'] = 'cn=user2,ou=people,dc=maxcrc,dc=com'
but result group 1 member. user2 added group. how make group, add several members it
member
multi-valued attribute (just objectclass
). looking @ code, problem seems overwrite value of member
attribute 2nd line. code should this:
attrs['member'] = [ 'cn=users1,ou=people,dc=maxcrc,dc=com', 'cn=users2,ou=people,dc=maxcrc,dc=com' ]`
or
attrs['member'] = [ 'cn=users1,ou=people,dc=maxcrc,dc=com' ] attrs['member'] += 'cn=users2,ou=people,dc=maxcrc,dc=com'
Comments
Post a Comment