namespace OC\Files\Cache;
use Doctrine\DBAL\Exception;
-use OC\Files\Filesystem;
use OC\Files\Storage\Wrapper\Jail;
use OC\Files\Storage\Wrapper\Encoding;
use OC\Hooks\BasicEmitter;
return null;
}
}
- // only proceed if $file is not a partial file nor a blacklisted file
- if (!self::isPartialFile($file) and !Filesystem::isFileBlacklisted($file)) {
+ // only proceed if $file is not a partial file, blacklist is handled by the storage
+ if (!self::isPartialFile($file)) {
//acquire a lock
if ($lock) {
private static $listeningForProviders = false;
+ /** @var string[]|null */
+ private static $blacklist = null;
+
/**
* classname which used for hooks handling
* used as signalclass in OC_Hooks::emit()
public static function isFileBlacklisted($filename) {
$filename = self::normalizePath($filename);
- $blacklist = \OC::$server->getConfig()->getSystemValue('blacklisted_files', ['.htaccess']);
+ if (self::$blacklist === null) {
+ self::$blacklist = \OC::$server->getConfig()->getSystemValue('blacklisted_files', ['.htaccess']);
+ }
+
$filename = strtolower(basename($filename));
- return in_array($filename, $blacklist);
+ return in_array($filename, self::$blacklist);
}
/**
use OC\Files\Storage\Wrapper\Wrapper;
use OCP\Files\EmptyFileNameException;
use OCP\Files\FileNameTooLongException;
+use OCP\Files\ForbiddenException;
use OCP\Files\GenericFileException;
use OCP\Files\InvalidCharacterInPathException;
use OCP\Files\InvalidDirectoryException;
* @inheritdoc
*/
public function getMetaData($path) {
+ if (Filesystem::isFileBlacklisted($path)) {
+ throw new ForbiddenException('Invalid path: ' . $path, false);
+ }
+
$permissions = $this->getPermissions($path);
if (!$permissions & \OCP\Constants::PERMISSION_READ) {
//can't read, nothing we can do
if (is_resource($dh)) {
$basePath = rtrim($directory, '/');
while (($file = readdir($dh)) !== false) {
- if (!Filesystem::isIgnoredDir($file) && !Filesystem::isFileBlacklisted($file)) {
+ if (!Filesystem::isIgnoredDir($file)) {
$childPath = $basePath . '/' . trim($file, '/');
$metadata = $this->getMetaData($childPath);
if ($metadata !== null) {
use OCP\Constants;
use OCP\Files\ForbiddenException;
use OCP\Files\GenericFileException;
+use OCP\Files\IMimeTypeDetector;
use OCP\Files\Storage\IStorage;
+use OCP\IConfig;
use OCP\ILogger;
/**
protected $realDataDir;
+ private IConfig $config;
+
+ private IMimeTypeDetector $mimeTypeDetector;
+
public function __construct($arguments) {
if (!isset($arguments['datadir']) || !is_string($arguments['datadir'])) {
throw new \InvalidArgumentException('No data directory set for local storage');
$this->datadir .= '/';
}
$this->dataDirLength = strlen($this->realDataDir);
+ $this->config = \OC::$server->get(IConfig::class);
+ $this->mimeTypeDetector = \OC::$server->get(IMimeTypeDetector::class);
}
public function __destruct() {
$statResult['size'] = $filesize;
$statResult[7] = $filesize;
}
+ if (is_array($statResult)) {
+ $statResult['full_path'] = $fullPath;
+ }
return $statResult;
}
}
if (!($path === '' || $path === '/')) { // deletable depends on the parents unix permissions
- $fullPath = $this->getSourcePath($path);
- $parent = dirname($fullPath);
+ $parent = dirname($stat['full_path']);
if (is_writable($parent)) {
$permissions += Constants::PERMISSION_DELETE;
}
}
$data = [];
- $data['mimetype'] = $isDir ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($path);
+ $data['mimetype'] = $isDir ? 'httpd/unix-directory' : $this->mimeTypeDetector->detectPath($path);
$data['mtime'] = $stat['mtime'];
if ($data['mtime'] === false) {
$data['mtime'] = time();
$fullPath = $this->datadir . $path;
$currentPath = $path;
- $allowSymlinks = \OC::$server->getConfig()->getSystemValue('localstorage.allowsymlinks', false);
+ $allowSymlinks = $this->config->getSystemValue('localstorage.allowsymlinks', false);
if ($allowSymlinks || $currentPath === '') {
return $fullPath;
}