tags:

views:

88

answers:

1

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
A: 
'ou'          => 'dc=Users',

This line needs to be change to:

'ou'          => 'Users',
lupindeterd