我正在調查各種LDAP操作的腳本。不過,我在Active Directory用戶創建中遇到了一些速度緩慢的問題。通過ldapmodify修改Active Directory密碼
dn: CN=Frank,CN=Users,DC=domain,dc=local
changeType: add
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: user
cn: Frank
userPrincipalName: [email protected]
sAMAccountName: frank
givenName: Frank
sn: Stein
displayName: Frank Stein
description: Frankenstein's User
userAccountControl: 512
unicodePwd: "AnExamplePassword1!"
當試圖通過LDIF添加的用戶,我使用了下面的命令:
ldapmodify -H 'ldaps://<ip-of-server>:636' -D 'DOMAIN\Administrator' -x -W -f frank-add.ldif
此失敗
當我在經由ldapmodify
命令加載它下面LDIF失敗以下錯誤:
ldap_add: Server is unwilling to perform (53)
additional info: 0000001F: SvcErr: DSID-031A120C, problem 5003 (WILL_NOT_PERFORM), data 0
這與密碼婆有問題licy拒絕用戶。
但是,下面的Python腳本工作:
#!/usr/bin/python
import ldap
import ldap.modlist as modlist
AD_LDAP_URL='ldaps://<ip-of-server>:636'
ADMIN_USER='DOMAIN\Administrator'
# User must be authorized to create accounts, naturally.
ADMIN_PASSWORD='password for ADMIN_USER'
BASE_DN='dc=domain,dc=local'
username='frank'
firstname='Frank'
surname='Stein'
displayName = "Frank Stein"
password='AnExamplePassword1!'
# The value of password still needs to adhere to the domain's password policy.
unicode_pass = unicode('\"' + password + '\"', 'iso-8859-1')
password_value = unicode_pass.encode('utf-16-le')
l = ldap.initialize(AD_LDAP_URL)
l.simple_bind_s(ADMIN_USER, ADMIN_PASSWORD)
dn=str('CN=%s,CN=Users,DC=domain,dc=local' % firstname)
attrs = {}
attrs['objectclass'] = ['top','person','organizationalPerson','user']
attrs['cn'] = str(username)
attrs['sAMAccountname'] = str(username)
attrs['unicodePwd'] = str(password_value)
attrs['givenName'] = str(firstname)
attrs['sn'] = str(surname)
attrs['displayName'] = str(displayName)
attrs['description'] = str("Frankenstein's User")
attrs['userPrincipalName'] = str("%[email protected]" % username)
attrs['userAccountControl'] = str(512)
ldif = modlist.addModlist(attrs)
l.add_s(dn,ldif)
使用Python腳本,我馬上就能使用用戶的密碼(減去了逃脫了引號)簽署。我仍然可以通過選擇一個像'password'這樣簡單的密碼來觸發相同的「不願意執行」錯誤。但是,在這種情況下,使用的密碼是相同的。
就我所見,操作應該是相同的。打破LDIF文件的區別在於我處理需要將密碼括起來的引號的方式。如果通過將userAccountControl的值設置爲544並且不包含密碼來創建禁用帳戶,則通過LDIF創建將成功。但是,這意味着我需要手動去並重置用戶的密碼。
到目前爲止,我已經通過LDIF嘗試以下密碼格式:
- 沒有引號。
- 簡單的引號。
- 經由通過ASCII \
- 轉義引號轉義引號:{\ 22}
- 使用Python爲Base64編碼的密碼(帶和不帶報價,並與LDIF的修飾以
unicodePwd::
格式)
雖然我很高興我有一個通過Python添加用戶的工作方法,但我仍然對使用LDIF文件時如何正確地跳出密碼值以及ldapmodify
感到困惑。有沒有我不考慮的替代方法?
我試過用引號將密碼編碼,但我的編碼方法必須關閉。我嘗試使用'base64.b64encode(unicode(「\」AnExamplePassword1!\「」))'在Python中對我的密碼進行編碼,產生'IkFuRXhhbXBsZVBhc3N3b3JkMSEi'。我能夠通過LDIF與您的密碼版本成功添加用戶。 – Gadgeteering
通過遵循我的Python腳本更密切地生成密碼的方法,我能夠生成unicodePwd的值。我將一些字符編碼視爲理所當然,因爲它在打印時看起來沒有改變。我經歷了與Python腳本相同的所有步驟,然後使用'base64.b64encode(password_value)'。這給了你我的'IgBB ...'價值。 – Gadgeteering
您是否在創建後測試了密碼? – Damien