File 0003-getcifsacl-Add-support-to-accept-more-paths.patch of Package cifs-utils.12585

From 9beaa8c3c895ca8460d81fb54a6a0de2bb21a277 Mon Sep 17 00:00:00 2001
From: Kenneth D'souza <kdsouza@redhat.com>
Date: Wed, 17 Apr 2019 22:49:09 +0530
Subject: [PATCH] getcifsacl: Add support to accept more paths

Accept more than one path on the getcifsacl command line.

Signed-off-by: Kenneth D'souza <kdsouza@redhat.com>
---
 getcifsacl.c | 80 +++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 44 insertions(+), 36 deletions(-)

diff --git a/getcifsacl.c b/getcifsacl.c
index fc78881..556178a 100644
--- a/getcifsacl.c
+++ b/getcifsacl.c
@@ -340,14 +340,52 @@ getcifsacl_usage(const char *prog)
 	fprintf(stderr, "\nRefer to getcifsacl(1) manpage for details\n");
 }
 
+static void
+getcifsacl(const char *filename, bool raw)
+{
+	ssize_t attrlen;
+	size_t bufsize = BUFSIZE;
+	char *attrval;
+	int failed = 0;
+cifsacl:
+	if (bufsize >= XATTR_SIZE_MAX) {
+		fprintf(stderr, "buffer to allocate exceeds max size of %d\n",
+			XATTR_SIZE_MAX);
+		exit(1);
+	}
+
+	attrval = malloc(bufsize * sizeof(char));
+	if (!attrval) {
+		fprintf(stderr, "error allocating memory for attribute value buffer\n");
+		exit(1);
+	}
+
+	attrlen = getxattr(filename, ATTRNAME, attrval, bufsize);
+	if (attrlen == -1) {
+		if (errno == ERANGE) {
+			free(attrval);
+			bufsize += BUFSIZE;
+			goto cifsacl;
+		} else {
+			fprintf(stderr, "Failed to getxattr %s: %s\n", filename,
+				strerror(errno));
+			failed = -1;
+		}
+	}
+
+	if (failed == 0) {
+		printf("# filename: %s\n", filename);
+		parse_sec_desc((struct cifs_ntsd *)attrval, attrlen, raw);
+		printf("\n");
+	}
+	free(attrval);
+}
+
 int
 main(const int argc, char *const argv[])
 {
 	int c, ret = 0;
 	bool raw = false;
-	ssize_t attrlen;
-	size_t bufsize = BUFSIZE;
-	char *filename, *attrval;
 	execname = basename(argv[0]);
 
 	if (argc < 2) {
@@ -374,8 +412,7 @@ main(const int argc, char *const argv[])
 		printf("you must specify a filename after options.\n");
 		printf("Usage: getcifsacl [option] <file_name>\n");
 		goto out;
-	} else
-		filename = argv[optind];
+	}
 
 	if (!raw && !plugin_loaded) {
 		ret = init_plugin(&plugin_handle);
@@ -386,38 +423,9 @@ main(const int argc, char *const argv[])
 			plugin_loaded = true;
 	}
 
-cifsacl:
-	if (bufsize >= XATTR_SIZE_MAX) {
-		printf("buffer to allocate exceeds max size of %d\n",
-				XATTR_SIZE_MAX);
-		ret = -1;
-		goto out;
-	}
-
-	attrval = malloc(bufsize * sizeof(char));
-	if (!attrval) {
-		printf("error allocating memory for attribute value buffer\n");
-		ret = -1;
-		goto out;
-	}
-
-	attrlen = getxattr(filename, ATTRNAME, attrval, bufsize);
-	if (attrlen == -1) {
-		if (errno == ERANGE) {
-			free(attrval);
-			bufsize += BUFSIZE;
-			goto cifsacl;
-		} else {
-			fprintf(stderr, "getxattr failed on %s: %s\n", filename, strerror(errno) );
-			free(attrval);
-			ret = -1;
-			goto out;
-		}
-	}
-
-	parse_sec_desc((struct cifs_ntsd *)attrval, attrlen, raw);
+	for(; optind < argc; optind++)
+		getcifsacl(argv[optind], raw);
 
-	free(attrval);
 out:
 	if (plugin_loaded)
 		exit_plugin(plugin_handle);
-- 
2.16.4