Refactor update_group to work as update_user
This commit is contained in:
parent
a3bd738b0f
commit
114e661761
3 changed files with 92 additions and 35 deletions
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();
|
||||
|
|
|
|||
Reference in a new issue