Re: Unable to ADD or MODIFY entries using NET::LDAP

Graham Barr <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.ldap
Message-ID <[email protected]>
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.