Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/user Add the -r flag to groupadd; it can be used to...



details:   https://anonhg.NetBSD.org/src/rev/68e8f1505ff6
branches:  trunk
changeset: 573680:68e8f1505ff6
user:      jmmv <jmmv%NetBSD.org@localhost>
date:      Sat Feb 05 10:43:14 2005 +0000

description:
Add the -r flag to groupadd; it can be used to specify a gid range in which
new groups should be created.  This is similar to useradd's -r flag.

Closes my own PR bin/22791.  Patch by URA Hiroshi with some minor changes
by me.

No objections in tech-userlevel@ for multiple days.

diffstat:

 usr.sbin/user/group.8    |   5 +++--
 usr.sbin/user/groupadd.8 |   9 +++++++--
 usr.sbin/user/user.c     |  21 +++++++++++++++------
 3 files changed, 25 insertions(+), 10 deletions(-)

diffs (136 lines):

diff -r 13b3d17f5fc3 -r 68e8f1505ff6 usr.sbin/user/group.8
--- a/usr.sbin/user/group.8     Sat Feb 05 00:36:26 2005 +0000
+++ b/usr.sbin/user/group.8     Sat Feb 05 10:43:14 2005 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: group.8,v 1.10 2003/02/25 10:36:21 wiz Exp $ */
+.\" $NetBSD: group.8,v 1.11 2005/02/05 10:43:14 jmmv Exp $ */
 .\"
 .\"
 .\" Copyright (c) 1999 Alistair G. Crooks.  All rights reserved.
@@ -31,7 +31,7 @@
 .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
 .\"
-.Dd November 30, 1999
+.Dd February 5, 2005
 .Dt GROUP 8
 .Os
 .Sh NAME
@@ -42,6 +42,7 @@
 .Cm add
 .Op Fl ov
 .Op Fl g Ar gid
+.Op Fl r Ar low Ns Li .. Ns Ar high
 .Ar group
 .Nm
 .Cm del
diff -r 13b3d17f5fc3 -r 68e8f1505ff6 usr.sbin/user/groupadd.8
--- a/usr.sbin/user/groupadd.8  Sat Feb 05 00:36:26 2005 +0000
+++ b/usr.sbin/user/groupadd.8  Sat Feb 05 10:43:14 2005 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: groupadd.8,v 1.9 2003/02/14 16:11:37 grant Exp $ */
+.\" $NetBSD: groupadd.8,v 1.10 2005/02/05 10:43:14 jmmv Exp $ */
 .\"
 .\"
 .\" Copyright (c) 1999 Alistair G. Crooks.  All rights reserved.
@@ -31,7 +31,7 @@
 .\" SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
 .\"
-.Dd November 30, 1999
+.Dd February 5, 2005
 .Dt GROUPADD 8
 .Os
 .Sh NAME
@@ -41,6 +41,7 @@
 .Nm
 .Op Fl ov
 .Op Fl g Ar gid
+.Op Fl r Ar low Ns Li .. Ns Ar high
 .Ar group
 .Sh DESCRIPTION
 The
@@ -52,6 +53,10 @@
 gives the numeric group identifier to be used for the new group.
 .It Fl o
 allow the new group to have a gid which is already in use for another group.
+.It Fl r Ar low Ns Li .. Ns Ar high
+sets the low and high bounds of a gid range for new groups.
+A new group can only be created if there are gids which can be assigned
+inside the range.
 .It Fl v
 enables verbose mode - explain the commands as they are executed.
 .El
diff -r 13b3d17f5fc3 -r 68e8f1505ff6 usr.sbin/user/user.c
--- a/usr.sbin/user/user.c      Sat Feb 05 00:36:26 2005 +0000
+++ b/usr.sbin/user/user.c      Sat Feb 05 10:43:14 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: user.c,v 1.76 2004/07/02 12:01:00 agc Exp $ */
+/* $NetBSD: user.c,v 1.77 2005/02/05 10:43:14 jmmv 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.76 2004/07/02 12:01:00 agc Exp $");
+__RCSID("$NetBSD: user.c,v 1.77 2005/02/05 10:43:14 jmmv Exp $");
 #endif
 
 #include <sys/types.h>
@@ -1521,8 +1521,8 @@
                (void) fprintf(stderr, "usage: %s [-e] [-v] user\n", prog);
 #endif
        } else if (strcmp(prog, "groupadd") == 0) {
-               (void) fprintf(stderr, "usage: %s [-g gid] [-o] [-v] group\n",
-                   prog);
+               (void) fprintf(stderr, "usage: %s [-g gid] [-o]"
+                   " [-r lowgid..highgid] [-v] group\n", prog);
        } else if (strcmp(prog, "groupdel") == 0) {
                (void) fprintf(stderr, "usage: %s [-v] group\n", prog);
        } else if (strcmp(prog, "groupmod") == 0) {
@@ -1891,7 +1891,7 @@
 }
 
 #ifdef EXTENSIONS
-#define GROUP_ADD_OPT_EXTENSIONS       "v"
+#define GROUP_ADD_OPT_EXTENSIONS       "r:v"
 #else
 #define GROUP_ADD_OPT_EXTENSIONS       
 #endif
@@ -1903,9 +1903,13 @@
        int     dupgid;
        int     gid;
        int     c;
+       int     lowgid;
+       int     highgid;
 
        gid = -1;
        dupgid = 0;
+       lowgid = LowGid;
+       highgid = HighGid;
        while ((c = getopt(argc, argv, "g:o" GROUP_ADD_OPT_EXTENSIONS)) != -1) {
                switch(c) {
                case 'g':
@@ -1918,6 +1922,11 @@
                        dupgid = 1;
                        break;
 #ifdef EXTENSIONS
+               case 'r':
+                       if (sscanf(optarg, "%d..%d", &lowgid, &highgid) != 2) {
+                               errx(EXIT_FAILURE, "Bad range `%s`", optarg);
+                       }
+                       break;
                case 'v':
                        verbose = 1;
                        break;
@@ -1933,7 +1942,7 @@
                usermgmt_usage("groupadd");
        }
        checkeuid();
-       if (gid < 0 && !getnextgid(&gid, LowGid, HighGid)) {
+       if (gid < 0 && !getnextgid(&gid, lowgid, highgid)) {
                err(EXIT_FAILURE, "can't add group: can't get next gid");
        }
        if (!dupgid && getgrgid((gid_t) gid) != NULL) {



Home | Main Index | Thread Index | Old Index