Delete personal groups in other modules
authorJamie Cameron <jcameron@webmin.com>
Sun, 22 Aug 2010 01:08:13 +0000 (18:08 -0700)
committerJamie Cameron <jcameron@webmin.com>
Sun, 22 Aug 2010 01:08:13 +0000 (18:08 -0700)
useradmin/CHANGELOG
useradmin/delete_user.cgi
useradmin/lang/en

index b6bdde1..d0d862f 100644 (file)
@@ -60,3 +60,5 @@ Converted commands in the module's API file to POD format, and added more detail
 Fixed a bug that caused an empty shell to appear in the shells list for new users.
 Fixed the hashing format for Blowfish passwords, to put $2a$ at the start instead of $2$.
 On Linux systems with SElinux enabled, the context user_u:object_r:user_home_dir_t is set on new home directories by default.
+---- Changes since 1.510 ----
+When deleting a user's personal group and user deletion in other modules is enabled, delete the group in other modules too.
index 93277eb..dc1e1f3 100755 (executable)
@@ -39,11 +39,13 @@ if ($in{'confirmed'}) {
                        push(@secs, $g->{'gid'});
                        }
                }
+
+       # Go ahead and do it!
        &set_user_envs($user, 'DELETE_USER', undef, \@secs);
        $merr = &making_changes();
        &error(&text('usave_emaking', "<tt>$merr</tt>")) if (defined($merr));
 
-       # Go ahead and do it!
+       # Delete in other modules first
        $in{'others'} = !$access{'dothers'} if ($access{'dothers'} != 1);
        if ($in{'others'}) {
                print "$text{'udel_other'}<br>\n";
@@ -57,10 +59,12 @@ if ($in{'confirmed'}) {
                        }
                }
        
+       # Delete the user
        print "$text{'udel_pass'}<br>\n";
        &delete_user($user);
        print "$text{'udel_done'}<p>\n";
 
+       # Delete the user from other groups
        print "$text{'udel_groups'}<br>\n";
        foreach $g (&list_groups()) {
                @mems = split(/,/, $g->{'members'});
@@ -75,11 +79,24 @@ if ($in{'confirmed'}) {
                }
        print "$text{'udel_done'}<p>\n";
 
+       # Delete the user's personal group, if it has no other members
        if ($mygroup && !$mygroup->{'members'}) {
                local $another;
                foreach $ou (&list_users()) {
                        $another = $ou if ($ou->{'gid'} == $mygroup->{'gid'});
                        }
+               if (!$another && $in{'others'}) {
+                       print "$text{'udel_ugroupother'}<br>\n";
+                       local $error_must_die = 1;
+                       eval { &other_modules("useradmin_delete_group",
+                                             $mygroup); };
+                       if ($@) {
+                               print &text('udel_failed', $@),"<p>\n";
+                               }
+                       else {
+                               print "$text{'gdel_done'}<p>\n";
+                               }
+                       }
                if (!$another) {
                        print "$text{'udel_ugroup'}<br>\n";
                        &delete_group($mygroup);
@@ -88,7 +105,8 @@ if ($in{'confirmed'}) {
                }
        &unlock_user_files();
 
-       if ($in{'delhome'} && $user->{'home'} !~ /^\/+$/ && $access{'delhome'} != 0) {
+       if ($in{'delhome'} && $user->{'home'} !~ /^\/+$/ &&
+           $access{'delhome'} != 0) {
                # Delete home directory
                print "$text{'udel_home'}<br>\n";
                &lock_file($user->{'home'});
index db19b4b..35c73b5 100644 (file)
@@ -237,6 +237,7 @@ udel_echanged=Password file has changed. Please return to the user list and sele
 udel_other=Deleting from other modules ..
 udel_pass=Deleting password file entry ..
 udel_groups=Removing from groups ..
+udel_ugroupother=Deleting this user's group in other modules ..
 udel_ugroup=Deleting this user's group ..
 udel_home=Deleting home directory ..
 udel_done=.. done