使用Net :: LDAP添加LDAP OU

时间:2009-12-07 09:17:35

标签: perl

使用Net :: LDAP添加OU的正确语法是什么,我尝试了以下方法:

#!/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;

并收到以下错误:

value of naming attribute 'ou' is not present in entry 64

但是,使用ldapmodify命令行并使用以下ldif,可以使用:

dn: ou=Users,dc=lab,dc=net
changetype: add
objectclass: top
objectclass: organizationalUnit
ou: Users

1 个答案:

答案 0 :(得分:2)

'ou'          => 'dc=Users',

此行需要更改为:

'ou'          => 'Users',