Skip to contentSkip to conversation

nfs4_getfacl: Add new option -c/--omit-header to not display comment header.

PATCH In review Kenneth D'souza 2 participants 5 messages Mar 26, 2019 – Apr 10, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfs4_getfacl: Add new option -c/--omit-header to not display comment header.

With this patch the filename will not be printed.

    $ nfs4_getfacl /test/
    # file: /test/
    A::OWNER@:rwaDxtTcCy
    A::GROUP@:rwaDxtcy
    A::EVERYONE@:rwaDxtcy
    $ nfs4_getfacl -c /test/

A::OWNER@:rwaDxtTcCy
A::GROUP@:rwaDxtcy
A::EVERYONE@:rwaDxtcy

---
 man/man1/nfs4_getfacl.1     |  6 ++++++
 nfs4_getfacl/nfs4_getfacl.c | 13 ++++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)
man/man1/nfs4_getfacl.1 +6 -0
index 83067c9..001723e 100644
@@ -28,6 +28,12 @@ flag is specified,
 .B nfs4_getfacl
 will list the NFSv4 ACLs of all files and directories recursively.
 
+If the
+.BR -c / --omit-header
+flag is specified,
+.B nfs4_getfacl 
+will not display the comment header (Do not print filename).
+
 The output format for an NFSv4 file ACL, e.g., is:
 .RS
 .nf
nfs4_getfacl/nfs4_getfacl.c +10 -3
index 5a9c911..8194e6f 100644
@@ -46,6 +46,7 @@ static void usage(int);
 static void more_help();
 static char *execname;
 static void print_acl_from_path();
+static int ignore_comment = 0;
 
 static int recursive(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf)
 {
@@ -57,6 +58,7 @@ static struct option long_options[] = {
         {"more-help",    0, 0, 'H' },
         {"help",         0, 0, 'h' },
         {"recursive",     0, 0, 'R' },
+	{"omit-header", 0, 0, 'c'},
         { NULL,          0, 0, 0,  },
 };
 
@@ -73,7 +75,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?hc", long_options, NULL)) != -1) {
 		switch(opt) {
 			case 'H':
 				more_help();
@@ -83,7 +85,9 @@ int main(int argc, char **argv)
 			case 'R':
 				do_recursive = 1;
 				break;
-
+			case 'c':
+				ignore_comment = 1; /* Do not display the comment header */
+				break;
 			default:
 				usage(1);
 				res = 0;
@@ -115,7 +119,10 @@ static void print_acl_from_path(const char *fpath)
 	struct nfs4_acl *acl;
 	acl = nfs4_acl_for_path(fpath);
 	if (acl != NULL) {
+		if(ignore_comment == 0)
 		printf("\n# file: %s\n", fpath);
+		else
+			printf("\n");
 		nfs4_print_acl(stdout, acl);
 		nfs4_free_acl(acl);
 	}
@@ -125,7 +132,7 @@ 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 [-R] file ...\n  -H, --more-help\tdisplay ACL format information\n  -?, -h, --help\tdisplay this help text\n  -R --recursive\trecurse into subdirectories\n  -c, --omit-header\tDo not display the comment header (Do not print filename)\n", execname);
 }
 
 static void more_help()
Signature · 1 line
2.20.1
#1 lore raw

Thanks, applying with some fixes:

Quoted 8 lines · Kenneth D'souza

With this patch the filename will not be printed.

    $ nfs4_getfacl /test/
    # file: /test/
    A::OWNER@:rwaDxtTcCy
    A::GROUP@:rwaDxtcy
    A::EVERYONE@:rwaDxtcy
Quoted 5 lines
    $ nfs4_getfacl -c /test/

A::OWNER@:rwaDxtTcCy
A::GROUP@:rwaDxtcy
A::EVERYONE@:rwaDxtcy

I don't see any reason for that blank line, I've removed it.

nfs4_getfacl/nfs4_getfacl.c static void print_acl_from_path(const char *fpath) · line 123

Quoted 6 lines
nfs4_getfacl/nfs4_getfacl.c +1 -0
@@ -115,7 +119,10 @@ static void print_acl_from_path(const char *fpath)
 	struct nfs4_acl *acl;
 	acl = nfs4_acl_for_path(fpath);
 	if (acl != NULL) {
+		if(ignore_comment == 0)
 		printf("\n# file: %s\n", fpath);

This needs to be indented.

nfs4_getfacl/nfs4_getfacl.c static void print_acl_from_path(const char *fpath) · line 125

Quoted 2 lines
nfs4_getfacl/nfs4_getfacl.c +2 -0
+		else
+			printf("\n");

I've removed the "else" clause.

And fixed a couple minor whitespace issues.

--b.

Quoted 14 lines
nfs4_getfacl/nfs4_getfacl.c +1 -1
 		nfs4_print_acl(stdout, acl);
 		nfs4_free_acl(acl);
 	}
@@ -125,7 +132,7 @@ 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 [-R] file ...\n  -H, --more-help\tdisplay ACL format information\n  -?, -h, --help\tdisplay this help text\n  -R --recursive\trecurse into subdirectories\n  -c, --omit-header\tDo not display the comment header (Do not print filename)\n", execname);
 }
 
 static void more_help()
Signature · 1 line
2.20.1
#2 lore raw
Quoted 12 lines · J. Bruce Fields

Thanks, applying with some fixes:

Quoted 8 lines · Kenneth D'souza

With this patch the filename will not be printed.

    $ nfs4_getfacl /test/
    # file: /test/
    A::OWNER@:rwaDxtTcCy
    A::GROUP@:rwaDxtcy
    A::EVERYONE@:rwaDxtcy
Quoted 8 lines
Quoted 5 lines
    $ nfs4_getfacl -c /test/

A::OWNER@:rwaDxtTcCy
A::GROUP@:rwaDxtcy
A::EVERYONE@:rwaDxtcy

I don't see any reason for that blank line, I've removed it.

I added the blank line so we print acl for each file on a new line when -c is used.

# nfs4_getfacl -Rc /test

A::OWNER@:rwaDxtTcCy
A::GROUP@:rwaDxtcy
A::EVERYONE@:rwaDxtcy

A::OWNER@:rwatTcCy
A::GROUP@:tcy
A::EVERYONE@:tcy

A::OWNER@:rwaDxtTcCy
A::GROUP@:rxtcy
A::EVERYONE@:rxtcy

Quoted 32 lines

nfs4_getfacl/nfs4_getfacl.c static void print_acl_from_path(const char *fpath) · line 123

Quoted 6 lines
nfs4_getfacl/nfs4_getfacl.c +1 -0
@@ -115,7 +119,10 @@ static void print_acl_from_path(const char *fpath)
      struct nfs4_acl *acl;
      acl = nfs4_acl_for_path(fpath);
      if (acl != NULL) {
+             if(ignore_comment == 0)
              printf("\n# file: %s\n", fpath);

This needs to be indented.

nfs4_getfacl/nfs4_getfacl.c static void print_acl_from_path(const char *fpath) · line 125

Quoted 2 lines
nfs4_getfacl/nfs4_getfacl.c +2 -0
+             else
+                     printf("\n");

I've removed the "else" clause.

And fixed a couple minor whitespace issues.

--b.

Quoted 14 lines
nfs4_getfacl/nfs4_getfacl.c +1 -2
              nfs4_print_acl(stdout, acl);
              nfs4_free_acl(acl);
      }
@@ -125,7 +132,7 @@ 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 [-R] file ...\n  -H, --more-help\tdisplay ACL format information\n  -?, -h, --help\tdisplay this help text\n  -R --recursive\trecurse into subdirectories\n  -c, --omit-header\tDo not display the comment header (Do not print filename)\n", execname);
 }
 
 static void more_help()
--

2.20.1

#3 lore raw
Quoted 15 lines · Kenneth Dsouza
Quoted 14 lines · J. Bruce Fields

Thanks, applying with some fixes:

Quoted 10 lines · Kenneth D'souza

With this patch the filename will not be printed.

    $ nfs4_getfacl /test/
    # file: /test/
    A::OWNER@:rwaDxtTcCy
    A::GROUP@:rwaDxtcy
    A::EVERYONE@:rwaDxtcy
    $ nfs4_getfacl -c /test/
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

A::OWNER@:rwaDxtTcCy
A::GROUP@:rwaDxtcy
A::EVERYONE@:rwaDxtcy

I don't see any reason for that blank line, I've removed it.

I added the blank line so we print acl for each file on a new line when -c is used.

OK, it does make sense to have a blank line between multiple ACLs.

Again I'd rather adopt the same behavior has getfacl/setfacl whenever we can. Looks like getfacl just appends a blank line regardless of whether -c is used or whether the are multiple ACLs:

	[bfields@patate ~]$ getfacl .
	# file: .
	# owner: bfields
	# group: bfields
	user::rwx
	group::--x
	other::--x
	
	[bfields@patate ~]$

I've added that to print_acl_from_path().

--b.

Quoted 47 lines
# nfs4_getfacl -Rc /test

A::OWNER@:rwaDxtTcCy
A::GROUP@:rwaDxtcy
A::EVERYONE@:rwaDxtcy

A::OWNER@:rwatTcCy
A::GROUP@:tcy
A::EVERYONE@:tcy

A::OWNER@:rwaDxtTcCy
A::GROUP@:rxtcy
A::EVERYONE@:rxtcy

Quoted 32 lines

nfs4_getfacl/nfs4_getfacl.c static void print_acl_from_path(const char *fpath) · line 123

Quoted 6 lines
nfs4_getfacl/nfs4_getfacl.c +1 -0
@@ -115,7 +119,10 @@ static void print_acl_from_path(const char *fpath)
      struct nfs4_acl *acl;
      acl = nfs4_acl_for_path(fpath);
      if (acl != NULL) {
+             if(ignore_comment == 0)
              printf("\n# file: %s\n", fpath);

This needs to be indented.

nfs4_getfacl/nfs4_getfacl.c static void print_acl_from_path(const char *fpath) · line 125

Quoted 2 lines
nfs4_getfacl/nfs4_getfacl.c +2 -0
+             else
+                     printf("\n");

I've removed the "else" clause.

And fixed a couple minor whitespace issues.

--b.

Quoted 14 lines
nfs4_getfacl/nfs4_getfacl.c +1 -2
              nfs4_print_acl(stdout, acl);
              nfs4_free_acl(acl);
      }
@@ -125,7 +132,7 @@ 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 [-R] file ...\n  -H, --more-help\tdisplay ACL format information\n  -?, -h, --help\tdisplay this help text\n  -R --recursive\trecurse into subdirectories\n  -c, --omit-header\tDo not display the comment header (Do not print filename)\n", execname);
 }
 
 static void more_help()
--

2.20.1

#4 lore raw

Thanks! Should we also add the below entries similar to getfacl?

$ nfs4_getfacl /test/
# file: /test/
# owner: test
# group: test
A::OWNER@:rwaDxtTcCy
A::GROUP@:rwaDxtcy
A::EVERYONE@:rwaDxtcy
Quoted 93 lines · J. Bruce Fields
Quoted 15 lines · Kenneth Dsouza
Quoted 14 lines · J. Bruce Fields

Thanks, applying with some fixes:

Quoted 10 lines · Kenneth D'souza

With this patch the filename will not be printed.

    $ nfs4_getfacl /test/
    # file: /test/
    A::OWNER@:rwaDxtTcCy
    A::GROUP@:rwaDxtcy
    A::EVERYONE@:rwaDxtcy
    $ nfs4_getfacl -c /test/
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

A::OWNER@:rwaDxtTcCy
A::GROUP@:rwaDxtcy
A::EVERYONE@:rwaDxtcy

I don't see any reason for that blank line, I've removed it.

I added the blank line so we print acl for each file on a new line when -c is used.

OK, it does make sense to have a blank line between multiple ACLs.

Again I'd rather adopt the same behavior has getfacl/setfacl whenever we can. Looks like getfacl just appends a blank line regardless of whether -c is used or whether the are multiple ACLs:

        [bfields@patate ~]$ getfacl .
        # file: .
        # owner: bfields
        # group: bfields
        user::rwx
        group::--x
        other::--x

        [bfields@patate ~]$

I've added that to print_acl_from_path().

--b.

Quoted 47 lines
# nfs4_getfacl -Rc /test

A::OWNER@:rwaDxtTcCy
A::GROUP@:rwaDxtcy
A::EVERYONE@:rwaDxtcy

A::OWNER@:rwatTcCy
A::GROUP@:tcy
A::EVERYONE@:tcy

A::OWNER@:rwaDxtTcCy
A::GROUP@:rxtcy
A::EVERYONE@:rxtcy

Quoted 32 lines

nfs4_getfacl/nfs4_getfacl.c static void print_acl_from_path(const char *fpath) · line 123

Quoted 6 lines
nfs4_getfacl/nfs4_getfacl.c +1 -0
@@ -115,7 +119,10 @@ static void print_acl_from_path(const char *fpath)
      struct nfs4_acl *acl;
      acl = nfs4_acl_for_path(fpath);
      if (acl != NULL) {
+             if(ignore_comment == 0)
              printf("\n# file: %s\n", fpath);

This needs to be indented.

nfs4_getfacl/nfs4_getfacl.c static void print_acl_from_path(const char *fpath) · line 125

Quoted 2 lines
nfs4_getfacl/nfs4_getfacl.c +2 -0
+             else
+                     printf("\n");

I've removed the "else" clause.

And fixed a couple minor whitespace issues.

--b.

Quoted 14 lines
nfs4_getfacl/nfs4_getfacl.c +1 -2
              nfs4_print_acl(stdout, acl);
              nfs4_free_acl(acl);
      }
@@ -125,7 +132,7 @@ 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 [-R] file ...\n  -H, --more-help\tdisplay ACL format information\n  -?, -h, --help\tdisplay this help text\n  -R --recursive\trecurse into subdirectories\n  -c, --omit-header\tDo not display the comment header (Do not print filename)\n", execname);
 }
 
 static void more_help()
--

2.20.1