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 を介してアクセスする必要がないようにするにはどうすればよいですか? どんな助けでも大歓迎です
ありがとう
アップデート
文字列を別の方法でエンコードし、デフォルトのポート 389 ではなく SSL ポート 636 に接続すると、これを機能させることができました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
これが将来誰かに役立つことを願っています