Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable26] fix(files_external): on case insensitive system, block case change #41222

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/files_external/lib/Lib/Backend/SMB.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public function __construct(IL10N $l, Password $legacyAuth) {
(new DefinitionParameter('show_hidden', $l->t('Show hidden files')))
->setType(DefinitionParameter::VALUE_BOOLEAN)
->setFlag(DefinitionParameter::FLAG_OPTIONAL),
(new DefinitionParameter('case_sensitive', $l->t('Case sensitive file system')))
->setType(DefinitionParameter::VALUE_BOOLEAN)
->setFlag(DefinitionParameter::FLAG_OPTIONAL)
->setDefaultValue(true)
->setTooltip($l->t('Disabling it will allow to use a case insentive file system, but comes with a performance penalty')),
(new DefinitionParameter('check_acl', $l->t('Verify ACL access when listing files')))
->setType(DefinitionParameter::VALUE_BOOLEAN)
->setFlag(DefinitionParameter::FLAG_OPTIONAL)
Expand Down
19 changes: 19 additions & 0 deletions apps/files_external/lib/Lib/Storage/SMB.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class SMB extends Common implements INotifyStorage {
/** @var bool */
protected $showHidden;

private bool $caseSensitive;

/** @var bool */
protected $checkAcl;

Expand Down Expand Up @@ -132,6 +134,7 @@ public function __construct($params) {
$this->root = rtrim($this->root, '/') . '/';

$this->showHidden = isset($params['show_hidden']) && $params['show_hidden'];
$this->caseSensitive = (bool) ($params['case_sensitive'] ?? true);
$this->checkAcl = isset($params['check_acl']) && $params['check_acl'];

$this->statCache = new CappedMemoryCache();
Expand Down Expand Up @@ -314,6 +317,12 @@ public function rename($source, $target, $retry = true): bool {
if ($this->isRootDir($source) || $this->isRootDir($target)) {
return false;
}
if ($this->caseSensitive === false
&& mb_strtolower($target) === mb_strtolower($source)
) {
// Forbid changing case only on case-insensitive file system
return false;
}

$absoluteSource = $this->buildPath($source);
$absoluteTarget = $this->buildPath($target);
Expand Down Expand Up @@ -663,6 +672,16 @@ public function mkdir($path) {

public function file_exists($path) {
try {
if ($this->caseSensitive === false) {
$filename = basename($path);
$siblings = $this->getDirectoryContent(dirname($this->buildPath($path)));
foreach ($siblings as $sibling) {
if ($sibling['name'] === $filename) {
return true;
}
}
return false;
}
$this->getFileInfo($path);
return true;
} catch (NotFoundException $e) {
Expand Down
Loading