Linux-NFS Archive on lore.kernel.org
 help / Atom feed
* [PATCH] Add support for -L(logical) and -P(physical) option in nfs4_getfacl.
@ 2018-12-05  2:10 Kenneth D'souza
  2019-01-28  3:03 ` Kenneth Dsouza
  0 siblings, 1 reply; 2+ messages in thread
From: Kenneth D'souza @ 2018-12-05  2:10 UTC (permalink / raw)
  To: linux-nfs; +Cc: bfields

Signed-off-by: Kenneth D'souza <kdsouza@redhat.com>
---
 man/man1/nfs4_getfacl.1     | 18 +++++++++++++-
 nfs4_getfacl/nfs4_getfacl.c | 47 +++++++++++++++++++++++++++++++++----
 2 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/man/man1/nfs4_getfacl.1 b/man/man1/nfs4_getfacl.1
index 83067c9..940a2b5 100644
--- a/man/man1/nfs4_getfacl.1
+++ b/man/man1/nfs4_getfacl.1
@@ -8,7 +8,7 @@
 .SH NAME
 nfs4_getfacl \- get NFSv4 file/directory access control lists
 .SH SYNOPSIS
-.B nfs4_getfacl [-HR]
+.B nfs4_getfacl [-HRLP]
 file ...
 .SH DESCRIPTION
 .B nfs4_getfacl 
@@ -28,6 +28,22 @@ flag is specified,
 .B nfs4_getfacl
 will list the NFSv4 ACLs of all files and directories recursively.
 
+If the
+.BR -L / --logical
+flag is specified,
+.B nfs4_getfacl
+will follow symbolic links to directories. The default behavior is to follow
+symbolic link arguments, and skip symbolic links encountered in subdirectories.
+Only effective in combination with -R.
+
+If the
+.BR -P / --physical
+flag is specified,
+.B nfs4_getfacl
+will not follow symbolic links to directories. This also skips symbolic link
+arguments.
+Only effective in combination with -R.
+
 The output format for an NFSv4 file ACL, e.g., is:
 .RS
 .nf
diff --git a/nfs4_getfacl/nfs4_getfacl.c b/nfs4_getfacl/nfs4_getfacl.c
index 5a9c911..dd5c1b9 100644
--- a/nfs4_getfacl/nfs4_getfacl.c
+++ b/nfs4_getfacl/nfs4_getfacl.c
@@ -46,9 +46,19 @@ static void usage(int);
 static void more_help();
 static char *execname;
 static void print_acl_from_path();
+static int walk_type = 0;
+static void logical();
 
 static int recursive(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf)
 {
+	if ((tflag == FTW_SL) && (walk_type == 2))
+                return 0;
+
+        if ((tflag == FTW_SL) && (walk_type == 1)) {
+                logical(fpath);
+                return 0;
+        }
+
 	print_acl_from_path(fpath);
 	return 0;
 }
@@ -56,14 +66,16 @@ static int recursive(const char *fpath, const struct stat *sb, int tflag, struct
 static struct option long_options[] = {
         {"more-help",    0, 0, 'H' },
         {"help",         0, 0, 'h' },
-        {"recursive",     0, 0, 'R' },
+        {"recursive",    0, 0, 'R' },
+	{"logical",	 0, 0, 'L' },
+	{"physical",     0, 0, 'P' },
         { NULL,          0, 0, 0,  },
 };
 
 int main(int argc, char **argv)
 {
 	int opt, res = 1;
-        int do_recursive = 0;
+        int flag, do_recursive = 0;
 	
 	execname = basename(argv[0]);
 
@@ -73,7 +85,7 @@ int main(int argc, char **argv)
 		goto out;
 	}
 
-	while ((opt = getopt_long(argc, argv, "HR?h", long_options, NULL)) != -1) {
+	while ((opt = getopt_long(argc, argv, "HR?hLP", long_options, NULL)) != -1) {
 		switch(opt) {
 			case 'H':
 				more_help();
@@ -84,6 +96,22 @@ int main(int argc, char **argv)
 				do_recursive = 1;
 				break;
 
+			case 'L':
+                                if (walk_type != 0) {
+                                        fprintf(stderr, "More than one walk type specified\n");
+                                        goto out;
+                                }
+                                walk_type = 1;  /* Follow all symbolic links */
+                                break;
+
+                        case 'P':
+                                if (walk_type != 0) {
+					fprintf(stderr, "More than one walk type specified\n");
+                                        goto out;
+                                }
+                                walk_type = 2;  /* Skip all symbolic links */
+                                break;
+
 			default:
 				usage(1);
 				res = 0;
@@ -99,7 +127,10 @@ int main(int argc, char **argv)
 
 	for(; optind < argc; optind++) {
 		if(do_recursive) {
-			if (nftw(argv[optind], recursive, 20, 0) == -1)
+			if (walk_type == 2 || walk_type == 1)
+                        flag = FTW_PHYS;
+
+			if (nftw(argv[optind], recursive, 20, flag) == -1)
 				printf("Invalid filename: %s\n", argv[optind]);
 		}
 		else
@@ -121,11 +152,17 @@ static void print_acl_from_path(const char *fpath)
 	}
 }
 
+static void logical(const char *fpath)
+{
+        if (nftw(fpath, recursive, 20, 0) == -1)
+                printf("Invalid filename: %s\n", fpath);
+}
+
 static void usage(int label)
 {
 	if (label)
 		fprintf(stderr, "%s %s -- get NFSv4 file or directory access control lists.\n", execname, VERSION);
-	fprintf(stderr, "Usage: %s [-R] file ...\n  -H, --more-help\tdisplay ACL format information\n  -?, -h, --help\tdisplay this help text\n  -R --recursive\trecurse into subdirectories\n", execname);
+	fprintf(stderr, "Usage: %s [-RPL] file ...\n  -H, --more-help\tdisplay ACL format information\n  -?, -h, --help\tdisplay this help text\n  -R, --recursive\trecurse into subdirectories\n  -L, --logical\t\tlogical walk, follow symbolic links\n  -P, --physical\tphysical walk, do not follow symbolic links\n", execname);
 }
 
 static void more_help()
-- 
2.17.2


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

* Re: [PATCH] Add support for -L(logical) and -P(physical) option in nfs4_getfacl.
  2018-12-05  2:10 [PATCH] Add support for -L(logical) and -P(physical) option in nfs4_getfacl Kenneth D'souza
@ 2019-01-28  3:03 ` Kenneth Dsouza
  0 siblings, 0 replies; 2+ messages in thread
From: Kenneth Dsouza @ 2019-01-28  3:03 UTC (permalink / raw)
  To: linux-nfs; +Cc: J. Bruce Fields

Ping ?

On Wed, Dec 5, 2018 at 7:41 AM Kenneth D'souza <kdsouza@redhat.com> wrote:
>
> Signed-off-by: Kenneth D'souza <kdsouza@redhat.com>
> ---
>  man/man1/nfs4_getfacl.1     | 18 +++++++++++++-
>  nfs4_getfacl/nfs4_getfacl.c | 47 +++++++++++++++++++++++++++++++++----
>  2 files changed, 59 insertions(+), 6 deletions(-)
>
> diff --git a/man/man1/nfs4_getfacl.1 b/man/man1/nfs4_getfacl.1
> index 83067c9..940a2b5 100644
> --- a/man/man1/nfs4_getfacl.1
> +++ b/man/man1/nfs4_getfacl.1
> @@ -8,7 +8,7 @@
>  .SH NAME
>  nfs4_getfacl \- get NFSv4 file/directory access control lists
>  .SH SYNOPSIS
> -.B nfs4_getfacl [-HR]
> +.B nfs4_getfacl [-HRLP]
>  file ...
>  .SH DESCRIPTION
>  .B nfs4_getfacl
> @@ -28,6 +28,22 @@ flag is specified,
>  .B nfs4_getfacl
>  will list the NFSv4 ACLs of all files and directories recursively.
>
> +If the
> +.BR -L / --logical
> +flag is specified,
> +.B nfs4_getfacl
> +will follow symbolic links to directories. The default behavior is to follow
> +symbolic link arguments, and skip symbolic links encountered in subdirectories.
> +Only effective in combination with -R.
> +
> +If the
> +.BR -P / --physical
> +flag is specified,
> +.B nfs4_getfacl
> +will not follow symbolic links to directories. This also skips symbolic link
> +arguments.
> +Only effective in combination with -R.
> +
>  The output format for an NFSv4 file ACL, e.g., is:
>  .RS
>  .nf
> diff --git a/nfs4_getfacl/nfs4_getfacl.c b/nfs4_getfacl/nfs4_getfacl.c
> index 5a9c911..dd5c1b9 100644
> --- a/nfs4_getfacl/nfs4_getfacl.c
> +++ b/nfs4_getfacl/nfs4_getfacl.c
> @@ -46,9 +46,19 @@ static void usage(int);
>  static void more_help();
>  static char *execname;
>  static void print_acl_from_path();
> +static int walk_type = 0;
> +static void logical();
>
>  static int recursive(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf)
>  {
> +       if ((tflag == FTW_SL) && (walk_type == 2))
> +                return 0;
> +
> +        if ((tflag == FTW_SL) && (walk_type == 1)) {
> +                logical(fpath);
> +                return 0;
> +        }
> +
>         print_acl_from_path(fpath);
>         return 0;
>  }
> @@ -56,14 +66,16 @@ static int recursive(const char *fpath, const struct stat *sb, int tflag, struct
>  static struct option long_options[] = {
>          {"more-help",    0, 0, 'H' },
>          {"help",         0, 0, 'h' },
> -        {"recursive",     0, 0, 'R' },
> +        {"recursive",    0, 0, 'R' },
> +       {"logical",      0, 0, 'L' },
> +       {"physical",     0, 0, 'P' },
>          { NULL,          0, 0, 0,  },
>  };
>
>  int main(int argc, char **argv)
>  {
>         int opt, res = 1;
> -        int do_recursive = 0;
> +        int flag, do_recursive = 0;
>
>         execname = basename(argv[0]);
>
> @@ -73,7 +85,7 @@ int main(int argc, char **argv)
>                 goto out;
>         }
>
> -       while ((opt = getopt_long(argc, argv, "HR?h", long_options, NULL)) != -1) {
> +       while ((opt = getopt_long(argc, argv, "HR?hLP", long_options, NULL)) != -1) {
>                 switch(opt) {
>                         case 'H':
>                                 more_help();
> @@ -84,6 +96,22 @@ int main(int argc, char **argv)
>                                 do_recursive = 1;
>                                 break;
>
> +                       case 'L':
> +                                if (walk_type != 0) {
> +                                        fprintf(stderr, "More than one walk type specified\n");
> +                                        goto out;
> +                                }
> +                                walk_type = 1;  /* Follow all symbolic links */
> +                                break;
> +
> +                        case 'P':
> +                                if (walk_type != 0) {
> +                                       fprintf(stderr, "More than one walk type specified\n");
> +                                        goto out;
> +                                }
> +                                walk_type = 2;  /* Skip all symbolic links */
> +                                break;
> +
>                         default:
>                                 usage(1);
>                                 res = 0;
> @@ -99,7 +127,10 @@ int main(int argc, char **argv)
>
>         for(; optind < argc; optind++) {
>                 if(do_recursive) {
> -                       if (nftw(argv[optind], recursive, 20, 0) == -1)
> +                       if (walk_type == 2 || walk_type == 1)
> +                        flag = FTW_PHYS;
> +
> +                       if (nftw(argv[optind], recursive, 20, flag) == -1)
>                                 printf("Invalid filename: %s\n", argv[optind]);
>                 }
>                 else
> @@ -121,11 +152,17 @@ static void print_acl_from_path(const char *fpath)
>         }
>  }
>
> +static void logical(const char *fpath)
> +{
> +        if (nftw(fpath, recursive, 20, 0) == -1)
> +                printf("Invalid filename: %s\n", fpath);
> +}
> +
>  static void usage(int label)
>  {
>         if (label)
>                 fprintf(stderr, "%s %s -- get NFSv4 file or directory access control lists.\n", execname, VERSION);
> -       fprintf(stderr, "Usage: %s [-R] file ...\n  -H, --more-help\tdisplay ACL format information\n  -?, -h, --help\tdisplay this help text\n  -R --recursive\trecurse into subdirectories\n", execname);
> +       fprintf(stderr, "Usage: %s [-RPL] file ...\n  -H, --more-help\tdisplay ACL format information\n  -?, -h, --help\tdisplay this help text\n  -R, --recursive\trecurse into subdirectories\n  -L, --logical\t\tlogical walk, follow symbolic links\n  -P, --physical\tphysical walk, do not follow symbolic links\n", execname);
>  }
>
>  static void more_help()
> --
> 2.17.2
>

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-05  2:10 [PATCH] Add support for -L(logical) and -P(physical) option in nfs4_getfacl Kenneth D'souza
2019-01-28  3:03 ` Kenneth Dsouza

Linux-NFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-nfs/0 linux-nfs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-nfs linux-nfs/ https://lore.kernel.org/linux-nfs \
		linux-nfs@vger.kernel.org linux-nfs@archiver.kernel.org
	public-inbox-index linux-nfs


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-nfs


AGPL code for this site: git clone https://public-inbox.org/ public-inbox