Refactor update_group to work as update_user
This commit is contained in:
parent
a3bd738b0f
commit
114e661761
31
ACU/LDAP.pm
31
ACU/LDAP.pm
@ -56,16 +56,15 @@ sub ldap_connect_anon()
|
||||
|
||||
## High end functions
|
||||
|
||||
sub add_group($$;$)
|
||||
sub add_group($$$;$)
|
||||
{
|
||||
my $ldap = shift // ldap_connect();
|
||||
my $cn = shift;
|
||||
my $year = shift;
|
||||
my $year = shift // get_year();
|
||||
my $ou = shift // "intra"; # expected roles or intra
|
||||
|
||||
my $dn = "cn=$cn,ou=$year,ou=$ou,ou=groups,dc=acu,dc=epita,dc=fr";
|
||||
|
||||
my $ldap = ldap_connect();
|
||||
|
||||
my $mesg = $ldap->add( $dn,
|
||||
attrs => [
|
||||
objectclass => "intraGroup",
|
||||
@ -74,8 +73,6 @@ sub add_group($$;$)
|
||||
);
|
||||
if ($mesg->code != 0) { die $mesg->error; }
|
||||
|
||||
$ldap->unbind or die ("couldn't disconnect correctly");
|
||||
|
||||
return $dn;
|
||||
}
|
||||
|
||||
@ -211,6 +208,28 @@ sub get_attribute($$$)
|
||||
return get_dn($ldap, $dn, $what)->get_value($what);
|
||||
}
|
||||
|
||||
sub search_dn($$@)
|
||||
{
|
||||
my $ldap = shift // ldap_connect();
|
||||
my $base = shift;
|
||||
my $filter = shift;
|
||||
|
||||
if ($base) {
|
||||
$base .= ","
|
||||
}
|
||||
|
||||
my $mesg = $ldap->search( # search
|
||||
base => $base."dc=acu,dc=epita,dc=fr",
|
||||
filter => $filter,
|
||||
attrs => [ ],
|
||||
scope => "sub"
|
||||
);
|
||||
if ($mesg->code != 0) { print $mesg->error; return undef; }
|
||||
if ($mesg->count != 1) { return undef; }
|
||||
|
||||
return $mesg->entry(0)->dn;
|
||||
}
|
||||
|
||||
sub update_attribute($$$@)
|
||||
{
|
||||
my $ldap = shift // ldap_connect();
|
||||
|
@ -14,32 +14,40 @@ use ACU::Process;
|
||||
|
||||
our $ou = "intra";
|
||||
|
||||
my %actions =
|
||||
my %group_actions =
|
||||
(
|
||||
"new" => \&group_new,
|
||||
"add" => \&group_add,
|
||||
"delete" => \&group_delete,
|
||||
"flush" => \&group_flush,
|
||||
"remove" => \&group_remove,
|
||||
"update" => \&group_update,
|
||||
"new" => \&_new,
|
||||
"add" => \&_add,
|
||||
"delete" => \&_delete,
|
||||
"flush" => \&_flush,
|
||||
"remove" => \&_remove,
|
||||
"update" => \&_update,
|
||||
);
|
||||
|
||||
sub group_new($$$)
|
||||
my %user_actions =
|
||||
(
|
||||
"add" => \&_add,
|
||||
"flush" => \&_flush,
|
||||
"remove" => \&_remove,
|
||||
"update" => \&_update,
|
||||
);
|
||||
|
||||
sub _new($$$)
|
||||
{
|
||||
my $ldap = shift;
|
||||
my $dn = shift;
|
||||
my $args = shift;
|
||||
|
||||
# Add group
|
||||
if (LDAP::add_group($args->{param}{cn}, LDAP::get_year) eq $dn)
|
||||
if (LDAP::add_group($ldap, $args->{param}{cn}, $args->{param}{year}) eq $dn)
|
||||
{
|
||||
if ($args->{param}{type}) {
|
||||
group_add $dn, $args
|
||||
group_add $dn, $args;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub group_add($$$)
|
||||
sub _add($$$)
|
||||
{
|
||||
my $ldap = shift;
|
||||
my $dn = shift;
|
||||
@ -49,16 +57,16 @@ sub group_add($$$)
|
||||
|
||||
# Add content if any
|
||||
for (my $i = $args->{unamed}; $i > 0; $i--) {
|
||||
LDAP::add_attribute($dn, $cnt_type, $args->{param}{$i});
|
||||
LDAP::add_attribute($ldap, $dn, $cnt_type, $args->{param}{$i});
|
||||
}
|
||||
}
|
||||
|
||||
sub group_delete($$$)
|
||||
sub _delete($$$)
|
||||
{
|
||||
return LDAP::delete_entry($_[0], $_[1]);
|
||||
}
|
||||
|
||||
sub group_flush($$)
|
||||
sub _flush($$)
|
||||
{
|
||||
my $ldap = shift;
|
||||
my $dn = shift;
|
||||
@ -69,7 +77,7 @@ sub group_flush($$)
|
||||
return LDAP::flush_attribute($ldap, $dn, $cnt_type);
|
||||
}
|
||||
|
||||
sub group_remove($$)
|
||||
sub _remove($$)
|
||||
{
|
||||
my $ldap = shift;
|
||||
my $dn = shift;
|
||||
@ -85,7 +93,7 @@ sub group_remove($$)
|
||||
return LDAP::delete_attributes($ldap, $dn, $cnt_type, @data);
|
||||
}
|
||||
|
||||
sub group_update($$)
|
||||
sub _update($$)
|
||||
{
|
||||
my $ldap = shift;
|
||||
my $dn = shift;
|
||||
@ -98,45 +106,74 @@ sub group_update($$)
|
||||
push @data, $i;
|
||||
}
|
||||
|
||||
LDAP::update_attribute($ldap, $dn, $cnt_type, @data);
|
||||
return LDAP::update_attribute($ldap, $dn, $cnt_type, @data);
|
||||
}
|
||||
|
||||
|
||||
sub group_get_type($)
|
||||
sub _get_type($)
|
||||
{
|
||||
my $param = shift;
|
||||
|
||||
# Extract data type
|
||||
if ($param{type} eq "members") {
|
||||
if ($param->{type} eq "members") {
|
||||
return "memberUid";
|
||||
}
|
||||
elsif ($param{type} eq "rights") {
|
||||
elsif ($param->{type} eq "rights") {
|
||||
return "intraRights" ;
|
||||
}
|
||||
else {
|
||||
die ("Unknown type to add: ".$param{type});
|
||||
die ("Unknown type to add: ".$param->{type});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub process
|
||||
sub process_group
|
||||
{
|
||||
my ($given_args, $args) = @_;
|
||||
|
||||
my $year = $param{year} // LDAP::get_year;
|
||||
my $dn = "cn=".$param{cn}."ou=$year,ou=$ou,ou=groups,dc=acu,dc=epita,dc=fr";
|
||||
my $action = $param{type} // "update";
|
||||
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";
|
||||
|
||||
# Read action
|
||||
if (! exists $actions{$action}) {
|
||||
if (! exists $group_actions{$action}) {
|
||||
return "Unknown command for update_group: ". $action;
|
||||
}
|
||||
|
||||
my $ldap = LDAP::ldap_connect();
|
||||
|
||||
$actions{$action}($ldap, $dn, $args);
|
||||
$group_actions{$action}($ldap, $dn, $args);
|
||||
|
||||
$ldap->unbind or print "couldn't disconnect correctly";
|
||||
$ldap->unbind or warn "couldn't disconnect correctly";
|
||||
}
|
||||
|
||||
Process::register("update_group", \&process);
|
||||
sub process_user
|
||||
{
|
||||
my ($given_args, $args) = @_;
|
||||
|
||||
my $action = $args->{param}{type} // "update";
|
||||
|
||||
# Read action
|
||||
if (! exists $user_actions{$action}) {
|
||||
return "Unknown command for update_user: ". $action;
|
||||
}
|
||||
|
||||
my $ldap = LDAP::ldap_connect();
|
||||
|
||||
my $dn = LDAP::search_dn($ldap, "ou=users", "uid=".$args->{param}{uid});
|
||||
|
||||
$user_actions{$action}($ldap, $dn, $args);
|
||||
|
||||
$ldap->unbind or warn "couldn't disconnect correctly";
|
||||
}
|
||||
|
||||
|
||||
if ($0 =~ /^update_group/) {
|
||||
Process::register("update_group", \&process_group);
|
||||
}
|
||||
elsif ($0 =~ /^update_user/) {
|
||||
Process::register("update_user", \&process_user);
|
||||
}
|
||||
else {
|
||||
die ("Bad filename.");
|
||||
}
|
||||
|
1
process/ldap/update_user.pl
Symbolic link
1
process/ldap/update_user.pl
Symbolic link
@ -0,0 +1 @@
|
||||
update_group.pl
|
Reference in New Issue
Block a user