2017-03-07 92 views
1

我试图在LDAP中创建用户帐户。用于连接LDAP的示例代码我可以连接到LDAP并在禁用模式下创建用户(UserAccountControl == 514)。当我尝试设置密码或启用帐户。会有错误等服务器不愿意在Active Directory中执行此操作5003

“{ '信息': '0000001F:SvcErr:DSID-031A12D2,问题5003(WILL_NOT_PERFORM),数据0 \ n', '降序': 'Server是不愿意执行'}”

我使用python-ldap库。这里是我的示例代码添加和启用用户帐户

user_attrs['objectclass'] = ['top', 'person', 'organizationalPerson', 'user'] 
    user_attrs['cn'] = username 
    user_attrs['givenName'] = username 
    user_attrs['sn'] = username 
    user_attrs['displayName'] = username 
    user_attrs['userAccountControl'] = '514' 
    user_attrs['mail'] = str(user["email"]) 
    user_attrs['department'] = str(user["department"]) 
    user_ldif = modlist.addModlist(user_attrs) 

    add_pass = [(ldap.MOD_REPLACE, 'unicodePwd', [password])] 
    # 512 will set user account to enabled 
    mod_acct = [(ldap.MOD_REPLACE, 'userAccountControl', '512')] 
    # Add the new user account 
    try: 
     ldap_connection.add_s(user_dn, user_ldif) 
    except ldap.LDAPError, error_message: 
     print "Error adding new user: %s" % error_message 
     return False 

    # Add the password 
    try: 
     ldap_connection.modify_s(user_dn, add_pass) 
    except ldap.LDAPError, error_message: 
     print "Error setting password: %s" % error_message 
     return False 

    # Change the account back to enabled 
    try: 
     ldap_connection.modify_s(user_dn, mod_acct) 
    except ldap.LDAPError, error_message: 
     print "Error enabling user: %s" % error_message 
     return False 
    print "User created %s" % username 

任何人请让我知道是否有任何解决方案或修复。

我在Ubuntu的ldap.conf:

TLS_CACERT /etc/ssl/certs/ca-certificates.crt

回答

相关问题