summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoras145665 <none@none>2006-07-20 12:27:26 -0700
committeras145665 <none@none>2006-07-20 12:27:26 -0700
commitbda8495c343003ad268b467cd347f95f25eeffc4 (patch)
treedb321c78247a411ff175c80728a6ff82f090ac92
parentf7209cf2d2e114162cab4b5252c05118a6b7e54a (diff)
downloadillumos-gate-bda8495c343003ad268b467cd347f95f25eeffc4.tar.gz
6332690 *chown*, *chgrp* assume that a numeric user or group name operand is the uid/gid
-rw-r--r--usr/src/cmd/chgrp/chgrp.c37
-rw-r--r--usr/src/cmd/chown/chown.c64
2 files changed, 53 insertions, 48 deletions
diff --git a/usr/src/cmd/chgrp/chgrp.c b/usr/src/cmd/chgrp/chgrp.c
index a4212b19a8..41089443fa 100644
--- a/usr/src/cmd/chgrp/chgrp.c
+++ b/usr/src/cmd/chgrp/chgrp.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -193,28 +192,30 @@ main(int argc, char *argv[])
usage();
}
- if (isnumber(argv[0])) {
- errno = 0;
- gid = (gid_t)strtol(argv[0], NULL, 10); /* gid is an int */
- if (errno != 0) {
- if (errno == ERANGE) {
- (void) fprintf(stderr, gettext(
+ if ((gr = getgrnam(argv[0])) != NULL) {
+ gid = gr->gr_gid;
+ } else {
+ if (isnumber(argv[0])) {
+ errno = 0;
+ /* gid is an int */
+ gid = (gid_t)strtol(argv[0], NULL, 10);
+ if (errno != 0) {
+ if (errno == ERANGE) {
+ (void) fprintf(stderr, gettext(
"chgrp: group id is too large\n"));
- exit(2);
- } else {
- (void) fprintf(stderr, gettext(
+ exit(2);
+ } else {
+ (void) fprintf(stderr, gettext(
"chgrp: invalid group id\n"));
- exit(2);
+ exit(2);
+ }
}
- }
- } else {
- if ((gr = getgrnam(argv[0])) == NULL) {
+ } else {
(void) fprintf(stderr, "chgrp: ");
(void) fprintf(stderr, gettext("unknown group: %s\n"),
argv[0]);
exit(2);
}
- gid = gr->gr_gid;
}
for (c = 1; c < argc; c++) {
diff --git a/usr/src/cmd/chown/chown.c b/usr/src/cmd/chown/chown.c
index d5912c9aa3..f5d637b1ea 100644
--- a/usr/src/cmd/chown/chown.c
+++ b/usr/src/cmd/chown/chown.c
@@ -171,7 +171,6 @@ main(int argc, char *argv[])
break;
}
}
-
/*
* Check for sufficient arguments
* or a usage error.
@@ -192,49 +191,54 @@ main(int argc, char *argv[])
*/
if ((grpp = strchr(argv[0], ':')) != NULL) {
*grpp++ = 0;
+ if ((grp = getgrnam(grpp)) != NULL) {
+ gid = grp->gr_gid;
+ } else {
+ if (isnumber(grpp)) {
+ errno = 0;
+ gid = (gid_t)strtol(grpp, NULL, 10);
+ if (errno != 0) {
+ if (errno == ERANGE) {
+ (void) fprintf(stderr, gettext(
+ "chown: group id too large\n"));
+ exit(2);
+ } else {
+ (void) fprintf(stderr, gettext(
+ "chown: invalid group id\n"));
+ exit(2);
+ }
+ }
+ } else {
+ (void) fprintf(stderr, gettext(
+ "chown: unknown group id %s\n"), grpp);
+ exit(2);
+ }
+ }
+ }
- if (isnumber(grpp)) {
+ if ((pwd = getpwnam(argv[0])) != NULL) {
+ uid = pwd->pw_uid;
+ } else {
+ if (isnumber(argv[0])) {
errno = 0;
- gid = (gid_t)strtol(grpp, NULL, 10);
+ uid = (uid_t)strtol(argv[0], NULL, 10);
if (errno != 0) {
if (errno == ERANGE) {
(void) fprintf(stderr, gettext(
- "chown: group id too large\n"));
+ "chown: user id too large\n"));
exit(2);
} else {
(void) fprintf(stderr, gettext(
- "chown: invalid group id\n"));
+ "chown: invalid user id\n"));
exit(2);
}
}
- } else if ((grp = getgrnam(grpp)) == NULL) {
+ } else {
(void) fprintf(stderr, gettext(
- "chown: unknown group id %s\n"), grpp);
+ "chown: unknown user id %s\n"), argv[0]);
exit(2);
- } else
- gid = grp->gr_gid;
- }
-
- if (isnumber(argv[0])) {
- errno = 0;
- uid = (uid_t)strtol(argv[0], NULL, 10);
- if (errno != 0) {
- if (errno == ERANGE) {
- (void) fprintf(stderr, gettext(
- "chown: user id too large\n"));
- exit(2);
- } else {
- (void) fprintf(stderr, gettext(
- "chown: invalid user id\n"));
- exit(2);
- }
}
- } else if ((pwd = getpwnam(argv[0])) == NULL) {
- (void) fprintf(stderr, gettext(
- "chown: unknown user id %s\n"), argv[0]);
- exit(2);
- } else
- uid = pwd->pw_uid;
+ }
for (c = 1; c < argc; c++) {
tree = NULL;