From: trondmy@kernel.org
To: Steve Dickson <SteveD@redhat.com>,
"J.Bruce Fields" <bfields@fieldses.org>
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 5/6] nfs4_setacl: Add support for the --dacl and --sacl options
Date: Sat, 14 May 2022 10:44:35 -0400 [thread overview]
Message-ID: <20220514144436.4298-6-trondmy@kernel.org> (raw)
In-Reply-To: <20220514144436.4298-5-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_setfacl/nfs4_setfacl.c | 67 +++++++++++++++++++++++++++++++++++--
1 file changed, 64 insertions(+), 3 deletions(-)
diff --git a/nfs4_setfacl/nfs4_setfacl.c b/nfs4_setfacl/nfs4_setfacl.c
index d0485ad53024..e5816085c8b0 100644
--- a/nfs4_setfacl/nfs4_setfacl.c
+++ b/nfs4_setfacl/nfs4_setfacl.c
@@ -79,6 +79,9 @@
#define EDITOR "vi" /* <- evangelism! */
#define u32 u_int32_t
+#define OPT_DACL 0x98
+#define OPT_SACL 0x99
+
static int apply_action(const char *, const struct stat *, int, struct FTW *);
static int do_apply_action(const char *, const struct stat *);
static int open_editor(const char *);
@@ -110,6 +113,8 @@ static struct option long_options[] = {
{ "recursive", 0, 0, 'R' },
{ "physical", 0, 0, 'P' },
{ "logical", 0, 0, 'L' },
+ { "dacl", 0, 0, OPT_DACL },
+ { "sacl", 0, 0, OPT_SACL },
{ NULL, 0, 0, 0, },
};
@@ -124,6 +129,8 @@ static char *mod_string;
static char *from_ace;
static char *to_ace;
+static enum acl_type acl_type = ACL_TYPE_ACL;
+
/* XXX: things we need to handle:
*
* - we need some sort of 'purge' operation that completely clears an ACL.
@@ -272,6 +279,13 @@ int main(int argc, char **argv)
paths[numpaths++] = optarg;
break;
+ case OPT_DACL:
+ acl_type = ACL_TYPE_DACL;
+ break;
+ case OPT_SACL:
+ acl_type = ACL_TYPE_SACL;
+ break;
+
case 'h':
case '?':
default:
@@ -334,6 +348,50 @@ out:
return err;
}
+static void nfs4_print_acl_error(const char *path)
+{
+ switch (errno) {
+ case ENODATA:
+ fprintf(stderr,"Attribute not found on file: %s\n", path);
+ break;
+ case EREMOTEIO:
+ fprintf(stderr,"An NFS server error occurred.\n");
+ break;
+ case EOPNOTSUPP:
+ fprintf(stderr,"Operation to request attribute not supported: "
+ "%s\n", path);
+ break;
+ default:
+ perror("Failed operation");
+ }
+}
+
+static struct nfs4_acl *nfs4_retrieve_acl(const char *path,
+ enum acl_type type)
+{
+ switch (type) {
+ case ACL_TYPE_DACL:
+ return nfs4_getdacl(path);
+ case ACL_TYPE_SACL:
+ return nfs4_getsacl(path);
+ default:
+ return nfs4_getacl(path);
+ }
+}
+
+static int nfs4_apply_acl(const char *path, struct nfs4_acl *acl,
+ enum acl_type type)
+{
+ switch (type) {
+ case ACL_TYPE_DACL:
+ return nfs4_setdacl(path, acl);
+ case ACL_TYPE_SACL:
+ return nfs4_setsacl(path, acl);
+ default:
+ return nfs4_setacl(path, acl);
+ }
+}
+
/* returns 0 on success, nonzero on failure */
static int apply_action(const char *_path, const struct stat *stat, int flag, struct FTW *ftw)
{
@@ -378,7 +436,7 @@ static int do_apply_action(const char *path, const struct stat *_st)
if (action == SUBSTITUTE_ACTION)
acl = nfs4_new_acl(S_ISDIR(st->st_mode));
else
- acl = nfs4_acl_for_path(path);
+ acl = nfs4_retrieve_acl(path, acl_type);
if (acl == NULL) {
fprintf(stderr, "Failed to instantiate ACL.\n");
@@ -438,8 +496,11 @@ static int do_apply_action(const char *path, const struct stat *_st)
if (is_test) {
fprintf(stderr, "## Test mode only - the resulting ACL for \"%s\": \n", path);
nfs4_print_acl(stdout, acl);
- } else
- err = nfs4_set_acl(acl, path);
+ } else {
+ err = nfs4_apply_acl(path, acl, acl_type);
+ if (err == -1)
+ nfs4_print_acl_error(path);
+ }
out:
nfs4_free_acl(acl);
--
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 ` [PATCH 4/6] nfs4_getacl: Add support for the --dacl and --sacl options trondmy
2022-05-14 14:44 ` trondmy [this message]
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-6-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).