Adding LDAP OU using Net::LDAP

Posted by lupindeterd on Stack Overflow See other posts from Stack Overflow or by lupindeterd
Published on 2009-12-07T09:17:35Z Indexed on 2010/04/18 18:03 UTC
Read the original article Hit count: 400

Filed under:

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

© Stack Overflow or respective owner

Related posts about perl