[hackers] [PATCH v3 2/2][sbase] chgrp: parse gid if operand is not group name

From: Richard Ipsum <richardipsum_AT_fastmail.co.uk>
Date: Thu, 4 Jul 2019 22:49:29 +0100

---
 chgrp.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/chgrp.c b/chgrp.c
index 7ee3553..21e7e22 100644
--- a/chgrp.c
+++ b/chgrp.c
_AT_@ -67,13 +67,16 @@ main(int argc, char *argv[])
 		usage();
 
 	errno = 0;
-	if (!(gr = getgrnam(argv[0]))) {
+	if ((gr = getgrnam(*argv))) {
+		gid = gr->gr_gid;
+	} else {
 		if (errno)
-			eprintf("getgrnam %s:", argv[0]);
-		else
-			eprintf("getgrnam %s: no such group\n", argv[0]);
+			eprintf("getgrnam %s:", *argv);
+		gid = estrtonum(*argv, 0, UINT_MAX);
 	}
-	gid = gr->gr_gid;
+
+	if (gid == -1)
+		usage();
 
 	for (argc--, argv++; *argv; argc--, argv++)
 		recurse(*argv, NULL, &r);
-- 
2.21.0
Received on Thu Jul 04 2019 - 23:49:29 CEST

This archive was generated by hypermail 2.3.0 : Fri Jul 05 2019 - 00:00:40 CEST