summaryrefslogtreecommitdiff
path: root/loginutils
diff options
context:
space:
mode:
authorDenys Vlasenko2010-11-07 17:51:58 +0100
committerDenys Vlasenko2010-11-07 17:51:58 +0100
commite057b0f94f679af834d5eb15e10c714c72c16740 (patch)
treeeb13aa93ad9c9fdcc8dcb3377f9152a5edbbfbd9 /loginutils
parentf595d8ed46d627af9808a3c881a0e9a7fb88e3cb (diff)
downloadbusybox-e057b0f94f679af834d5eb15e10c714c72c16740.zip
busybox-e057b0f94f679af834d5eb15e10c714c72c16740.tar.gz
delgroup: correct the check for users who still use the group
Signed-off-by: Tito <farmatito@tiscali.it> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'loginutils')
-rw-r--r--loginutils/deluser.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/loginutils/deluser.c b/loginutils/deluser.c
index 12fbbc6..8ee72ef 100644
--- a/loginutils/deluser.c
+++ b/loginutils/deluser.c
@@ -48,21 +48,21 @@ int deluser_main(int argc, char **argv)
if (ENABLE_FEATURE_SHADOWPASSWDS)
sfile = bb_path_shadow_file;
} else {
+ struct group *gr;
do_delgroup:
/* "delgroup GROUP" or "delgroup USER GROUP" */
- xgetgrnam(name); /* bail out if GROUP is wrong */
+ gr = xgetgrnam(name); /* bail out if GROUP is wrong */
if (!member) {
- /* "delgroup GROUP".
- * If user with the same name exists,
- * bail out.
- */
-//BUG: check should be done by GID, not by matching name!
-//1. find GROUP's GID
-//2. check that /etc/passwd doesn't have lines of the form
-// user:pwd:uid:GID:...
-//3. bail out if at least one such line exists
- if (getpwnam(name) != NULL)
- bb_error_msg_and_die("'%s' still has '%s' as their primary group!", name, name);
+ /* "delgroup GROUP" */
+ struct passwd *pw;
+ struct passwd pwent;
+ /* Check if the group is in use */
+#define passwd_buf bb_common_bufsiz1
+ while (!getpwent_r(&pwent, passwd_buf, sizeof(passwd_buf), &pw)) {
+ if (pwent.pw_gid == gr->gr_gid)
+ bb_error_msg_and_die("'%s' still has '%s' as their primary group!", pwent.pw_name, name);
+ }
+ //endpwent();
}
pfile = bb_path_group_file;
if (ENABLE_FEATURE_SHADOWPASSWDS)