optimize update-ldap-pseudonyms

tags/ipasserelle-base-0.2.65-1
Daniel Berteaud 13 years ago
parent e192df1880
commit f5ce3d17c0
  1. 38
      root/etc/e-smith/events/actions/update-ldap-pseudonyms

@ -45,18 +45,15 @@ if (($ip eq 'disabled') || ($alias eq 'disabled')){
my $l = $c->get('ldap'); my $l = $c->get('ldap');
my $status = $l->prop('status') || "disabled"; my $status = $l->prop('status') || "disabled";
unless ($status eq "enabled" ) unless ($status eq "enabled" ){
{
warn "Not running action script $0, LDAP service not enabled!\n"; warn "Not running action script $0, LDAP service not enabled!\n";
exit(0); exit(0);
} }
my $hostname = $c->get('SystemName') my $hostname = $c->get('SystemName') || die("Couldn't determine system name");
|| die("Couldn't determine system name");
$hostname = $hostname->value; $hostname = $hostname->value;
my $domain = $c->get('DomainName') my $domain = $c->get('DomainName') || die("Couldn't determine domain name");
|| die("Couldn't determine domain name");
$domain = $domain->value; $domain = $domain->value;
my @accounts; my @accounts;
@ -64,18 +61,15 @@ my $account;
my $event = shift || die "Event name must be specified"; my $event = shift || die "Event name must be specified";
if ($event eq 'ldap-update' or if ($event eq 'ldap-update' or
$event eq 'bootstrap-ldap-save' or $event eq 'bootstrap-ldap-save' or
$event =~ m/(pseudonym)\-(create|modify|delete)/) $event =~ m/(pseudonym)\-(create|modify|delete)/){
{
@accounts = ($a->users,$a->groups); @accounts = ($a->users,$a->groups);
push(@accounts, $a->get('admin')); push(@accounts, $a->get('admin'));
} }
else else{
{
my @name = @ARGV; my @name = @ARGV;
die "Account name argument missing." unless scalar (@name) >= 1; die "Account name argument missing." unless scalar (@name) >= 1;
foreach my $name (@name) foreach my $name (@name){
{
$account = $a->get($name); $account = $a->get($name);
die "Account $name not found.\n" unless defined $account; die "Account $name not found.\n" unless defined $account;
@ -95,8 +89,7 @@ $ldap->bind(
); );
my $result; my $result;
foreach my $acct (@accounts) foreach my $acct (@accounts){
{
my $key = $acct->key; my $key = $acct->key;
my @pseudo = ("$key"); my @pseudo = ("$key");
@ -136,14 +129,27 @@ foreach my $acct (@accounts)
$ou = "Groups"; $ou = "Groups";
$dn = "cn"; $dn = "cn";
} }
$result = $ldap->modify( $result = $ldap->search(base => "ou=$ou,$base",
filter => "$dn=$key");
$result->code && warn "failed to search for entry $dn=$key,ou=$ou,$base: ", $result->error;
my @mails = ();
foreach my $entry ($result->all_entries()){
push @mails, $entry->get_value('mail');
}
my $alias = join('\0', sort @alias);
my $mails = join('\0', sort @mails);
unless ($alias eq $mails){
$result = $ldap->modify(
"$dn=$key,ou=$ou,$base", "$dn=$key,ou=$ou,$base",
replace => { replace => {
mail => \@alias mail => \@alias
} }
); );
$result->code && warn "failed to modify entry $dn=$key,ou=$ou,$base: ", $result->error; $result->code && warn "failed to modify entry $dn=$key,ou=$ou,$base: ", $result->error;
}
} }
$ldap->unbind; $ldap->unbind;

Loading…
Cancel
Save