diff options
author | William Hubbs <w.d.hubbs@gmail.com> | 2014-07-13 14:12:36 -0500 |
---|---|---|
committer | William Hubbs <w.d.hubbs@gmail.com> | 2014-07-13 14:12:36 -0500 |
commit | 71d6d61b28c4c0f285ec51459551d900dfa4ea71 (patch) | |
tree | 546709a3656d5c13f0aece0c9292d59e58095126 /src/rc | |
parent | 40141244e349e6e1d2dfb9ebfbcbf62f68d33a9d (diff) |
checkpath: fix logic for the writable option
The -W option does not need an argument of its own; it can take the
first path after all other options are processed on the command line.
Also, move the processing for the -W option out of the switch so it will
be in the same loop as the other processing.
Diffstat (limited to 'src/rc')
-rw-r--r-- | src/rc/checkpath.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/rc/checkpath.c b/src/rc/checkpath.c index 3c6c5ca6..6a0f8939 100644 --- a/src/rc/checkpath.c +++ b/src/rc/checkpath.c @@ -187,7 +187,7 @@ parse_owner(struct passwd **user, struct group **group, const char *owner) #include "_usage.h" #define extraopts "path1 [path2] [...]" -#define getoptstring "dDfFpm:o:W:" getoptstring_COMMON +#define getoptstring "dDfFpm:o:W" getoptstring_COMMON static const struct option longopts[] = { { "directory", 0, NULL, 'd'}, { "directory-truncate", 0, NULL, 'D'}, @@ -196,7 +196,7 @@ static const struct option longopts[] = { { "pipe", 0, NULL, 'p'}, { "mode", 1, NULL, 'm'}, { "owner", 1, NULL, 'o'}, - { "writable", 1, NULL, 'W'}, + { "writable", 0, NULL, 'W'}, longopts_COMMON }; static const char * const longopts_help[] = { @@ -225,6 +225,7 @@ checkpath(int argc, char **argv) int retval = EXIT_SUCCESS; bool trunc = false; bool chowner = false; + bool writable = false; while ((opt = getopt_long(argc, argv, getoptstring, longopts, (int *) 0)) != -1) @@ -255,9 +256,7 @@ checkpath(int argc, char **argv) applet, optarg); break; case 'W': - if (argv[optind] != NULL) - ewarn("-W/--writable takes only one path, everything else will be ignored"); - exit(!is_writable(optarg)); + writable = true; break; case_RC_COMMON_GETOPT @@ -267,8 +266,8 @@ checkpath(int argc, char **argv) if (optind >= argc) usage(EXIT_FAILURE); - if (type == inode_unknown) - eerrorx("%s: -d, -f, -p, or -W must be specified.", applet); + if (writable && type != inode_unknown) + eerrorx("%s: -W cannot be specified along with -d, -f or -p", applet); if (pw) { uid = pw->pw_uid; @@ -278,6 +277,8 @@ checkpath(int argc, char **argv) gid = gr->gr_gid; while (optind < argc) { + if (writable) + exit(!is_writable(argv[optind])); if (do_check(argv[optind], uid, gid, mode, type, trunc, chowner)) retval = EXIT_FAILURE; optind++; |