Active Directory LDAP moves user to different OUs - Ruby

I fell into the trap of integrating with Active Directory. I need to be able to move users from one department to another. I use net-ldap 0.5.0, which is located on the main github branch and dug in the source code, and found out that you can do this

$ldap.rename( olddn: "cn=bradford ricechip,ou=agents,ou=ihs,ou=test environment,dc=ctatechs,dc=com", newrdn: "cn=bradford ricechip", new_superior: "ou=coach,ou=ihs,ou=test environment,dc=ctatechs,dc=com" ) 

I get: #<OpenStruct code=53, error_message="00000057: LdapErr: DSID-0C090A95, comment: Old RDN must be deleted, data 0, v1772\x00", matched_dn="", message="Unwilling to perform"> . I think I don’t understand how to remove the old RDN, and then move the user to a new OU.

This is the only question I have. If I need to provide anything else, just let me know. Thanks in advance for your help!

+4
source share
1 answer

Here's how we solved it:

 @ldap.rename( olddn: user.dn, newrdn: "CN=#{user.cn}", delete_attributes: true, new_superior: "#{new_ou}" ) 

We also used the ldap-ruby version on Github, not the RubyGems version.

+2
source

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


All Articles