[hackers] [sbase] chown: fix user:group option parsing || Quentin Rameau

From: <git_AT_suckless.org>
Date: Mon, 21 Dec 2015 20:08:02 +0100 (CET)

commit a02d66b8fc651979b7f905f78722a6192896eb90
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Mon Dec 21 19:37:10 2015 +0100
Commit: sin <sin_AT_2f30.org>
CommitDate: Mon Dec 21 19:07:51 2015 +0000

    chown: fix user:group option parsing
    
    Check that either user or group is correctly passed, and adapt
    documention according to that.

diff --git a/chown.1 b/chown.1
index 4bb3b8b..d2bebca 100644
--- a/chown.1
+++ b/chown.1
_AT_@ -11,15 +11,23 @@
 .Fl R
 .Op Fl H | L | P
 .Oc
-.Op Ar owner Op Ar :group
+.Ar owner Ns Op Pf : Op Ar group
+.Op Ar file ...
+.Nm
+.Op Fl h
+.Oo
+.Fl R
+.Op Fl H | L | P
+.Oc
+.Pf : Ar group
 .Op Ar file ...
 .Sh DESCRIPTION
 .Nm
-sets the user or group id of each
+sets the user and/or group id of each
 .Ar file
 to the uid of
 .Ar owner
-or the gid of
+and/or the gid of
 .Ar group
 respectively.
 .Sh OPTIONS
diff --git a/chown.c b/chown.c
index 1bf9cbb..2009507 100644
--- a/chown.c
+++ b/chown.c
_AT_@ -40,8 +40,9 @@ chownpwgr(const char *path, struct stat *st, void *data, struct recursor *r)
 static void
 usage(void)
 {
- eprintf("usage: %s [-h] [-R [-H | -L | -P]] [owner][:[group]] "
- "file ...\n", argv0);
+ eprintf("usage: %s [-h] [-R [-H | -L | -P]] owner[:[group]] file ...\n"
+ " %s [-h] [-R [-H | -L | -P]] :group file ...\n",
+ argv0, argv0);
 }
 
 int
_AT_@ -99,6 +100,9 @@ main(int argc, char *argv[])
                         gid = estrtonum(group, 0, UINT_MAX);
                 }
         }
+ if (uid == (uid_t)-1 && gid == (gid_t)-1)
+ usage();
+
         for (argc--, argv++; *argv; argc--, argv++)
                 recurse(*argv, NULL, &r);
 
Received on Mon Dec 21 2015 - 20:08:02 CET

This archive was generated by hypermail 2.3.0 : Mon Dec 21 2015 - 20:12:14 CET