Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

userdel: --force: Allow the flag to be specified twice, for more granularity #1071

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion man/userdel.8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,16 @@
<para>
This option forces the removal of the user account
and any other requested actions,
skipping any safety checks.
skipping safety checks.
</para>
<para>
If specified once,
a user is removed
even if it's still logged in,
and its primary group is removed
even if it's the primary group of another user.
If specified twice,
it skips all safety checks.
Comment on lines +85 to +91
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this distinction make sense? Should the group thing go with -ff?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok, but I ask just in case.

</para>
<para>
<emphasis>Note:</emphasis> This option is dangerous and may leave
Expand Down
16 changes: 8 additions & 8 deletions src/userdel.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static uid_t user_id;
static gid_t user_gid;
static char *user_home;

static bool fflg = false;
static int fflg = 0;
static bool rflg = false;
#ifdef WITH_SELINUX
static bool Zflg = false;
Expand Down Expand Up @@ -312,7 +312,7 @@ static void remove_usergroup (void)
return;
}

if (!fflg) {
if (fflg < 1) {
/*
* Scan the passwd file to check if this group is still
* used as a primary group.
alejandro-colomar marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -832,7 +832,7 @@ static int remove_mailbox (void)
}
}

if (fflg) {
if (fflg >= 2) {
if (unlink (mailfile) != 0) {
fprintf (stderr,
_("%s: warning: can't remove %s: %s\n"),
Expand Down Expand Up @@ -997,8 +997,8 @@ int main (int argc, char **argv)
#endif /* !WITH_SELINUX */
long_options, NULL)) != -1) {
switch (c) {
case 'f': /* force remove even if not owned by user */
fflg = true;
case 'f':
fflg++;
break;
case 'h':
usage (E_SUCCESS);
Expand Down Expand Up @@ -1131,7 +1131,7 @@ int main (int argc, char **argv)
* a cron job may be started on her behalf, etc.
*/
if ((prefix[0] == '\0') && !Rflg && user_busy (user_name, user_id) != 0) {
if (!fflg) {
if (fflg < 1) {
#ifdef WITH_AUDIT
audit_logger (AUDIT_DEL_USER, Prog,
"deleting user logged in",
Expand Down Expand Up @@ -1160,7 +1160,7 @@ int main (int argc, char **argv)
_("%s: %s home directory (%s) not found\n"),
Prog, user_name, user_home);
rflg = 0;
} else if ((0 == home_owned) && !fflg) {
} else if ((0 == home_owned) && fflg < 2) {
fprintf (stderr,
_("%s: %s not owned by %s, not removing\n"),
Prog, user_home, user_name);
Expand All @@ -1172,7 +1172,7 @@ int main (int argc, char **argv)

#ifdef EXTRA_CHECK_HOME_DIR
/* This may be slow, the above should be good enough. */
if (rflg && !fflg) {
if (rflg && fflg < 2) {
struct passwd *pwd;
/*
* For safety, refuse to remove the home directory if it
Expand Down
Loading