NetBSD Problem Report #22791
Received: (qmail 25122 invoked by uid 605); 14 Sep 2003 17:30:52 -0000
Message-Id: <20030914173042.2CBDF24B@sun.local>
Date: Sun, 14 Sep 2003 19:30:42 +0200 (CEST)
From: jmmv@menta.net
Sender: gnats-bugs-owner@NetBSD.org
Reply-To: jmmv@menta.net
To: gnats-bugs@gnats.netbsd.org
Subject: Implement -r option in groupadd
X-Send-Pr-Version: 3.95
>Number: 22791
>Category: bin
>Synopsis: Implement -r option in groupadd
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: jmmv
>State: closed
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Sun Sep 14 17:31:00 +0000 2003
>Closed-Date: Sat Feb 05 10:43:59 +0000 2005
>Last-Modified: Sat Feb 05 10:44:01 +0000 2005
>Originator: Julio M. Merino Vidal
>Release: NetBSD 1.6ZB
>Organization:
Julio M. Merino Vidal <jmmv@menta.net>
The NetBSD Project - http://www.NetBSD.org/
>Environment:
System: NetBSD dawn.local 1.6ZB NetBSD 1.6ZB (DAWN) #0: Sun Sep 14 17:32:28 CEST 2003 jmmv@dawn.local:/home/NetBSD/obj/home/NetBSD/src/sys/arch/i386/compile/DAWN i386
Architecture: i386
Machine: i386
>Description:
The useradd utility provides the '-r' flag, which lets the admin
specify a range where new uid's may be allocated. groupadd misses
this flag, which could be used to give a gid range.
You may think where this is be useful. pkgsrc, for example. You
could tell it to automatically create new users and groups in a given
range, to avoid mixing them with regular users.
>How-To-Repeat:
>Fix:
Not provided. Shouldn't be difficult for someone who is familiar with
the code.
>Release-Note:
>Audit-Trail:
From: URA Hiroshi <ura@hiru.aoba.yokohama.jp>
To: jmmv@menta.net
Cc: gnats-bugs@netbsd.org
Subject: Re: bin/22791: Implement -r option in groupadd
Date: Fri, 14 Jan 2005 03:51:21 +0900 (JST)
>> Sun, 14 Sep 2003 19:30:42 +0200 (CEST), jmmv@menta.net said:
> >Number: 22791
> >Category: bin
> >Synopsis: Implement -r option in groupadd
> >Description:
> The useradd utility provides the '-r' flag, which lets the admin
> specify a range where new uid's may be allocated. groupadd misses
> this flag, which could be used to give a gid range.
>
> You may think where this is be useful. pkgsrc, for example. You
> could tell it to automatically create new users and groups in a given
> range, to avoid mixing them with regular users.
> >Fix:
> Not provided. Shouldn't be difficult for someone who is familiar with
> the code.
I wrote the following patch.
--
ura
Index: usr.sbin/user/group.8
===================================================================
RCS file: /cvsroot/src/usr.sbin/user/group.8,v
retrieving revision 1.10
diff -u -u -r1.10 group.8
--- usr.sbin/user/group.8 25 Feb 2003 10:36:21 -0000 1.10
+++ usr.sbin/user/group.8 13 Jan 2005 18:35:33 -0000
@@ -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
Index: usr.sbin/user/groupadd.8
===================================================================
RCS file: /cvsroot/src/usr.sbin/user/groupadd.8,v
retrieving revision 1.9
diff -u -u -r1.9 groupadd.8
--- usr.sbin/user/groupadd.8 14 Feb 2003 16:11:37 -0000 1.9
+++ usr.sbin/user/groupadd.8 13 Jan 2005 18:35:34 -0000
@@ -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 gid ranges for new groups. A new group
+can only be created if there are gids which can be assigned from one
+of the free ranges.
.It Fl v
enables verbose mode - explain the commands as they are executed.
.El
Index: usr.sbin/user/user.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/user/user.c,v
retrieving revision 1.76
diff -u -u -r1.76 user.c
--- usr.sbin/user/user.c 2 Jul 2004 12:01:00 -0000 1.76
+++ usr.sbin/user/user.c 13 Jan 2005 18:35:39 -0000
@@ -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,6 +1903,8 @@
int dupgid;
int gid;
int c;
+ int lowgid = LowGid;
+ int highgid = HighGid;
gid = -1;
dupgid = 0;
@@ -1918,6 +1920,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 +1940,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) {
Responsible-Changed-From-To: bin-bug-people->jmmv
Responsible-Changed-By: jmmv@netbsd.org
Responsible-Changed-When: Sat, 15 Jan 2005 17:11:40 +0000
Responsible-Changed-Why:
I originally filled the PR, so I'll look at applying this patch (which,
after a quick read looks promising).
State-Changed-From-To: open->closed
State-Changed-By: jmmv@netbsd.org
State-Changed-When: Sat, 05 Feb 2005 10:43:59 +0000
State-Changed-Why:
I've just applied the proposed patch with some minor changes.
From: "Julio M. Merino Vidal" <jmmv@netbsd.org>
To: gnats-bugs@netbsd.org
Cc:
Subject: PR/22791 CVS commit: src/usr.sbin/user
Date: Sat, 5 Feb 2005 10:43:14 +0000 (UTC)
Module Name: src
Committed By: jmmv
Date: Sat Feb 5 10:43:14 UTC 2005
Modified Files:
src/usr.sbin/user: group.8 groupadd.8 user.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -r1.10 -r1.11 src/usr.sbin/user/group.8
cvs rdiff -r1.9 -r1.10 src/usr.sbin/user/groupadd.8
cvs rdiff -r1.76 -r1.77 src/usr.sbin/user/user.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.