1 /*
2 Copyright 2013-2014 EditShare, 2013-2015 Skytechnology sp. z o.o.
3
4 This file is part of LizardFS.
5
6 LizardFS is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 3.
9
10 LizardFS is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with LizardFS. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #pragma once
20
21 #include "common/platform.h"
22
23 #include <memory>
24
25 #include "common/exception.h"
26 #include "mount/mastercomm.h"
27
28 LIZARDFS_CREATE_EXCEPTION_CLASS_MSG(AclAcquisitionException, Exception, "ACL acquiring");
29
30 struct RichACLWithOwner {
31 RichACL acl;
32 uint32_t owner_id;
33 };
34
35 typedef std::shared_ptr<RichACLWithOwner> AclCacheEntry;
36
37 typedef LruCache<
38 LruCacheOption::UseTreeMap,
39 LruCacheOption::Reentrant,
40 AclCacheEntry,
41 uint32_t, uint32_t, uint32_t> AclCache;
42
getAcl(uint32_t inode,uint32_t uid,uint32_t gid)43 inline AclCacheEntry getAcl(uint32_t inode, uint32_t uid, uint32_t gid) {
44 AclCacheEntry entry(new RichACLWithOwner());
45 uint8_t status = fs_getacl(inode, uid, gid, entry->acl, entry->owner_id);
46 if (status == LIZARDFS_STATUS_OK) {
47 return entry;
48 } else if (status == LIZARDFS_ERROR_ENOATTR) {
49 return AclCacheEntry();
50 } else {
51 throw AclAcquisitionException(status);
52 }
53 }
54