我正在尝试使用已使用net-ldap
gem 设置的密码创建一个 AD 帐户。我能够很好地连接到服务器。而且我也可以在不传递:unicodepwd
属性的情况下添加新用户,但是在创建新用户时没有设置密码。当我传递该属性时,不会创建用户并且它失败error code 53
并显示以下消息Unwilling to perform
。如果我在创建用户密码后尝试替换用户密码,也会遇到同样的错误。我遇到了许多潜在的答案,但没有一个对我有用。
def initialize
@client = Net::LDAP.new
@client.host = server_ip
@client.base = base
@client.port = 389
@client.auth(username, password)
if @client.bind
puts "Connected"
add("TEST", "JEST", "testjest")
else
puts "Not Connected"
display_error
end
end
def add(first_name, last_name, username)
dn = dn_value
attrs = {
:objectclass => ["top", "person", "organizationalPerson", "user"],
:cn => fullname(first_name, last_name),
:sn => last_name.capitalize,
:givenname => first_name.capitalize,
:displayname => fullname(first_name, last_name),
:name => fullname(first_name, last_name),
:samaccountname => username,
:unicodePwd => '"password"'.encode("utf-16")
}
@client.add(:dn => dn, :attributes => attrs)
if @client.get_operation_result.code != 0
puts "Failed to add user #{fullname(first_name, last_name)}"
display_error
else
puts "Added user #{fullname(first_name, last_name)}"
end
end
当我创建用户并且不必通过 gui 访问它来更新密码时,如何为用户设置密码?任何帮助表示赞赏
谢谢
更新
一旦我以不同的方式对字符串进行编码并连接到 SSL 端口 636 而不是默认端口 389,我就能够让它工作。使用encode
是问题,似乎它错误地编码了密码。
这是我的新连接
@client = Net::LDAP.new
@client.host = server_ip
@client.base = base
@client.port = 636
@client.encryption(:method => :simple_tls)
@client.auth(username, password)
以及我用来编码密码的方法
def encode_passwd(string)
newstring = ""
string = "\"" + string + "\""
string.split("").each do |c|
newstring = "#{newstring}#{c}\000"
end
return newstring
end
希望这对将来的人有所帮助