On 7 Dec 2009, at 11:06, Lupin Deterd wrote:

> On 12/7/09, Chris Ridd <chrisr...@mac.com> wrote:
>> 
>> On 7 Dec 2009, at 09:38, Lupin Deterd wrote:
>> 
>>> Hi,
>>> 
>>> What is the correct syntax of adding an OU using Net::LDAP, I tried
>>> the following:
>>> !/usr/bin/perl -w
>>> 
>>> use 5.10.1; use strict;
>>> 
>>> use Net::LDAP; use Data::Dumper;
>>> 
>>> my $ldap = Net::LDAP->new("192.168.183.2") or die "$@"; my $mesg =
>>> $ldap->bind( "cn=admin,dc=lab,dc=net", password => 'xxx' );
>>> 
>>> $mesg = $ldap->add( "ou=Users,dc=lab,dc=net", attrs => [
>>> 
>>>   'ou'          => 'dc=Users',
>>>   'objectClass' => [ 'top', 'organizationalUnit' ]
>>> ]
>>> 
>>> );
>>> 
>>> say $mesg->error; say $mesg->code;
>>> 
>>> And got the following error:
>>> 
>>> value of naming attribute 'ou' is not present in entry 64
>>> 
>>> However using the ldapmodify command line, and using this following ldif,
>>> works:
>>> 
>>> dn: ou=Users,dc=lab,dc=net changetype: add objectclass: top
>>> objectclass: organizationalUnit ou: Users
>> 
>> In that case, your add call should say:
>> 
>>    'ou' => 'Users',
>> 
>> instead of:
>> 
>>    'ou' => 'dc=Users',
>> 
>> Cheers,
>> 
>> Chris
>> 
> Thanks Chris, it works.

No problem. You should also check that your bind is succeeding. It returns a 
$mesg object (like add does) and you should use its ->code() method in the same 
sort of way to see if it worked.

Cheers,

Chris

Reply via email to