aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSören Tempel <soeren+git@soeren-tempel.net>2020-06-09 17:51:26 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2020-06-09 18:04:31 +0200
commit0356607264b8e1476d98a81667488ba1d6295d23 (patch)
tree65879ea7e3ebdb9171baaed1b5c8c9be12446135
parentd30d1ebc117db182a6156df182057291d6fbaae1 (diff)
downloadbusybox-w32-0356607264b8e1476d98a81667488ba1d6295d23.tar.gz
busybox-w32-0356607264b8e1476d98a81667488ba1d6295d23.tar.bz2
busybox-w32-0356607264b8e1476d98a81667488ba1d6295d23.zip
deluser: check if specified home is a directory before removing it
On Alpine, some users use /dev/null as a home directory. When removing such a user with `deluser --remove-home` this causes the /dev/null device file to be removed which is undesirable. To prevent this pitfall, check if the home directory specified for the user is an actual directory (or a symlink to a directory). Implementations of similar tools for other operating systems also implement such checks. For instance, the OpenBSD rmuser(1) implementation [0]. [0]: https://github.com/openbsd/src/blob/b69faa6c70c5bfcfdddc6138cd8e0ee18cc15b03/usr.sbin/adduser/rmuser.perl#L143-L151 function old new delta deluser_main 337 380 +43 Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--loginutils/deluser.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/loginutils/deluser.c b/loginutils/deluser.c
index 56bc7eaa6..8e7df737c 100644
--- a/loginutils/deluser.c
+++ b/loginutils/deluser.c
@@ -99,8 +99,14 @@ int deluser_main(int argc, char **argv)
99 pfile = bb_path_passwd_file; 99 pfile = bb_path_passwd_file;
100 if (ENABLE_FEATURE_SHADOWPASSWDS) 100 if (ENABLE_FEATURE_SHADOWPASSWDS)
101 sfile = bb_path_shadow_file; 101 sfile = bb_path_shadow_file;
102 if (opt_delhome) 102 if (opt_delhome) {
103 remove_file(pw->pw_dir, FILEUTILS_RECUR); 103 struct stat st;
104
105 /* Make sure home is an actual directory before
106 * removing it (e.g. users with /dev/null as home) */
107 if (stat(pw->pw_dir, &st) == 0 && S_ISDIR(st.st_mode))
108 remove_file(pw->pw_dir, FILEUTILS_RECUR);
109 }
104 } else { 110 } else {
105 struct group *gr; 111 struct group *gr;
106 do_delgroup: 112 do_delgroup: