Dear Perl LDAP users!
I have some difficulties while trying to update the LDAP entry. I have
looked through the mail archive and I see that this topic is raised
quite often.
Ideally I would like to create an entry, that I would like to use either
for adding or for updating (the choice is not known at the moment of
creation). I see from debug output, that "changetype=add", but I call
$ldap->modify() which should override this...
=== CODE ===
my $entry = Net::LDAP::Entry->new();
my $ldif = Net::LDAP::LDIF->new(\*STDOUT, 'w', 'encode' => 'base64',
'change' => 1);
$entry->add('objectClass' => [ qw(inetOrgPerson mozillaAbPersonAlpha) ]);
# Somehow computed value, $1 = first name, $2 = surname:
$entry->dn("cn=$1 $2");
# These entries only when adding a new entry:
$entry->add(
'givenName' => $1,
'sn' => $2,
'cn' => "$1 $2",
'mail' => $contact->{email}
);
# These entries when adding/updating a new entry:
$entry->replace('mail' => $contact->{email});
$entry->replace('telephoneNumber' => $contact->{'telephone'});
$entry->replace('mobile' => $contact->{'mobile'});
eval { $ldap->search('base' => $entry->dn(), 'filter' => '(cn=*)',
'scope' => 'base', 'sizelimit' => 1) };
if ($@)
{
print "Adding " . $entry->dn() . "\n";
eval { $ldap->add($entry) };
carp $@ if $@;
}
else
{
print "Updating " . $entry->dn() . "\n";
$ldif->write_entry($entry);
$ldap->debug(15);
$ldap->modify($entry);
}
=== END OF CODE ===
=== OUTPUT ===
Updating cn=Dmitry Katsubo,cn=persons,cn=centurion
dn: cn=Dmitry Katsubo,cn=persons,cn=centurion
changetype: add
objectClass: inetOrgPerson
objectClass: mozillaAbPersonAlpha
givenName: Dmitry
sn: Katsubo
cn: Dmitry Katsubo
mail: Dmitry Katsubo <[email protected]>
mobile: +31 65 196-30-34
Net::LDAP=HASH(0x2165c1c) sending:
30 32 02 01 03 66 2D 04 29 63 6E 3D 44 6D 69 74 02...f-.)cn=Dmit
72 79 20 4B 61 74 73 75 62 6F 2C 63 6E 3D 70 65 ry Katsubo,cn=pe
72 73 6F 6E 73 2C 63 6E 3D 63 65 6E 74 75 72 69 rsons,cn=centuri
6F 6E 30 00 __ __ __ __ __ __ __ __ __ __ __ __ on0.
0000 50: SEQUENCE {
0002 1: INTEGER = 3
0005 45: [APPLICATION 6] {
0007 41: STRING = 'cn=Dmitry Katsubo,cn=persons,cn=centurion'
0032 0: SEQUENCE {
0034 : }
0034 : }
0034 : }
Net::LDAP=HASH(0x2165c1c) received:
30 0C 02 01 03 67 07 0A 01 00 04 00 04 00 __ __ 0....g........
0000 12: SEQUENCE {
0002 1: INTEGER = 3
0005 7: [APPLICATION 7] {
0007 1: ENUM = 0
000A 0: STRING = ''
000C 0: STRING = ''
000E : }
000E : }
=== END OF OUTPUT ===
I also tried the following:
$entry->changetype('modify')->update($ldap);
instead of
$ldap->modify($entry);
with no effect (also debug was not shown).
Can somebody give an advice how to update the entry correctly?
Thanks!