From 5fad7ef128c20d4b5b590de5b9d4d7c54e5a672c Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Thu, 20 Nov 2014 14:39:11 +1000 Subject: [PATCH] * LDV::LDAP->update : finished, but not tested --- lib/LDV/LDAP.pm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/LDV/LDAP.pm b/lib/LDV/LDAP.pm index b40807a..56a7c38 100644 --- a/lib/LDV/LDAP.pm +++ b/lib/LDV/LDAP.pm @@ -109,10 +109,14 @@ sub update { unless ($data); my $dn = sprintf "uid=%s,%s", $uid, $self->{userbase}; - foreach my $key (keys($attrs)) { - ... + while (my ($key, $value) = each(%$attrs)) { + next if ($value and exists $data->{$key}); + delete $attrs->{$key}; } + my $result = $conn->modify($dn, replace => $attrs); + $conn->unbind; + return $result->error if ($result->code); return; } @@ -160,7 +164,10 @@ Get user attributes. Returns HASH on success or undef if not found. =head2 C my $ldap = LDV::LDAP->new(\%opts); + my $err = $ldap->update($user, \%attrs); -TODO +Returns nothing on success or scalar with text on error. +Each key in %attrs must exists for this user's entry. +Empty values will be silently skipped. =cut