diff options
author | Pavel Shilovsky <pshilov@microsoft.com> | 2020-11-09 15:27:51 -0800 |
---|---|---|
committer | Pavel Shilovsky <pshilov@microsoft.com> | 2020-12-04 16:37:41 -0800 |
commit | 6da2dd375de7fa4d9f553128fc2580d536cb04b1 (patch) | |
tree | c5d58b466061b62e2b61b3790e12991052414a35 /getcifsacl.c | |
parent | 1f37d9c1b7c209c438871bdf5aa0d42124f42d4f (diff) | |
download | cifs-utils-6da2dd375de7fa4d9f553128fc2580d536cb04b1.tar.gz cifs-utils-6da2dd375de7fa4d9f553128fc2580d536cb04b1.tar.bz2 cifs-utils-6da2dd375de7fa4d9f553128fc2580d536cb04b1.zip |
getcifsacl: return error if input path doesn't exist
Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
Diffstat (limited to 'getcifsacl.c')
-rw-r--r-- | getcifsacl.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/getcifsacl.c b/getcifsacl.c index d58b769..89851f6 100644 --- a/getcifsacl.c +++ b/getcifsacl.c @@ -344,13 +344,13 @@ getcifsacl_usage(const char *prog) fprintf(stderr, "\nRefer to getcifsacl(1) manpage for details\n"); } -static void +static int getcifsacl(const char *filename) { ssize_t attrlen; size_t bufsize = BUFSIZE; char *attrval; - int failed = 0; + int rc = 0; cifsacl: if (bufsize >= XATTR_SIZE_MAX) { fprintf(stderr, "buffer to allocate exceeds max size of %d\n", @@ -373,16 +373,17 @@ cifsacl: } else { fprintf(stderr, "Failed to getxattr %s: %s\n", filename, strerror(errno)); - failed = -1; + rc = -1; } } - if (failed == 0) { + if (rc == 0) { printf("# filename: %s\n", filename); parse_sec_desc((struct cifs_ntsd *)attrval, attrlen, raw); printf("\n"); } free(attrval); + return rc; } static int recursive(const char *filename, const struct stat *sb, int tflag, struct FTW *ftwbuf) @@ -390,8 +391,7 @@ static int recursive(const char *filename, const struct stat *sb, int tflag, str (void)sb; (void)tflag; (void)ftwbuf; - getcifsacl(filename); - return 0; + return getcifsacl(filename); } int @@ -400,6 +400,7 @@ main(const int argc, char *const argv[]) int c, ret = 0; execname = basename(argv[0]); int do_recursive = 0; + int tmp_rc; if (argc < 2) { fprintf(stderr, "%s: you must specify a filename.\n", execname); @@ -439,13 +440,16 @@ main(const int argc, char *const argv[]) plugin_loaded = true; } + ret = 0; for(; optind < argc; optind++) { - if(do_recursive) { + if (do_recursive) { if (nftw(argv[optind], recursive, 20, 0) == -1) fprintf(stderr, "Invalid filename %s: %s\n", argv[optind], strerror(errno)); + } else { + tmp_rc = getcifsacl(argv[optind]); + if (tmp_rc && !ret) + ret = tmp_rc; } - else - getcifsacl(argv[optind]); } out: |