Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/chown change the parsing of chown user[:gid] to the...
details: https://anonhg.NetBSD.org/src/rev/062553c0b8e1
branches: trunk
changeset: 485984:062553c0b8e1
user: darrenr <darrenr%NetBSD.org@localhost>
date: Wed May 10 12:22:34 2000 +0000
description:
change the parsing of chown user[:gid] to the following:
1. if there is a colon present, use that as a separator for user:group
2. if there is no colon, attempt to convert the arg into a username,
searching backwards in the string for a '.' for us.er.group
3. if the arg doesn't match a username and has a '.' in it, split it
up and try user.group
diffstat:
usr.sbin/chown/chown.c | 36 +++++++++++++++++++++++-------------
1 files changed, 23 insertions(+), 13 deletions(-)
diffs (81 lines):
diff -r a07f2bc514e3 -r 062553c0b8e1 usr.sbin/chown/chown.c
--- a/usr.sbin/chown/chown.c Wed May 10 11:17:50 2000 +0000
+++ b/usr.sbin/chown/chown.c Wed May 10 12:22:34 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: chown.c,v 1.20 1999/11/09 15:06:30 drochner Exp $ */
+/* $NetBSD: chown.c,v 1.21 2000/05/10 12:22:34 darrenr Exp $ */
/*
* Copyright (c) 1988, 1993, 1994
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)chown.c 8.8 (Berkeley) 4/4/94";
#else
-__RCSID("$NetBSD: chown.c,v 1.20 1999/11/09 15:06:30 drochner Exp $");
+__RCSID("$NetBSD: chown.c,v 1.21 2000/05/10 12:22:34 darrenr Exp $");
#endif
#endif /* not lint */
@@ -64,7 +64,7 @@
#include <unistd.h>
static void a_gid __P((const char *));
-static void a_uid __P((const char *));
+static int a_uid __P((const char *));
static id_t id __P((const char *, const char *));
int main __P((int, char **));
static void usage __P((void));
@@ -149,17 +149,19 @@
uid = (uid_t)-1;
gid = (gid_t)-1;
if (ischown) {
-#ifdef SUPPORT_DOT
- if ((cp = strchr(*argv, '.')) != NULL) {
- *cp++ = '\0';
- a_gid(cp);
- } else
-#endif
if ((cp = strchr(*argv, ':')) != NULL) {
*cp++ = '\0';
a_gid(cp);
}
- a_uid(*argv);
+#ifdef SUPPORT_DOT
+ else if ((cp = strrchr(*argv, '.')) != NULL) {
+ if (a_uid(*argv) == -1) {
+ *cp++ = '\0';
+ a_gid(cp);
+ }
+ }
+#endif
+ (void) a_uid(*argv);
} else
a_gid(*argv);
@@ -218,15 +220,23 @@
gid = ((gr = getgrnam(s)) == NULL) ? id(s, "group") : gr->gr_gid;
}
-static void
+static int
a_uid(s)
const char *s;
{
struct passwd *pw;
if (*s == '\0') /* Argument was "[:.]gid". */
- return;
- uid = ((pw = getpwnam(s)) == NULL) ? id(s, "user") : pw->pw_uid;
+ return 0;
+ pw = getpwnam(s);
+ if (pw != NULL) {
+ uid = pw->pw_uid;
+ return 0;
+ }
+ if (isalpha(*s))
+ return -1;
+ uid = id(s, "user");
+ return 0;
}
static id_t
Home |
Main Index |
Thread Index |
Old Index