[activeldap-discuss] Moving Objects To New Container
Matt Mencel
MR-Mencel at wiu.edu
Fri Apr 16 18:29:09 EDT 2010
I took a look at Alexey's Ruby/LDAP code on github. No idea if this would work....but the PERL examples I've seen put newsuperior before deleteoldrdn in the params list. Just wondering if all it takes is a patch submission?
Thanks,
Matt
# conn.c
/*
* call-seq:
* conn.modrdn(dn, new_rdn, new_superior, delete_old_rdn) => self
*
* Modify the RDN of the entry with DN, +dn+, giving it the new RDN,
* +new_rdn+. Move to a new container if +new_superior+ is given.
* If +delete_old_rdn+ is *true*, the old RDN value will be deleted from
* the entry.
*/
VALUE
rb_ldap_conn_modrdn_s (VALUE self, VALUE dn, VALUE newrdn, , VALUE newsuperior, VALUE delete_p)
{
RB_LDAP_DATA *ldapdata;
char *c_dn;
char *c_newrdn;
char *c_newsuperior;
int c_delete_p;
GET_LDAP_DATA (self, ldapdata);
c_dn = StringValueCStr (dn);
c_newrdn = StringValueCStr (newrdn);
c_newsuperior = StringValueCStr (newsuperior);
c_delete_p = (delete_p == Qtrue) ? 1 : 0;
ldapdata->err = ldap_modrdn2_s (ldapdata->ldap, c_dn, c_newrdn, c_newsuperior, c_delete_p);
Check_LDAP_Result (ldapdata->err);
return self;
};
# conn.c line 1796
# If the number here specifies the number of required params...then it should be 3 and not 4...
# but I wasn't sure exactly what to do except it was related to the number of params.
rb_ldap_conn_define_method ("modrdn", rb_ldap_conn_modrdn_s, 4);
# win/winldap.h line 286
ULONG ldap_modrdn2_s(LDAP *ld, PCHAR olddn, PCHAR newdn, PCHAR newsuperior, int delold_flag);
# rbldap.h line 117
VALUE rb_ldap_conn_modrdn_s (VALUE, VALUE, VALUE, VALUE, VALUE);
----- Original Message -----
From: "Matt Mencel" <MR-Mencel at wiu.edu>
To: ruby-activeldap-discuss at rubyforge.org
Sent: Tuesday, April 13, 2010 2:14:06 PM
Subject: [activeldap-discuss] Moving Objects To New Container
Say I have this object:
user.cn = USERA
user.dn = CN=USERA,OU=OLDOU
...and I want to move this object to a new ou of OU=NEWOU. I see these two methods...
modify_rdn (dn, new_rdn, delete_old_rdn, new_superior, options={})
modify_rdn_entry (dn, new_rdn, delete_old_rdn, new_superior, options={})
Something like this...??
user = User.find("USERA")
user.modify_rdn("CN=USERA,OU=OLDOU", "CN=USERA", true, "OU=NEWOU", {})
user.save
However... modify_rdn gives me...
"undefined method `modify_rdn' for #<User:.....>"
...and modify_rdn_entry gives me...
"not implemented: modify RDN with new superior"
Looks like this is currently not possible with ActiveLdap....or is there another way?
Thanks,
Matt
----- Original Message -----
From: "Richard 3 Nicholas" <NICHOLR3 at uk.ibm.com>
To: ruby-activeldap-discuss at rubyforge.org
Sent: Wednesday, July 16, 2008 12:16:20 PM
Subject: [Ruby-activeldap-discuss] I'm having fun with ActiveLdap::DistinguishedName class...
I want to move an object from its current container into a sub container (ou=toBeDeleted) and this would seem to be the way to do it...
modify_rdn(dn, new_rdn, delete_old_rdn, new_superior, options={})
now, I have the dn. The new rdn, would be "cn=old cn", so that isn't a problem. delete_old_rdn is true, so that isn't a problem. The issue is new_superior. I need to take the cn off the front of the DN, and replace it with the new OU.
I thought it would be great to make use of activeLdap's DistinguishedName handler to save me the problem of rolling my own DistinguishedName parser.
ActiveLdap::DistinguishedName.parse( my_object.dn ) does just what I'd expect. I can then look at the .rdns value and use strip to get rid of the cn on the end. I can add { "ou" => "toBeDeleted" } to the start of the array, but then I can't get the resultant array of hashes back into an ActiveLdap::DistinguishedName type and from there back into a string.
>> arr
=> [{"CN"=>"Computers"}, {"dc"=>"ads"}, {"dc"=>"blah"}, {"dc"=>"com"}]
>> newdn.rdns = arr
NoMethodError: undefined method `rdns=' for #<ActiveLdap::DistinguishedName:0xb292c @rdns=[]>
from (irb):74
>>
>> ActiveLdap::DistinguishedName.new(arr)
=> #<ActiveLdap::DistinguishedName:0x45ae854 @rdns=[[{"CN"=>"Computers"}, {"dc"=>"ads"}, {"dc"=>"blah"}, {"dc"=>"com"}]]>
>> ActiveLdap::DistinguishedName.new(arr).to_s
NoMethodError: undefined method `upcase' for {"CN"=>"Computers"}:Hash
from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/distinguished_name.rb:227:in `to_s'
from (irb):76:in `sort_by'
from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/distinguished_name.rb:226:in `each'
from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/distinguished_name.rb:226:in `sort_by'
from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/distinguished_name.rb:226:in `to_s'
from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/distinguished_name.rb:225:in `collect'
from c:/ruby/lib/ruby/gems/1.8/gems/activeldap-1.0.1/lib/active_ldap/distinguished_name.rb:225:in `to_s'
from (irb):76
>>
The reason that the second method fails is rdns ends up wrapped in another array. The following change would fix the problem, but the behaviour of ActiveLdap::DistinguishedName.new( ["cn","anything"] ) would change....
file: distinguished_name.rb
def initialize(*rdns)
if rdns.size == 1 and rdns[0].is_a?(Array)
rdns = rdns[0]
end
@rdns = rdns.collect do |rdn|
if rdn.is_a?(Array) and rdn.size == 2
{rdn[0] => rdn[1]}
else
rdn
end
end
end
Is there any really easy way to make the parser do what I want?
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
_______________________________________________
Ruby-activeldap-discuss mailing list
Ruby-activeldap-discuss at rubyforge.org
http://rubyforge.org/mailman/listinfo/ruby-activeldap-discuss
_______________________________________________
ruby-activeldap-discuss mailing list
ruby-activeldap-discuss at rubyforge.org
http://rubyforge.org/mailman/listinfo/ruby-activeldap-discuss
More information about the ruby-activeldap-discuss
mailing list