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.

106 lines
3.2 KiB

13 years ago
#!/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"){
13 years ago
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'){
13 years ago
@accounts = ($a->users);
push(@accounts, $a->get('admin'));
}
else{
13 years ago
my @name = @ARGV;
die "Account name argument missing." unless scalar (@name) >= 1;
foreach my $name (@name){
13 years ago
$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;
13 years ago
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') || '';
13 years ago
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 '');
foreach ($function1, $function2, $function3, $function4){
push @titles, $_ if ($_ ne '');
}
@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);
13 years ago
}
$ldap->unbind;
13 years ago
exit ($x);