Re: [PATCH] getcifsacl: Add support to accept more paths

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



ср, 17 апр. 2019 г. в 10:19, Kenneth D'souza <kdsouza@xxxxxxxxxx>:
>
> Accept more than one path on the getcifsacl command line.
>
> Signed-off-by: Kenneth D'souza <kdsouza@xxxxxxxxxx>
> ---
>  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




[Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux