@@ -30,66 +30,66 @@ |
||
30 | 30 | * Uses a simple FIFO expiry mechanism |
31 | 31 | */ |
32 | 32 | class CappedMemoryCache implements ICache, \ArrayAccess { |
33 | - private $capacity; |
|
34 | - private $cache = []; |
|
35 | - |
|
36 | - public function __construct($capacity = 512) { |
|
37 | - $this->capacity = $capacity; |
|
38 | - } |
|
39 | - |
|
40 | - public function hasKey($key) { |
|
41 | - return isset($this->cache[$key]); |
|
42 | - } |
|
43 | - |
|
44 | - public function get($key) { |
|
45 | - return isset($this->cache[$key]) ? $this->cache[$key] : null; |
|
46 | - } |
|
47 | - |
|
48 | - public function set($key, $value, $ttl = 0) { |
|
49 | - if (is_null($key)) { |
|
50 | - $this->cache[] = $value; |
|
51 | - } else { |
|
52 | - $this->cache[$key] = $value; |
|
53 | - } |
|
54 | - $this->garbageCollect(); |
|
55 | - } |
|
56 | - |
|
57 | - public function remove($key) { |
|
58 | - unset($this->cache[$key]); |
|
59 | - return true; |
|
60 | - } |
|
61 | - |
|
62 | - public function clear($prefix = '') { |
|
63 | - $this->cache = []; |
|
64 | - return true; |
|
65 | - } |
|
66 | - |
|
67 | - public function offsetExists($offset) { |
|
68 | - return $this->hasKey($offset); |
|
69 | - } |
|
70 | - |
|
71 | - public function &offsetGet($offset) { |
|
72 | - return $this->cache[$offset]; |
|
73 | - } |
|
74 | - |
|
75 | - public function offsetSet($offset, $value) { |
|
76 | - $this->set($offset, $value); |
|
77 | - } |
|
78 | - |
|
79 | - public function offsetUnset($offset) { |
|
80 | - $this->remove($offset); |
|
81 | - } |
|
82 | - |
|
83 | - public function getData() { |
|
84 | - return $this->cache; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - private function garbageCollect() { |
|
89 | - while (count($this->cache) > $this->capacity) { |
|
90 | - reset($this->cache); |
|
91 | - $key = key($this->cache); |
|
92 | - $this->remove($key); |
|
93 | - } |
|
94 | - } |
|
33 | + private $capacity; |
|
34 | + private $cache = []; |
|
35 | + |
|
36 | + public function __construct($capacity = 512) { |
|
37 | + $this->capacity = $capacity; |
|
38 | + } |
|
39 | + |
|
40 | + public function hasKey($key) { |
|
41 | + return isset($this->cache[$key]); |
|
42 | + } |
|
43 | + |
|
44 | + public function get($key) { |
|
45 | + return isset($this->cache[$key]) ? $this->cache[$key] : null; |
|
46 | + } |
|
47 | + |
|
48 | + public function set($key, $value, $ttl = 0) { |
|
49 | + if (is_null($key)) { |
|
50 | + $this->cache[] = $value; |
|
51 | + } else { |
|
52 | + $this->cache[$key] = $value; |
|
53 | + } |
|
54 | + $this->garbageCollect(); |
|
55 | + } |
|
56 | + |
|
57 | + public function remove($key) { |
|
58 | + unset($this->cache[$key]); |
|
59 | + return true; |
|
60 | + } |
|
61 | + |
|
62 | + public function clear($prefix = '') { |
|
63 | + $this->cache = []; |
|
64 | + return true; |
|
65 | + } |
|
66 | + |
|
67 | + public function offsetExists($offset) { |
|
68 | + return $this->hasKey($offset); |
|
69 | + } |
|
70 | + |
|
71 | + public function &offsetGet($offset) { |
|
72 | + return $this->cache[$offset]; |
|
73 | + } |
|
74 | + |
|
75 | + public function offsetSet($offset, $value) { |
|
76 | + $this->set($offset, $value); |
|
77 | + } |
|
78 | + |
|
79 | + public function offsetUnset($offset) { |
|
80 | + $this->remove($offset); |
|
81 | + } |
|
82 | + |
|
83 | + public function getData() { |
|
84 | + return $this->cache; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + private function garbageCollect() { |
|
89 | + while (count($this->cache) > $this->capacity) { |
|
90 | + reset($this->cache); |
|
91 | + $key = key($this->cache); |
|
92 | + $this->remove($key); |
|
93 | + } |
|
94 | + } |
|
95 | 95 | } |
@@ -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 |
@@ -35,94 +35,94 @@ |
||
35 | 35 | |
36 | 36 | class File implements \OCP\Encryption\IFile { |
37 | 37 | |
38 | - /** @var Util */ |
|
39 | - protected $util; |
|
40 | - |
|
41 | - /** @var IRootFolder */ |
|
42 | - private $rootFolder; |
|
43 | - |
|
44 | - /** @var IManager */ |
|
45 | - private $shareManager; |
|
46 | - |
|
47 | - /** |
|
48 | - * cache results of already checked folders |
|
49 | - * |
|
50 | - * @var array |
|
51 | - */ |
|
52 | - protected $cache; |
|
53 | - |
|
54 | - public function __construct(Util $util, |
|
55 | - IRootFolder $rootFolder, |
|
56 | - IManager $shareManager) { |
|
57 | - $this->util = $util; |
|
58 | - $this->cache = new CappedMemoryCache(); |
|
59 | - $this->rootFolder = $rootFolder; |
|
60 | - $this->shareManager = $shareManager; |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * get list of users with access to the file |
|
66 | - * |
|
67 | - * @param string $path to the file |
|
68 | - * @return array ['users' => $uniqueUserIds, 'public' => $public] |
|
69 | - */ |
|
70 | - public function getAccessList($path) { |
|
71 | - |
|
72 | - // Make sure that a share key is generated for the owner too |
|
73 | - [$owner, $ownerPath] = $this->util->getUidAndFilename($path); |
|
74 | - |
|
75 | - // always add owner to the list of users with access to the file |
|
76 | - $userIds = [$owner]; |
|
77 | - |
|
78 | - if (!$this->util->isFile($owner . '/' . $ownerPath)) { |
|
79 | - return ['users' => $userIds, 'public' => false]; |
|
80 | - } |
|
81 | - |
|
82 | - $ownerPath = substr($ownerPath, strlen('/files')); |
|
83 | - $userFolder = $this->rootFolder->getUserFolder($owner); |
|
84 | - try { |
|
85 | - $file = $userFolder->get($ownerPath); |
|
86 | - } catch (NotFoundException $e) { |
|
87 | - $file = null; |
|
88 | - } |
|
89 | - $ownerPath = $this->util->stripPartialFileExtension($ownerPath); |
|
90 | - |
|
91 | - // first get the shares for the parent and cache the result so that we don't |
|
92 | - // need to check all parents for every file |
|
93 | - $parent = dirname($ownerPath); |
|
94 | - $parentNode = $userFolder->get($parent); |
|
95 | - if (isset($this->cache[$parent])) { |
|
96 | - $resultForParents = $this->cache[$parent]; |
|
97 | - } else { |
|
98 | - $resultForParents = $this->shareManager->getAccessList($parentNode); |
|
99 | - $this->cache[$parent] = $resultForParents; |
|
100 | - } |
|
101 | - $userIds = array_merge($userIds, $resultForParents['users']); |
|
102 | - $public = $resultForParents['public'] || $resultForParents['remote']; |
|
103 | - |
|
104 | - |
|
105 | - // Find out who, if anyone, is sharing the file |
|
106 | - if ($file !== null) { |
|
107 | - $resultForFile = $this->shareManager->getAccessList($file, false); |
|
108 | - $userIds = array_merge($userIds, $resultForFile['users']); |
|
109 | - $public = $resultForFile['public'] || $resultForFile['remote'] || $public; |
|
110 | - } |
|
111 | - |
|
112 | - // check if it is a group mount |
|
113 | - if (\OCP\App::isEnabled("files_external")) { |
|
114 | - $mounts = \OCA\Files_External\MountConfig::getSystemMountPoints(); |
|
115 | - foreach ($mounts as $mount) { |
|
116 | - if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) { |
|
117 | - $mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']); |
|
118 | - $userIds = array_merge($userIds, $mountedFor); |
|
119 | - } |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - // Remove duplicate UIDs |
|
124 | - $uniqueUserIds = array_unique($userIds); |
|
125 | - |
|
126 | - return ['users' => $uniqueUserIds, 'public' => $public]; |
|
127 | - } |
|
38 | + /** @var Util */ |
|
39 | + protected $util; |
|
40 | + |
|
41 | + /** @var IRootFolder */ |
|
42 | + private $rootFolder; |
|
43 | + |
|
44 | + /** @var IManager */ |
|
45 | + private $shareManager; |
|
46 | + |
|
47 | + /** |
|
48 | + * cache results of already checked folders |
|
49 | + * |
|
50 | + * @var array |
|
51 | + */ |
|
52 | + protected $cache; |
|
53 | + |
|
54 | + public function __construct(Util $util, |
|
55 | + IRootFolder $rootFolder, |
|
56 | + IManager $shareManager) { |
|
57 | + $this->util = $util; |
|
58 | + $this->cache = new CappedMemoryCache(); |
|
59 | + $this->rootFolder = $rootFolder; |
|
60 | + $this->shareManager = $shareManager; |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * get list of users with access to the file |
|
66 | + * |
|
67 | + * @param string $path to the file |
|
68 | + * @return array ['users' => $uniqueUserIds, 'public' => $public] |
|
69 | + */ |
|
70 | + public function getAccessList($path) { |
|
71 | + |
|
72 | + // Make sure that a share key is generated for the owner too |
|
73 | + [$owner, $ownerPath] = $this->util->getUidAndFilename($path); |
|
74 | + |
|
75 | + // always add owner to the list of users with access to the file |
|
76 | + $userIds = [$owner]; |
|
77 | + |
|
78 | + if (!$this->util->isFile($owner . '/' . $ownerPath)) { |
|
79 | + return ['users' => $userIds, 'public' => false]; |
|
80 | + } |
|
81 | + |
|
82 | + $ownerPath = substr($ownerPath, strlen('/files')); |
|
83 | + $userFolder = $this->rootFolder->getUserFolder($owner); |
|
84 | + try { |
|
85 | + $file = $userFolder->get($ownerPath); |
|
86 | + } catch (NotFoundException $e) { |
|
87 | + $file = null; |
|
88 | + } |
|
89 | + $ownerPath = $this->util->stripPartialFileExtension($ownerPath); |
|
90 | + |
|
91 | + // first get the shares for the parent and cache the result so that we don't |
|
92 | + // need to check all parents for every file |
|
93 | + $parent = dirname($ownerPath); |
|
94 | + $parentNode = $userFolder->get($parent); |
|
95 | + if (isset($this->cache[$parent])) { |
|
96 | + $resultForParents = $this->cache[$parent]; |
|
97 | + } else { |
|
98 | + $resultForParents = $this->shareManager->getAccessList($parentNode); |
|
99 | + $this->cache[$parent] = $resultForParents; |
|
100 | + } |
|
101 | + $userIds = array_merge($userIds, $resultForParents['users']); |
|
102 | + $public = $resultForParents['public'] || $resultForParents['remote']; |
|
103 | + |
|
104 | + |
|
105 | + // Find out who, if anyone, is sharing the file |
|
106 | + if ($file !== null) { |
|
107 | + $resultForFile = $this->shareManager->getAccessList($file, false); |
|
108 | + $userIds = array_merge($userIds, $resultForFile['users']); |
|
109 | + $public = $resultForFile['public'] || $resultForFile['remote'] || $public; |
|
110 | + } |
|
111 | + |
|
112 | + // check if it is a group mount |
|
113 | + if (\OCP\App::isEnabled("files_external")) { |
|
114 | + $mounts = \OCA\Files_External\MountConfig::getSystemMountPoints(); |
|
115 | + foreach ($mounts as $mount) { |
|
116 | + if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) { |
|
117 | + $mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']); |
|
118 | + $userIds = array_merge($userIds, $mountedFor); |
|
119 | + } |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + // Remove duplicate UIDs |
|
124 | + $uniqueUserIds = array_unique($userIds); |
|
125 | + |
|
126 | + return ['users' => $uniqueUserIds, 'public' => $public]; |
|
127 | + } |
|
128 | 128 | } |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | */ |
67 | 67 | private function buildFileNameWithSuffix($absolutePath, $postFix = '') { |
68 | 68 | if ($postFix !== '') { |
69 | - $postFix = '.' . ltrim($postFix, '.'); |
|
69 | + $postFix = '.'.ltrim($postFix, '.'); |
|
70 | 70 | $postFix = str_replace(['\\', '/'], '', $postFix); |
71 | 71 | $absolutePath .= '-'; |
72 | 72 | } |
73 | 73 | |
74 | - return $absolutePath . $postFix; |
|
74 | + return $absolutePath.$postFix; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | $this->current[] = $uniqueFileName; |
128 | 128 | |
129 | 129 | // Build a name without postfix |
130 | - $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix); |
|
130 | + $path = $this->buildFileNameWithSuffix($uniqueFileName.'-folder', $postFix); |
|
131 | 131 | mkdir($path, 0700); |
132 | 132 | $this->current[] = $path; |
133 | 133 | |
134 | - return $path . '/'; |
|
134 | + return $path.'/'; |
|
135 | 135 | } else { |
136 | 136 | $this->log->warning( |
137 | 137 | 'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions', |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | if ($dh) { |
191 | 191 | while (($file = readdir($dh)) !== false) { |
192 | 192 | if (substr($file, 0, 7) === self::TMP_PREFIX) { |
193 | - $path = $this->tmpBaseDir . '/' . $file; |
|
193 | + $path = $this->tmpBaseDir.'/'.$file; |
|
194 | 194 | $mtime = filemtime($path); |
195 | 195 | if ($mtime < $cutOfTime) { |
196 | 196 | $files[] = $path; |
@@ -37,244 +37,244 @@ |
||
37 | 37 | use Psr\Log\LoggerInterface; |
38 | 38 | |
39 | 39 | class TempManager implements ITempManager { |
40 | - /** @var string[] Current temporary files and folders, used for cleanup */ |
|
41 | - protected $current = []; |
|
42 | - /** @var string i.e. /tmp on linux systems */ |
|
43 | - protected $tmpBaseDir; |
|
44 | - /** @var LoggerInterface */ |
|
45 | - protected $log; |
|
46 | - /** @var IConfig */ |
|
47 | - protected $config; |
|
48 | - /** @var IniGetWrapper */ |
|
49 | - protected $iniGetWrapper; |
|
40 | + /** @var string[] Current temporary files and folders, used for cleanup */ |
|
41 | + protected $current = []; |
|
42 | + /** @var string i.e. /tmp on linux systems */ |
|
43 | + protected $tmpBaseDir; |
|
44 | + /** @var LoggerInterface */ |
|
45 | + protected $log; |
|
46 | + /** @var IConfig */ |
|
47 | + protected $config; |
|
48 | + /** @var IniGetWrapper */ |
|
49 | + protected $iniGetWrapper; |
|
50 | 50 | |
51 | - /** Prefix */ |
|
52 | - public const TMP_PREFIX = 'oc_tmp_'; |
|
51 | + /** Prefix */ |
|
52 | + public const TMP_PREFIX = 'oc_tmp_'; |
|
53 | 53 | |
54 | - public function __construct(LoggerInterface $logger, IConfig $config, IniGetWrapper $iniGetWrapper) { |
|
55 | - $this->log = $logger; |
|
56 | - $this->config = $config; |
|
57 | - $this->iniGetWrapper = $iniGetWrapper; |
|
58 | - $this->tmpBaseDir = $this->getTempBaseDir(); |
|
59 | - } |
|
54 | + public function __construct(LoggerInterface $logger, IConfig $config, IniGetWrapper $iniGetWrapper) { |
|
55 | + $this->log = $logger; |
|
56 | + $this->config = $config; |
|
57 | + $this->iniGetWrapper = $iniGetWrapper; |
|
58 | + $this->tmpBaseDir = $this->getTempBaseDir(); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Builds the filename with suffix and removes potential dangerous characters |
|
63 | - * such as directory separators. |
|
64 | - * |
|
65 | - * @param string $absolutePath Absolute path to the file / folder |
|
66 | - * @param string $postFix Postfix appended to the temporary file name, may be user controlled |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - private function buildFileNameWithSuffix($absolutePath, $postFix = '') { |
|
70 | - if ($postFix !== '') { |
|
71 | - $postFix = '.' . ltrim($postFix, '.'); |
|
72 | - $postFix = str_replace(['\\', '/'], '', $postFix); |
|
73 | - $absolutePath .= '-'; |
|
74 | - } |
|
61 | + /** |
|
62 | + * Builds the filename with suffix and removes potential dangerous characters |
|
63 | + * such as directory separators. |
|
64 | + * |
|
65 | + * @param string $absolutePath Absolute path to the file / folder |
|
66 | + * @param string $postFix Postfix appended to the temporary file name, may be user controlled |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + private function buildFileNameWithSuffix($absolutePath, $postFix = '') { |
|
70 | + if ($postFix !== '') { |
|
71 | + $postFix = '.' . ltrim($postFix, '.'); |
|
72 | + $postFix = str_replace(['\\', '/'], '', $postFix); |
|
73 | + $absolutePath .= '-'; |
|
74 | + } |
|
75 | 75 | |
76 | - return $absolutePath . $postFix; |
|
77 | - } |
|
76 | + return $absolutePath . $postFix; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Create a temporary file and return the path |
|
81 | - * |
|
82 | - * @param string $postFix Postfix appended to the temporary file name |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function getTemporaryFile($postFix = '') { |
|
86 | - if (is_writable($this->tmpBaseDir)) { |
|
87 | - // To create an unique file and prevent the risk of race conditions |
|
88 | - // or duplicated temporary files by other means such as collisions |
|
89 | - // we need to create the file using `tempnam` and append a possible |
|
90 | - // postfix to it later |
|
91 | - $file = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
92 | - $this->current[] = $file; |
|
79 | + /** |
|
80 | + * Create a temporary file and return the path |
|
81 | + * |
|
82 | + * @param string $postFix Postfix appended to the temporary file name |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function getTemporaryFile($postFix = '') { |
|
86 | + if (is_writable($this->tmpBaseDir)) { |
|
87 | + // To create an unique file and prevent the risk of race conditions |
|
88 | + // or duplicated temporary files by other means such as collisions |
|
89 | + // we need to create the file using `tempnam` and append a possible |
|
90 | + // postfix to it later |
|
91 | + $file = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
92 | + $this->current[] = $file; |
|
93 | 93 | |
94 | - // If a postfix got specified sanitize it and create a postfixed |
|
95 | - // temporary file |
|
96 | - if ($postFix !== '') { |
|
97 | - $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix); |
|
98 | - touch($fileNameWithPostfix); |
|
99 | - chmod($fileNameWithPostfix, 0600); |
|
100 | - $this->current[] = $fileNameWithPostfix; |
|
101 | - return $fileNameWithPostfix; |
|
102 | - } |
|
94 | + // If a postfix got specified sanitize it and create a postfixed |
|
95 | + // temporary file |
|
96 | + if ($postFix !== '') { |
|
97 | + $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix); |
|
98 | + touch($fileNameWithPostfix); |
|
99 | + chmod($fileNameWithPostfix, 0600); |
|
100 | + $this->current[] = $fileNameWithPostfix; |
|
101 | + return $fileNameWithPostfix; |
|
102 | + } |
|
103 | 103 | |
104 | - return $file; |
|
105 | - } else { |
|
106 | - $this->log->warning( |
|
107 | - 'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions', |
|
108 | - [ |
|
109 | - 'dir' => $this->tmpBaseDir, |
|
110 | - ] |
|
111 | - ); |
|
112 | - return false; |
|
113 | - } |
|
114 | - } |
|
104 | + return $file; |
|
105 | + } else { |
|
106 | + $this->log->warning( |
|
107 | + 'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions', |
|
108 | + [ |
|
109 | + 'dir' => $this->tmpBaseDir, |
|
110 | + ] |
|
111 | + ); |
|
112 | + return false; |
|
113 | + } |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * Create a temporary folder and return the path |
|
118 | - * |
|
119 | - * @param string $postFix Postfix appended to the temporary folder name |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - public function getTemporaryFolder($postFix = '') { |
|
123 | - if (is_writable($this->tmpBaseDir)) { |
|
124 | - // To create an unique directory and prevent the risk of race conditions |
|
125 | - // or duplicated temporary files by other means such as collisions |
|
126 | - // we need to create the file using `tempnam` and append a possible |
|
127 | - // postfix to it later |
|
128 | - $uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
129 | - $this->current[] = $uniqueFileName; |
|
116 | + /** |
|
117 | + * Create a temporary folder and return the path |
|
118 | + * |
|
119 | + * @param string $postFix Postfix appended to the temporary folder name |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + public function getTemporaryFolder($postFix = '') { |
|
123 | + if (is_writable($this->tmpBaseDir)) { |
|
124 | + // To create an unique directory and prevent the risk of race conditions |
|
125 | + // or duplicated temporary files by other means such as collisions |
|
126 | + // we need to create the file using `tempnam` and append a possible |
|
127 | + // postfix to it later |
|
128 | + $uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
129 | + $this->current[] = $uniqueFileName; |
|
130 | 130 | |
131 | - // Build a name without postfix |
|
132 | - $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix); |
|
133 | - mkdir($path, 0700); |
|
134 | - $this->current[] = $path; |
|
131 | + // Build a name without postfix |
|
132 | + $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix); |
|
133 | + mkdir($path, 0700); |
|
134 | + $this->current[] = $path; |
|
135 | 135 | |
136 | - return $path . '/'; |
|
137 | - } else { |
|
138 | - $this->log->warning( |
|
139 | - 'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions', |
|
140 | - [ |
|
141 | - 'dir' => $this->tmpBaseDir, |
|
142 | - ] |
|
143 | - ); |
|
144 | - return false; |
|
145 | - } |
|
146 | - } |
|
136 | + return $path . '/'; |
|
137 | + } else { |
|
138 | + $this->log->warning( |
|
139 | + 'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions', |
|
140 | + [ |
|
141 | + 'dir' => $this->tmpBaseDir, |
|
142 | + ] |
|
143 | + ); |
|
144 | + return false; |
|
145 | + } |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * Remove the temporary files and folders generated during this request |
|
150 | - */ |
|
151 | - public function clean() { |
|
152 | - $this->cleanFiles($this->current); |
|
153 | - } |
|
148 | + /** |
|
149 | + * Remove the temporary files and folders generated during this request |
|
150 | + */ |
|
151 | + public function clean() { |
|
152 | + $this->cleanFiles($this->current); |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * @param string[] $files |
|
157 | - */ |
|
158 | - protected function cleanFiles($files) { |
|
159 | - foreach ($files as $file) { |
|
160 | - if (file_exists($file)) { |
|
161 | - try { |
|
162 | - \OC_Helper::rmdirr($file); |
|
163 | - } catch (\UnexpectedValueException $ex) { |
|
164 | - $this->log->warning( |
|
165 | - "Error deleting temporary file/folder: {file} - Reason: {error}", |
|
166 | - [ |
|
167 | - 'file' => $file, |
|
168 | - 'error' => $ex->getMessage(), |
|
169 | - ] |
|
170 | - ); |
|
171 | - } |
|
172 | - } |
|
173 | - } |
|
174 | - } |
|
155 | + /** |
|
156 | + * @param string[] $files |
|
157 | + */ |
|
158 | + protected function cleanFiles($files) { |
|
159 | + foreach ($files as $file) { |
|
160 | + if (file_exists($file)) { |
|
161 | + try { |
|
162 | + \OC_Helper::rmdirr($file); |
|
163 | + } catch (\UnexpectedValueException $ex) { |
|
164 | + $this->log->warning( |
|
165 | + "Error deleting temporary file/folder: {file} - Reason: {error}", |
|
166 | + [ |
|
167 | + 'file' => $file, |
|
168 | + 'error' => $ex->getMessage(), |
|
169 | + ] |
|
170 | + ); |
|
171 | + } |
|
172 | + } |
|
173 | + } |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * Remove old temporary files and folders that were failed to be cleaned |
|
178 | - */ |
|
179 | - public function cleanOld() { |
|
180 | - $this->cleanFiles($this->getOldFiles()); |
|
181 | - } |
|
176 | + /** |
|
177 | + * Remove old temporary files and folders that were failed to be cleaned |
|
178 | + */ |
|
179 | + public function cleanOld() { |
|
180 | + $this->cleanFiles($this->getOldFiles()); |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Get all temporary files and folders generated by oc older than an hour |
|
185 | - * |
|
186 | - * @return string[] |
|
187 | - */ |
|
188 | - protected function getOldFiles() { |
|
189 | - $cutOfTime = time() - 3600; |
|
190 | - $files = []; |
|
191 | - $dh = opendir($this->tmpBaseDir); |
|
192 | - if ($dh) { |
|
193 | - while (($file = readdir($dh)) !== false) { |
|
194 | - if (substr($file, 0, 7) === self::TMP_PREFIX) { |
|
195 | - $path = $this->tmpBaseDir . '/' . $file; |
|
196 | - $mtime = filemtime($path); |
|
197 | - if ($mtime < $cutOfTime) { |
|
198 | - $files[] = $path; |
|
199 | - } |
|
200 | - } |
|
201 | - } |
|
202 | - } |
|
203 | - return $files; |
|
204 | - } |
|
183 | + /** |
|
184 | + * Get all temporary files and folders generated by oc older than an hour |
|
185 | + * |
|
186 | + * @return string[] |
|
187 | + */ |
|
188 | + protected function getOldFiles() { |
|
189 | + $cutOfTime = time() - 3600; |
|
190 | + $files = []; |
|
191 | + $dh = opendir($this->tmpBaseDir); |
|
192 | + if ($dh) { |
|
193 | + while (($file = readdir($dh)) !== false) { |
|
194 | + if (substr($file, 0, 7) === self::TMP_PREFIX) { |
|
195 | + $path = $this->tmpBaseDir . '/' . $file; |
|
196 | + $mtime = filemtime($path); |
|
197 | + if ($mtime < $cutOfTime) { |
|
198 | + $files[] = $path; |
|
199 | + } |
|
200 | + } |
|
201 | + } |
|
202 | + } |
|
203 | + return $files; |
|
204 | + } |
|
205 | 205 | |
206 | - /** |
|
207 | - * Get the temporary base directory configured on the server |
|
208 | - * |
|
209 | - * @return string Path to the temporary directory or null |
|
210 | - * @throws \UnexpectedValueException |
|
211 | - */ |
|
212 | - public function getTempBaseDir() { |
|
213 | - if ($this->tmpBaseDir) { |
|
214 | - return $this->tmpBaseDir; |
|
215 | - } |
|
206 | + /** |
|
207 | + * Get the temporary base directory configured on the server |
|
208 | + * |
|
209 | + * @return string Path to the temporary directory or null |
|
210 | + * @throws \UnexpectedValueException |
|
211 | + */ |
|
212 | + public function getTempBaseDir() { |
|
213 | + if ($this->tmpBaseDir) { |
|
214 | + return $this->tmpBaseDir; |
|
215 | + } |
|
216 | 216 | |
217 | - $directories = []; |
|
218 | - if ($temp = $this->config->getSystemValue('tempdirectory', null)) { |
|
219 | - $directories[] = $temp; |
|
220 | - } |
|
221 | - if ($temp = $this->iniGetWrapper->get('upload_tmp_dir')) { |
|
222 | - $directories[] = $temp; |
|
223 | - } |
|
224 | - if ($temp = getenv('TMP')) { |
|
225 | - $directories[] = $temp; |
|
226 | - } |
|
227 | - if ($temp = getenv('TEMP')) { |
|
228 | - $directories[] = $temp; |
|
229 | - } |
|
230 | - if ($temp = getenv('TMPDIR')) { |
|
231 | - $directories[] = $temp; |
|
232 | - } |
|
233 | - if ($temp = sys_get_temp_dir()) { |
|
234 | - $directories[] = $temp; |
|
235 | - } |
|
217 | + $directories = []; |
|
218 | + if ($temp = $this->config->getSystemValue('tempdirectory', null)) { |
|
219 | + $directories[] = $temp; |
|
220 | + } |
|
221 | + if ($temp = $this->iniGetWrapper->get('upload_tmp_dir')) { |
|
222 | + $directories[] = $temp; |
|
223 | + } |
|
224 | + if ($temp = getenv('TMP')) { |
|
225 | + $directories[] = $temp; |
|
226 | + } |
|
227 | + if ($temp = getenv('TEMP')) { |
|
228 | + $directories[] = $temp; |
|
229 | + } |
|
230 | + if ($temp = getenv('TMPDIR')) { |
|
231 | + $directories[] = $temp; |
|
232 | + } |
|
233 | + if ($temp = sys_get_temp_dir()) { |
|
234 | + $directories[] = $temp; |
|
235 | + } |
|
236 | 236 | |
237 | - foreach ($directories as $dir) { |
|
238 | - if ($this->checkTemporaryDirectory($dir)) { |
|
239 | - return $dir; |
|
240 | - } |
|
241 | - } |
|
237 | + foreach ($directories as $dir) { |
|
238 | + if ($this->checkTemporaryDirectory($dir)) { |
|
239 | + return $dir; |
|
240 | + } |
|
241 | + } |
|
242 | 242 | |
243 | - $temp = tempnam(dirname(__FILE__), ''); |
|
244 | - if (file_exists($temp)) { |
|
245 | - unlink($temp); |
|
246 | - return dirname($temp); |
|
247 | - } |
|
248 | - throw new \UnexpectedValueException('Unable to detect system temporary directory'); |
|
249 | - } |
|
243 | + $temp = tempnam(dirname(__FILE__), ''); |
|
244 | + if (file_exists($temp)) { |
|
245 | + unlink($temp); |
|
246 | + return dirname($temp); |
|
247 | + } |
|
248 | + throw new \UnexpectedValueException('Unable to detect system temporary directory'); |
|
249 | + } |
|
250 | 250 | |
251 | - /** |
|
252 | - * Check if a temporary directory is ready for use |
|
253 | - * |
|
254 | - * @param mixed $directory |
|
255 | - * @return bool |
|
256 | - */ |
|
257 | - private function checkTemporaryDirectory($directory) { |
|
258 | - // suppress any possible errors caused by is_writable |
|
259 | - // checks missing or invalid path or characters, wrong permissions etc |
|
260 | - try { |
|
261 | - if (is_writable($directory)) { |
|
262 | - return true; |
|
263 | - } |
|
264 | - } catch (\Exception $e) { |
|
265 | - } |
|
266 | - $this->log->warning('Temporary directory {dir} is not present or writable', |
|
267 | - ['dir' => $directory] |
|
268 | - ); |
|
269 | - return false; |
|
270 | - } |
|
251 | + /** |
|
252 | + * Check if a temporary directory is ready for use |
|
253 | + * |
|
254 | + * @param mixed $directory |
|
255 | + * @return bool |
|
256 | + */ |
|
257 | + private function checkTemporaryDirectory($directory) { |
|
258 | + // suppress any possible errors caused by is_writable |
|
259 | + // checks missing or invalid path or characters, wrong permissions etc |
|
260 | + try { |
|
261 | + if (is_writable($directory)) { |
|
262 | + return true; |
|
263 | + } |
|
264 | + } catch (\Exception $e) { |
|
265 | + } |
|
266 | + $this->log->warning('Temporary directory {dir} is not present or writable', |
|
267 | + ['dir' => $directory] |
|
268 | + ); |
|
269 | + return false; |
|
270 | + } |
|
271 | 271 | |
272 | - /** |
|
273 | - * Override the temporary base directory |
|
274 | - * |
|
275 | - * @param string $directory |
|
276 | - */ |
|
277 | - public function overrideTempBaseDir($directory) { |
|
278 | - $this->tmpBaseDir = $directory; |
|
279 | - } |
|
272 | + /** |
|
273 | + * Override the temporary base directory |
|
274 | + * |
|
275 | + * @param string $directory |
|
276 | + */ |
|
277 | + public function overrideTempBaseDir($directory) { |
|
278 | + $this->tmpBaseDir = $directory; |
|
279 | + } |
|
280 | 280 | } |
@@ -36,54 +36,54 @@ |
||
36 | 36 | * @method void setName(string $name) |
37 | 37 | */ |
38 | 38 | class Tag extends Entity { |
39 | - protected $owner; |
|
40 | - protected $type; |
|
41 | - protected $name; |
|
39 | + protected $owner; |
|
40 | + protected $type; |
|
41 | + protected $name; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Constructor. |
|
45 | - * |
|
46 | - * @param string $owner The tag's owner |
|
47 | - * @param string $type The type of item this tag is used for |
|
48 | - * @param string $name The tag's name |
|
49 | - */ |
|
50 | - public function __construct($owner = null, $type = null, $name = null) { |
|
51 | - $this->setOwner($owner); |
|
52 | - $this->setType($type); |
|
53 | - $this->setName($name); |
|
54 | - } |
|
43 | + /** |
|
44 | + * Constructor. |
|
45 | + * |
|
46 | + * @param string $owner The tag's owner |
|
47 | + * @param string $type The type of item this tag is used for |
|
48 | + * @param string $name The tag's name |
|
49 | + */ |
|
50 | + public function __construct($owner = null, $type = null, $name = null) { |
|
51 | + $this->setOwner($owner); |
|
52 | + $this->setType($type); |
|
53 | + $this->setName($name); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Transform a database columnname to a property |
|
58 | - * |
|
59 | - * @param string $columnName the name of the column |
|
60 | - * @return string the property name |
|
61 | - * @todo migrate existing database columns to the correct names |
|
62 | - * to be able to drop this direct mapping |
|
63 | - */ |
|
64 | - public function columnToProperty($columnName) { |
|
65 | - if ($columnName === 'category') { |
|
66 | - return 'name'; |
|
67 | - } elseif ($columnName === 'uid') { |
|
68 | - return 'owner'; |
|
69 | - } else { |
|
70 | - return parent::columnToProperty($columnName); |
|
71 | - } |
|
72 | - } |
|
56 | + /** |
|
57 | + * Transform a database columnname to a property |
|
58 | + * |
|
59 | + * @param string $columnName the name of the column |
|
60 | + * @return string the property name |
|
61 | + * @todo migrate existing database columns to the correct names |
|
62 | + * to be able to drop this direct mapping |
|
63 | + */ |
|
64 | + public function columnToProperty($columnName) { |
|
65 | + if ($columnName === 'category') { |
|
66 | + return 'name'; |
|
67 | + } elseif ($columnName === 'uid') { |
|
68 | + return 'owner'; |
|
69 | + } else { |
|
70 | + return parent::columnToProperty($columnName); |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Transform a property to a database column name |
|
76 | - * |
|
77 | - * @param string $property the name of the property |
|
78 | - * @return string the column name |
|
79 | - */ |
|
80 | - public function propertyToColumn($property) { |
|
81 | - if ($property === 'name') { |
|
82 | - return 'category'; |
|
83 | - } elseif ($property === 'owner') { |
|
84 | - return 'uid'; |
|
85 | - } else { |
|
86 | - return parent::propertyToColumn($property); |
|
87 | - } |
|
88 | - } |
|
74 | + /** |
|
75 | + * Transform a property to a database column name |
|
76 | + * |
|
77 | + * @param string $property the name of the property |
|
78 | + * @return string the column name |
|
79 | + */ |
|
80 | + public function propertyToColumn($property) { |
|
81 | + if ($property === 'name') { |
|
82 | + return 'category'; |
|
83 | + } elseif ($property === 'owner') { |
|
84 | + return 'uid'; |
|
85 | + } else { |
|
86 | + return parent::propertyToColumn($property); |
|
87 | + } |
|
88 | + } |
|
89 | 89 | } |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | $owners = [$owners]; |
55 | 55 | } |
56 | 56 | |
57 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
58 | - . 'WHERE `uid` IN (' . str_repeat('?,', count($owners) - 1) . '?) AND `type` = ? ORDER BY `category`'; |
|
57 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `'.$this->getTableName().'` ' |
|
58 | + . 'WHERE `uid` IN ('.str_repeat('?,', count($owners) - 1).'?) AND `type` = ? ORDER BY `category`'; |
|
59 | 59 | return $this->findEntities($sql, array_merge($owners, [$type])); |
60 | 60 | } |
61 | 61 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @return bool |
67 | 67 | */ |
68 | 68 | public function tagExists($tag) { |
69 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
69 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `'.$this->getTableName().'` ' |
|
70 | 70 | . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
71 | 71 | try { |
72 | 72 | $this->findEntity($sql, [$tag->getOwner(), $tag->getType(), $tag->getName()]); |
@@ -35,46 +35,46 @@ |
||
35 | 35 | */ |
36 | 36 | class TagMapper extends Mapper { |
37 | 37 | |
38 | - /** |
|
39 | - * Constructor. |
|
40 | - * |
|
41 | - * @param IDBConnection $db Instance of the Db abstraction layer. |
|
42 | - */ |
|
43 | - public function __construct(IDBConnection $db) { |
|
44 | - parent::__construct($db, 'vcategory', Tag::class); |
|
45 | - } |
|
38 | + /** |
|
39 | + * Constructor. |
|
40 | + * |
|
41 | + * @param IDBConnection $db Instance of the Db abstraction layer. |
|
42 | + */ |
|
43 | + public function __construct(IDBConnection $db) { |
|
44 | + parent::__construct($db, 'vcategory', Tag::class); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Load tags from the database. |
|
49 | - * |
|
50 | - * @param array|string $owners The user(s) whose tags we are going to load. |
|
51 | - * @param string $type The type of item for which we are loading tags. |
|
52 | - * @return array An array of Tag objects. |
|
53 | - */ |
|
54 | - public function loadTags($owners, $type) { |
|
55 | - if (!is_array($owners)) { |
|
56 | - $owners = [$owners]; |
|
57 | - } |
|
47 | + /** |
|
48 | + * Load tags from the database. |
|
49 | + * |
|
50 | + * @param array|string $owners The user(s) whose tags we are going to load. |
|
51 | + * @param string $type The type of item for which we are loading tags. |
|
52 | + * @return array An array of Tag objects. |
|
53 | + */ |
|
54 | + public function loadTags($owners, $type) { |
|
55 | + if (!is_array($owners)) { |
|
56 | + $owners = [$owners]; |
|
57 | + } |
|
58 | 58 | |
59 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
60 | - . 'WHERE `uid` IN (' . str_repeat('?,', count($owners) - 1) . '?) AND `type` = ? ORDER BY `category`'; |
|
61 | - return $this->findEntities($sql, array_merge($owners, [$type])); |
|
62 | - } |
|
59 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
60 | + . 'WHERE `uid` IN (' . str_repeat('?,', count($owners) - 1) . '?) AND `type` = ? ORDER BY `category`'; |
|
61 | + return $this->findEntities($sql, array_merge($owners, [$type])); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Check if a given Tag object already exists in the database. |
|
66 | - * |
|
67 | - * @param Tag $tag The tag to look for in the database. |
|
68 | - * @return bool |
|
69 | - */ |
|
70 | - public function tagExists($tag) { |
|
71 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
72 | - . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
|
73 | - try { |
|
74 | - $this->findEntity($sql, [$tag->getOwner(), $tag->getType(), $tag->getName()]); |
|
75 | - } catch (DoesNotExistException $e) { |
|
76 | - return false; |
|
77 | - } |
|
78 | - return true; |
|
79 | - } |
|
64 | + /** |
|
65 | + * Check if a given Tag object already exists in the database. |
|
66 | + * |
|
67 | + * @param Tag $tag The tag to look for in the database. |
|
68 | + * @return bool |
|
69 | + */ |
|
70 | + public function tagExists($tag) { |
|
71 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
72 | + . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
|
73 | + try { |
|
74 | + $this->findEntity($sql, [$tag->getOwner(), $tag->getType(), $tag->getName()]); |
|
75 | + } catch (DoesNotExistException $e) { |
|
76 | + return false; |
|
77 | + } |
|
78 | + return true; |
|
79 | + } |
|
80 | 80 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | * @package OC\AppFramework\Middleware\Security\Exceptions |
33 | 33 | */ |
34 | 34 | class StrictCookieMissingException extends SecurityException { |
35 | - public function __construct() { |
|
36 | - parent::__construct('Strict Cookie has not been found in request.', Http::STATUS_PRECONDITION_FAILED); |
|
37 | - } |
|
35 | + public function __construct() { |
|
36 | + parent::__construct('Strict Cookie has not been found in request.', Http::STATUS_PRECONDITION_FAILED); |
|
37 | + } |
|
38 | 38 | } |