Allow a numeric ID to be preceeded by '#' to avoid the name lookup.

Update man pages to match.
This commit is contained in:
dsl 2003-09-25 10:30:10 +00:00
parent 703c60f5c6
commit e045a0f96e
3 changed files with 26 additions and 18 deletions

View File

@ -29,9 +29,9 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)chgrp.1 8.3 (Berkeley) 3/31/94
.\" $NetBSD: chgrp.1,v 1.16 2003/08/07 11:25:14 agc Exp $
.\" $NetBSD: chgrp.1,v 1.17 2003/09/25 10:30:10 dsl Exp $
.\"
.Dd January 18, 2003
.Dd September 25, 2003
.Dt CHGRP 1
.Os
.Sh NAME
@ -110,8 +110,11 @@ The
.Ar group
operand can be either a group name from the group database,
or a numeric group ID.
If a group name is also a numeric group ID, the operand is used as a
group name.
Since it is valid to have a group name that is numeric (and
doesn't have the numeric ID that matches its name) the name lookup
is always done first.
Preceeding the ID with a ``#'' character will force it to be taken
as a number.
.Pp
The user invoking
.Nm
@ -147,5 +150,6 @@ utility is expected to be POSIX 1003.2 compatible.
.Pp
The
.Fl v
option is an extension to
option and the use of ``#'' to force a numeric group ID
are extensions to
.St -p1003.2 .

View File

@ -26,9 +26,9 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)chown.8 8.3 (Berkeley) 3/31/94
.\" $NetBSD: chown.8,v 1.18 2003/08/07 11:25:14 agc Exp $
.\" $NetBSD: chown.8,v 1.19 2003/09/25 10:30:10 dsl Exp $
.\"
.Dd January 18, 2003
.Dd September 25, 2003
.Dt CHOWN 8
.Os
.Sh NAME
@ -114,14 +114,15 @@ operand is specified, it must be preceded by a colon (``:'') character.
.Pp
The
.Ar owner
may be either a numeric user ID or a user name.
If a user name is also a numeric user ID, the operand is used as a
user name.
may be either a user name or a numeric user ID.
The
.Ar group
may be either a numeric group ID or a group name.
If a group name is also a numeric group ID, the operand is used as a
group name.
may be either a group name or a numeric group ID.
Since it is valid to have a user or group name that is numeric (and
doesn't have the numeric ID that matches its name) the name lookup
is always done first.
Preceeding an ID with a ``#'' character will force it to be taken
as a number.
.Pp
The ownership of a file may only be altered by a super-user for
obvious security reasons.
@ -155,5 +156,6 @@ command is expected to be POSIX 1003.2 compliant.
.Pp
The
.Fl v
option is an extension to
option and the use of ``#'' to force a numeric lookup
are extensions to
.St -p1003.2 .

View File

@ -1,4 +1,4 @@
/* $NetBSD: chown.c,v 1.28 2003/08/07 11:25:14 agc Exp $ */
/* $NetBSD: chown.c,v 1.29 2003/09/25 10:30:10 dsl Exp $ */
/*
* Copyright (c) 1988, 1993, 1994, 2003
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1993, 1994, 2003\n\
#if 0
static char sccsid[] = "@(#)chown.c 8.8 (Berkeley) 4/4/94";
#else
__RCSID("$NetBSD: chown.c,v 1.28 2003/08/07 11:25:14 agc Exp $");
__RCSID("$NetBSD: chown.c,v 1.29 2003/09/25 10:30:10 dsl Exp $");
#endif
#endif /* not lint */
@ -231,7 +231,7 @@ a_gid(s)
if (*s == '\0') /* Argument was "uid[:.]". */
return;
gr = getgrnam(s);
gr = *s == '#' ? NULL : getgrnam(s);
if (gr == NULL)
gid = id(s, "group");
else
@ -245,7 +245,7 @@ a_uid(s)
{
if (*s == '\0') /* Argument was "[:.]gid". */
return;
if (uid_from_user(s, &uid) == -1) {
if (*s == '#' || uid_from_user(s, &uid) == -1) {
uid = id(s, "user");
}
return;
@ -259,6 +259,8 @@ id(name, type)
char *ep;
errno = 0;
if (*name == '#')
name++;
val = (id_t)strtoul(name, &ep, 10);
if (errno)
err(EXIT_FAILURE, "%s", name);