#! /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 $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 $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(shift); } sub group_flush($$) { my $dn = shift; my $args = shift; my $cnt_type = group_get_type $args->{param}; return LDAP::flush_attribute($dn, $cnt_type); } sub group_remove($$) { 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($dn, $cnt_type, \@data); } sub group_update($$) { 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($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; } return $actions{$action}($dn, $args); } Process::register("update_group", \&process);