|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Lukas Reschke <[email protected]> |
|
6
|
|
|
* @author Thomas Müller <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* @license AGPL-3.0 |
|
9
|
|
|
* |
|
10
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
11
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
12
|
|
|
* as published by the Free Software Foundation. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace OCA\DAV\Connector\Sabre; |
|
25
|
|
|
|
|
26
|
|
|
use Sabre\CalDAV\Principal\User; |
|
27
|
|
|
use Sabre\DAV\Exception\NotFound; |
|
28
|
|
|
use Sabre\DAV\IFile; |
|
29
|
|
|
use Sabre\DAV\INode; |
|
30
|
|
|
use \Sabre\DAV\PropFind; |
|
31
|
|
|
use \Sabre\DAV\PropPatch; |
|
32
|
|
|
use Sabre\DAVACL\Exception\NeedPrivileges; |
|
33
|
|
|
use \Sabre\HTTP\RequestInterface; |
|
34
|
|
|
use \Sabre\HTTP\ResponseInterface; |
|
35
|
|
|
use Sabre\HTTP\URLUtil; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Class DavAclPlugin is a wrapper around \Sabre\DAVACL\Plugin that returns 404 |
|
39
|
|
|
* responses in case the resource to a response has been forbidden instead of |
|
40
|
|
|
* a 403. This is used to prevent enumeration of valid resources. |
|
41
|
|
|
* |
|
42
|
|
|
* @see https://github.com/owncloud/core/issues/22578 |
|
43
|
|
|
* @package OCA\DAV\Connector\Sabre |
|
44
|
|
|
*/ |
|
45
|
|
|
class DavAclPlugin extends \Sabre\DAVACL\Plugin { |
|
46
|
|
|
public function __construct() { |
|
47
|
|
|
$this->hideNodesFromListings = true; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) { |
|
|
|
|
|
|
51
|
|
|
$access = parent::checkPrivileges($uri, $privileges, $recursion, false); |
|
52
|
|
|
if($access === false && $throwExceptions) { |
|
53
|
|
|
/** @var INode $node */ |
|
54
|
|
|
$node = $this->server->tree->getNodeForPath($uri); |
|
55
|
|
|
|
|
56
|
|
|
switch(get_class($node)) { |
|
57
|
|
|
case 'OCA\DAV\CardDAV\AddressBook': |
|
58
|
|
|
$type = 'Addressbook'; |
|
59
|
|
|
break; |
|
60
|
|
|
default: |
|
61
|
|
|
$type = 'Node'; |
|
62
|
|
|
break; |
|
63
|
|
|
} |
|
64
|
|
|
throw new NotFound( |
|
65
|
|
|
sprintf( |
|
66
|
|
|
"%s with name '%s' could not be found", |
|
67
|
|
|
$type, |
|
68
|
|
|
$node->getName() |
|
69
|
|
|
) |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $access; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function propFind(PropFind $propFind, INode $node) { |
|
77
|
|
|
// If the node is neither readable nor writable then fail unless its of |
|
78
|
|
|
// the standard user-principal |
|
79
|
|
|
if(!($node instanceof User)) { |
|
|
|
|
|
|
80
|
|
|
$path = $propFind->getPath(); |
|
81
|
|
|
$readPermissions = $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false); |
|
82
|
|
|
$writePermissions = $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, false); |
|
83
|
|
|
if ($readPermissions === false && $writePermissions === false) { |
|
84
|
|
|
$this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, true); |
|
85
|
|
|
$this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, true); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
return parent::propFind($propFind, $node); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.