Archived
1
0
This repository has been archived on 2021-10-08. You can view files and clone it, but cannot push or open issues or pull requests.
ACU/process/ldap/update_group.pl
Mercier Pierre-Olivier a3bd738b0f Refactoring LDAP package
2013-09-02 20:43:18 +02:00

143 lines
2.5 KiB
Perl

#! /usr/bin/env perl
use v5.10.1;
use strict;
use warnings;
use Pod::Usage;
BEGIN {
push @INC, "../../";
}
use ACU::LDAP;
use ACU::Process;
our $ou = "intra";
my %actions =
(
"new" => \&group_new,
"add" => \&group_add,
"delete" => \&group_delete,
"flush" => \&group_flush,
"remove" => \&group_remove,
"update" => \&group_update,
);
sub group_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 ($args->{param}{type}) {
group_add $dn, $args
}
}
}
sub group_add($$$)
{
my $ldap = shift;
my $dn = shift;
my $args = shift;
my $cnt_type = group_get_type $args->{param};
# Add content if any
for (my $i = $args->{unamed}; $i > 0; $i--) {
LDAP::add_attribute($dn, $cnt_type, $args->{param}{$i});
}
}
sub group_delete($$$)
{
return LDAP::delete_entry($_[0], $_[1]);
}
sub group_flush($$)
{
my $ldap = shift;
my $dn = shift;
my $args = shift;
my $cnt_type = group_get_type $args->{param};
return LDAP::flush_attribute($ldap, $dn, $cnt_type);
}
sub group_remove($$)
{
my $ldap = shift;
my $dn = shift;
my $args = shift;
my $cnt_type = group_get_type $args->{param};
my @data;
for (my $i = $args->{unamed}; $i > 0; $i--) {
push @data, $i;
}
return LDAP::delete_attributes($ldap, $dn, $cnt_type, @data);
}
sub group_update($$)
{
my $ldap = shift;
my $dn = shift;
my $args = shift;
my $cnt_type = group_get_type $args->{param};
my @data;
for (my $i = $args->{unamed}; $i > 0; $i--) {
push @data, $i;
}
LDAP::update_attribute($ldap, $dn, $cnt_type, @data);
}
sub group_get_type($)
{
my $param = shift;
# Extract data type
if ($param{type} eq "members") {
return "memberUid";
}
elsif ($param{type} eq "rights") {
return "intraRights" ;
}
else {
die ("Unknown type to add: ".$param{type});
}
}
sub process
{
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";
# Read action
if (! exists $actions{$action}) {
return "Unknown command for update_group: ". $action;
}
my $ldap = LDAP::ldap_connect();
$actions{$action}($ldap, $dn, $args);
$ldap->unbind or print "couldn't disconnect correctly";
}
Process::register("update_group", \&process);