[PATCH v1 03/17] Add a function to set POSIX ACLs

rick.macklem
2025-12-31T02:22:10Z

This patch adds the function that sets a POSIX draft ACL
called nfsd4_proc_setacl() and calls it from nfsd4_setattr()
to set the POSIX draft ACLs when a SETATTR of the new
POSIX draft ACL attributes is done by a NFSv4.2 client.

Signed-off-by: Rick Macklem <rmacklem@uoguelph.ca>
---
fs/nfsd/nfs4proc.c | 32 ++++++++++++++++++++++++++++++++
fs/nfsd/xdr4.h | 2 ++
2 files changed, 34 insertions(+)

diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index 2b805fc51262..b92477c87db1 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -1162,6 +1162,31 @@ vet_deleg_attrs(struct nfsd4_setattr *setattr, struct nfs4_delegation *dp)
}
}

+/*
+ * Set the Access and/or Default ACL of a file.
+ */
+static __be32
+nfsd4_proc_setacl(struct svc_rqst *rqstp, svc_fh *fh, struct inode *inode,
+ struct posix_acl *dpacl, struct posix_acl *pacl)
+{
+ int error = 0;
+
+ if (dpacl == NULL && pacl == NULL)
+ return nfs_ok;
+
+ inode_lock(inode);
+
+ if (dpacl != NULL)
+ error = set_posix_acl(&nop_mnt_idmap, fh->fh_dentry,
+ ACL_TYPE_DEFAULT, dpacl);
+ if (!error && pacl != NULL)
+ error = set_posix_acl(&nop_mnt_idmap, fh->fh_dentry,
+ ACL_TYPE_ACCESS, pacl);
+
+ inode_unlock(inode);
+ return nfserrno(error);
+}
+
static __be32
nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
union nfsd4_op_u *u)
@@ -1229,11 +1254,18 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
cstate->current_fh.fh_no_wcc = true;
status = nfsd_setattr(rqstp, &cstate->current_fh, &attrs, NULL);
cstate->current_fh.fh_no_wcc = save_no_wcc;
+ if (!status && (setattr->sa_dpacl != NULL || setattr->sa_pacl != NULL))
+ status = nfsd4_proc_setacl(rqstp, &cstate->current_fh, inode,
+ setattr->sa_dpacl, setattr->sa_pacl);
if (!status)
status = nfserrno(attrs.na_labelerr);
if (!status)
status = nfserrno(attrs.na_aclerr);
out:
+ if (setattr->sa_dpacl != NULL)
+ posix_acl_release(setattr->sa_dpacl);
+ if (setattr->sa_pacl != NULL)
+ posix_acl_release(setattr->sa_pacl);
nfsd_attrs_free(&attrs);
fh_drop_write(&cstate->current_fh);
return status;
diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
index ae75846b3cd7..eebbcc579c31 100644
--- a/fs/nfsd/xdr4.h
+++ b/fs/nfsd/xdr4.h
@@ -483,6 +483,8 @@ struct nfsd4_setattr {
struct iattr sa_iattr; /* request */
struct nfs4_acl *sa_acl;
struct xdr_netobj sa_label;
+ struct posix_acl *sa_dpacl;
+ struct posix_acl *sa_pacl;
};

struct nfsd4_setclientid {
--
2.49.0