Archived
1
0
Fork 0

Some fixes in LDAP

This commit is contained in:
Mercier Pierre-Olivier 2013-09-03 07:20:58 +02:00
parent 65f11b676b
commit 9c27bf131e
2 changed files with 116 additions and 29 deletions

View file

@ -9,6 +9,7 @@ BEGIN {
push @INC, "../../";
}
use ACU::Log;
use ACU::LDAP;
use ACU::Process;
@ -32,6 +33,8 @@ my %user_actions =
"update" => \&_update,
);
my $_get_type;
sub _new($$$)
{
my $ldap = shift;
@ -53,7 +56,7 @@ sub _add($$$)
my $dn = shift;
my $args = shift;
my $cnt_type = group_get_type $args->{param};
my $cnt_type = $_get_type->($args->{param});
# Add content if any
for (my $i = $args->{unamed}; $i > 0; $i--) {
@ -72,7 +75,7 @@ sub _flush($$)
my $dn = shift;
my $args = shift;
my $cnt_type = group_get_type $args->{param};
my $cnt_type = $_get_type->($args->{param});
return LDAP::flush_attribute($ldap, $dn, $cnt_type);
}
@ -83,7 +86,7 @@ sub _remove($$)
my $dn = shift;
my $args = shift;
my $cnt_type = group_get_type $args->{param};
my $cnt_type = $_get_type->($args->{param});
my @data;
for (my $i = $args->{unamed}; $i > 0; $i--) {
@ -99,7 +102,9 @@ sub _update($$)
my $dn = shift;
my $args = shift;
my $cnt_type = group_get_type $args->{param};
my $cnt_type = $_get_type->($args->{param});
return user_update($ldap, $dn, $args) if ($cnt_type eq "userInfos");
my @data;
for (my $i = $args->{unamed}; $i > 0; $i--) {
@ -109,20 +114,66 @@ sub _update($$)
return LDAP::update_attribute($ldap, $dn, $cnt_type, @data);
}
sub user_update($$)
{
my $ldap = shift;
my $dn = shift;
my $args = shift;
sub _get_type($)
LDAP::update_attribute($ldap, $dn, "cn", $args->{param}{cn}) if ($args->{param}{cn});
LDAP::update_attribute($ldap, $dn, "cn", $args->{param}{firstname}." ".$args->{param}{lastname}) if ($args->{param}{firstname} && $args->{param}{lastname});
LDAP::update_attribute($ldap, $dn, "l", $args->{param}{l}) if ($args->{param}{l});
LDAP::update_attribute($ldap, $dn, "mail", $args->{param}{mail}) if ($args->{param}{mail});
LDAP::update_attribute($ldap, $dn, "postalAddress", $args->{param}{postalAddress}) if ($args->{param}{postalAddress});
LDAP::update_attribute($ldap, $dn, "postalCode", $args->{param}{postalCode}) if ($args->{param}{postalCode});
LDAP::update_attribute($ldap, $dn, "sn", $args->{param}{sn}) if ($args->{param}{sn});
LDAP::update_attribute($ldap, $dn, "telephoneNumber", $args->{param}{telephoneNumber}) if ($args->{param}{telephoneNumber});
LDAP::update_attribute($ldap, $dn, "sshPublicKey", $args->{param}{sshPublicKey}) if ($args->{param}{sshPublicKey});
LDAP::update_attribute($ldap, $dn, "strongAuthKey", $args->{param}{strongAuthKey}) if ($args->{param}{strongAuthKey});
LDAP::update_attribute($ldap, $dn, "c", $args->{param}{c}) if ($args->{param}{c});
LDAP::update_attribute($ldap, $dn, "title", $args->{param}{title}) if ($args->{param}{title});
LDAP::update_attribute($ldap, $dn, "intraRight", $args->{param}{intraRight}) if ($args->{param}{intraRight});
LDAP::update_attribute($ldap, $dn, "intraTheme", $args->{param}{intraTheme}) if ($args->{param}{intraTheme});
LDAP::update_attribute($ldap, $dn, "birthdate", $args->{param}{birthdate}) if ($args->{param}{birthdate});
}
sub group_get_type($)
{
my $param = shift;
my $type = $param->{type} // "members";
# Extract data type
if ($param->{type} eq "members") {
if ($type eq "members") {
return "memberUid";
}
elsif ($param->{type} eq "rights") {
elsif ($type eq "rights") {
return "intraRights" ;
}
else {
die ("Unknown type to add: ".$param->{type});
die ("Unknown type to add: ".$type);
}
}
sub user_get_type($)
{
my $param = shift;
my $type = $param->{type} // "userInfos";
# Extract data type
if ($type eq "rights") {
return "intraRights" ;
}
elsif ($type eq "sshkeys") {
return "sshPublicKey" ;
}
elsif ($type eq "userInfos") {
return "userInfos" ;
}
else {
die ("Unknown type to add: ".$type);
}
}
@ -133,7 +184,7 @@ sub process_group
my $year = $args->{param}{year} // LDAP::get_year;
my $dn = "cn=".$args->{param}{cn}."ou=$year,ou=$ou,ou=groups,dc=acu,dc=epita,dc=fr";
my $action = $args->{param}{type} // "update";
my $action = $args->{param}{action} // "update";
# Read action
if (! exists $group_actions{$action}) {
@ -145,13 +196,15 @@ sub process_group
$group_actions{$action}($ldap, $dn, $args);
$ldap->unbind or warn "couldn't disconnect correctly";
return "Ok";
}
sub process_user
{
my ($given_args, $args) = @_;
my $action = $args->{param}{type} // "update";
my $action = $args->{param}{action} // "update";
# Read action
if (! exists $user_actions{$action}) {
@ -165,13 +218,16 @@ sub process_user
$user_actions{$action}($ldap, $dn, $args);
$ldap->unbind or warn "couldn't disconnect correctly";
return "Ok";
}
if ($0 =~ /^update_group/) {
$_get_type = \&group_get_type;
Process::register("update_group", \&process_group);
}
elsif ($0 =~ /^update_user/) {
$_get_type = \&user_get_type;
Process::register("update_user", \&process_user);
}
else {