You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

104 lines
3.3 KiB

#!/usr/bin/perl -w
use strict;
use Errno;
use esmith::ConfigDB;
use esmith::AccountsDB;
use esmith::util;
use Net::LDAP;
my $c = esmith::ConfigDB->open_ro;
my $a = esmith::AccountsDB->open_ro;
my $x = 0; # exit value
my $l = $c->get('ldap');
my $status = $l->prop('status') || "disabled";
unless ($status eq "enabled"){
warn "Not running action script $0, LDAP service not enabled!\n";
exit(0);
}
my $domain = $c->get('DomainName')
|| die("Couldn't determine domain name");
$domain = $domain->value;
my @accounts;
my $account;
my $event = shift || die "Event name is missing\n";
if ($event eq 'ldap-update' or
$event eq 'bootstrap-ldap-save'){
@accounts = ($a->users);
push(@accounts, $a->get('admin'));
}
else{
my @name = @ARGV;
die "Account name argument missing." unless scalar (@name) >= 1;
foreach my $name (@name){
$account = $a->get($name);
die "Account $name not found.\n" unless defined $account;
push @accounts, $account;
}
}
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') || '';
my $mobile = $acc->prop('Mobile') || '';
my $extension = $acc->prop('Extension') || '';
my $fax = $acc->prop('Fax') || '';
my $function1 = $acc->prop('Function1') || '';
my $function2 = $acc->prop('Function2') || '';
my $function3 = $acc->prop('Function3') || '';
my $function4 = $acc->prop('Function4') || '';
my $initials = $acc->prop('Initials') || '';
my $dshell = $acc->prop('DesktopShell') || '';
my $preferredemail = $acc->prop('PreferredEmail') || '';
$preferredemail = "$user\@$domain" if ($preferredemail eq '');
my $web = $acc->prop('Url') || '';
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);