Archived
1
0
Fork 0

Refactor update_group to work as update_user

This commit is contained in:
Mercier Pierre-Olivier 2013-09-02 21:09:51 +02:00
commit 114e661761
3 changed files with 92 additions and 35 deletions

View file

@ -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();