Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/user Warn if the group being removed is still the p...



details:   https://anonhg.NetBSD.org/src/rev/27f5a6935d25
branches:  trunk
changeset: 584279:27f5a6935d25
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Sep 12 15:45:03 2005 +0000

description:
Warn if the group being removed is still the primary group of an existing
user. From Liam Foy.

diffstat:

 usr.sbin/user/user.c |  37 ++++++++++++++++++++++++++++++-------
 1 files changed, 30 insertions(+), 7 deletions(-)

diffs (65 lines):

diff -r 6802c555fb53 -r 27f5a6935d25 usr.sbin/user/user.c
--- a/usr.sbin/user/user.c      Mon Sep 12 15:42:12 2005 +0000
+++ b/usr.sbin/user/user.c      Mon Sep 12 15:45:03 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: user.c,v 1.90 2005/09/09 22:04:09 wiz Exp $ */
+/* $NetBSD: user.c,v 1.91 2005/09/12 15:45:03 christos Exp $ */
 
 /*
  * Copyright (c) 1999 Alistair G. Crooks.  All rights reserved.
@@ -35,7 +35,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1999 \
                The NetBSD Foundation, Inc.  All rights reserved.");
-__RCSID("$NetBSD: user.c,v 1.90 2005/09/09 22:04:09 wiz Exp $");
+__RCSID("$NetBSD: user.c,v 1.91 2005/09/12 15:45:03 christos Exp $");
 #endif
 
 #include <sys/types.h>
@@ -198,11 +198,11 @@
 #define UNSET_INACTIVE "Null (unset)"
 #define UNSET_EXPIRY   "Null (unset)"
 
-static int asystem(const char *fmt, ...)
-       __attribute__((__format__(__printf__, 1, 2)));
-static int is_number(const char *);
-       
-static int     verbose;
+static int             asystem(const char *fmt, ...)
+                           __attribute__((__format__(__printf__, 1, 2)));
+static int             is_number(const char *);
+static struct group    *find_group_info(const char *);
+static int             verbose;
 
 static char *
 skipspace(char *s)
@@ -543,6 +543,29 @@
                if (entc == groupc &&
                    strncmp(group, buf, (unsigned) entc) == 0) {
                        if (newent == NULL) {
+                               struct group    *grp_rm;
+                               struct passwd   *user_pwd;
+
+                               /*
+                                * Check that the group being removed
+                                * isn't any user's Primary group. Just
+                                * warn if it is. This could cause problems
+                                * if the group GID was reused for a
+                                * different purpose.
+                                */
+
+                               grp_rm = find_group_info(group);
+                               while ((user_pwd = getpwent()) != NULL) {
+                                       if (user_pwd->pw_gid == grp_rm->gr_gid) {
+                                               warnx("Warning: group `%s'(%d)"
+                                                  " is the primary group of"
+                                                  " `%s'. Use caution if you"
+                                                  " later add this GID.",
+                                                  grp_rm->gr_name,
+                                                  grp_rm->gr_gid, user_pwd->pw_name);
+                                       }
+                               }
+                               endpwent();
                                continue;
                        } else {
                                cc = strlen(newent);



Home | Main Index | Thread Index | Old Index