move unlink proxy to a hook which handles pre and post conditions
This commit is contained in:
parent
1f30bffba3
commit
5610842e56
|
@ -32,6 +32,8 @@ class Hooks {
|
||||||
|
|
||||||
// file for which we want to rename the keys after the rename operation was successful
|
// file for which we want to rename the keys after the rename operation was successful
|
||||||
private static $renamedFiles = array();
|
private static $renamedFiles = array();
|
||||||
|
// file for which we want to delete the keys after the delete operation was successful
|
||||||
|
private static $deleteFiles = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Startup encryption backend upon user login
|
* @brief Startup encryption backend upon user login
|
||||||
|
@ -630,4 +632,66 @@ class Hooks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief if the file was really deleted we remove the encryption keys
|
||||||
|
* @param array $params
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static function postDelete($params) {
|
||||||
|
|
||||||
|
if (!isset(self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$deletedFile = self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]];
|
||||||
|
$path = $deletedFile['path'];
|
||||||
|
$user = $deletedFile['uid'];
|
||||||
|
|
||||||
|
// we don't need to remember the file any longer
|
||||||
|
unset(self::$deleteFiles[$params[\OC\Files\Filesystem::signal_param_path]]);
|
||||||
|
|
||||||
|
$view = new \OC\Files\View('/');
|
||||||
|
|
||||||
|
// return if the file still exists and wasn't deleted correctly
|
||||||
|
if ($view->file_exists('/' . $user . '/files/' . $path)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable encryption proxy to prevent recursive calls
|
||||||
|
$proxyStatus = \OC_FileProxy::$enabled;
|
||||||
|
\OC_FileProxy::$enabled = false;
|
||||||
|
|
||||||
|
// Delete keyfile & shareKey so it isn't orphaned
|
||||||
|
if (!Keymanager::deleteFileKey($view, $path, $user)) {
|
||||||
|
\OCP\Util::writeLog('Encryption library',
|
||||||
|
'Keyfile or shareKey could not be deleted for file "' . $user.'/files/'.$path . '"', \OCP\Util::ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
Keymanager::delAllShareKeys($view, $user, $path);
|
||||||
|
|
||||||
|
\OC_FileProxy::$enabled = $proxyStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,8 @@ class Helper {
|
||||||
|
|
||||||
\OCP\Util::connectHook('OC_Filesystem', 'rename', 'OCA\Encryption\Hooks', 'preRename');
|
\OCP\Util::connectHook('OC_Filesystem', 'rename', 'OCA\Encryption\Hooks', 'preRename');
|
||||||
\OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OCA\Encryption\Hooks', 'postRename');
|
\OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OCA\Encryption\Hooks', 'postRename');
|
||||||
|
\OCP\Util::connectHook('OC_Filesystem', 'post_delete', 'OCA\Encryption\Hooks', 'postDelete');
|
||||||
|
\OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Encryption\Hooks', 'preDelete');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -203,47 +203,6 @@ class Proxy extends \OC_FileProxy {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief When a file is deleted, remove its keyfile also
|
|
||||||
*/
|
|
||||||
public function preUnlink($path) {
|
|
||||||
|
|
||||||
$relPath = Helper::stripUserFilesPath($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') || $relPath === false) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable encryption proxy to prevent recursive calls
|
|
||||||
$proxyStatus = \OC_FileProxy::$enabled;
|
|
||||||
\OC_FileProxy::$enabled = false;
|
|
||||||
|
|
||||||
$view = new \OC_FilesystemView('/');
|
|
||||||
|
|
||||||
$userId = \OCP\USER::getUser();
|
|
||||||
|
|
||||||
$util = new Util($view, $userId);
|
|
||||||
|
|
||||||
list($owner, $ownerPath) = $util->getUidAndFilename($relPath);
|
|
||||||
|
|
||||||
// Delete keyfile & shareKey so it isn't orphaned
|
|
||||||
if (!Keymanager::deleteFileKey($view, $ownerPath)) {
|
|
||||||
\OCP\Util::writeLog('Encryption library',
|
|
||||||
'Keyfile or shareKey could not be deleted for file "' . $ownerPath . '"', \OCP\Util::ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
Keymanager::delAllShareKeys($view, $owner, $ownerPath);
|
|
||||||
|
|
||||||
\OC_FileProxy::$enabled = $proxyStatus;
|
|
||||||
|
|
||||||
// If we don't return true then file delete will fail; better
|
|
||||||
// to leave orphaned keyfiles than to disallow file deletion
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $path
|
* @param $path
|
||||||
* @return bool
|
* @return bool
|
||||||
|
|
Loading…
Reference in New Issue