Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ACL.php « src « smb « icewind « 3rdparty « files_external « apps - github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0b5b05a86af11d9bf0e84abde184c732dc35e29b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php declare(strict_types=1);
/**
 * @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
 *
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

namespace Icewind\SMB;

class ACL {
	const TYPE_ALLOW = 0;
	const TYPE_DENY = 1;

	const MASK_READ = 0x0001;
	const MASK_WRITE = 0x0002;
	const MASK_EXECUTE = 0x00020;
	const MASK_DELETE = 0x10000;

	const FLAG_OBJECT_INHERIT = 0x1;
	const FLAG_CONTAINER_INHERIT = 0x2;

	/** @var int */
	private $type;
	/** @var int */
	private $flags;
	/** @var int */
	private $mask;

	public function __construct(int $type, int $flags, int $mask) {
		$this->type = $type;
		$this->flags = $flags;
		$this->mask = $mask;
	}

	/**
	 * Check if the acl allows a specific permissions
	 *
	 * Note that this does not take inherited acls into account
	 *
	 * @param int $mask one of the ACL::MASK_* constants
	 * @return bool
	 */
	public function allows(int $mask): bool {
		return $this->type === self::TYPE_ALLOW && ($this->mask & $mask) === $mask;
	}

	/**
	 * Check if the acl allows a specific permissions
	 *
	 * Note that this does not take inherited acls into account
	 *
	 * @param int $mask one of the ACL::MASK_* constants
	 * @return bool
	 */
	public function denies(int $mask): bool {
		return $this->type === self::TYPE_DENY && ($this->mask & $mask) === $mask;
	}

	public function getType(): int {
		return $this->type;
	}

	public function getFlags(): int {
		return $this->flags;
	}

	public function getMask(): int {
		return $this->mask;
	}
}