aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xuserdrake238
1 files changed, 26 insertions, 12 deletions
diff --git a/userdrake2 b/userdrake2
index 7816e6d..c2c093f 100755
--- a/userdrake2
+++ b/userdrake2
@@ -213,30 +213,23 @@ sub AddUser {
if ($groupchoice == 0 && !$error) {
#You choose to put it in the existing group
$u{gid} = $gr->Gid($GetValue);
- #debug Info (to be removed before final)
- printf("EXISTGROUP: le Gid du group sera %d\n groupchoice = %d\n", $u{gid}, $groupchoice);
} elsif ($groupchoice == 1) {
# Put it in 'users' group
- $u{gid} = Add2UsersGroup();
- #debug Info (to be removed before final)
- printf("USERGROUP: le Gid du group sera %d\n groupchoice = %d\n", $u{gid}, $groupchoice);
+ $u{gid} = Add2UsersGroup($u{username});
}
} else {
#it's a new group: Add it
my $newgroup = $ctx->InitGroup($u{username},$is_system);
$u{gid} = $newgroup->Gid($GetValue);
$ctx->GroupAdd($newgroup);
- #debug Info (to be removed before final
- printf("NEWGROUP : le Gid du group sera %d\n", $u{gid});
}
}
} else {
- $u{gid} = Add2UsersGroup();
+ $u{gid} = Add2UsersGroup($u{username});
#debug Info (to be removed before final)
printf("le Gid du group sera %d", $u{gid});
}
if(!$error) {
- print "############# Test Succesfull ##############\n";
$u{gecos} = $us->{o}->{fullname}->get_text(); $u{loginshell} = $us->{o}->{shells}->entry->get_text();
$userEnt->Gecos($u{gecos}); $userEnt->LoginShell($u{loginshell}); $userEnt->Gid($u{gid});
$ctx->UserAdd($userEnt, $is_system, $dontcreatehomedir);
@@ -261,8 +254,10 @@ sub AddUser {
$w->{rwindow}->show_all;
$w->main;
}
-sub Add2UsersGroup() {
+sub Add2UsersGroup {
+ my $name = shift;
my $usersgroup = $ctx->LookupGroupByName('users');
+ $usersgroup->MemberName($name, 1);
return $usersgroup->Gid($GetValue);
}
sub ChooseGroup() {
@@ -343,15 +338,34 @@ sub AddGroup {
$w->main;
}
+sub UpdateOrDelUsersInGroup {
+ my ($name, $action) = @_;
+ my $groups = $ctx->GroupsEnumerateFull();
+ if ($action) {
+ foreach my $g (@$groups) {
+ my $members = $g->MemberName(1, 0);
+ any { $_ eq $name } @$members and $g->MemberName($name, 2);
+ $ctx->GroupModify($g);
+ }
+ } else {
+ print ("Updating MemberName \n");
+ }
+}
sub Delete {
my $page = $nb->get_current_page();
if ($page == 0) {
my (undef, $iter) = $usertree->get_selection->get_selected;
- my $username = $utree_model->get($iter,0);
+ my $username = $utree_model->get($iter, 0);
$iter->free;
my $userEnt = $ctx->LookupUserByName($username);
$ctx->UserDel($userEnt);
- my $groups = $ctx->GroupsEnumerateFull();
+ UpdateOrDelUsersInGroup($username, 1);
+ #Let's check out the user's primary group
+ my $usergid = $userEnt->Gid($GetValue);
+ my $groupEnt = $ctx->LookupGroupById($usergid); my $member = $groupEnt->MemberName(1, 0);
+ if (!$groupEnt && @$member) { $groupEnt->Gid($GetValue) > 500 and $ctx->GroupDel($groupEnt) };
+ my $removehome = GimmeChoice(N(" Remove Home Directory"), N("Do you want to delete the user's home directory?"));
+ $removehome and $ctx->Clean($userEnt);
Refresh($sysfilter)
} elsif ($page == 1) {
my (undef, $iter) = $grouptree->get_selection->get_selected;