]> Git Repo - linux.git/blame - fs/nfsd/nfs3acl.c
Linux 6.14-rc3
[linux.git] / fs / nfsd / nfs3acl.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
a257cdd0 2/*
a257cdd0
AG
3 * Process version 3 NFSACL requests.
4 *
5 * Copyright (C) 2002-2003 Andreas Gruenbacher <[email protected]>
6 */
7
9a74af21
BH
8#include "nfsd.h"
9/* FIXME: nfsacl.h is a broken header */
a257cdd0 10#include <linux/nfsacl.h>
5a0e3ad6 11#include <linux/gfp.h>
9a74af21
BH
12#include "cache.h"
13#include "xdr3.h"
0a3adade 14#include "vfs.h"
a257cdd0 15
a257cdd0
AG
16/*
17 * NULL call.
18 */
7111c66e 19static __be32
a6beb732 20nfsd3_proc_null(struct svc_rqst *rqstp)
a257cdd0 21{
cc028a10 22 return rpc_success;
a257cdd0
AG
23}
24
25/*
26 * Get the Access and/or Default ACL of a file.
27 */
a6beb732 28static __be32 nfsd3_proc_getacl(struct svc_rqst *rqstp)
a257cdd0 29{
a6beb732
CH
30 struct nfsd3_getaclargs *argp = rqstp->rq_argp;
31 struct nfsd3_getaclres *resp = rqstp->rq_resp;
a257cdd0 32 struct posix_acl *acl;
4ac7249e
CH
33 struct inode *inode;
34 svc_fh *fh;
a257cdd0
AG
35
36 fh = fh_copy(&resp->fh, &argp->fh);
14168d67
CL
37 resp->status = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
38 if (resp->status != nfs_ok)
39 goto out;
a257cdd0 40
2b0143b5 41 inode = d_inode(fh->fh_dentry);
4ac7249e 42
14168d67
CL
43 if (argp->mask & ~NFS_ACL_MASK) {
44 resp->status = nfserr_inval;
45 goto out;
46 }
a257cdd0
AG
47 resp->mask = argp->mask;
48
49 if (resp->mask & (NFS_ACL|NFS_ACLCNT)) {
cac2f8b8 50 acl = get_inode_acl(inode, ACL_TYPE_ACCESS);
a257cdd0
AG
51 if (acl == NULL) {
52 /* Solaris returns the inode's minimum ACL. */
a257cdd0
AG
53 acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
54 }
35e634b8 55 if (IS_ERR(acl)) {
14168d67 56 resp->status = nfserrno(PTR_ERR(acl));
35e634b8
KM
57 goto fail;
58 }
a257cdd0
AG
59 resp->acl_access = acl;
60 }
61 if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) {
62 /* Check how Solaris handles requests for the Default ACL
63 of a non-directory! */
cac2f8b8 64 acl = get_inode_acl(inode, ACL_TYPE_DEFAULT);
a257cdd0 65 if (IS_ERR(acl)) {
14168d67 66 resp->status = nfserrno(PTR_ERR(acl));
4ac7249e 67 goto fail;
a257cdd0
AG
68 }
69 resp->acl_default = acl;
70 }
71
72 /* resp->acl_{access,default} are released in nfs3svc_release_getacl. */
14168d67 73out:
cc028a10 74 return rpc_success;
a257cdd0
AG
75
76fail:
77 posix_acl_release(resp->acl_access);
78 posix_acl_release(resp->acl_default);
7faf14a7
LL
79 resp->acl_access = NULL;
80 resp->acl_default = NULL;
14168d67 81 goto out;
a257cdd0
AG
82}
83
84/*
85 * Set the Access and/or Default ACL of a file.
86 */
a6beb732 87static __be32 nfsd3_proc_setacl(struct svc_rqst *rqstp)
a257cdd0 88{
a6beb732
CH
89 struct nfsd3_setaclargs *argp = rqstp->rq_argp;
90 struct nfsd3_attrstat *resp = rqstp->rq_resp;
4ac7249e 91 struct inode *inode;
a257cdd0 92 svc_fh *fh;
4ac7249e 93 int error;
a257cdd0
AG
94
95 fh = fh_copy(&resp->fh, &argp->fh);
14168d67
CL
96 resp->status = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR);
97 if (resp->status != nfs_ok)
4ac7249e 98 goto out;
a257cdd0 99
2b0143b5 100 inode = d_inode(fh->fh_dentry);
a257cdd0 101
4ac7249e
CH
102 error = fh_want_write(fh);
103 if (error)
104 goto out_errno;
105
bb4d53d6 106 inode_lock(inode);
99965378 107
13e83a49 108 error = set_posix_acl(&nop_mnt_idmap, fh->fh_dentry, ACL_TYPE_ACCESS,
e65ce2a5 109 argp->acl_access);
4ac7249e 110 if (error)
99965378 111 goto out_drop_lock;
13e83a49 112 error = set_posix_acl(&nop_mnt_idmap, fh->fh_dentry, ACL_TYPE_DEFAULT,
e65ce2a5 113 argp->acl_default);
4ac7249e 114
99965378 115out_drop_lock:
bb4d53d6 116 inode_unlock(inode);
4ac7249e
CH
117 fh_drop_write(fh);
118out_errno:
14168d67 119 resp->status = nfserrno(error);
4ac7249e 120out:
a257cdd0
AG
121 /* argp->acl_{access,default} may have been allocated in
122 nfs3svc_decode_setaclargs. */
123 posix_acl_release(argp->acl_access);
124 posix_acl_release(argp->acl_default);
cc028a10 125 return rpc_success;
a257cdd0
AG
126}
127
128/*
129 * XDR decode functions
130 */
05027eaf 131
c44b31c2 132static bool
16c66364 133nfs3svc_decode_getaclargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
a257cdd0 134{
026fec7e
CH
135 struct nfsd3_getaclargs *args = rqstp->rq_argp;
136
05027eaf 137 if (!svcxdr_decode_nfs_fh3(xdr, &args->fh))
c44b31c2 138 return false;
05027eaf 139 if (xdr_stream_decode_u32(xdr, &args->mask) < 0)
c44b31c2 140 return false;
a257cdd0 141
c44b31c2 142 return true;
a257cdd0
AG
143}
144
c44b31c2 145static bool
16c66364 146nfs3svc_decode_setaclargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
a257cdd0 147{
68519ff2 148 struct nfsd3_setaclargs *argp = rqstp->rq_argp;
a257cdd0 149
68519ff2 150 if (!svcxdr_decode_nfs_fh3(xdr, &argp->fh))
c44b31c2 151 return false;
68519ff2 152 if (xdr_stream_decode_u32(xdr, &argp->mask) < 0)
c44b31c2 153 return false;
68519ff2 154 if (argp->mask & ~NFS_ACL_MASK)
c44b31c2 155 return false;
68519ff2
CL
156 if (!nfs_stream_decode_acl(xdr, NULL, (argp->mask & NFS_ACL) ?
157 &argp->acl_access : NULL))
c44b31c2 158 return false;
68519ff2
CL
159 if (!nfs_stream_decode_acl(xdr, NULL, (argp->mask & NFS_DFACL) ?
160 &argp->acl_default : NULL))
c44b31c2 161 return false;
a257cdd0 162
c44b31c2 163 return true;
a257cdd0
AG
164}
165
166/*
167 * XDR encode functions
168 */
169
170/* GETACL */
130e2054 171static bool
fda49441 172nfs3svc_encode_getaclres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
a257cdd0 173{
63f8de37 174 struct nfsd3_getaclres *resp = rqstp->rq_resp;
a257cdd0 175 struct dentry *dentry = resp->fh.fh_dentry;
ab1016d3 176 struct inode *inode;
a257cdd0 177
20798dfe 178 if (!svcxdr_encode_nfsstat3(xdr, resp->status))
130e2054 179 return false;
20798dfe
CL
180 switch (resp->status) {
181 case nfs_ok:
ab1016d3 182 inode = d_inode(dentry);
20798dfe 183 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh))
130e2054 184 return false;
20798dfe 185 if (xdr_stream_encode_u32(xdr, resp->mask) < 0)
130e2054 186 return false;
20798dfe 187
841fd0a3
CL
188 if (!nfs_stream_encode_acl(xdr, inode, resp->acl_access,
189 resp->mask & NFS_ACL, 0))
190 return false;
191 if (!nfs_stream_encode_acl(xdr, inode, resp->acl_default,
192 resp->mask & NFS_DFACL,
193 NFS_ACL_DEFAULT))
130e2054 194 return false;
20798dfe
CL
195 break;
196 default:
197 if (!svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh))
130e2054 198 return false;
20798dfe 199 }
a257cdd0 200
130e2054 201 return true;
a257cdd0
AG
202}
203
204/* SETACL */
130e2054 205static bool
fda49441 206nfs3svc_encode_setaclres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
a257cdd0 207{
63f8de37
CH
208 struct nfsd3_attrstat *resp = rqstp->rq_resp;
209
15e432bf
CL
210 return svcxdr_encode_nfsstat3(xdr, resp->status) &&
211 svcxdr_encode_post_op_attr(rqstp, xdr, &resp->fh);
a257cdd0
AG
212}
213
214/*
215 * XDR release functions
216 */
8537488b 217static void nfs3svc_release_getacl(struct svc_rqst *rqstp)
a257cdd0 218{
8537488b
CH
219 struct nfsd3_getaclres *resp = rqstp->rq_resp;
220
a257cdd0
AG
221 fh_put(&resp->fh);
222 posix_acl_release(resp->acl_access);
223 posix_acl_release(resp->acl_default);
a257cdd0
AG
224}
225
a257cdd0
AG
226#define ST 1 /* status*/
227#define AT 21 /* attributes */
228#define pAT (1+AT) /* post attributes - conditional */
229#define ACL (1+NFS_ACL_MAX_ENTRIES*3) /* Access Control List */
230
ba1df797
CL
231static const struct svc_procedure nfsd_acl_procedures3[3] = {
232 [ACLPROC3_NULL] = {
233 .pc_func = nfsd3_proc_null,
788f7183
CL
234 .pc_decode = nfssvc_decode_voidarg,
235 .pc_encode = nfssvc_encode_voidres,
236 .pc_argsize = sizeof(struct nfsd_voidargs),
103cc1fa 237 .pc_argzero = sizeof(struct nfsd_voidargs),
788f7183 238 .pc_ressize = sizeof(struct nfsd_voidres),
ba1df797
CL
239 .pc_cachetype = RC_NOCACHE,
240 .pc_xdrressize = ST,
2289e87b 241 .pc_name = "NULL",
ba1df797
CL
242 },
243 [ACLPROC3_GETACL] = {
244 .pc_func = nfsd3_proc_getacl,
245 .pc_decode = nfs3svc_decode_getaclargs,
246 .pc_encode = nfs3svc_encode_getaclres,
247 .pc_release = nfs3svc_release_getacl,
248 .pc_argsize = sizeof(struct nfsd3_getaclargs),
103cc1fa 249 .pc_argzero = sizeof(struct nfsd3_getaclargs),
ba1df797
CL
250 .pc_ressize = sizeof(struct nfsd3_getaclres),
251 .pc_cachetype = RC_NOCACHE,
252 .pc_xdrressize = ST+1+2*(1+ACL),
2289e87b 253 .pc_name = "GETACL",
ba1df797
CL
254 },
255 [ACLPROC3_SETACL] = {
256 .pc_func = nfsd3_proc_setacl,
257 .pc_decode = nfs3svc_decode_setaclargs,
258 .pc_encode = nfs3svc_encode_setaclres,
259 .pc_release = nfs3svc_release_fhandle,
260 .pc_argsize = sizeof(struct nfsd3_setaclargs),
103cc1fa 261 .pc_argzero = sizeof(struct nfsd3_setaclargs),
ba1df797
CL
262 .pc_ressize = sizeof(struct nfsd3_attrstat),
263 .pc_cachetype = RC_NOCACHE,
264 .pc_xdrressize = ST+pAT,
2289e87b 265 .pc_name = "SETACL",
ba1df797 266 },
a257cdd0
AG
267};
268
65ba3d24
CL
269static DEFINE_PER_CPU_ALIGNED(unsigned long,
270 nfsd_acl_count3[ARRAY_SIZE(nfsd_acl_procedures3)]);
e9679189
CH
271const struct svc_version nfsd_acl_version3 = {
272 .vs_vers = 3,
65ba3d24 273 .vs_nproc = ARRAY_SIZE(nfsd_acl_procedures3),
e9679189
CH
274 .vs_proc = nfsd_acl_procedures3,
275 .vs_count = nfsd_acl_count3,
276 .vs_dispatch = nfsd_dispatch,
277 .vs_xdrsize = NFS3_SVC_XDRSIZE,
a257cdd0
AG
278};
279
This page took 1.498795 seconds and 4 git commands to generate.