From: trondmy@kernel.org
To: Steve Dickson <SteveD@redhat.com>,
"J.Bruce Fields" <bfields@fieldses.org>
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 4/6] nfs4_getacl: Add support for the --dacl and --sacl options
Date: Sat, 14 May 2022 10:44:34 -0400 [thread overview]
Message-ID: <20220514144436.4298-5-trondmy@kernel.org> (raw)
In-Reply-To: <20220514144436.4298-4-trondmy@kernel.org>
From: Trond Myklebust <trond.myklebust@hammerspace.com>
Add support for the NFSv4.1 dacl and sacl attributes.
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
nfs4_getfacl/nfs4_getfacl.c | 72 +++++++++++++++++++++++++++++++++----
1 file changed, 65 insertions(+), 7 deletions(-)
diff --git a/nfs4_getfacl/nfs4_getfacl.c b/nfs4_getfacl/nfs4_getfacl.c
index 1222dd907c9e..954cf7edb19a 100644
--- a/nfs4_getfacl/nfs4_getfacl.c
+++ b/nfs4_getfacl/nfs4_getfacl.c
@@ -42,15 +42,30 @@
#include <ftw.h>
#include <getopt.h>
+#define OPT_DACL 0x98
+#define OPT_SACL 0x99
+
static void usage(int);
static void more_help();
static char *execname;
-static void print_acl_from_path();
+static void print_acl_from_path(const char *, enum acl_type);
static int ignore_comment = 0;
-static int recursive(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf)
+static int print_acl(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf)
+{
+ print_acl_from_path(fpath, ACL_TYPE_ACL);
+ return 0;
+}
+
+static int print_dacl(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf)
{
- print_acl_from_path(fpath);
+ print_acl_from_path(fpath, ACL_TYPE_DACL);
+ return 0;
+}
+
+static int print_sacl(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf)
+{
+ print_acl_from_path(fpath, ACL_TYPE_SACL);
return 0;
}
@@ -59,6 +74,8 @@ static struct option long_options[] = {
{"help", 0, 0, 'h' },
{"recursive", 0, 0, 'R' },
{"omit-header", 0, 0, 'c'},
+ {"dacl", 0, 0, OPT_DACL},
+ {"sacl", 0, 0, OPT_SACL},
{ NULL, 0, 0, 0, },
};
@@ -66,6 +83,9 @@ int main(int argc, char **argv)
{
int opt, res = 1;
int do_recursive = 0;
+ int (*recursive)(const char *fpath, const struct stat *sb,
+ int tflag, struct FTW *ftwbuf) = print_acl;
+ enum acl_type type = ACL_TYPE_ACL;
execname = basename(argv[0]);
@@ -88,6 +108,14 @@ int main(int argc, char **argv)
case 'c':
ignore_comment = 1;
break;
+ case OPT_DACL:
+ type = ACL_TYPE_DACL;
+ recursive = print_dacl;
+ break;
+ case OPT_SACL:
+ type = ACL_TYPE_SACL;
+ recursive = print_sacl;
+ break;
case 'h':
usage(1);
res = 0;
@@ -111,23 +139,51 @@ int main(int argc, char **argv)
printf("Invalid filename: %s\n", argv[optind]);
}
else
- print_acl_from_path(argv[optind]);
+ print_acl_from_path(argv[optind], type);
res = 0;
}
out:
return res;
}
-static void print_acl_from_path(const char *fpath)
+static void print_acl_from_path(const char *fpath, enum acl_type type)
{
struct nfs4_acl *acl;
- acl = nfs4_acl_for_path(fpath);
+
+ switch (type) {
+ case ACL_TYPE_ACL:
+ acl = nfs4_getacl(fpath);
+ break;
+ case ACL_TYPE_DACL:
+ acl = nfs4_getdacl(fpath);
+ break;
+ case ACL_TYPE_SACL:
+ acl = nfs4_getsacl(fpath);
+ break;
+ }
+
if (acl != NULL) {
if (ignore_comment == 0)
printf("# file: %s\n", fpath);
nfs4_print_acl(stdout, acl);
printf("\n");
nfs4_free_acl(acl);
+ } else {
+ switch (errno) {
+ case ENODATA:
+ fprintf(stderr,"Attribute not found on file: %s\n",
+ fpath);
+ break;
+ case EREMOTEIO:
+ fprintf(stderr,"An NFS server error occurred.\n");
+ break;
+ case EOPNOTSUPP:
+ fprintf(stderr,"Operation to request attribute not "
+ "supported: %s\n", fpath);
+ break;
+ default:
+ perror("Failed operation");
+ }
}
}
@@ -142,7 +198,9 @@ static void usage(int label)
" -H, --more-help display ACL format information\n"
" -h, --help display this help text\n"
" -R, --recursive recurse into subdirectories\n"
- " -c, --omit-header Do not display the comment header (Do not print filename)\n";
+ " -c, --omit-header Do not display the comment header (Do not print filename)\n"
+ " --dacl display the NFSv4.1 dacl\n"
+ " --sacl display the NFSv4.1 sacl\n";
fprintf(stderr, gfusage, execname);
}
--
2.36.1
next prev parent reply other threads:[~2022-05-14 14:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-14 14:44 [PATCH 0/6] Allow nfs4-acl-tools to access 'dacl' and 'sacl' trondmy
2022-05-14 14:44 ` [PATCH 1/6] libnfs4acl: Add helpers to set the dacl and sacl trondmy
2022-05-14 14:44 ` [PATCH 2/6] libnfs4acl: Add support for the NFS4.1 ACE_INHERITED_ACE flag trondmy
2022-05-14 14:44 ` [PATCH 3/6] The NFSv41 DACL and SACL prepend an extra field to the acl trondmy
2022-05-14 14:44 ` trondmy [this message]
2022-05-14 14:44 ` [PATCH 5/6] nfs4_setacl: Add support for the --dacl and --sacl options trondmy
2022-05-14 14:44 ` [PATCH 6/6] Edit manpages to document the new --dacl, --sacl and inheritance features trondmy
2022-05-15 1:59 ` [PATCH 0/6] Allow nfs4-acl-tools to access 'dacl' and 'sacl' J.Bruce Fields
2022-05-15 3:23 ` Trond Myklebust
2022-05-19 13:47 ` Steve Dickson
2022-05-19 13:53 ` bfields
2022-05-19 18:52 ` Steve Dickson
2022-05-19 19:01 ` bfields
2022-06-21 13:43 ` Steve Dickson
2022-06-21 13:58 ` J.Bruce Fields
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220514144436.4298-5-trondmy@kernel.org \
--to=trondmy@kernel.org \
--cc=SteveD@redhat.com \
--cc=bfields@fieldses.org \
--cc=linux-nfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).