2 * Process version 3 NFSACL requests.
4 * Copyright (C) 2002-2003 Andreas Gruenbacher <agruen@suse.de>
8 /* FIXME: nfsacl.h is a broken header */
9 #include <linux/nfsacl.h>
10 #include <linux/gfp.h>
15 #define RETURN_STATUS(st) { resp->status = (st); return (st); }
21 nfsd3_proc_null(struct svc_rqst
*rqstp
, void *argp
, void *resp
)
27 * Get the Access and/or Default ACL of a file.
29 static __be32
nfsd3_proc_getacl(struct svc_rqst
* rqstp
,
30 struct nfsd3_getaclargs
*argp
, struct nfsd3_getaclres
*resp
)
32 struct posix_acl
*acl
;
37 fh
= fh_copy(&resp
->fh
, &argp
->fh
);
38 nfserr
= fh_verify(rqstp
, &resp
->fh
, 0, NFSD_MAY_NOP
);
40 RETURN_STATUS(nfserr
);
42 inode
= fh
->fh_dentry
->d_inode
;
44 if (argp
->mask
& ~(NFS_ACL
|NFS_ACLCNT
|NFS_DFACL
|NFS_DFACLCNT
))
45 RETURN_STATUS(nfserr_inval
);
46 resp
->mask
= argp
->mask
;
48 if (resp
->mask
& (NFS_ACL
|NFS_ACLCNT
)) {
49 acl
= get_acl(inode
, ACL_TYPE_ACCESS
);
51 nfserr
= nfserrno(PTR_ERR(acl
));
55 /* Solaris returns the inode's minimum ACL. */
56 acl
= posix_acl_from_mode(inode
->i_mode
, GFP_KERNEL
);
58 resp
->acl_access
= acl
;
60 if (resp
->mask
& (NFS_DFACL
|NFS_DFACLCNT
)) {
61 /* Check how Solaris handles requests for the Default ACL
62 of a non-directory! */
63 acl
= get_acl(inode
, ACL_TYPE_DEFAULT
);
65 nfserr
= nfserrno(PTR_ERR(acl
));
68 resp
->acl_default
= acl
;
71 /* resp->acl_{access,default} are released in nfs3svc_release_getacl. */
75 posix_acl_release(resp
->acl_access
);
76 posix_acl_release(resp
->acl_default
);
77 RETURN_STATUS(nfserr
);
81 * Set the Access and/or Default ACL of a file.
83 static __be32
nfsd3_proc_setacl(struct svc_rqst
* rqstp
,
84 struct nfsd3_setaclargs
*argp
,
85 struct nfsd3_attrstat
*resp
)
92 fh
= fh_copy(&resp
->fh
, &argp
->fh
);
93 nfserr
= fh_verify(rqstp
, &resp
->fh
, 0, NFSD_MAY_SATTR
);
97 inode
= fh
->fh_dentry
->d_inode
;
98 if (!IS_POSIXACL(inode
) || !inode
->i_op
->set_acl
) {
103 error
= fh_want_write(fh
);
107 error
= inode
->i_op
->set_acl(inode
, argp
->acl_access
, ACL_TYPE_ACCESS
);
110 error
= inode
->i_op
->set_acl(inode
, argp
->acl_default
,
116 nfserr
= nfserrno(error
);
118 /* argp->acl_{access,default} may have been allocated in
119 nfs3svc_decode_setaclargs. */
120 posix_acl_release(argp
->acl_access
);
121 posix_acl_release(argp
->acl_default
);
122 RETURN_STATUS(nfserr
);
126 * XDR decode functions
128 static int nfs3svc_decode_getaclargs(struct svc_rqst
*rqstp
, __be32
*p
,
129 struct nfsd3_getaclargs
*args
)
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
,
141 struct nfsd3_setaclargs
*args
)
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
|NFS_ACLCNT
|NFS_DFACL
|NFS_DFACLCNT
) ||
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
,
172 struct nfsd3_getaclres
*resp
)
174 struct dentry
*dentry
= resp
->fh
.fh_dentry
;
176 p
= nfs3svc_encode_post_op_attr(rqstp
, p
, &resp
->fh
);
177 if (resp
->status
== 0 && dentry
&& dentry
->d_inode
) {
178 struct inode
*inode
= dentry
->d_inode
;
179 struct kvec
*head
= rqstp
->rq_res
.head
;
184 *p
++ = htonl(resp
->mask
);
185 if (!xdr_ressize_check(rqstp
, p
))
187 base
= (char *)p
- (char *)head
->iov_base
;
189 rqstp
->rq_res
.page_len
= w
= nfsacl_size(
190 (resp
->mask
& NFS_ACL
) ? resp
->acl_access
: NULL
,
191 (resp
->mask
& NFS_DFACL
) ? resp
->acl_default
: NULL
);
193 if (!*(rqstp
->rq_next_page
++))
198 n
= nfsacl_encode(&rqstp
->rq_res
, base
, inode
,
200 resp
->mask
& NFS_ACL
, 0);
202 n
= nfsacl_encode(&rqstp
->rq_res
, base
+ n
, inode
,
204 resp
->mask
& NFS_DFACL
,
209 if (!xdr_ressize_check(rqstp
, p
))
216 static int nfs3svc_encode_setaclres(struct svc_rqst
*rqstp
, __be32
*p
,
217 struct nfsd3_attrstat
*resp
)
219 p
= nfs3svc_encode_post_op_attr(rqstp
, p
, &resp
->fh
);
221 return xdr_ressize_check(rqstp
, p
);
225 * XDR release functions
227 static int nfs3svc_release_getacl(struct svc_rqst
*rqstp
, __be32
*p
,
228 struct nfsd3_getaclres
*resp
)
231 posix_acl_release(resp
->acl_access
);
232 posix_acl_release(resp
->acl_default
);
236 #define nfs3svc_decode_voidargs NULL
237 #define nfs3svc_release_void NULL
238 #define nfsd3_setaclres nfsd3_attrstat
239 #define nfsd3_voidres nfsd3_voidargs
240 struct nfsd3_voidargs
{ int dummy
; };
242 #define PROC(name, argt, rest, relt, cache, respsize) \
243 { (svc_procfunc) nfsd3_proc_##name, \
244 (kxdrproc_t) nfs3svc_decode_##argt##args, \
245 (kxdrproc_t) nfs3svc_encode_##rest##res, \
246 (kxdrproc_t) nfs3svc_release_##relt, \
247 sizeof(struct nfsd3_##argt##args), \
248 sizeof(struct nfsd3_##rest##res), \
254 #define ST 1 /* status*/
255 #define AT 21 /* attributes */
256 #define pAT (1+AT) /* post attributes - conditional */
257 #define ACL (1+NFS_ACL_MAX_ENTRIES*3) /* Access Control List */
259 static struct svc_procedure nfsd_acl_procedures3
[] = {
260 PROC(null
, void, void, void, RC_NOCACHE
, ST
),
261 PROC(getacl
, getacl
, getacl
, getacl
, RC_NOCACHE
, ST
+1+2*(1+ACL
)),
262 PROC(setacl
, setacl
, setacl
, fhandle
, RC_NOCACHE
, ST
+pAT
),
265 struct svc_version nfsd_acl_version3
= {
268 .vs_proc
= nfsd_acl_procedures3
,
269 .vs_dispatch
= nfsd_dispatch
,
270 .vs_xdrsize
= NFS3_SVC_XDRSIZE
,