【问题标题】:add user to active directory by ldap python通过 ldap python 将用户添加到活动目录
【发布时间】:2018-05-25 11:30:43
【问题描述】:

我编写了以下代码,用于将用户添加到 Active Directory 2012。
我使用pycharmpython3.5 但我收到了这个错误:

{'info': '000020D6: SvcErr: DSID-0310081B, problem 5012 (DIR_ERROR), data 0\n', 'desc': 'Operations error'}

我的代码如下:

server = 'ldap://31.184.132.39:389'
ldap_pass = 'function92'
ldap_bind = 'ou=DaaSUsers,dc=xaas,dc=local'

def create_user_activedirectory(username , password , name ):
    username = str(username)
    password=str(password)
    name=str(name)
    con = ldap.initialize(server)
    con.simple_bind_s("administrator@xaas.local", "function92")
    dn = "cn="+username+", ou=DaaSUsers, o=XaaS.local"
    mymodlist = {
         "objectClass": ["account".encode('utf-8'), "posixAccount".encode('utf-8'), "shadowAccount" .encode('utf-8')],
        #"objectClass": [str("inetOrgPerson").encode('utf-8')],
        "cn":[str(name).encode('utf-8')],
        "uid": [str(username).encode('utf-8')],
        "uidNumber": [str("5025").encode('utf-8')],
        "gidNumber": [str("30033").encode('utf-8')],
        "homeDirectory": [str("/home/"+name).encode('utf-8')],
        "loginShell": ["/bin/bash".encode('utf-8')],
        "gecos" : [str(username).encode('utf-8')],
        "userPassword": [password.encode('utf-8')] ,
        "shadowLastChange": [str("0").encode('utf-8')],
        "shadowMax": [str("0").encode('utf-8')],
        "shadowWarning": [str("0").encode('utf-8')],
        "sn": ["De Paepe".encode('utf8')],
        "givenName": ["Maarten".encode('utf8')],
        "displayName": ["Maarten De Paepe".encode('utf8')],
    }
    con.add_s(dn,ldap.modlist.addModlist(mymodlist))
    con.unbind_s()

请帮帮我。

【问题讨论】:

    标签: python python-3.x active-directory ldap


    【解决方案1】:

    该错误通常意味着它不喜欢您提供的某些值。以下是我注意到的几件事,但可能不是全部:

    1. objectClass。这些类在您的域中实际上有效吗?是否有任何现有的用户帐户具有这些类?用户对象的默认类通常是“organizationalPerson”、“person”、“top”和“user”。大多数情况下,您不需要自己实际设置此属性。

    2. 我没有看到你设置 sAMAccountNameuserPrincipalName。这些是必需的属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-02
      • 1970-01-01
      • 1970-01-01
      • 2010-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多