From: Jesse W. Hathaway Date: Fri, 12 Jun 2015 22:32:50 +0000 (-0500) Subject: Allow deleting the group even if it is the primary group of a user X-Git-Tag: 4.3.0~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c32fd4a29846a713554d27c3fb05f68408da2ab;p=shadow Allow deleting the group even if it is the primary group of a user This is helpful when using configuration management tools such as Puppet, where you are managing the groups in a central location and you don't need this safeguard. Signed-off-by: "Jesse W. Hathaway" Acked-by: Serge Hallyn --- diff --git a/src/groupdel.c b/src/groupdel.c index da993475..d613a66e 100644 --- a/src/groupdel.c +++ b/src/groupdel.c @@ -60,6 +60,7 @@ const char *Prog; static char *group_name; static gid_t group_id = -1; +static bool check_group_busy = true; #ifdef SHADOWGRP static bool is_shadow_grp; @@ -96,6 +97,7 @@ static /*@noreturn@*/void usage (int status) Prog); (void) fputs (_(" -h, --help display this help message and exit\n"), usageout); (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); + (void) fputs (_(" -f, --force delete group even if it is the primary group of a user\n"), usageout); (void) fputs ("\n", usageout); exit (status); } @@ -321,7 +323,7 @@ static void process_flags (int argc, char **argv) {NULL, 0, NULL, '\0'} }; - while ((c = getopt_long (argc, argv, "hR:", + while ((c = getopt_long (argc, argv, "hfR:", long_options, NULL)) != -1) { switch (c) { case 'h': @@ -329,6 +331,9 @@ static void process_flags (int argc, char **argv) /*@notreached@*/break; case 'R': /* no-op, handled in process_root_flag () */ break; + case 'f': + check_group_busy = false; + break; default: usage (E_USAGE); } @@ -465,7 +470,9 @@ int main (int argc, char **argv) /* * Make sure this isn't the primary group of anyone. */ - group_busy (group_id); + if (check_group_busy) { + group_busy (group_id); + } /* * Do the hard stuff - open the files, delete the group entries,