diff options
author | as145665 <none@none> | 2006-07-20 12:27:26 -0700 |
---|---|---|
committer | as145665 <none@none> | 2006-07-20 12:27:26 -0700 |
commit | bda8495c343003ad268b467cd347f95f25eeffc4 (patch) | |
tree | db321c78247a411ff175c80728a6ff82f090ac92 /usr/src/cmd/chgrp | |
parent | f7209cf2d2e114162cab4b5252c05118a6b7e54a (diff) | |
download | illumos-gate-bda8495c343003ad268b467cd347f95f25eeffc4.tar.gz |
6332690 *chown*, *chgrp* assume that a numeric user or group name operand is the uid/gid
Diffstat (limited to 'usr/src/cmd/chgrp')
-rw-r--r-- | usr/src/cmd/chgrp/chgrp.c | 37 |
1 files changed, 19 insertions, 18 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++) { |