linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] getcifsacl: Add support to accept more paths
@ 2019-04-17 17:19 Kenneth D'souza
  2019-04-18 19:36 ` Pavel Shilovsky
  0 siblings, 1 reply; 2+ messages in thread
From: Kenneth D'souza @ 2019-04-17 17:19 UTC (permalink / raw)
  To: linux-cifs; +Cc: piastryyy

Accept more than one path on the getcifsacl command line.

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

diff --git a/getcifsacl.c b/getcifsacl.c
index fc78881..df3099d 100644
--- a/getcifsacl.c
+++ b/getcifsacl.c
@@ -340,14 +340,54 @@ 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) {
+		printf("buffer to allocate exceeds max size of %d\n",
+				XATTR_SIZE_MAX);
+		exit(1);
+	}
+
+	attrval = malloc(bufsize * sizeof(char));
+	if (!attrval) {
+		printf("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 +414,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 +425,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.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] getcifsacl: Add support to accept more paths
  2019-04-17 17:19 [PATCH] getcifsacl: Add support to accept more paths Kenneth D'souza
@ 2019-04-18 19:36 ` Pavel Shilovsky
  0 siblings, 0 replies; 2+ messages in thread
From: Pavel Shilovsky @ 2019-04-18 19:36 UTC (permalink / raw)
  To: Kenneth D'souza; +Cc: linux-cifs

ср, 17 апр. 2019 г. в 10:19, Kenneth D'souza <kdsouza@redhat.com>:
>
> Accept more than one path on the getcifsacl command line.
>
> Signed-off-by: Kenneth D'souza <kdsouza@redhat.com>
> ---
>  getcifsacl.c | 82 +++++++++++++++++++++++++++++-----------------------
>  1 file changed, 46 insertions(+), 36 deletions(-)
>
> diff --git a/getcifsacl.c b/getcifsacl.c
> index fc78881..df3099d 100644
> --- a/getcifsacl.c
> +++ b/getcifsacl.c
> @@ -340,14 +340,54 @@ 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) {
> +               printf("buffer to allocate exceeds max size of %d\n",
> +                               XATTR_SIZE_MAX);
> +               exit(1);
> +       }
> +
> +       attrval = malloc(bufsize * sizeof(char));
> +       if (!attrval) {
> +               printf("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 +414,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 +425,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.20.1
>

Fixed the code style and merged:
https://github.com/piastry/cifs-utils/commit/9beaa8c3c895ca8460d81fb54a6a0de2bb21a277

Also fixed the usage message separately:
https://github.com/piastry/cifs-utils/commit/f2955af017f604003e3c8c3efe0fb0fb85584cea

--
Best regards,
Pavel Shilovsky

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-04-18 19:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-17 17:19 [PATCH] getcifsacl: Add support to accept more paths Kenneth D'souza
2019-04-18 19:36 ` Pavel Shilovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).