|
|
@ -1,25 +1,20 @@ |
|
|
|
#!/usr/bin/perl -w |
|
|
|
#!/usr/bin/perl -w |
|
|
|
|
|
|
|
|
|
|
|
package esmith; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use strict; |
|
|
|
use strict; |
|
|
|
use Errno; |
|
|
|
use Errno; |
|
|
|
use esmith::ConfigDB; |
|
|
|
use esmith::ConfigDB; |
|
|
|
use esmith::AccountsDB; |
|
|
|
use esmith::AccountsDB; |
|
|
|
use esmith::util; |
|
|
|
use esmith::util; |
|
|
|
use Net::LDAP; |
|
|
|
use Net::LDAP; |
|
|
|
use File::Temp; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my $c = esmith::ConfigDB->open_ro; |
|
|
|
my $c = esmith::ConfigDB->open_ro; |
|
|
|
my $a = esmith::AccountsDB->open_ro; |
|
|
|
my $a = esmith::AccountsDB->open_ro; |
|
|
|
|
|
|
|
|
|
|
|
my $ldapauth = $c->get('ldap')->prop('Authentication') || 'disabled'; |
|
|
|
|
|
|
|
my $x = 0; # exit value |
|
|
|
my $x = 0; # exit value |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
@ -32,18 +27,15 @@ my @accounts; |
|
|
|
my $account; |
|
|
|
my $account; |
|
|
|
my $event = shift || die "Event name is missing\n"; |
|
|
|
my $event = shift || die "Event name is missing\n"; |
|
|
|
if ($event eq 'ldap-update' or |
|
|
|
if ($event eq 'ldap-update' or |
|
|
|
$event eq 'bootstrap-ldap-save') |
|
|
|
$event eq 'bootstrap-ldap-save'){ |
|
|
|
{ |
|
|
|
|
|
|
|
@accounts = ($a->users); |
|
|
|
@accounts = ($a->users); |
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
@ -51,6 +43,19 @@ else |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my $base = esmith::util::ldapBase ($domain); |
|
|
|
|
|
|
|
my $pw = esmith::util::LdapPassword(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my $ldap = Net::LDAP->new('localhost') |
|
|
|
|
|
|
|
or die "$@"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$ldap->bind( |
|
|
|
|
|
|
|
dn => "cn=root,$base", |
|
|
|
|
|
|
|
password => $pw |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my $result; |
|
|
|
|
|
|
|
|
|
|
|
foreach my $acc (@accounts){ |
|
|
|
foreach my $acc (@accounts){ |
|
|
|
my $user = $acc->key; |
|
|
|
my $user = $acc->key; |
|
|
|
my $postalcode = $acc->prop('PostalCode') || ''; |
|
|
|
my $postalcode = $acc->prop('PostalCode') || ''; |
|
|
@ -65,31 +70,35 @@ foreach my $acc (@accounts){ |
|
|
|
my $dshell = $acc->prop('DesktopShell') || ''; |
|
|
|
my $dshell = $acc->prop('DesktopShell') || ''; |
|
|
|
my $preferredemail = $acc->prop('PreferredEmail') || ''; |
|
|
|
my $preferredemail = $acc->prop('PreferredEmail') || ''; |
|
|
|
$preferredemail = "$user\@$domain" if ($preferredemail eq ''); |
|
|
|
$preferredemail = "$user\@$domain" if ($preferredemail eq ''); |
|
|
|
|
|
|
|
my $web = $acc->prop('Url') || ''; |
|
|
|
|
|
|
|
|
|
|
|
my $tmpattr = File::Temp->new(); |
|
|
|
my (@postalcode,@mobile,@extension,@fax,@titles,@initials,@dshell,@preferredemail,@web) = (); |
|
|
|
print $tmpattr "postalCode: $postalcode\n"; |
|
|
|
@postalcode = ($postalcode) unless ($postalcode eq ''); |
|
|
|
print $tmpattr "mobile: $mobile\n"; |
|
|
|
@mobile = ($mobile) unless ($mobile eq ''); |
|
|
|
print $tmpattr "extensionNumber: $extension\n"; |
|
|
|
@extension = ($extension) unless ($extension eq ''); |
|
|
|
print $tmpattr "facsimileTelephoneNumber: $fax\n"; |
|
|
|
@fax = ($fax) unless ($fax eq ''); |
|
|
|
print $tmpattr "title: $function1\n" if ($function1 ne ''); |
|
|
|
@titles = qw($function1 $function2 $function3 $function4) |
|
|
|
print $tmpattr "title: $function2\n" if ($function2 ne ''); |
|
|
|
unless ($function1 eq '' && $function2 eq '' && $function3 eq '' && $function4 eq ''); |
|
|
|
print $tmpattr "title: $function3\n" if ($function3 ne ''); |
|
|
|
@dshell = ($dshell) unless ($dshell eq ''); |
|
|
|
print $tmpattr "title: $function4\n" if ($function4 ne ''); |
|
|
|
@preferredemail = ($preferredemail) unless ($preferredemail eq ''); |
|
|
|
# remove the emplyeeType attr if all 4 functions are empty |
|
|
|
@web = ($web) unless ($web eq ''); |
|
|
|
if ($function1 eq '' && |
|
|
|
$result = $ldap->modify( |
|
|
|
$function2 eq '' && |
|
|
|
"uid=$user,ou=Users,$base", |
|
|
|
$function3 eq '' && |
|
|
|
replace => { |
|
|
|
$function4 eq ''){ |
|
|
|
postalCode => \@postalcode, |
|
|
|
print $tmpattr "title: \n"; |
|
|
|
mobile => \@mobile, |
|
|
|
|
|
|
|
extensionNumber => \@extension, |
|
|
|
|
|
|
|
facsimileTelephoneNumber => \@fax, |
|
|
|
|
|
|
|
title => \@titles, |
|
|
|
|
|
|
|
initials => \@initials, |
|
|
|
|
|
|
|
desktopLoginShell => \@dshell, |
|
|
|
|
|
|
|
preferredMail => \@preferredemail, |
|
|
|
|
|
|
|
labeledURI => \@web |
|
|
|
} |
|
|
|
} |
|
|
|
print $tmpattr "initials: $initials\n"; |
|
|
|
); |
|
|
|
print $tmpattr "desktopLoginShell: $dshell\n"; |
|
|
|
$result->code && ($x = 255, warn "failed to modify entry uid=$user,ou=Users,$base: ", $result->error); |
|
|
|
print $tmpattr "preferredMail: $preferredemail\n"; |
|
|
|
|
|
|
|
$tmpattr->flush(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
system("/usr/sbin/cpu", "usermod", "-a", "$tmpattr", $user) == 0 |
|
|
|
|
|
|
|
or ( $x = $ldapauth ne 'enabled' ? $x : 255, warn "Failed to modify ldap informations for account $user.\n" ); |
|
|
|
|
|
|
|
undef $tmpattr; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$ldap->unbind; |
|
|
|
|
|
|
|
|
|
|
|
exit ($x); |
|
|
|
exit ($x); |
|
|
|