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