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
|
|
|
/** @var int */ |
37
|
|
|
private $type; |
38
|
|
|
/** @var int */ |
39
|
|
|
private $flags; |
40
|
|
|
/** @var int */ |
41
|
|
|
private $mask; |
42
|
|
|
|
43
|
|
|
public function __construct(int $type, int $flags, int $mask) { |
44
|
|
|
$this->type = $type; |
45
|
|
|
$this->flags = $flags; |
46
|
|
|
$this->mask = $mask; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Check if the acl allows a specific permissions |
51
|
|
|
* |
52
|
|
|
* Note that this does not take inherited acls into account |
53
|
|
|
* |
54
|
|
|
* @param int $mask one of the ACL::MASK_* constants |
55
|
|
|
* @return bool |
56
|
|
|
*/ |
57
|
|
|
public function allows(int $mask): bool { |
58
|
|
|
return $this->type === self::TYPE_ALLOW && ($this->mask & $mask) === $mask; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Check if the acl allows a specific permissions |
63
|
|
|
* |
64
|
|
|
* Note that this does not take inherited acls into account |
65
|
|
|
* |
66
|
|
|
* @param int $mask one of the ACL::MASK_* constants |
67
|
|
|
* @return bool |
68
|
|
|
*/ |
69
|
|
|
public function denies(int $mask): bool { |
70
|
|
|
return $this->type === self::TYPE_DENY && ($this->mask & $mask) === $mask; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getType(): int { |
74
|
|
|
return $this->type; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getFlags(): int { |
78
|
|
|
return $this->flags; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getMask(): int { |
82
|
|
|
return $this->mask; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|