Completed
Push — master ( 065daa...3c5e45 )
by Robin
04:15
created

ACL   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 58
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A allows() 0 3 2
A denies() 0 3 2
A getType() 0 3 1
A getFlags() 0 3 1
A getMask() 0 3 1
1
<?php declare(strict_types=1);
2
/**
3
 * @copyright Copyright (c) 2020 Robin Appelman <[email protected]>
4
 *
5
 * @license GNU AGPL version 3 or any later version
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Affero General Public License as
9
 * published by the Free Software Foundation, either version 3 of the
10
 * License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 *
20
 */
21
22
namespace Icewind\SMB;
23
24
class ACL {
25
	const TYPE_ALLOW = 0;
26
	const TYPE_DENY = 1;
27
28
	const MASK_READ = 0x0001;
29
	const MASK_WRITE = 0x0002;
30
	const MASK_EXECUTE = 0x00020;
31
	const MASK_DELETE = 0x10000;
32
33
	const FLAG_OBJECT_INHERIT = 0x1;
34
	const FLAG_CONTAINER_INHERIT = 0x2;
35
36
	private $type;
37
	private $flags;
38
	private $mask;
39
40
	public function __construct(int $type, int $flags, int $mask) {
41
		$this->type = $type;
42
		$this->flags = $flags;
43
		$this->mask = $mask;
44
	}
45
46
	/**
47
	 * Check if the acl allows a specific permissions
48
	 *
49
	 * Note that this does not take inherited acls into account
50
	 *
51
	 * @param int $mask one of the ACL::MASK_* constants
52
	 * @return bool
53
	 */
54
	public function allows(int $mask): bool {
55
		return $this->type === self::TYPE_ALLOW && ($this->mask & $mask) === $mask;
56
	}
57
58
	/**
59
	 * Check if the acl allows a specific permissions
60
	 *
61
	 * Note that this does not take inherited acls into account
62
	 *
63
	 * @param int $mask one of the ACL::MASK_* constants
64
	 * @return bool
65
	 */
66
	public function denies(int $mask): bool {
67
		return $this->type === self::TYPE_DENY && ($this->mask & $mask) === $mask;
68
	}
69
70
	public function getType(): int {
71
		return $this->type;
72
	}
73
74
	public function getFlags(): int {
75
		return $this->flags;
76
	}
77
78
	public function getMask(): int {
79
		return $this->mask;
80
	}
81
}
82