$keyPair = $this->crypt->createKeyPair();
- // Disable encryption proxy to prevent recursive calls
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
-
// Save public key
$this->setPublicKey($user, $keyPair['publicKey']);
} else {
$this->log->error('Encryption Could not update users encryption password');
}
-
- \OC_FileProxy::$enabled = $proxyStatus;
}
}
}
$userTrashSize = self::getTrashbinSize($user);
// disable proxy to prevent recursive calls
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
$trashPath = '/files_trashbin/files/' . $filename . '.d' . $timestamp;
try {
$sizeOfAddedFiles = $view->filesize('/files/' . $file_path);
}
\OC_Log::write('files_trashbin', 'Couldn\'t move ' . $file_path . ' to the trash bin', \OC_log::ERROR);
}
- \OC_FileProxy::$enabled = $proxyStatus;
if ($view->file_exists('/files/' . $file_path)) { // failed to delete the original file, abort
$view->unlink($trashPath);
$size = 0;
if (\OCP\App::isEnabled('files_versions')) {
- // disable proxy to prevent recursive calls
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
-
$user = \OCP\User::getUser();
$rootView = new \OC\Files\View('/');
$rootView->rename($owner . '/files_versions' . $v['path'] . '.v' . $v['version'], $user . '/files_trashbin/versions/' . $filename . '.v' . $v['version'] . '.d' . $timestamp);
}
}
-
- // enable proxy
- \OC_FileProxy::$enabled = $proxyStatus;
}
return $size;
$target = \OC\Files\Filesystem::normalizePath('files/' . $location . '/' . $uniqueFilename);
$mtime = $view->filemtime($source);
- // disable proxy to prevent recursive calls
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
-
// restore file
$restoreResult = $view->rename($source, $target);
$query->execute(array($user, $filename, $timestamp));
}
- // enable proxy
- \OC_FileProxy::$enabled = $proxyStatus;
-
return true;
}
- // enable proxy
- \OC_FileProxy::$enabled = $proxyStatus;
-
return false;
}
private static function restoreVersions(\OC\Files\View $view, $file, $filename, $uniqueFilename, $location, $timestamp) {
if (\OCP\App::isEnabled('files_versions')) {
- // disable proxy to prevent recursive calls
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
$user = \OCP\User::getUser();
$rootView = new \OC\Files\View('/');
// file has been deleted in between
if (empty($ownerPath)) {
- \OC_FileProxy::$enabled = $proxyStatus;
return false;
}
}
}
}
-
- // enable proxy
- \OC_FileProxy::$enabled = $proxyStatus;
}
}
self::scheduleExpire($filename, $versionsSize, $neededSpace);
- // disable proxy to prevent multiple fopen calls
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
-
// store a new version of a file
$mtime = $users_view->filemtime('files/' . $filename);
$users_view->copy('files/' . $filename, 'files_versions/' . $filename . '.v' . $mtime);
// call getFileInfo to enforce a file cache entry for the new version
$users_view->getFileInfo('files_versions/' . $filename . '.v' . $mtime);
-
- // reset proxy state
- \OC_FileProxy::$enabled = $proxyStatus;
}
}
$version = 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename);
if ( !$users_view->file_exists($version)) {
- // disable proxy to prevent multiple fopen calls
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
-
$users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename));
- // reset proxy state
- \OC_FileProxy::$enabled = $proxyStatus;
-
$versionCreated = true;
}
*/
public function get($key) {
$result = null;
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
if ($this->hasKey($key)) {
$storage = $this->getStorage();
$result = $storage->file_get_contents($key);
}
- \OC_FileProxy::$enabled = $proxyStatus;
return $result;
}
*/
public function size($key) {
$result = 0;
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
if ($this->hasKey($key)) {
$storage = $this->getStorage();
$result = $storage->filesize($key);
}
- \OC_FileProxy::$enabled = $proxyStatus;
return $result;
}
public function set($key, $value, $ttl = 0) {
$storage = $this->getStorage();
$result = false;
- $proxyStatus = \OC_FileProxy::$enabled;
// unique id to avoid chunk collision, just in case
$uniqueId = \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(
16,
// use part file to prevent hasKey() to find the key
// while it is being written
$keyPart = $key . '.' . $uniqueId . '.part';
- \OC_FileProxy::$enabled = false;
if ($storage and $storage->file_put_contents($keyPart, $value)) {
if ($ttl === 0) {
$ttl = 86400; // 60*60*24
$result = $storage->touch($keyPart, time() + $ttl);
$result &= $storage->rename($keyPart, $key);
}
- \OC_FileProxy::$enabled = $proxyStatus;
return $result;
}
$absolutePath = \OC\Files\Filesystem::normalizePath(\OC\Files\Filesystem::getView()->getAbsolutePath($path));
$data = '';
// use file_put_contents as method because that best matches what this function does
- if (OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data)
- && \OC\Files\Filesystem::isValidPath($path)) {
+ if (\OC\Files\Filesystem::isValidPath($path)) {
$path = \OC\Files\Filesystem::getView()->getRelativePath($absolutePath);
$exists = \OC\Files\Filesystem::file_exists($path);
$run = true;
\OC\Files\Filesystem::signal_post_write,
array( \OC\Files\Filesystem::signal_param_path => $path)
);
- OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count);
return $count > 0;
}else{
return false;
+++ /dev/null
-<?php
-/**
- * @author Bart Visscher <bartv@thisnet.nl>
- * @author Felix Moeller <mail@felixmoeller.de>
- * @author Jörn Friedrich Dreyer <jfd@butonic.de>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <icewind@owncloud.com>
- * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
- * @author Scrutinizer Auto-Fixer <auto-fixer@scrutinizer-ci.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Vincent Petry <pvince81@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-/**
- * Class for manipulating filesystem requests
- *
- * Manipulation happens by using 2 kind of proxy operations, pre and post proxies
- * that manipulate the filesystem call and the result of the call respectively
- *
- * A pre-proxy recieves the filepath as arugments (or 2 filespaths in case of
- * operations like copy or move) and return a boolean
- * If a pre-proxy returns false the file operation will be canceled
- * All filesystem operations have a pre-proxy
- *
- * A post-proxy recieves 2 arguments, the filepath and the result of the operation.
- * The return value of the post-proxy will be used as the new result of the operation
- * The operations that have a post-proxy are:
- * file_get_contents, is_file, is_dir, file_exists, stat, is_readable,
- * is_writable, filemtime, filectime, file_get_contents,
- * getMimeType, hash, fopen, free_space and search
- */
-
-class OC_FileProxy{
- private static $proxies=array();
- public static $enabled=true;
-
- /**
- * fallback function when a proxy operation is not implemented
- * @param string $function the name of the proxy operation
- * @param mixed $arguments
- *
- * this implements a dummy proxy for all operations
- */
- public function __call($function, $arguments) {
- if(substr($function, 0, 3)=='pre') {
- return true;
- }else{
- return $arguments[1];
- }
- }
-
- /**
- * register a proxy to be used
- * @param OC_FileProxy $proxy
- */
- public static function register($proxy) {
- self::$proxies[]=$proxy;
- }
-
- /**
- * @param string $operation
- */
- public static function getProxies($operation = null) {
- if ($operation === null) {
- // return all
- return self::$proxies;
- }
- $proxies=array();
- foreach(self::$proxies as $proxy) {
- if(method_exists($proxy, $operation)) {
- $proxies[]=$proxy;
- }
- }
- return $proxies;
- }
-
- /**
- * @param string $operation
- * @param string|boolean $filepath
- */
- public static function runPreProxies($operation,&$filepath,&$filepath2=null) {
- if(!self::$enabled) {
- return true;
- }
- $operation='pre'.$operation;
- $proxies=self::getProxies($operation);
- foreach($proxies as $proxy) {
- if(!is_null($filepath2)) {
- if($proxy->$operation($filepath, $filepath2)===false) {
- return false;
- }
- }else{
- if($proxy->$operation($filepath)===false) {
- return false;
- }
- }
- }
- return true;
- }
-
- /**
- * @param string $operation
- * @param string|boolean $path
- *
- * @return string
- */
- public static function runPostProxies($operation, $path, $result) {
- if(!self::$enabled) {
- return $result;
- }
- $operation='post'.$operation;
- $proxies=self::getProxies($operation);
- foreach($proxies as $proxy) {
- $result=$proxy->$operation($path, $result);
- }
- return $result;
- }
-
- public static function clearProxies() {
- self::$proxies=array();
- }
-}
public function file_put_contents($path, $data) {
if (is_resource($data)) { //not having to deal with streams in file_put_contents makes life easier
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
- if (\OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data)
- and Filesystem::isValidPath($path)
+ if (Filesystem::isValidPath($path)
and !Filesystem::isFileBlacklisted($path)
) {
$path = $this->getRelativePath($absolutePath);
if ($this->shouldEmitHooks($path) && $result !== false) {
$this->emit_file_hooks_post($exists, $path);
}
- \OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count);
return $result;
} else {
return false;
$absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1));
$absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2));
if (
- \OC_FileProxy::runPreProxies('rename', $absolutePath1, $absolutePath2)
- and Filesystem::isValidPath($path2)
+ Filesystem::isValidPath($path2)
and Filesystem::isValidPath($path1)
and !Filesystem::isFileBlacklisted($path2)
) {
$sourceMountPoint = $mount->getMountPoint();
$result = $mount->moveMount($absolutePath2);
$manager->moveMount($sourceMountPoint, $mount->getMountPoint());
- \OC_FileProxy::runPostProxies('rename', $absolutePath1, $absolutePath2);
} else {
$result = false;
}
} elseif ($mp1 == $mp2) {
if ($storage1) {
$result = $storage1->rename($internalPath1, $internalPath2);
- \OC_FileProxy::runPostProxies('rename', $absolutePath1, $absolutePath2);
} else {
$result = false;
}
$absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($path1));
$absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($path2));
if (
- \OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2)
- and Filesystem::isValidPath($path2)
+ Filesystem::isValidPath($path2)
and Filesystem::isValidPath($path1)
and !Filesystem::isFileBlacklisted($path2)
) {
public function hash($type, $path, $raw = false) {
$postFix = (substr($path, -1, 1) === '/') ? '/' : '';
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
- if (\OC_FileProxy::runPreProxies('hash', $absolutePath) && Filesystem::isValidPath($path)) {
+ if (Filesystem::isValidPath($path)) {
$path = $this->getRelativePath($absolutePath);
if ($path == null) {
return false;
list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
if ($storage) {
$result = $storage->hash($type, $internalPath, $raw);
- $result = \OC_FileProxy::runPostProxies('hash', $absolutePath, $result);
return $result;
}
}
private function basicOperation($operation, $path, $hooks = array(), $extraParam = null) {
$postFix = (substr($path, -1, 1) === '/') ? '/' : '';
$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
- if (\OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam)
- and Filesystem::isValidPath($path)
+ if (Filesystem::isValidPath($path)
and !Filesystem::isFileBlacklisted($path)
) {
$path = $this->getRelativePath($absolutePath);
$result = $storage->$operation($internalPath);
}
- $result = \OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result);
-
if (in_array('delete', $hooks) and $result) {
$this->updater->remove($path);
}
$data['permissions'] |= \OCP\Constants::PERMISSION_DELETE;
}
- $data = \OC_FileProxy::runPostProxies('getFileInfo', $path, $data);
-
return new FileInfo($path, $storage, $internalPath, $data, $mount);
}
$dir = '/files';
if (!$folder->nodeExists($dir)) {
$folder = $folder->newFolder($dir);
-
- if (\OCP\App::isEnabled('files_encryption')) {
- // disable encryption proxy to prevent recursive calls
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
- }
-
\OC_Util::copySkeleton($user, $folder);
-
- if (\OCP\App::isEnabled('files_encryption')) {
- // re-enable proxy - our work is done
- \OC_FileProxy::$enabled = $proxyStatus;
- }
} else {
$folder = $folder->get($dir);
}
OC_Hook::clear();
OC_Log::$enabled = false;
-OC_FileProxy::clearProxies();
parent::setUp();
//clear all proxies and hooks so we can do clean testing
- \OC_FileProxy::clearProxies();
\OC_Hook::clear('OC_Filesystem');
//set up temporary storage
parent::setUp();
//clear all proxies and hooks so we can do clean testing
- \OC_FileProxy::clearProxies();
\OC_Hook::clear('OC_Filesystem');
//set up temporary storage
self::tearDownAfterClassCleanFileCache();
self::tearDownAfterClassCleanStrayDataFiles($dataDir);
self::tearDownAfterClassCleanStrayHooks();
- self::tearDownAfterClassCleanProxies();
parent::tearDownAfterClass();
}
\OC_Hook::clear();
}
- /**
- * Clean up the list of file proxies
- *
- * Also reenables file proxies, in case a test disabled them
- */
- static protected function tearDownAfterClassCleanProxies() {
- \OC_FileProxy::$enabled = true;
- \OC_FileProxy::clearProxies();
- }
-
/**
* Login and setup FS as a given user,
* sets the given user as the current user.