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_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_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(inode
, ACL_TYPE_ACCESS
, argp
->acl_access
);
109 error
= set_posix_acl(inode
, ACL_TYPE_DEFAULT
, argp
->acl_default
);
115 resp
->status
= nfserrno(error
);
117 /* argp->acl_{access,default} may have been allocated in
118 nfs3svc_decode_setaclargs. */
119 posix_acl_release(argp
->acl_access
);
120 posix_acl_release(argp
->acl_default
);
125 * XDR decode functions
127 static int nfs3svc_decode_getaclargs(struct svc_rqst
*rqstp
, __be32
*p
)
129 struct nfsd3_getaclargs
*args
= rqstp
->rq_argp
;
131 p
= nfs3svc_decode_fh(p
, &args
->fh
);
134 args
->mask
= ntohl(*p
); p
++;
136 return xdr_argsize_check(rqstp
, p
);
140 static int nfs3svc_decode_setaclargs(struct svc_rqst
*rqstp
, __be32
*p
)
142 struct nfsd3_setaclargs
*args
= rqstp
->rq_argp
;
143 struct kvec
*head
= rqstp
->rq_arg
.head
;
147 p
= nfs3svc_decode_fh(p
, &args
->fh
);
150 args
->mask
= ntohl(*p
++);
151 if (args
->mask
& ~NFS_ACL_MASK
||
152 !xdr_argsize_check(rqstp
, p
))
155 base
= (char *)p
- (char *)head
->iov_base
;
156 n
= nfsacl_decode(&rqstp
->rq_arg
, base
, NULL
,
157 (args
->mask
& NFS_ACL
) ?
158 &args
->acl_access
: NULL
);
160 n
= nfsacl_decode(&rqstp
->rq_arg
, base
+ n
, NULL
,
161 (args
->mask
& NFS_DFACL
) ?
162 &args
->acl_default
: NULL
);
167 * XDR encode functions
171 static int nfs3svc_encode_getaclres(struct svc_rqst
*rqstp
, __be32
*p
)
173 struct nfsd3_getaclres
*resp
= rqstp
->rq_resp
;
174 struct dentry
*dentry
= resp
->fh
.fh_dentry
;
177 p
= nfs3svc_encode_post_op_attr(rqstp
, p
, &resp
->fh
);
178 if (resp
->status
== 0 && dentry
&& d_really_is_positive(dentry
)) {
179 struct inode
*inode
= d_inode(dentry
);
180 struct kvec
*head
= rqstp
->rq_res
.head
;
185 *p
++ = htonl(resp
->mask
);
186 if (!xdr_ressize_check(rqstp
, p
))
188 base
= (char *)p
- (char *)head
->iov_base
;
190 rqstp
->rq_res
.page_len
= w
= nfsacl_size(
191 (resp
->mask
& NFS_ACL
) ? resp
->acl_access
: NULL
,
192 (resp
->mask
& NFS_DFACL
) ? resp
->acl_default
: NULL
);
194 if (!*(rqstp
->rq_next_page
++))
199 n
= nfsacl_encode(&rqstp
->rq_res
, base
, inode
,
201 resp
->mask
& NFS_ACL
, 0);
203 n
= nfsacl_encode(&rqstp
->rq_res
, base
+ n
, inode
,
205 resp
->mask
& NFS_DFACL
,
210 if (!xdr_ressize_check(rqstp
, p
))
217 static int nfs3svc_encode_setaclres(struct svc_rqst
*rqstp
, __be32
*p
)
219 struct nfsd3_attrstat
*resp
= rqstp
->rq_resp
;
222 p
= nfs3svc_encode_post_op_attr(rqstp
, p
, &resp
->fh
);
223 return xdr_ressize_check(rqstp
, p
);
227 * XDR release functions
229 static void nfs3svc_release_getacl(struct svc_rqst
*rqstp
)
231 struct nfsd3_getaclres
*resp
= rqstp
->rq_resp
;
234 posix_acl_release(resp
->acl_access
);
235 posix_acl_release(resp
->acl_default
);
238 struct nfsd3_voidargs
{ int dummy
; };
240 #define ST 1 /* status*/
241 #define AT 21 /* attributes */
242 #define pAT (1+AT) /* post attributes - conditional */
243 #define ACL (1+NFS_ACL_MAX_ENTRIES*3) /* Access Control List */
245 static const struct svc_procedure nfsd_acl_procedures3
[3] = {
247 .pc_func
= nfsd3_proc_null
,
248 .pc_decode
= nfssvc_decode_voidarg
,
249 .pc_encode
= nfssvc_encode_voidres
,
250 .pc_argsize
= sizeof(struct nfsd_voidargs
),
251 .pc_ressize
= sizeof(struct nfsd_voidres
),
252 .pc_cachetype
= RC_NOCACHE
,
255 [ACLPROC3_GETACL
] = {
256 .pc_func
= nfsd3_proc_getacl
,
257 .pc_decode
= nfs3svc_decode_getaclargs
,
258 .pc_encode
= nfs3svc_encode_getaclres
,
259 .pc_release
= nfs3svc_release_getacl
,
260 .pc_argsize
= sizeof(struct nfsd3_getaclargs
),
261 .pc_ressize
= sizeof(struct nfsd3_getaclres
),
262 .pc_cachetype
= RC_NOCACHE
,
263 .pc_xdrressize
= ST
+1+2*(1+ACL
),
265 [ACLPROC3_SETACL
] = {
266 .pc_func
= nfsd3_proc_setacl
,
267 .pc_decode
= nfs3svc_decode_setaclargs
,
268 .pc_encode
= nfs3svc_encode_setaclres
,
269 .pc_release
= nfs3svc_release_fhandle
,
270 .pc_argsize
= sizeof(struct nfsd3_setaclargs
),
271 .pc_ressize
= sizeof(struct nfsd3_attrstat
),
272 .pc_cachetype
= RC_NOCACHE
,
273 .pc_xdrressize
= ST
+pAT
,
277 static unsigned int nfsd_acl_count3
[ARRAY_SIZE(nfsd_acl_procedures3
)];
278 const struct svc_version nfsd_acl_version3
= {
281 .vs_proc
= nfsd_acl_procedures3
,
282 .vs_count
= nfsd_acl_count3
,
283 .vs_dispatch
= nfsd_dispatch
,
284 .vs_xdrsize
= NFS3_SVC_XDRSIZE
,