|
|
@ -111,13 +111,25 @@ sub update { |
|
|
|
unless ($data); |
|
|
|
unless ($data); |
|
|
|
|
|
|
|
|
|
|
|
my $dn = sprintf "uid=%s,%s", $uid, $self->{userbase}; |
|
|
|
my $dn = sprintf "uid=%s,%s", $uid, $self->{userbase}; |
|
|
|
my %upd = (); |
|
|
|
my %allowed = map { $_ => 1 } @{$self->{defattrs}}; |
|
|
|
|
|
|
|
my @chg = (); |
|
|
|
while (my ($key, $value) = each(%$attrs)) { |
|
|
|
while (my ($key, $value) = each(%$attrs)) { |
|
|
|
next unless ($value and exists $data->{$key}); |
|
|
|
next unless exists $allowed{$key}; |
|
|
|
next if ($key eq 'uid'); # rename protection |
|
|
|
next if ($key eq 'uid'); # rename protection |
|
|
|
$upd{$key} = $value; |
|
|
|
if ($value and not exists $data->{$key}) { |
|
|
|
|
|
|
|
push @chg, add => [$key => $value]; |
|
|
|
|
|
|
|
next; |
|
|
|
} |
|
|
|
} |
|
|
|
my $result = $conn->modify($dn, replace => \%upd); |
|
|
|
if ($data->{$key} and $value) { |
|
|
|
|
|
|
|
push @chg, replace => [$key => $value]; |
|
|
|
|
|
|
|
next; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if ($data->{$key} and not $value) { |
|
|
|
|
|
|
|
push @chg, delete => [$key => $value]; |
|
|
|
|
|
|
|
next; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
my $result = $conn->modify($dn, changes => \@chg); |
|
|
|
$conn->unbind; |
|
|
|
$conn->unbind; |
|
|
|
|
|
|
|
|
|
|
|
return $result->error if ($result->code); |
|
|
|
return $result->error if ($result->code); |
|
|
@ -171,7 +183,8 @@ Get user attributes. Returns HASH on success or undef if not found. |
|
|
|
my $err = $ldap->update($user, \%attrs); |
|
|
|
my $err = $ldap->update($user, \%attrs); |
|
|
|
|
|
|
|
|
|
|
|
Returns nothing on success or scalar with text on error. |
|
|
|
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. |
|
|
|
See list of allowed keys in config, 'ldap/defattrs' parameter. |
|
|
|
|
|
|
|
'uid' key will be ignored, because it's structural in our schema. |
|
|
|
|
|
|
|
|
|
|
|
=cut |
|
|
|
=cut |
|
|
|