summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2015-02-05 18:35:52 +0100
committerDenys Vlasenko2015-02-05 18:35:52 +0100
commita14fa79592eadec0d5e296c66e79dfe36ce798c7 (patch)
treed825fa4b4719521c66db7fe739d64c16d89c6599
parent3c5d133c7def0718e313928c69bde2e9784ce58e (diff)
downloadbusybox-a14fa79592eadec0d5e296c66e79dfe36ce798c7.zip
busybox-a14fa79592eadec0d5e296c66e79dfe36ce798c7.tar.gz
deluser: implement --remove-home
function old new delta deluser_main 308 355 +47 packed_usage 30149 30156 +7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 54/0) Total: 54 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--loginutils/deluser.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/loginutils/deluser.c b/loginutils/deluser.c
index e39ac55..2d98ecc 100644
--- a/loginutils/deluser.c
+++ b/loginutils/deluser.c
@@ -11,9 +11,10 @@
*/
//usage:#define deluser_trivial_usage
-//usage: "USER"
+//usage: IF_LONG_OPTS("[--remove-home] ") "USER"
//usage:#define deluser_full_usage "\n\n"
//usage: "Delete USER from the system"
+// --remove-home is self-explanatory enough to put it in --help
//usage:#define delgroup_trivial_usage
//usage: IF_FEATURE_DEL_USER_FROM_GROUP("[USER] ")"GROUP"
@@ -37,6 +38,19 @@ int deluser_main(int argc, char **argv)
/* Are we deluser or delgroup? */
int do_deluser = (ENABLE_DELUSER && (!ENABLE_DELGROUP || applet_name[3] == 'u'));
+#if !ENABLE_LONG_OPTS
+ const int opt_delhome = 0;
+#else
+ int opt_delhome = 0;
+ if (do_deluser) {
+ applet_long_options =
+ "remove-home\0" No_argument "\xff";
+ opt_delhome = getopt32(argv, "");
+ argv += opt_delhome;
+ argc -= opt_delhome;
+ }
+#endif
+
if (geteuid() != 0)
bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
@@ -55,10 +69,14 @@ int deluser_main(int argc, char **argv)
case 2:
if (do_deluser) {
/* "deluser USER" */
- xgetpwnam(name); /* bail out if USER is wrong */
+ struct passwd *pw;
+
+ pw = xgetpwnam(name); /* bail out if USER is wrong */
pfile = bb_path_passwd_file;
if (ENABLE_FEATURE_SHADOWPASSWDS)
sfile = bb_path_shadow_file;
+ if (opt_delhome)
+ remove_file(pw->pw_dir, FILEUTILS_RECUR);
} else {
struct group *gr;
do_delgroup: