Skip to content

Commit 97e9a9e

Browse files
rmacklemchucklever
authored andcommitted
NFSD: Add nfsd4_encode_fattr4_posix_access_acl
The POSIX ACL extension to NFSv4 defines FATTR4_POSIX_ACCESS_ACL for retrieving the access ACL of a file or directory. This patch adds the XDR encoder for that attribute. The access ACL is retrieved via get_inode_acl(). If the filesystem provides no explicit access ACL, one is synthesized from the file mode via posix_acl_from_mode(). Each entry is encoded as a posixace4: tag type, permission bits, and principal name (empty for structural entries, resolved via idmapping for USER/GROUP entries). Unlike the default ACL encoder which applies only to directories, this encoder handles all inode types and ensures an access ACL is always available through mode-based synthesis when needed. Signed-off-by: Rick Macklem <rmacklem@uoguelph.ca> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 5e62c90 commit 97e9a9e

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

fs/nfsd/nfs4xdr.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3016,6 +3016,7 @@ struct nfsd4_fattr_args {
30163016
#endif
30173017
#ifdef CONFIG_NFSD_V4_POSIX_ACLS
30183018
struct posix_acl *dpacl;
3019+
struct posix_acl *pacl;
30193020
#endif
30203021
u32 rdattr_err;
30213022
bool contextsupport;
@@ -3585,6 +3586,12 @@ static __be32 nfsd4_encode_fattr4_posix_default_acl(struct xdr_stream *xdr,
35853586
return nfsd4_encode_posixacl(xdr, args->rqstp, args->dpacl);
35863587
}
35873588

3589+
static __be32 nfsd4_encode_fattr4_posix_access_acl(struct xdr_stream *xdr,
3590+
const struct nfsd4_fattr_args *args)
3591+
{
3592+
return nfsd4_encode_posixacl(xdr, args->rqstp, args->pacl);
3593+
}
3594+
35883595
#endif /* CONFIG_NFSD_V4_POSIX_ACLS */
35893596

35903597
static const nfsd4_enc_attr nfsd4_enc_fattr4_encode_ops[] = {
@@ -3699,10 +3706,12 @@ static const nfsd4_enc_attr nfsd4_enc_fattr4_encode_ops[] = {
36993706
[FATTR4_ACL_TRUEFORM] = nfsd4_encode_fattr4_acl_trueform,
37003707
[FATTR4_ACL_TRUEFORM_SCOPE] = nfsd4_encode_fattr4_acl_trueform_scope,
37013708
[FATTR4_POSIX_DEFAULT_ACL] = nfsd4_encode_fattr4_posix_default_acl,
3709+
[FATTR4_POSIX_ACCESS_ACL] = nfsd4_encode_fattr4_posix_access_acl,
37023710
#else
37033711
[FATTR4_ACL_TRUEFORM] = nfsd4_encode_fattr4__noop,
37043712
[FATTR4_ACL_TRUEFORM_SCOPE] = nfsd4_encode_fattr4__noop,
37053713
[FATTR4_POSIX_DEFAULT_ACL] = nfsd4_encode_fattr4__noop,
3714+
[FATTR4_POSIX_ACCESS_ACL] = nfsd4_encode_fattr4__noop,
37063715
#endif
37073716
};
37083717

@@ -3746,6 +3755,7 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,
37463755
#endif
37473756
#ifdef CONFIG_NFSD_V4_POSIX_ACLS
37483757
args.dpacl = NULL;
3758+
args.pacl = NULL;
37493759
#endif
37503760

37513761
/*
@@ -3877,6 +3887,29 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,
38773887
}
38783888
}
38793889
}
3890+
if (attrmask[2] & FATTR4_WORD2_POSIX_ACCESS_ACL) {
3891+
struct inode *inode = d_inode(dentry);
3892+
struct posix_acl *pacl;
3893+
3894+
pacl = get_inode_acl(inode, ACL_TYPE_ACCESS);
3895+
if (!pacl)
3896+
pacl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
3897+
if (IS_ERR(pacl)) {
3898+
switch (PTR_ERR(pacl)) {
3899+
case -EOPNOTSUPP:
3900+
attrmask[2] &= ~FATTR4_WORD2_POSIX_ACCESS_ACL;
3901+
break;
3902+
case -EINVAL:
3903+
status = nfserr_attrnotsupp;
3904+
goto out;
3905+
default:
3906+
err = PTR_ERR(pacl);
3907+
goto out_nfserr;
3908+
}
3909+
} else {
3910+
args.pacl = pacl;
3911+
}
3912+
}
38803913
#endif /* CONFIG_NFSD_V4_POSIX_ACLS */
38813914

38823915
/* attrmask */
@@ -3905,6 +3938,8 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,
39053938
#ifdef CONFIG_NFSD_V4_POSIX_ACLS
39063939
if (args.dpacl)
39073940
posix_acl_release(args.dpacl);
3941+
if (args.pacl)
3942+
posix_acl_release(args.pacl);
39083943
#endif /* CONFIG_NFSD_V4_POSIX_ACLS */
39093944
#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
39103945
if (args.context.context)

0 commit comments

Comments
 (0)