[英]Adding AD group with python-ldap
我試圖在 AD 中創建組但沒有成功,下面是我的代碼:
import ldap
import ldap.modlist as modlist
LDAPserver = 'hidden'
LDAPlogin = 'hidden'
LDAPpassword = 'hidden'
l = ldap.initialize('ldap://' + LDAPserver)
l.simple_bind_s(LDAPlogin, LDAPpassword)
dn = 'OU=someunit,OU=someunit,OU=someunit,OU=someunit,DC=my-company,DC=local'
attrs = {}
attrs['objectclass'] = ['top','Group']
attrs['cn'] = 'group name to be created'
attrs['description'] = 'Test Group'
ldif = modlist.addModlist(attrs)
l.add_s(dn,ldif)
l.unbind_s()
以下片段給了我一個錯誤:
ldap.INSUFFICIENT_ACCESS: {'info': '00000005: SecErr: DSID-031521D0, problem 4003
(INSUFF_ACCESS_RIGHTS), data 0\n', 'desc': 'Insufficient access'}
但是,使用相同的憑據,我可以使用LDAP Admin等一些 UI 工具創建組
所以我想我有適當的權限來創建組,但 python-ldap 仍然沒有成功。
我還可以查詢現有組並通過腳本獲取其成員。
我相信問題出在我的屬性上,也許 Active Directory 需要將一些不同的值插入到attrs變量中。 AD 在 Win Server 2012 R2 下運行。
任何幫助,將不勝感激 :)
dn
實際上應該是CN=<groupname>
+ base_dn
,所以在你的情況下是這樣的
dn = 'CN=groupname,OU=someunit,OU=someunit,OU=someunit,OU=someunit,DC=my-company,DC=local'
請嘗試將LDAPlogin
替換為完整的綁定dn
值,例如
"cn=hidden,dc=example,dc=com"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.