Net-ldap create user with password

I am trying to create an AD account with a password already set using net-ldapgem. I can connect to the server perfectly. And I can also add a new user without passing an attribute :unicodepwd, however, when a new user is created, the password is not set. When I pass this attribute, the user is not created, and it fails with error code 53and the following message Unwilling to perform. I also get the same error if I try to replace the user password after creating it. I came across many potential answers, but none of them worked for me.

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

How to set a password for a user when I create a user and not have access to it through gui to update the password? Any help is appreciated

thank

UPDATE

, - 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

, -

+4
2

Net::LDAP::Password.generate ActiveDirectory. :unicodePwd LDAP-Entry-Attribute ( ruby-gem net-ldap parlance),

unicodepwd = "\"#{plain_text_password}\"".encode(Encoding::UTF_16LE).force_encoding(Encoding::ASCII_8BIT)

. : https://msdn.microsoft.com/en-us/library/cc223248.aspx

+1

, , Net:: LDAP!

Net::LDAP::Password.generate(:md5, 'yourPlaintextPass')

0

Source: https://habr.com/ru/post/1548147/


All Articles