Whamcloud - gitweb
681404597ba4a003c46565948b1a567fd7b6f60c
[fs/lustre-release.git] / lustre / mdc / mdc_acl.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * GPL HEADER START
4  *
5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 only,
9  * as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License version 2 for more details (a copy is included
15  * in the LICENSE file that accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License
18  * version 2 along with this program; If not, see
19  * http://www.gnu.org/licenses/gpl-2.0.html
20  *
21  * GPL HEADER END
22  */
23 #include <lustre_acl.h>
24
25 #include "mdc_internal.h"
26
27 int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md)
28 {
29         struct req_capsule *pill = &req->rq_pill;
30         struct mdt_body *body = md->body;
31         struct posix_acl *acl;
32         void *buf;
33         int rc;
34
35         /* for ACL, it's possible that FLACL is set but aclsize is zero.
36          * only when aclsize != 0 there's an actual segment for ACL
37          * in reply buffer.
38          */
39         if (!body->mbo_aclsize) {
40                 md->posix_acl = NULL;
41                 return 0;
42         }
43
44         buf = req_capsule_server_sized_get(pill, &RMF_ACL, body->mbo_aclsize);
45         if (!buf)
46                 return -EPROTO;
47
48         acl = posix_acl_from_xattr(&init_user_ns, buf, body->mbo_aclsize);
49         if (IS_ERR_OR_NULL(acl)) {
50                 rc = acl ? PTR_ERR(acl) : 0;
51                 CERROR("convert xattr to acl: %d\n", rc);
52                 return rc;
53         }
54
55         rc = posix_acl_valid(&init_user_ns, acl);
56         if (rc) {
57                 CERROR("validate acl: %d\n", rc);
58                 posix_acl_release(acl);
59                 return rc;
60         }
61
62         md->posix_acl = acl;
63         return 0;
64 }