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
)
33 struct posix_acl
*acl
;
36 fh
= fh_copy(&resp
->fh
, &argp
->fh
);
37 nfserr
= fh_verify(rqstp
, &resp
->fh
, 0, NFSD_MAY_NOP
);
39 RETURN_STATUS(nfserr
);
41 if (argp
->mask
& ~(NFS_ACL
|NFS_ACLCNT
|NFS_DFACL
|NFS_DFACLCNT
))
42 RETURN_STATUS(nfserr_inval
);
43 resp
->mask
= argp
->mask
;
45 if (resp
->mask
& (NFS_ACL
|NFS_ACLCNT
)) {
46 acl
= nfsd_get_posix_acl(fh
, ACL_TYPE_ACCESS
);
48 int err
= PTR_ERR(acl
);
50 if (err
== -ENODATA
|| err
== -EOPNOTSUPP
)
53 nfserr
= nfserrno(err
);
58 /* Solaris returns the inode's minimum ACL. */
60 struct inode
*inode
= fh
->fh_dentry
->d_inode
;
61 acl
= posix_acl_from_mode(inode
->i_mode
, GFP_KERNEL
);
63 resp
->acl_access
= acl
;
65 if (resp
->mask
& (NFS_DFACL
|NFS_DFACLCNT
)) {
66 /* Check how Solaris handles requests for the Default ACL
67 of a non-directory! */
69 acl
= nfsd_get_posix_acl(fh
, ACL_TYPE_DEFAULT
);
71 int err
= PTR_ERR(acl
);
73 if (err
== -ENODATA
|| err
== -EOPNOTSUPP
)
76 nfserr
= nfserrno(err
);
80 resp
->acl_default
= acl
;
83 /* resp->acl_{access,default} are released in nfs3svc_release_getacl. */
87 posix_acl_release(resp
->acl_access
);
88 posix_acl_release(resp
->acl_default
);
89 RETURN_STATUS(nfserr
);
93 * Set the Access and/or Default ACL of a file.
95 static __be32
nfsd3_proc_setacl(struct svc_rqst
* rqstp
,
96 struct nfsd3_setaclargs
*argp
,
97 struct nfsd3_attrstat
*resp
)
102 fh
= fh_copy(&resp
->fh
, &argp
->fh
);
103 nfserr
= fh_verify(rqstp
, &resp
->fh
, 0, NFSD_MAY_SATTR
);
106 nfserr
= nfserrno( nfsd_set_posix_acl(
107 fh
, ACL_TYPE_ACCESS
, argp
->acl_access
) );
110 nfserr
= nfserrno( nfsd_set_posix_acl(
111 fh
, ACL_TYPE_DEFAULT
, argp
->acl_default
) );
114 /* argp->acl_{access,default} may have been allocated in
115 nfs3svc_decode_setaclargs. */
116 posix_acl_release(argp
->acl_access
);
117 posix_acl_release(argp
->acl_default
);
118 RETURN_STATUS(nfserr
);
122 * XDR decode functions
124 static int nfs3svc_decode_getaclargs(struct svc_rqst
*rqstp
, __be32
*p
,
125 struct nfsd3_getaclargs
*args
)
127 if (!(p
= nfs3svc_decode_fh(p
, &args
->fh
)))
129 args
->mask
= ntohl(*p
); p
++;
131 return xdr_argsize_check(rqstp
, p
);
135 static int nfs3svc_decode_setaclargs(struct svc_rqst
*rqstp
, __be32
*p
,
136 struct nfsd3_setaclargs
*args
)
138 struct kvec
*head
= rqstp
->rq_arg
.head
;
142 if (!(p
= nfs3svc_decode_fh(p
, &args
->fh
)))
144 args
->mask
= ntohl(*p
++);
145 if (args
->mask
& ~(NFS_ACL
|NFS_ACLCNT
|NFS_DFACL
|NFS_DFACLCNT
) ||
146 !xdr_argsize_check(rqstp
, p
))
149 base
= (char *)p
- (char *)head
->iov_base
;
150 n
= nfsacl_decode(&rqstp
->rq_arg
, base
, NULL
,
151 (args
->mask
& NFS_ACL
) ?
152 &args
->acl_access
: NULL
);
154 n
= nfsacl_decode(&rqstp
->rq_arg
, base
+ n
, NULL
,
155 (args
->mask
& NFS_DFACL
) ?
156 &args
->acl_default
: NULL
);
161 * XDR encode functions
165 static int nfs3svc_encode_getaclres(struct svc_rqst
*rqstp
, __be32
*p
,
166 struct nfsd3_getaclres
*resp
)
168 struct dentry
*dentry
= resp
->fh
.fh_dentry
;
170 p
= nfs3svc_encode_post_op_attr(rqstp
, p
, &resp
->fh
);
171 if (resp
->status
== 0 && dentry
&& dentry
->d_inode
) {
172 struct inode
*inode
= dentry
->d_inode
;
173 struct kvec
*head
= rqstp
->rq_res
.head
;
178 *p
++ = htonl(resp
->mask
);
179 if (!xdr_ressize_check(rqstp
, p
))
181 base
= (char *)p
- (char *)head
->iov_base
;
183 rqstp
->rq_res
.page_len
= w
= nfsacl_size(
184 (resp
->mask
& NFS_ACL
) ? resp
->acl_access
: NULL
,
185 (resp
->mask
& NFS_DFACL
) ? resp
->acl_default
: NULL
);
187 if (!*(rqstp
->rq_next_page
++))
192 n
= nfsacl_encode(&rqstp
->rq_res
, base
, inode
,
194 resp
->mask
& NFS_ACL
, 0);
196 n
= nfsacl_encode(&rqstp
->rq_res
, base
+ n
, inode
,
198 resp
->mask
& NFS_DFACL
,
203 if (!xdr_ressize_check(rqstp
, p
))
210 static int nfs3svc_encode_setaclres(struct svc_rqst
*rqstp
, __be32
*p
,
211 struct nfsd3_attrstat
*resp
)
213 p
= nfs3svc_encode_post_op_attr(rqstp
, p
, &resp
->fh
);
215 return xdr_ressize_check(rqstp
, p
);
219 * XDR release functions
221 static int nfs3svc_release_getacl(struct svc_rqst
*rqstp
, __be32
*p
,
222 struct nfsd3_getaclres
*resp
)
225 posix_acl_release(resp
->acl_access
);
226 posix_acl_release(resp
->acl_default
);
230 #define nfs3svc_decode_voidargs NULL
231 #define nfs3svc_release_void NULL
232 #define nfsd3_setaclres nfsd3_attrstat
233 #define nfsd3_voidres nfsd3_voidargs
234 struct nfsd3_voidargs
{ int dummy
; };
236 #define PROC(name, argt, rest, relt, cache, respsize) \
237 { (svc_procfunc) nfsd3_proc_##name, \
238 (kxdrproc_t) nfs3svc_decode_##argt##args, \
239 (kxdrproc_t) nfs3svc_encode_##rest##res, \
240 (kxdrproc_t) nfs3svc_release_##relt, \
241 sizeof(struct nfsd3_##argt##args), \
242 sizeof(struct nfsd3_##rest##res), \
248 #define ST 1 /* status*/
249 #define AT 21 /* attributes */
250 #define pAT (1+AT) /* post attributes - conditional */
251 #define ACL (1+NFS_ACL_MAX_ENTRIES*3) /* Access Control List */
253 static struct svc_procedure nfsd_acl_procedures3
[] = {
254 PROC(null
, void, void, void, RC_NOCACHE
, ST
),
255 PROC(getacl
, getacl
, getacl
, getacl
, RC_NOCACHE
, ST
+1+2*(1+ACL
)),
256 PROC(setacl
, setacl
, setacl
, fhandle
, RC_NOCACHE
, ST
+pAT
),
259 struct svc_version nfsd_acl_version3
= {
262 .vs_proc
= nfsd_acl_procedures3
,
263 .vs_dispatch
= nfsd_dispatch
,
264 .vs_xdrsize
= NFS3_SVC_XDRSIZE
,