@@ -29,13 +29,13 @@ |
||
29 | 29 | */ |
30 | 30 | class Audio extends File { |
31 | 31 | |
32 | - /** |
|
33 | - * Type name; translated in templates |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $type = 'audio'; |
|
32 | + /** |
|
33 | + * Type name; translated in templates |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $type = 'audio'; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @TODO add ID3 information |
|
40 | - */ |
|
38 | + /** |
|
39 | + * @TODO add ID3 information |
|
40 | + */ |
|
41 | 41 | } |
@@ -29,13 +29,13 @@ |
||
29 | 29 | */ |
30 | 30 | class Image extends File { |
31 | 31 | |
32 | - /** |
|
33 | - * Type name; translated in templates |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $type = 'image'; |
|
32 | + /** |
|
33 | + * Type name; translated in templates |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $type = 'image'; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @TODO add EXIF information |
|
40 | - */ |
|
38 | + /** |
|
39 | + * @TODO add EXIF information |
|
40 | + */ |
|
41 | 41 | } |
@@ -29,9 +29,9 @@ |
||
29 | 29 | */ |
30 | 30 | class Folder extends File { |
31 | 31 | |
32 | - /** |
|
33 | - * Type name; translated in templates |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $type = 'folder'; |
|
32 | + /** |
|
33 | + * Type name; translated in templates |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $type = 'folder'; |
|
37 | 37 | } |
@@ -33,44 +33,44 @@ |
||
33 | 33 | */ |
34 | 34 | class File extends \OCP\Search\Provider { |
35 | 35 | |
36 | - /** |
|
37 | - * Search for files and folders matching the given query |
|
38 | - * @param string $query |
|
39 | - * @return \OCP\Search\Result |
|
40 | - */ |
|
41 | - public function search($query) { |
|
42 | - $files = Filesystem::search($query); |
|
43 | - $results = []; |
|
44 | - // edit results |
|
45 | - foreach ($files as $fileData) { |
|
46 | - // skip versions |
|
47 | - if (strpos($fileData['path'], '_versions') === 0) { |
|
48 | - continue; |
|
49 | - } |
|
50 | - // skip top-level folder |
|
51 | - if ($fileData['name'] === 'files' && $fileData['parent'] === -1) { |
|
52 | - continue; |
|
53 | - } |
|
54 | - // create audio result |
|
55 | - if ($fileData['mimepart'] === 'audio') { |
|
56 | - $result = new \OC\Search\Result\Audio($fileData); |
|
57 | - } |
|
58 | - // create image result |
|
59 | - elseif ($fileData['mimepart'] === 'image') { |
|
60 | - $result = new \OC\Search\Result\Image($fileData); |
|
61 | - } |
|
62 | - // create folder result |
|
63 | - elseif ($fileData['mimetype'] === 'httpd/unix-directory') { |
|
64 | - $result = new \OC\Search\Result\Folder($fileData); |
|
65 | - } |
|
66 | - // or create file result |
|
67 | - else { |
|
68 | - $result = new \OC\Search\Result\File($fileData); |
|
69 | - } |
|
70 | - // add to results |
|
71 | - $results[] = $result; |
|
72 | - } |
|
73 | - // return |
|
74 | - return $results; |
|
75 | - } |
|
36 | + /** |
|
37 | + * Search for files and folders matching the given query |
|
38 | + * @param string $query |
|
39 | + * @return \OCP\Search\Result |
|
40 | + */ |
|
41 | + public function search($query) { |
|
42 | + $files = Filesystem::search($query); |
|
43 | + $results = []; |
|
44 | + // edit results |
|
45 | + foreach ($files as $fileData) { |
|
46 | + // skip versions |
|
47 | + if (strpos($fileData['path'], '_versions') === 0) { |
|
48 | + continue; |
|
49 | + } |
|
50 | + // skip top-level folder |
|
51 | + if ($fileData['name'] === 'files' && $fileData['parent'] === -1) { |
|
52 | + continue; |
|
53 | + } |
|
54 | + // create audio result |
|
55 | + if ($fileData['mimepart'] === 'audio') { |
|
56 | + $result = new \OC\Search\Result\Audio($fileData); |
|
57 | + } |
|
58 | + // create image result |
|
59 | + elseif ($fileData['mimepart'] === 'image') { |
|
60 | + $result = new \OC\Search\Result\Image($fileData); |
|
61 | + } |
|
62 | + // create folder result |
|
63 | + elseif ($fileData['mimetype'] === 'httpd/unix-directory') { |
|
64 | + $result = new \OC\Search\Result\Folder($fileData); |
|
65 | + } |
|
66 | + // or create file result |
|
67 | + else { |
|
68 | + $result = new \OC\Search\Result\File($fileData); |
|
69 | + } |
|
70 | + // add to results |
|
71 | + $results[] = $result; |
|
72 | + } |
|
73 | + // return |
|
74 | + return $results; |
|
75 | + } |
|
76 | 76 | } |
@@ -27,104 +27,104 @@ |
||
27 | 27 | use OCP\ICertificate; |
28 | 28 | |
29 | 29 | class Certificate implements ICertificate { |
30 | - protected $name; |
|
31 | - |
|
32 | - protected $commonName; |
|
33 | - |
|
34 | - protected $organization; |
|
35 | - |
|
36 | - protected $serial; |
|
37 | - |
|
38 | - protected $issueDate; |
|
39 | - |
|
40 | - protected $expireDate; |
|
41 | - |
|
42 | - protected $issuerName; |
|
43 | - |
|
44 | - protected $issuerOrganization; |
|
45 | - |
|
46 | - /** |
|
47 | - * @param string $data base64 encoded certificate |
|
48 | - * @param string $name |
|
49 | - * @throws \Exception If the certificate could not get parsed |
|
50 | - */ |
|
51 | - public function __construct($data, $name) { |
|
52 | - $this->name = $name; |
|
53 | - $gmt = new \DateTimeZone('GMT'); |
|
54 | - |
|
55 | - // If string starts with "file://" ignore the certificate |
|
56 | - $query = 'file://'; |
|
57 | - if (strtolower(substr($data, 0, strlen($query))) === $query) { |
|
58 | - throw new \Exception('Certificate could not get parsed.'); |
|
59 | - } |
|
60 | - |
|
61 | - $info = openssl_x509_parse($data); |
|
62 | - if (!is_array($info)) { |
|
63 | - throw new \Exception('Certificate could not get parsed.'); |
|
64 | - } |
|
65 | - |
|
66 | - $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
|
67 | - $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
|
68 | - $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
69 | - $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
70 | - $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
|
71 | - $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function getName() { |
|
78 | - return $this->name; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @return string|null |
|
83 | - */ |
|
84 | - public function getCommonName() { |
|
85 | - return $this->commonName; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function getOrganization() { |
|
92 | - return $this->organization; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * @return \DateTime |
|
97 | - */ |
|
98 | - public function getIssueDate() { |
|
99 | - return $this->issueDate; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @return \DateTime |
|
104 | - */ |
|
105 | - public function getExpireDate() { |
|
106 | - return $this->expireDate; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public function isExpired() { |
|
113 | - $now = new \DateTime(); |
|
114 | - return $this->issueDate > $now or $now > $this->expireDate; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @return string|null |
|
119 | - */ |
|
120 | - public function getIssuerName() { |
|
121 | - return $this->issuerName; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @return string|null |
|
126 | - */ |
|
127 | - public function getIssuerOrganization() { |
|
128 | - return $this->issuerOrganization; |
|
129 | - } |
|
30 | + protected $name; |
|
31 | + |
|
32 | + protected $commonName; |
|
33 | + |
|
34 | + protected $organization; |
|
35 | + |
|
36 | + protected $serial; |
|
37 | + |
|
38 | + protected $issueDate; |
|
39 | + |
|
40 | + protected $expireDate; |
|
41 | + |
|
42 | + protected $issuerName; |
|
43 | + |
|
44 | + protected $issuerOrganization; |
|
45 | + |
|
46 | + /** |
|
47 | + * @param string $data base64 encoded certificate |
|
48 | + * @param string $name |
|
49 | + * @throws \Exception If the certificate could not get parsed |
|
50 | + */ |
|
51 | + public function __construct($data, $name) { |
|
52 | + $this->name = $name; |
|
53 | + $gmt = new \DateTimeZone('GMT'); |
|
54 | + |
|
55 | + // If string starts with "file://" ignore the certificate |
|
56 | + $query = 'file://'; |
|
57 | + if (strtolower(substr($data, 0, strlen($query))) === $query) { |
|
58 | + throw new \Exception('Certificate could not get parsed.'); |
|
59 | + } |
|
60 | + |
|
61 | + $info = openssl_x509_parse($data); |
|
62 | + if (!is_array($info)) { |
|
63 | + throw new \Exception('Certificate could not get parsed.'); |
|
64 | + } |
|
65 | + |
|
66 | + $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
|
67 | + $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
|
68 | + $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
69 | + $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
70 | + $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
|
71 | + $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function getName() { |
|
78 | + return $this->name; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @return string|null |
|
83 | + */ |
|
84 | + public function getCommonName() { |
|
85 | + return $this->commonName; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function getOrganization() { |
|
92 | + return $this->organization; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * @return \DateTime |
|
97 | + */ |
|
98 | + public function getIssueDate() { |
|
99 | + return $this->issueDate; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @return \DateTime |
|
104 | + */ |
|
105 | + public function getExpireDate() { |
|
106 | + return $this->expireDate; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public function isExpired() { |
|
113 | + $now = new \DateTime(); |
|
114 | + return $this->issueDate > $now or $now > $this->expireDate; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @return string|null |
|
119 | + */ |
|
120 | + public function getIssuerName() { |
|
121 | + return $this->issuerName; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @return string|null |
|
126 | + */ |
|
127 | + public function getIssuerOrganization() { |
|
128 | + return $this->issuerOrganization; |
|
129 | + } |
|
130 | 130 | } |
@@ -65,8 +65,8 @@ |
||
65 | 65 | |
66 | 66 | $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
67 | 67 | $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
68 | - $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
69 | - $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
68 | + $this->issueDate = new \DateTime('@'.$info['validFrom_time_t'], $gmt); |
|
69 | + $this->expireDate = new \DateTime('@'.$info['validTo_time_t'], $gmt); |
|
70 | 70 | $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
71 | 71 | $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
72 | 72 | } |
@@ -89,7 +89,7 @@ |
||
89 | 89 | $user = $this->userManager->get($userId); |
90 | 90 | if ($user !== null) { |
91 | 91 | $key = $this->keyManager->getKey($user); |
92 | - return (bool)openssl_verify( |
|
92 | + return (bool) openssl_verify( |
|
93 | 93 | json_encode($data['message']), |
94 | 94 | base64_decode($data['signature']), |
95 | 95 | $key->getPublic(), |
@@ -32,76 +32,76 @@ |
||
32 | 32 | use OCP\IUserManager; |
33 | 33 | |
34 | 34 | class Signer { |
35 | - /** @var Manager */ |
|
36 | - private $keyManager; |
|
37 | - /** @var ITimeFactory */ |
|
38 | - private $timeFactory; |
|
39 | - /** @var IUserManager */ |
|
40 | - private $userManager; |
|
35 | + /** @var Manager */ |
|
36 | + private $keyManager; |
|
37 | + /** @var ITimeFactory */ |
|
38 | + private $timeFactory; |
|
39 | + /** @var IUserManager */ |
|
40 | + private $userManager; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param Manager $keyManager |
|
44 | - * @param ITimeFactory $timeFactory |
|
45 | - * @param IUserManager $userManager |
|
46 | - */ |
|
47 | - public function __construct(Manager $keyManager, |
|
48 | - ITimeFactory $timeFactory, |
|
49 | - IUserManager $userManager) { |
|
50 | - $this->keyManager = $keyManager; |
|
51 | - $this->timeFactory = $timeFactory; |
|
52 | - $this->userManager = $userManager; |
|
53 | - } |
|
42 | + /** |
|
43 | + * @param Manager $keyManager |
|
44 | + * @param ITimeFactory $timeFactory |
|
45 | + * @param IUserManager $userManager |
|
46 | + */ |
|
47 | + public function __construct(Manager $keyManager, |
|
48 | + ITimeFactory $timeFactory, |
|
49 | + IUserManager $userManager) { |
|
50 | + $this->keyManager = $keyManager; |
|
51 | + $this->timeFactory = $timeFactory; |
|
52 | + $this->userManager = $userManager; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Returns a signed blob for $data |
|
57 | - * |
|
58 | - * @param string $type |
|
59 | - * @param array $data |
|
60 | - * @param IUser $user |
|
61 | - * @return array ['message', 'signature'] |
|
62 | - */ |
|
63 | - public function sign(string $type, array $data, IUser $user): array { |
|
64 | - $privateKey = $this->keyManager->getKey($user)->getPrivate(); |
|
65 | - $data = [ |
|
66 | - 'data' => $data, |
|
67 | - 'type' => $type, |
|
68 | - 'signer' => $user->getCloudId(), |
|
69 | - 'timestamp' => $this->timeFactory->getTime(), |
|
70 | - ]; |
|
71 | - openssl_sign(json_encode($data), $signature, $privateKey, OPENSSL_ALGO_SHA512); |
|
55 | + /** |
|
56 | + * Returns a signed blob for $data |
|
57 | + * |
|
58 | + * @param string $type |
|
59 | + * @param array $data |
|
60 | + * @param IUser $user |
|
61 | + * @return array ['message', 'signature'] |
|
62 | + */ |
|
63 | + public function sign(string $type, array $data, IUser $user): array { |
|
64 | + $privateKey = $this->keyManager->getKey($user)->getPrivate(); |
|
65 | + $data = [ |
|
66 | + 'data' => $data, |
|
67 | + 'type' => $type, |
|
68 | + 'signer' => $user->getCloudId(), |
|
69 | + 'timestamp' => $this->timeFactory->getTime(), |
|
70 | + ]; |
|
71 | + openssl_sign(json_encode($data), $signature, $privateKey, OPENSSL_ALGO_SHA512); |
|
72 | 72 | |
73 | - return [ |
|
74 | - 'message' => $data, |
|
75 | - 'signature' => base64_encode($signature), |
|
76 | - ]; |
|
77 | - } |
|
73 | + return [ |
|
74 | + 'message' => $data, |
|
75 | + 'signature' => base64_encode($signature), |
|
76 | + ]; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Whether the data is signed properly |
|
81 | - * |
|
82 | - * @param array $data |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - public function verify(array $data): bool { |
|
86 | - if (isset($data['message']) |
|
87 | - && isset($data['signature']) |
|
88 | - && isset($data['message']['signer']) |
|
89 | - ) { |
|
90 | - $location = strrpos($data['message']['signer'], '@'); |
|
91 | - $userId = substr($data['message']['signer'], 0, $location); |
|
79 | + /** |
|
80 | + * Whether the data is signed properly |
|
81 | + * |
|
82 | + * @param array $data |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + public function verify(array $data): bool { |
|
86 | + if (isset($data['message']) |
|
87 | + && isset($data['signature']) |
|
88 | + && isset($data['message']['signer']) |
|
89 | + ) { |
|
90 | + $location = strrpos($data['message']['signer'], '@'); |
|
91 | + $userId = substr($data['message']['signer'], 0, $location); |
|
92 | 92 | |
93 | - $user = $this->userManager->get($userId); |
|
94 | - if ($user !== null) { |
|
95 | - $key = $this->keyManager->getKey($user); |
|
96 | - return (bool)openssl_verify( |
|
97 | - json_encode($data['message']), |
|
98 | - base64_decode($data['signature']), |
|
99 | - $key->getPublic(), |
|
100 | - OPENSSL_ALGO_SHA512 |
|
101 | - ); |
|
102 | - } |
|
103 | - } |
|
93 | + $user = $this->userManager->get($userId); |
|
94 | + if ($user !== null) { |
|
95 | + $key = $this->keyManager->getKey($user); |
|
96 | + return (bool)openssl_verify( |
|
97 | + json_encode($data['message']), |
|
98 | + base64_decode($data['signature']), |
|
99 | + $key->getPublic(), |
|
100 | + OPENSSL_ALGO_SHA512 |
|
101 | + ); |
|
102 | + } |
|
103 | + } |
|
104 | 104 | |
105 | - return false; |
|
106 | - } |
|
105 | + return false; |
|
106 | + } |
|
107 | 107 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | use OCP\Encryption\Exceptions\GenericEncryptionException; |
28 | 28 | |
29 | 29 | class EncryptionHeaderToLargeException extends GenericEncryptionException { |
30 | - public function __construct() { |
|
31 | - parent::__construct('max header size exceeded'); |
|
32 | - } |
|
30 | + public function __construct() { |
|
31 | + parent::__construct('max header size exceeded'); |
|
32 | + } |
|
33 | 33 | } |
@@ -73,7 +73,7 @@ |
||
73 | 73 | // always add owner to the list of users with access to the file |
74 | 74 | $userIds = [$owner]; |
75 | 75 | |
76 | - if (!$this->util->isFile($owner . '/' . $ownerPath)) { |
|
76 | + if (!$this->util->isFile($owner.'/'.$ownerPath)) { |
|
77 | 77 | return ['users' => $userIds, 'public' => false]; |
78 | 78 | } |
79 | 79 |
@@ -33,95 +33,95 @@ |
||
33 | 33 | |
34 | 34 | class File implements \OCP\Encryption\IFile { |
35 | 35 | |
36 | - /** @var Util */ |
|
37 | - protected $util; |
|
38 | - |
|
39 | - /** @var IRootFolder */ |
|
40 | - private $rootFolder; |
|
41 | - |
|
42 | - /** @var IManager */ |
|
43 | - private $shareManager; |
|
44 | - |
|
45 | - /** |
|
46 | - * cache results of already checked folders |
|
47 | - * |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - protected $cache; |
|
51 | - |
|
52 | - public function __construct(Util $util, |
|
53 | - IRootFolder $rootFolder, |
|
54 | - IManager $shareManager) { |
|
55 | - $this->util = $util; |
|
56 | - $this->cache = new CappedMemoryCache(); |
|
57 | - $this->rootFolder = $rootFolder; |
|
58 | - $this->shareManager = $shareManager; |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * get list of users with access to the file |
|
64 | - * |
|
65 | - * @param string $path to the file |
|
66 | - * @return array ['users' => $uniqueUserIds, 'public' => $public] |
|
67 | - */ |
|
68 | - public function getAccessList($path) { |
|
69 | - |
|
70 | - // Make sure that a share key is generated for the owner too |
|
71 | - list($owner, $ownerPath) = $this->util->getUidAndFilename($path); |
|
72 | - |
|
73 | - // always add owner to the list of users with access to the file |
|
74 | - $userIds = [$owner]; |
|
75 | - |
|
76 | - if (!$this->util->isFile($owner . '/' . $ownerPath)) { |
|
77 | - return ['users' => $userIds, 'public' => false]; |
|
78 | - } |
|
79 | - |
|
80 | - $ownerPath = substr($ownerPath, strlen('/files')); |
|
81 | - $userFolder = $this->rootFolder->getUserFolder($owner); |
|
82 | - try { |
|
83 | - $file = $userFolder->get($ownerPath); |
|
84 | - } catch (NotFoundException $e) { |
|
85 | - $file = null; |
|
86 | - } |
|
87 | - $ownerPath = $this->util->stripPartialFileExtension($ownerPath); |
|
88 | - |
|
89 | - // first get the shares for the parent and cache the result so that we don't |
|
90 | - // need to check all parents for every file |
|
91 | - $parent = dirname($ownerPath); |
|
92 | - $parentNode = $userFolder->get($parent); |
|
93 | - if (isset($this->cache[$parent])) { |
|
94 | - $resultForParents = $this->cache[$parent]; |
|
95 | - } else { |
|
96 | - $resultForParents = $this->shareManager->getAccessList($parentNode); |
|
97 | - $this->cache[$parent] = $resultForParents; |
|
98 | - } |
|
99 | - $userIds = array_merge($userIds, $resultForParents['users']); |
|
100 | - $public = $resultForParents['public'] || $resultForParents['remote']; |
|
101 | - |
|
102 | - |
|
103 | - // Find out who, if anyone, is sharing the file |
|
104 | - if ($file !== null) { |
|
105 | - $resultForFile = $this->shareManager->getAccessList($file, false); |
|
106 | - $userIds = array_merge($userIds, $resultForFile['users']); |
|
107 | - $public = $resultForFile['public'] || $resultForFile['remote'] || $public; |
|
108 | - } |
|
109 | - |
|
110 | - // check if it is a group mount |
|
111 | - if (\OCP\App::isEnabled("files_external")) { |
|
112 | - $mounts = \OC_Mount_Config::getSystemMountPoints(); |
|
113 | - foreach ($mounts as $mount) { |
|
114 | - if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) { |
|
115 | - $mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']); |
|
116 | - $userIds = array_merge($userIds, $mountedFor); |
|
117 | - } |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - // Remove duplicate UIDs |
|
122 | - $uniqueUserIds = array_unique($userIds); |
|
123 | - |
|
124 | - return ['users' => $uniqueUserIds, 'public' => $public]; |
|
125 | - } |
|
36 | + /** @var Util */ |
|
37 | + protected $util; |
|
38 | + |
|
39 | + /** @var IRootFolder */ |
|
40 | + private $rootFolder; |
|
41 | + |
|
42 | + /** @var IManager */ |
|
43 | + private $shareManager; |
|
44 | + |
|
45 | + /** |
|
46 | + * cache results of already checked folders |
|
47 | + * |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + protected $cache; |
|
51 | + |
|
52 | + public function __construct(Util $util, |
|
53 | + IRootFolder $rootFolder, |
|
54 | + IManager $shareManager) { |
|
55 | + $this->util = $util; |
|
56 | + $this->cache = new CappedMemoryCache(); |
|
57 | + $this->rootFolder = $rootFolder; |
|
58 | + $this->shareManager = $shareManager; |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * get list of users with access to the file |
|
64 | + * |
|
65 | + * @param string $path to the file |
|
66 | + * @return array ['users' => $uniqueUserIds, 'public' => $public] |
|
67 | + */ |
|
68 | + public function getAccessList($path) { |
|
69 | + |
|
70 | + // Make sure that a share key is generated for the owner too |
|
71 | + list($owner, $ownerPath) = $this->util->getUidAndFilename($path); |
|
72 | + |
|
73 | + // always add owner to the list of users with access to the file |
|
74 | + $userIds = [$owner]; |
|
75 | + |
|
76 | + if (!$this->util->isFile($owner . '/' . $ownerPath)) { |
|
77 | + return ['users' => $userIds, 'public' => false]; |
|
78 | + } |
|
79 | + |
|
80 | + $ownerPath = substr($ownerPath, strlen('/files')); |
|
81 | + $userFolder = $this->rootFolder->getUserFolder($owner); |
|
82 | + try { |
|
83 | + $file = $userFolder->get($ownerPath); |
|
84 | + } catch (NotFoundException $e) { |
|
85 | + $file = null; |
|
86 | + } |
|
87 | + $ownerPath = $this->util->stripPartialFileExtension($ownerPath); |
|
88 | + |
|
89 | + // first get the shares for the parent and cache the result so that we don't |
|
90 | + // need to check all parents for every file |
|
91 | + $parent = dirname($ownerPath); |
|
92 | + $parentNode = $userFolder->get($parent); |
|
93 | + if (isset($this->cache[$parent])) { |
|
94 | + $resultForParents = $this->cache[$parent]; |
|
95 | + } else { |
|
96 | + $resultForParents = $this->shareManager->getAccessList($parentNode); |
|
97 | + $this->cache[$parent] = $resultForParents; |
|
98 | + } |
|
99 | + $userIds = array_merge($userIds, $resultForParents['users']); |
|
100 | + $public = $resultForParents['public'] || $resultForParents['remote']; |
|
101 | + |
|
102 | + |
|
103 | + // Find out who, if anyone, is sharing the file |
|
104 | + if ($file !== null) { |
|
105 | + $resultForFile = $this->shareManager->getAccessList($file, false); |
|
106 | + $userIds = array_merge($userIds, $resultForFile['users']); |
|
107 | + $public = $resultForFile['public'] || $resultForFile['remote'] || $public; |
|
108 | + } |
|
109 | + |
|
110 | + // check if it is a group mount |
|
111 | + if (\OCP\App::isEnabled("files_external")) { |
|
112 | + $mounts = \OC_Mount_Config::getSystemMountPoints(); |
|
113 | + foreach ($mounts as $mount) { |
|
114 | + if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) { |
|
115 | + $mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']); |
|
116 | + $userIds = array_merge($userIds, $mountedFor); |
|
117 | + } |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + // Remove duplicate UIDs |
|
122 | + $uniqueUserIds = array_unique($userIds); |
|
123 | + |
|
124 | + return ['users' => $uniqueUserIds, 'public' => $public]; |
|
125 | + } |
|
126 | 126 | |
127 | 127 | } |
@@ -33,159 +33,159 @@ |
||
33 | 33 | */ |
34 | 34 | class Update { |
35 | 35 | |
36 | - /** @var \OC\Files\View */ |
|
37 | - protected $view; |
|
38 | - |
|
39 | - /** @var \OC\Encryption\Util */ |
|
40 | - protected $util; |
|
41 | - |
|
42 | - /** @var \OC\Files\Mount\Manager */ |
|
43 | - protected $mountManager; |
|
44 | - |
|
45 | - /** @var \OC\Encryption\Manager */ |
|
46 | - protected $encryptionManager; |
|
47 | - |
|
48 | - /** @var string */ |
|
49 | - protected $uid; |
|
50 | - |
|
51 | - /** @var \OC\Encryption\File */ |
|
52 | - protected $file; |
|
53 | - |
|
54 | - /** |
|
55 | - * |
|
56 | - * @param \OC\Files\View $view |
|
57 | - * @param \OC\Encryption\Util $util |
|
58 | - * @param \OC\Files\Mount\Manager $mountManager |
|
59 | - * @param \OC\Encryption\Manager $encryptionManager |
|
60 | - * @param \OC\Encryption\File $file |
|
61 | - * @param string $uid |
|
62 | - */ |
|
63 | - public function __construct( |
|
64 | - View $view, |
|
65 | - Util $util, |
|
66 | - Mount\Manager $mountManager, |
|
67 | - Manager $encryptionManager, |
|
68 | - File $file, |
|
69 | - $uid |
|
70 | - ) { |
|
71 | - $this->view = $view; |
|
72 | - $this->util = $util; |
|
73 | - $this->mountManager = $mountManager; |
|
74 | - $this->encryptionManager = $encryptionManager; |
|
75 | - $this->file = $file; |
|
76 | - $this->uid = $uid; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * hook after file was shared |
|
81 | - * |
|
82 | - * @param array $params |
|
83 | - */ |
|
84 | - public function postShared($params) { |
|
85 | - if ($this->encryptionManager->isEnabled()) { |
|
86 | - if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { |
|
87 | - $path = Filesystem::getPath($params['fileSource']); |
|
88 | - list($owner, $ownerPath) = $this->getOwnerPath($path); |
|
89 | - $absPath = '/' . $owner . '/files/' . $ownerPath; |
|
90 | - $this->update($absPath); |
|
91 | - } |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * hook after file was unshared |
|
97 | - * |
|
98 | - * @param array $params |
|
99 | - */ |
|
100 | - public function postUnshared($params) { |
|
101 | - if ($this->encryptionManager->isEnabled()) { |
|
102 | - if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { |
|
103 | - $path = Filesystem::getPath($params['fileSource']); |
|
104 | - list($owner, $ownerPath) = $this->getOwnerPath($path); |
|
105 | - $absPath = '/' . $owner . '/files/' . $ownerPath; |
|
106 | - $this->update($absPath); |
|
107 | - } |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * inform encryption module that a file was restored from the trash bin, |
|
113 | - * e.g. to update the encryption keys |
|
114 | - * |
|
115 | - * @param array $params |
|
116 | - */ |
|
117 | - public function postRestore($params) { |
|
118 | - if ($this->encryptionManager->isEnabled()) { |
|
119 | - $path = Filesystem::normalizePath('/' . $this->uid . '/files/' . $params['filePath']); |
|
120 | - $this->update($path); |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * inform encryption module that a file was renamed, |
|
126 | - * e.g. to update the encryption keys |
|
127 | - * |
|
128 | - * @param array $params |
|
129 | - */ |
|
130 | - public function postRename($params) { |
|
131 | - $source = $params['oldpath']; |
|
132 | - $target = $params['newpath']; |
|
133 | - if ( |
|
134 | - $this->encryptionManager->isEnabled() && |
|
135 | - dirname($source) !== dirname($target) |
|
136 | - ) { |
|
137 | - list($owner, $ownerPath) = $this->getOwnerPath($target); |
|
138 | - $absPath = '/' . $owner . '/files/' . $ownerPath; |
|
139 | - $this->update($absPath); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * get owner and path relative to data/<owner>/files |
|
145 | - * |
|
146 | - * @param string $path path to file for current user |
|
147 | - * @return array ['owner' => $owner, 'path' => $path] |
|
148 | - * @throw \InvalidArgumentException |
|
149 | - */ |
|
150 | - protected function getOwnerPath($path) { |
|
151 | - $info = Filesystem::getFileInfo($path); |
|
152 | - $owner = Filesystem::getOwner($path); |
|
153 | - $view = new View('/' . $owner . '/files'); |
|
154 | - $path = $view->getPath($info->getId()); |
|
155 | - if ($path === null) { |
|
156 | - throw new \InvalidArgumentException('No file found for ' . $info->getId()); |
|
157 | - } |
|
158 | - |
|
159 | - return [$owner, $path]; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * notify encryption module about added/removed users from a file/folder |
|
164 | - * |
|
165 | - * @param string $path relative to data/ |
|
166 | - * @throws Exceptions\ModuleDoesNotExistsException |
|
167 | - */ |
|
168 | - public function update($path) { |
|
169 | - $encryptionModule = $this->encryptionManager->getEncryptionModule(); |
|
170 | - |
|
171 | - // if the encryption module doesn't encrypt the files on a per-user basis |
|
172 | - // we have nothing to do here. |
|
173 | - if ($encryptionModule->needDetailedAccessList() === false) { |
|
174 | - return; |
|
175 | - } |
|
176 | - |
|
177 | - // if a folder was shared, get a list of all (sub-)folders |
|
178 | - if ($this->view->is_dir($path)) { |
|
179 | - $allFiles = $this->util->getAllFiles($path); |
|
180 | - } else { |
|
181 | - $allFiles = [$path]; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - |
|
186 | - foreach ($allFiles as $file) { |
|
187 | - $usersSharing = $this->file->getAccessList($file); |
|
188 | - $encryptionModule->update($file, $this->uid, $usersSharing); |
|
189 | - } |
|
190 | - } |
|
36 | + /** @var \OC\Files\View */ |
|
37 | + protected $view; |
|
38 | + |
|
39 | + /** @var \OC\Encryption\Util */ |
|
40 | + protected $util; |
|
41 | + |
|
42 | + /** @var \OC\Files\Mount\Manager */ |
|
43 | + protected $mountManager; |
|
44 | + |
|
45 | + /** @var \OC\Encryption\Manager */ |
|
46 | + protected $encryptionManager; |
|
47 | + |
|
48 | + /** @var string */ |
|
49 | + protected $uid; |
|
50 | + |
|
51 | + /** @var \OC\Encryption\File */ |
|
52 | + protected $file; |
|
53 | + |
|
54 | + /** |
|
55 | + * |
|
56 | + * @param \OC\Files\View $view |
|
57 | + * @param \OC\Encryption\Util $util |
|
58 | + * @param \OC\Files\Mount\Manager $mountManager |
|
59 | + * @param \OC\Encryption\Manager $encryptionManager |
|
60 | + * @param \OC\Encryption\File $file |
|
61 | + * @param string $uid |
|
62 | + */ |
|
63 | + public function __construct( |
|
64 | + View $view, |
|
65 | + Util $util, |
|
66 | + Mount\Manager $mountManager, |
|
67 | + Manager $encryptionManager, |
|
68 | + File $file, |
|
69 | + $uid |
|
70 | + ) { |
|
71 | + $this->view = $view; |
|
72 | + $this->util = $util; |
|
73 | + $this->mountManager = $mountManager; |
|
74 | + $this->encryptionManager = $encryptionManager; |
|
75 | + $this->file = $file; |
|
76 | + $this->uid = $uid; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * hook after file was shared |
|
81 | + * |
|
82 | + * @param array $params |
|
83 | + */ |
|
84 | + public function postShared($params) { |
|
85 | + if ($this->encryptionManager->isEnabled()) { |
|
86 | + if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { |
|
87 | + $path = Filesystem::getPath($params['fileSource']); |
|
88 | + list($owner, $ownerPath) = $this->getOwnerPath($path); |
|
89 | + $absPath = '/' . $owner . '/files/' . $ownerPath; |
|
90 | + $this->update($absPath); |
|
91 | + } |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * hook after file was unshared |
|
97 | + * |
|
98 | + * @param array $params |
|
99 | + */ |
|
100 | + public function postUnshared($params) { |
|
101 | + if ($this->encryptionManager->isEnabled()) { |
|
102 | + if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { |
|
103 | + $path = Filesystem::getPath($params['fileSource']); |
|
104 | + list($owner, $ownerPath) = $this->getOwnerPath($path); |
|
105 | + $absPath = '/' . $owner . '/files/' . $ownerPath; |
|
106 | + $this->update($absPath); |
|
107 | + } |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * inform encryption module that a file was restored from the trash bin, |
|
113 | + * e.g. to update the encryption keys |
|
114 | + * |
|
115 | + * @param array $params |
|
116 | + */ |
|
117 | + public function postRestore($params) { |
|
118 | + if ($this->encryptionManager->isEnabled()) { |
|
119 | + $path = Filesystem::normalizePath('/' . $this->uid . '/files/' . $params['filePath']); |
|
120 | + $this->update($path); |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * inform encryption module that a file was renamed, |
|
126 | + * e.g. to update the encryption keys |
|
127 | + * |
|
128 | + * @param array $params |
|
129 | + */ |
|
130 | + public function postRename($params) { |
|
131 | + $source = $params['oldpath']; |
|
132 | + $target = $params['newpath']; |
|
133 | + if ( |
|
134 | + $this->encryptionManager->isEnabled() && |
|
135 | + dirname($source) !== dirname($target) |
|
136 | + ) { |
|
137 | + list($owner, $ownerPath) = $this->getOwnerPath($target); |
|
138 | + $absPath = '/' . $owner . '/files/' . $ownerPath; |
|
139 | + $this->update($absPath); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * get owner and path relative to data/<owner>/files |
|
145 | + * |
|
146 | + * @param string $path path to file for current user |
|
147 | + * @return array ['owner' => $owner, 'path' => $path] |
|
148 | + * @throw \InvalidArgumentException |
|
149 | + */ |
|
150 | + protected function getOwnerPath($path) { |
|
151 | + $info = Filesystem::getFileInfo($path); |
|
152 | + $owner = Filesystem::getOwner($path); |
|
153 | + $view = new View('/' . $owner . '/files'); |
|
154 | + $path = $view->getPath($info->getId()); |
|
155 | + if ($path === null) { |
|
156 | + throw new \InvalidArgumentException('No file found for ' . $info->getId()); |
|
157 | + } |
|
158 | + |
|
159 | + return [$owner, $path]; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * notify encryption module about added/removed users from a file/folder |
|
164 | + * |
|
165 | + * @param string $path relative to data/ |
|
166 | + * @throws Exceptions\ModuleDoesNotExistsException |
|
167 | + */ |
|
168 | + public function update($path) { |
|
169 | + $encryptionModule = $this->encryptionManager->getEncryptionModule(); |
|
170 | + |
|
171 | + // if the encryption module doesn't encrypt the files on a per-user basis |
|
172 | + // we have nothing to do here. |
|
173 | + if ($encryptionModule->needDetailedAccessList() === false) { |
|
174 | + return; |
|
175 | + } |
|
176 | + |
|
177 | + // if a folder was shared, get a list of all (sub-)folders |
|
178 | + if ($this->view->is_dir($path)) { |
|
179 | + $allFiles = $this->util->getAllFiles($path); |
|
180 | + } else { |
|
181 | + $allFiles = [$path]; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + foreach ($allFiles as $file) { |
|
187 | + $usersSharing = $this->file->getAccessList($file); |
|
188 | + $encryptionModule->update($file, $this->uid, $usersSharing); |
|
189 | + } |
|
190 | + } |
|
191 | 191 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { |
87 | 87 | $path = Filesystem::getPath($params['fileSource']); |
88 | 88 | list($owner, $ownerPath) = $this->getOwnerPath($path); |
89 | - $absPath = '/' . $owner . '/files/' . $ownerPath; |
|
89 | + $absPath = '/'.$owner.'/files/'.$ownerPath; |
|
90 | 90 | $this->update($absPath); |
91 | 91 | } |
92 | 92 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') { |
103 | 103 | $path = Filesystem::getPath($params['fileSource']); |
104 | 104 | list($owner, $ownerPath) = $this->getOwnerPath($path); |
105 | - $absPath = '/' . $owner . '/files/' . $ownerPath; |
|
105 | + $absPath = '/'.$owner.'/files/'.$ownerPath; |
|
106 | 106 | $this->update($absPath); |
107 | 107 | } |
108 | 108 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function postRestore($params) { |
118 | 118 | if ($this->encryptionManager->isEnabled()) { |
119 | - $path = Filesystem::normalizePath('/' . $this->uid . '/files/' . $params['filePath']); |
|
119 | + $path = Filesystem::normalizePath('/'.$this->uid.'/files/'.$params['filePath']); |
|
120 | 120 | $this->update($path); |
121 | 121 | } |
122 | 122 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | dirname($source) !== dirname($target) |
136 | 136 | ) { |
137 | 137 | list($owner, $ownerPath) = $this->getOwnerPath($target); |
138 | - $absPath = '/' . $owner . '/files/' . $ownerPath; |
|
138 | + $absPath = '/'.$owner.'/files/'.$ownerPath; |
|
139 | 139 | $this->update($absPath); |
140 | 140 | } |
141 | 141 | } |
@@ -150,10 +150,10 @@ discard block |
||
150 | 150 | protected function getOwnerPath($path) { |
151 | 151 | $info = Filesystem::getFileInfo($path); |
152 | 152 | $owner = Filesystem::getOwner($path); |
153 | - $view = new View('/' . $owner . '/files'); |
|
153 | + $view = new View('/'.$owner.'/files'); |
|
154 | 154 | $path = $view->getPath($info->getId()); |
155 | 155 | if ($path === null) { |
156 | - throw new \InvalidArgumentException('No file found for ' . $info->getId()); |
|
156 | + throw new \InvalidArgumentException('No file found for '.$info->getId()); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | return [$owner, $path]; |