/** * @brief remember the file which should be deleted and it's owner * @param array $params * @return boolean */ public static function preDelete($params) { $path = $params[\OC\Files\Filesystem::signal_param_path]; // skip this method if the trash bin is enabled or if we delete a file // outside of /data/user/files if (\OCP\App::isEnabled('files_trashbin')) { return true; } $util = new Util(new \OC_FilesystemView('/'), \OCP\USER::getUser()); list($owner, $ownerPath) = $util->getUidAndFilename($path); self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]] = array('uid' => $owner, 'path' => $ownerPath); }
/** * @medium */ function testGetUidAndFilename() { \OC_User::setUserId(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1); $filename = '/tmp-' . uniqid() . '.test'; // Disable encryption proxy to prevent recursive calls $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; $this->view->file_put_contents($this->userId . '/files/' . $filename, $this->dataShort); // Re-enable proxy - our work is done \OC_FileProxy::$enabled = $proxyStatus; $util = new Encryption\Util($this->view, $this->userId); list($fileOwnerUid, $file) = $util->getUidAndFilename($filename); $this->assertEquals(\Test_Encryption_Util::TEST_ENCRYPTION_UTIL_USER1, $fileOwnerUid); $this->assertEquals($file, $filename); $this->view->unlink($this->userId . '/files/' . $filename); }
/** * retrieve shareKey for an encrypted file * @param \OC\Files\View $view * @param string $userId * @param \OCA\Encryption\Util $util * @param string $filePath * @return string file key or false * @note The sharekey returned is encrypted. Decryption * of the keyfile must be performed by client code */ public static function getShareKey(\OC\Files\View $view, $userId, $util, $filePath) { // try reusing key file if part file $proxyStatus = \OC_FileProxy::$enabled; \OC_FileProxy::$enabled = false; list($owner, $filename) = $util->getUidAndFilename($filePath); $filename = Helper::stripPartialFileExtension($filename); // in case of system wide mount points the keys are stored directly in the data directory if ($util->isSystemWideMountPoint($filename)) { $shareKeyPath = '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey'; } else { $shareKeyPath = '/' . $owner . '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey'; } if ($view->file_exists($shareKeyPath)) { $result = $view->file_get_contents($shareKeyPath); } else { $result = false; } \OC_FileProxy::$enabled = $proxyStatus; return $result; }
/** * unmount file from yourself * remember files/folders which get unmounted */ public static function preUmount($params) { $path = $params[\OC\Files\Filesystem::signal_param_path]; $user = \OCP\USER::getUser(); $view = new \OC\Files\View(); $itemType = $view->is_dir('/' . $user . '/files' . $path) ? 'folder' : 'file'; $util = new Util($view, $user); list($owner, $ownerPath) = $util->getUidAndFilename($path); self::$umountedFiles[$params[\OC\Files\Filesystem::signal_param_path]] = array('uid' => $owner, 'path' => $ownerPath, 'itemType' => $itemType); }