On Apr 20, 2010, at 5:09 PM, piet paaltjens wrote: > Hi, > i'm new to Net::LDAP and have difficulty to make Net::LDAP execute an 'add' > or 'modify'. Can somebody point out what i'm doing wrong? > This is my code: > #!d:\perl\bin\perl.exe > > use Data::Dumper; > use Net::LDAP; > > use strict; > > my > ($attr,$ldap,$mesg,$userToAuthenticate,$passwd,@ocs,@atts,@bju_attrs,%add_attrs,%modify_attrs); > > @bju_attrs = qw ( givenName sn physicalDeliveryOfficeName telephoneNumber > streetAddress postOfficeBox l st postalCode c co countryCode homePhone pager > mobile facsimileTelephoneNumber ipPhone title department company manager > directReports); > > $add_attrs { givenName } = "JustaName"; > $modify_attrs {company} = "Roodbms"; > > $userToAuthenticate = $ARGV[0]; > #print STDOUT ("userToAuthenticate= $userToAuthenticate\n"); > $passwd = $ARGV[1]; > #print STDOUT ("passwd= $passwd\n"); > > $ldap = Net::LDAP->new ( "mymachine.mydomain" ) or die "$@"; > > $mesg = $ldap->bind ( "$userToAuthenticate", > password => "$passwd", > version => 3 ); > > print STDOUT ("After: bind\, mesg= \n".Dumper(%$mesg)."\n\n"); > > #my @Attrs = qw( ); # request all available attributes > # to be returned. > > #my $result = LDAPsearch ( $ldap, "sn=ordinary", \...@attrs); > my $result = LDAPsearch ( $ldap, "sn=ordinary", \...@bju_attrs); > print STDOUT ("result= \n".Dumper(%$result)."\n\n"); > print_result_by_entry($result); > # > # Now attempt to add/modify (a) value(s) to/of a DN > # > my $dn = "DC=Roodbms,CN=Users,CN=ordinary"; # This is shown in > LDAPExplorerTool2 > # > # First attempt: ADD > # > foreach $attr (keys %add_attrs) > { > print STDOUT ("Adding attribute: $attr with value: ".$add_attrs{$attr}."\n"); > } > > my $result = LDAPaddUsingHash ( $ldap, $dn, \%add_attrs );
You do not check the result of the add, it probably tells you that you passed a bad DN. actually you do not check any return status, you just dump the object contents. You really should check $result->code $dn = "DC=Roodbms,CN=Users,CN=ordinary"; but as you can tell from your search results, you DN is "CN=ordinary,CN=Users,DC=Roodbms" so I would suggest that LDAPExplorerTool2 is reporting the DN backwards Graham.