1 // SPDX-License-Identifier: GPL-2.0
3 * Process version 3 NFSACL requests.
5 * Copyright (C) 2002-2003 Andreas Gruenbacher <agruen@suse.de>
9 /* FIXME: nfsacl.h is a broken header */
10 #include <linux/nfsacl.h>
11 #include <linux/gfp.h>
20 nfsd3_proc_null(struct svc_rqst
*rqstp
)
26 * Get the Access and/or Default ACL of a file.
28 static __be32
nfsd3_proc_getacl(struct svc_rqst
*rqstp
)
30 struct nfsd3_getaclargs
*argp
= rqstp
->rq_argp
;
31 struct nfsd3_getaclres
*resp
= rqstp
->rq_resp
;
32 struct posix_acl
*acl
;
36 fh
= fh_copy(&resp
->fh
, &argp
->fh
);
37 resp
->status
= fh_verify(rqstp
, &resp
->fh
, 0, NFSD_MAY_NOP
);
38 if (resp
->status
!= nfs_ok
)
41 inode
= d_inode(fh
->fh_dentry
);
43 if (argp
->mask
& ~NFS_ACL_MASK
) {
44 resp
->status
= nfserr_inval
;
47 resp
->mask
= argp
->mask
;
49 if (resp
->mask
& (NFS_ACL
|NFS_ACLCNT
)) {
50 acl
= get_inode_acl(inode
, ACL_TYPE_ACCESS
);
52 /* Solaris returns the inode's minimum ACL. */
53 acl
= posix_acl_from_mode(inode
->i_mode
, GFP_KERNEL
);
56 resp
->status
= nfserrno(PTR_ERR(acl
));
59 resp
->acl_access
= acl
;
61 if (resp
->mask
& (NFS_DFACL
|NFS_DFACLCNT
)) {
62 /* Check how Solaris handles requests for the Default ACL
63 of a non-directory! */
64 acl
= get_inode_acl(inode
, ACL_TYPE_DEFAULT
);
66 resp
->status
= nfserrno(PTR_ERR(acl
));
69 resp
->acl_default
= acl
;
72 /* resp->acl_{access,default} are released in nfs3svc_release_getacl. */
77 posix_acl_release(resp
->acl_access
);
78 posix_acl_release(resp
->acl_default
);
83 * Set the Access and/or Default ACL of a file.
85 static __be32
nfsd3_proc_setacl(struct svc_rqst
*rqstp
)
87 struct nfsd3_setaclargs
*argp
= rqstp
->rq_argp
;
88 struct nfsd3_attrstat
*resp
= rqstp
->rq_resp
;
93 fh
= fh_copy(&resp
->fh
, &argp
->fh
);
94 resp
->status
= fh_verify(rqstp
, &resp
->fh
, 0, NFSD_MAY_SATTR
);
95 if (resp
->status
!= nfs_ok
)
98 inode
= d_inode(fh
->fh_dentry
);
100 error
= fh_want_write(fh
);
106 error
= set_posix_acl(&nop_mnt_idmap
, fh
->fh_dentry
, ACL_TYPE_ACCESS
,
110 error
= set_posix_acl(&nop_mnt_idmap
, fh
->fh_dentry
, ACL_TYPE_DEFAULT
,
117 resp
->status
= nfserrno(error
);
119 /* argp->acl_{access,default} may have been allocated in
120 nfs3svc_decode_setaclargs. */
121 posix_acl_release(argp
->acl_access
);
122 posix_acl_release(argp
->acl_default
);
127 * XDR decode functions
131 nfs3svc_decode_getaclargs(struct svc_rqst
*rqstp
, struct xdr_stream
*xdr
)
133 struct nfsd3_getaclargs
*args
= rqstp
->rq_argp
;
135 if (!svcxdr_decode_nfs_fh3(xdr
, &args
->fh
))
137 if (xdr_stream_decode_u32(xdr
, &args
->mask
) < 0)
144 nfs3svc_decode_setaclargs(struct svc_rqst
*rqstp
, struct xdr_stream
*xdr
)
146 struct nfsd3_setaclargs
*argp
= rqstp
->rq_argp
;
148 if (!svcxdr_decode_nfs_fh3(xdr
, &argp
->fh
))
150 if (xdr_stream_decode_u32(xdr
, &argp
->mask
) < 0)
152 if (argp
->mask
& ~NFS_ACL_MASK
)
154 if (!nfs_stream_decode_acl(xdr
, NULL
, (argp
->mask
& NFS_ACL
) ?
155 &argp
->acl_access
: NULL
))
157 if (!nfs_stream_decode_acl(xdr
, NULL
, (argp
->mask
& NFS_DFACL
) ?
158 &argp
->acl_default
: NULL
))
165 * XDR encode functions
170 nfs3svc_encode_getaclres(struct svc_rqst
*rqstp
, struct xdr_stream
*xdr
)
172 struct nfsd3_getaclres
*resp
= rqstp
->rq_resp
;
173 struct dentry
*dentry
= resp
->fh
.fh_dentry
;
176 if (!svcxdr_encode_nfsstat3(xdr
, resp
->status
))
178 switch (resp
->status
) {
180 inode
= d_inode(dentry
);
181 if (!svcxdr_encode_post_op_attr(rqstp
, xdr
, &resp
->fh
))
183 if (xdr_stream_encode_u32(xdr
, resp
->mask
) < 0)
186 if (!nfs_stream_encode_acl(xdr
, inode
, resp
->acl_access
,
187 resp
->mask
& NFS_ACL
, 0))
189 if (!nfs_stream_encode_acl(xdr
, inode
, resp
->acl_default
,
190 resp
->mask
& NFS_DFACL
,
195 if (!svcxdr_encode_post_op_attr(rqstp
, xdr
, &resp
->fh
))
204 nfs3svc_encode_setaclres(struct svc_rqst
*rqstp
, struct xdr_stream
*xdr
)
206 struct nfsd3_attrstat
*resp
= rqstp
->rq_resp
;
208 return svcxdr_encode_nfsstat3(xdr
, resp
->status
) &&
209 svcxdr_encode_post_op_attr(rqstp
, xdr
, &resp
->fh
);
213 * XDR release functions
215 static void nfs3svc_release_getacl(struct svc_rqst
*rqstp
)
217 struct nfsd3_getaclres
*resp
= rqstp
->rq_resp
;
220 posix_acl_release(resp
->acl_access
);
221 posix_acl_release(resp
->acl_default
);
224 #define ST 1 /* status*/
225 #define AT 21 /* attributes */
226 #define pAT (1+AT) /* post attributes - conditional */
227 #define ACL (1+NFS_ACL_MAX_ENTRIES*3) /* Access Control List */
229 static const struct svc_procedure nfsd_acl_procedures3
[3] = {
231 .pc_func
= nfsd3_proc_null
,
232 .pc_decode
= nfssvc_decode_voidarg
,
233 .pc_encode
= nfssvc_encode_voidres
,
234 .pc_argsize
= sizeof(struct nfsd_voidargs
),
235 .pc_argzero
= sizeof(struct nfsd_voidargs
),
236 .pc_ressize
= sizeof(struct nfsd_voidres
),
237 .pc_cachetype
= RC_NOCACHE
,
241 [ACLPROC3_GETACL
] = {
242 .pc_func
= nfsd3_proc_getacl
,
243 .pc_decode
= nfs3svc_decode_getaclargs
,
244 .pc_encode
= nfs3svc_encode_getaclres
,
245 .pc_release
= nfs3svc_release_getacl
,
246 .pc_argsize
= sizeof(struct nfsd3_getaclargs
),
247 .pc_argzero
= sizeof(struct nfsd3_getaclargs
),
248 .pc_ressize
= sizeof(struct nfsd3_getaclres
),
249 .pc_cachetype
= RC_NOCACHE
,
250 .pc_xdrressize
= ST
+1+2*(1+ACL
),
253 [ACLPROC3_SETACL
] = {
254 .pc_func
= nfsd3_proc_setacl
,
255 .pc_decode
= nfs3svc_decode_setaclargs
,
256 .pc_encode
= nfs3svc_encode_setaclres
,
257 .pc_release
= nfs3svc_release_fhandle
,
258 .pc_argsize
= sizeof(struct nfsd3_setaclargs
),
259 .pc_argzero
= sizeof(struct nfsd3_setaclargs
),
260 .pc_ressize
= sizeof(struct nfsd3_attrstat
),
261 .pc_cachetype
= RC_NOCACHE
,
262 .pc_xdrressize
= ST
+pAT
,
267 static DEFINE_PER_CPU_ALIGNED(unsigned long,
268 nfsd_acl_count3
[ARRAY_SIZE(nfsd_acl_procedures3
)]);
269 const struct svc_version nfsd_acl_version3
= {
271 .vs_nproc
= ARRAY_SIZE(nfsd_acl_procedures3
),
272 .vs_proc
= nfsd_acl_procedures3
,
273 .vs_count
= nfsd_acl_count3
,
274 .vs_dispatch
= nfsd_dispatch
,
275 .vs_xdrsize
= NFS3_SVC_XDRSIZE
,