Archived
1
0

Fix grep in LDAP.pm

This commit is contained in:
Mercier Pierre-Olivier 2013-09-03 15:12:05 +02:00
parent ff0dc53738
commit b7edef35d7

View File

@ -145,13 +145,16 @@ sub add_attribute($$$@)
my @data = $entry->get_value($what); my @data = $entry->get_value($what);
for my $value (@_) for my $value (@_)
{ {
if (! grep("^$value\$", @data)) { if (! grep { /^\Q$value\E$/ } @data) {
$mod = 1; $mod = 1;
ACU::Log::do_debug("Add attribute $value to $dn"); ACU::Log::do_debug("Add attribute $value to $dn");
push @data, $value; push @data, $value;
} }
else {
ACU::Log::do_warn("Attribute $what with value $value for $dn already exists.");
}
} }
if ($mod) if ($mod)
@ -160,7 +163,6 @@ sub add_attribute($$$@)
my $mesg = $entry->update($ldap) or die $!; my $mesg = $entry->update($ldap) or die $!;
if ($mesg->code != 0) { ACU::Log::do_warn($mesg->error); return 0; } if ($mesg->code != 0) { ACU::Log::do_warn($mesg->error); return 0; }
if ($mesg->count != 1) { ACU::Log::do_warn("$dn not found or multiple entries match"); return 0; }
return 1; return 1;
} }
@ -181,10 +183,10 @@ sub delete_attribute($$$@)
my @data = $entry->get_value($what); my @data = $entry->get_value($what);
for my $value (@_) for my $value (@_)
{ {
if (grep("^$value\$", @data)) { if (grep { /^\Q$value\E$/ } @data) {
ACU::Log::do_debug("Remove attribute $what ($value) from $dn"); ACU::Log::do_debug("Remove attribute $what ($value) from $dn");
@data = grep(!"^$value\$", @data); @data = grep { ! /^\Q$value\E$/ } @data;
$mod = 1; $mod = 1;
} }
else { else {