无法使用 net-ldap 启用活动目录用户
Cannot enable active directory user using net-ldap
我们在尝试使用 net/ldap
库启用活动目录用户 (windows server 2012 r2
) 时遇到问题。
设置
首先,我们通过这个方法创建一个用户:
def create_user(attrs)
dn = "cn=#{attrs[:cn]},cn=Users,#{@base}"
cn = attrs[:cn]
pass = ascii_convert(attrs[:pwd])
updated_attrs = { cn: cn,
objectclass: ['user'],
samaccountname: cn,
userprincipalname: "#{attrs[:cn]}@#{@domain}",
unicodepwd: pass
}
@connection.add(dn: dn, attributes: updated_attrs)
result = @connection.get_operation_result
raise LdapError.new("Create AD user error: #{result}") if result.code != 0
end
这会创建用户,默认情况下将其 userAccountControl
属性设置为 546
(这是我们想要的),在活动目录中检查时显示为:
0x222 (ACCOUNTDISABLE|PASSWD_NOTREQD|NORMAL_ACCOUNT)
.
问题
稍后我们要启用该用户,因此我们调用:
def enable_user!(dn, cn)
u = search_query(find_user(cn)).try(:first)
if u
@connection.replace_attribute(dn, :useraccountcontrol, '512')
else
false
end
end
但是,如果我打印 @connection.get_operation_result
,我得到:
<OpenStruct code=53, error_message="0000052D: SvcErr: DSID-031A12D2, problem 5003 (WILL_NOT_PERFORM), data 0\n\u0000", matched_dn="", message="Unwilling to perform">
使用此方法,我们希望 userAccountControl
等于 512
,这相当于 0x200 (NORMAL_ACCOUNT)
.
我尝试过的事情
注意:连接是通过 SSL (LDAPS) 进行的,并且绑定到管理员 AD 帐户。
- this answer
- 在
enable_user!
方法中使用 #modify
而不是 #replace_attribute
。
- 传递十六进制值而不是整数表示。
- 使用 apache directory studio 执行相同的修改。
我注意到一件有趣的事,我可以将 useraccountcontrol
修改为 514
,即:
0x202 (ACCOUNTDISABLE|NORMAL_ACCOUNT)
所以,看来我可以修改这个属性,只要它保持禁用状态,当我尝试更改为启用时,就会看到错误。
错误 0000052D
是 system error code。具体来说就是:
ERROR_PASSWORD_RESTRICTION
1325 (0x52D)
Unable to update the password. The value provided for the new password does not meet the length, complexity, or history requirements of the domain.
问题似乎是您启用的帐户应用了密码策略,因此启用它时密码策略将无法满足。
我会先弄清楚该帐户的密码策略是什么,然后将密码设置为符合该策略标准的内容,然后再翻转位以启用它。
但是,如果您确实希望用户无需密码即可登录,则应将密码设置为空。但我不确定在什么情况下是可取的。
我们在尝试使用 net/ldap
库启用活动目录用户 (windows server 2012 r2
) 时遇到问题。
设置
首先,我们通过这个方法创建一个用户:
def create_user(attrs)
dn = "cn=#{attrs[:cn]},cn=Users,#{@base}"
cn = attrs[:cn]
pass = ascii_convert(attrs[:pwd])
updated_attrs = { cn: cn,
objectclass: ['user'],
samaccountname: cn,
userprincipalname: "#{attrs[:cn]}@#{@domain}",
unicodepwd: pass
}
@connection.add(dn: dn, attributes: updated_attrs)
result = @connection.get_operation_result
raise LdapError.new("Create AD user error: #{result}") if result.code != 0
end
这会创建用户,默认情况下将其 userAccountControl
属性设置为 546
(这是我们想要的),在活动目录中检查时显示为:
0x222 (ACCOUNTDISABLE|PASSWD_NOTREQD|NORMAL_ACCOUNT)
.
问题
稍后我们要启用该用户,因此我们调用:
def enable_user!(dn, cn)
u = search_query(find_user(cn)).try(:first)
if u
@connection.replace_attribute(dn, :useraccountcontrol, '512')
else
false
end
end
但是,如果我打印 @connection.get_operation_result
,我得到:
<OpenStruct code=53, error_message="0000052D: SvcErr: DSID-031A12D2, problem 5003 (WILL_NOT_PERFORM), data 0\n\u0000", matched_dn="", message="Unwilling to perform">
使用此方法,我们希望 userAccountControl
等于 512
,这相当于 0x200 (NORMAL_ACCOUNT)
.
我尝试过的事情
注意:连接是通过 SSL (LDAPS) 进行的,并且绑定到管理员 AD 帐户。
- this answer
- 在
enable_user!
方法中使用#modify
而不是#replace_attribute
。 - 传递十六进制值而不是整数表示。
- 使用 apache directory studio 执行相同的修改。
我注意到一件有趣的事,我可以将 useraccountcontrol
修改为 514
,即:
0x202 (ACCOUNTDISABLE|NORMAL_ACCOUNT)
所以,看来我可以修改这个属性,只要它保持禁用状态,当我尝试更改为启用时,就会看到错误。
错误 0000052D
是 system error code。具体来说就是:
ERROR_PASSWORD_RESTRICTION
1325 (0x52D)
Unable to update the password. The value provided for the new password does not meet the length, complexity, or history requirements of the domain.
问题似乎是您启用的帐户应用了密码策略,因此启用它时密码策略将无法满足。
我会先弄清楚该帐户的密码策略是什么,然后将密码设置为符合该策略标准的内容,然后再翻转位以启用它。
但是,如果您确实希望用户无需密码即可登录,则应将密码设置为空。但我不确定在什么情况下是可取的。