Archived
1
0

lpt can add group and grant-mail works

This commit is contained in:
Mercier Pierre-Olivier 2013-09-06 05:22:35 +02:00
parent de445361e8
commit cc1b765e58
2 changed files with 28 additions and 24 deletions

View File

@ -21,7 +21,7 @@ my $bindsecret = "";
sub ldap_get_password
{
return Password::get_password ".secret_ldap";
return Password::get_password "/home/2014/mercie_d/.secret_ldap";
}
our $secret_search = \&ldap_get_password;
@ -123,9 +123,9 @@ sub get_dn($$@)
my $mesg = $ldap->search( # search
base => "$dn",
filter => "(objectClass=top)",
filter => "(objectClass=*)",
attrs => @_,
scope => "base"
scope => "sub"
);
if ($mesg->code != 0) { log(WARN, $mesg->error); return undef; }
if ($mesg->count != 1) { log(WARN, "$dn not found or multiple entries match"); return undef; }
@ -235,6 +235,8 @@ sub get_attribute($$$)
my $dn = shift;
my $what = shift;
if (!$dn) { return undef; }
return get_dn($ldap, $dn, $what)->get_value($what);
}

View File

@ -308,8 +308,15 @@ sub cmd_account_grantmail($)
my $dn = LDAP::search_dn($ldap, "ou=users", "uid=$login");
LDAP::update_attribute($ldap, $dn, "mailAccountActive", "yes");
LDAP::add_attribute($ldap, $dn, "objectClass", "MailAccount");
my $entry = LDAP::get_dn($ldap, $dn, "mailAccountActive", "objectClass");
my @oc = $entry->get_value("objectClass");
push @oc, "MailAccount";
$entry->replace("mailAccountActive" => [ "yes" ]);
$entry->replace("objectClass" => @oc);
$entry->update($ldap);
log(INFO, "$login now grants to receive e-mail. Remember to add some aliases!");
@ -833,52 +840,47 @@ sub cmd_group_list(@)
sub cmd_group_add(@)
{
if ($#ARGV < 1)
my $group = shift;
if ($#_ < 0)
{
log(USAGE, "<lpt> group add <group> <login>");
log(USAGE, "<lpt> group <group-name> add <login>");
exit(1);
}
my $group = $ARGV[0];
my $login = $ARGV[1];
my $login = shift;
my $ldap = LDAP::ldap_connect();
my $mesg = $ldap->search( # search a group
base => "cn=$group,ou=groups,dc=acu,dc=epita,dc=fr",
base => "cn=$group,ou=system,ou=groups,dc=acu,dc=epita,dc=fr",
filter => "objectClass=posixGroup",
attrs => ['memberUid']
) or die $!;
$mesg->code && die $mesg->error;
$mesg->count > 0 || return -1;
foreach my $entry ($mesg->sorted('memberUid'))
foreach my $entry ($mesg->entries)
{
my @mem = $entry->get_value("memberUid");
foreach my $user (@mem)
foreach my $member (@mem)
{
if ($user eq $login)
if ($member eq $login)
{
print "$login est deja dans le groupe $group\n";
log WARN, "$login est déjà dans le groupe $group";
$ldap->unbind;
exit -1;
exit 1;
}
}
push(@mem, $login);
$entry->replace("memberUid" => [@mem]);
push @mem, $login;
$entry->replace("memberUid" => \@mem);
$entry->update($ldap);
print "Nouvelle liste des membres de $group :\n";
foreach my $user (@mem)
{
print "$user\n";
}
log INFO, "$login ajouté au groupe $group avec succès.";
}
$ldap->unbind; # take down session
system('service nscd restart');
}
sub cmd_group_remove(@)