简体   繁体   中英

Python ldap3 create group

I am new to python and the ldap3 module. However I want to create a AD group in a specific OU. How can this be done?

# import class and constants
from ldap3 import Server, Connection, ALL

# define the server
s = Server('servername', get_info=ALL)  # define an unsecure LDAP server, 

# define the connection
c = Connection(s, user='user_dn', password='user_password')

ou = "OU=Staff,OU=RU,DC=DOMAIN,DC=LOCAL"
groupname="ADM_Local"
description="local group for access to IPA"

How can I add the group ADM_Local in the defined ou and add the description to the group? The documentation does not say anything about how its done: https://ldap3.readthedocs.io/tutorial_operations.html#create-an-entry

You need to use the groupOfNames structural objectClass (or derived). Note that depending on your ldap server implementation the member attribute may be required to prevent creating empty groups.

groupDN = 'cn=ADM_Local,ou=Staff,ou=RU,dc=domain,dc=local'
objectClass = 'groupOfNames'
attr = {
  'cn': 'ADM_Local',
  'member': 'uid=admin,ou=people,dc=domain,dc=local',
  'description': 'local group for access to IPA'
}

c.add(groupDN , objectClass , attr)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM