Skip to content

Commit

Permalink
Merge pull request #32723 from MartinBrugnara/master
Browse files Browse the repository at this point in the history
Expose umask override value as config parameter: localstorage.umask
  • Loading branch information
PVince81 authored Jun 10, 2022
2 parents 56b1453 + 7409569 commit bea755f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 12 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,18 @@
*/
'localstorage.allowsymlinks' => false,

/**
* Nextcloud overrides umask to ensure suitable access permissions
* regardless of webserver/php-fpm configuration and worker state.
* WARNING: Modifying this value has security implications and
* may soft-break the installation.
*
* Most installs shall not modify this value.
*
* Defaults to ``0022``
*/
'localstorage.umask' => 0022,

/**
* EXPERIMENTAL: option whether to include external storage in quota
* calculation, defaults to false.
Expand Down
14 changes: 9 additions & 5 deletions lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @author Jörn Friedrich Dreyer <[email protected]>
* @author Klaas Freitag <[email protected]>
* @author Lukas Reschke <[email protected]>
* @author Martin Brugnara <[email protected]>
* @author Michael Gapczynski <[email protected]>
* @author Morris Jobke <[email protected]>
* @author Robin Appelman <[email protected]>
Expand Down Expand Up @@ -66,6 +67,8 @@ class Local extends \OC\Files\Storage\Common {

private IMimeTypeDetector $mimeTypeDetector;

private $defUMask;

public function __construct($arguments) {
if (!isset($arguments['datadir']) || !is_string($arguments['datadir'])) {
throw new \InvalidArgumentException('No data directory set for local storage');
Expand All @@ -84,6 +87,7 @@ public function __construct($arguments) {
$this->dataDirLength = strlen($this->realDataDir);
$this->config = \OC::$server->get(IConfig::class);
$this->mimeTypeDetector = \OC::$server->get(IMimeTypeDetector::class);
$this->defUMask = $this->config->getSystemValue('localstorage.umask', 0022);
}

public function __destruct() {
Expand All @@ -95,7 +99,7 @@ public function getId() {

public function mkdir($path) {
$sourcePath = $this->getSourcePath($path);
$oldMask = umask(022);
$oldMask = umask($this->defUMask);
$result = @mkdir($sourcePath, 0777, true);
umask($oldMask);
return $result;
Expand Down Expand Up @@ -273,7 +277,7 @@ public function touch($path, $mtime = null) {
if ($this->file_exists($path) and !$this->isUpdatable($path)) {
return false;
}
$oldMask = umask(022);
$oldMask = umask($this->defUMask);
if (!is_null($mtime)) {
$result = @touch($this->getSourcePath($path), $mtime);
} else {
Expand All @@ -292,7 +296,7 @@ public function file_get_contents($path) {
}

public function file_put_contents($path, $data) {
$oldMask = umask(022);
$oldMask = umask($this->defUMask);
$result = file_put_contents($this->getSourcePath($path), $data);
umask($oldMask);
return $result;
Expand Down Expand Up @@ -365,15 +369,15 @@ public function copy($path1, $path2) {
if ($this->is_dir($path1)) {
return parent::copy($path1, $path2);
} else {
$oldMask = umask(022);
$oldMask = umask($this->defUMask);
$result = copy($this->getSourcePath($path1), $this->getSourcePath($path2));
umask($oldMask);
return $result;
}
}

public function fopen($path, $mode) {
$oldMask = umask(022);
$oldMask = umask($this->defUMask);
$result = fopen($this->getSourcePath($path), $mode);
umask($oldMask);
return $result;
Expand Down

0 comments on commit bea755f

Please sign in to comment.