Skip to content
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
10 changes: 5 additions & 5 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -809,11 +809,11 @@

/**
* In certain environments it is desired to have a read-only configuration file.
* When this switch is set to ``true`` Nextcloud will not verify whether the
* configuration is writable. However, it will not be possible to configure
* all options via the Web interface. Furthermore, when updating Nextcloud
* it is required to make the configuration file writable again for the update
* process.
* When this switch is set to ``true``, writing to the config file will be
* forbidden. Therefore, it will not be possible to configure all options via
* the Web interface. Furthermore, when updating Nextcloud it is required to
* make the configuration file writable again and to set this switch to ``false``
* for the update process.
*
* Defaults to ``false``
*/
Expand Down
26 changes: 26 additions & 0 deletions lib/private/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class Config {
protected $configFilePath;
/** @var string */
protected $configFileName;
/** @var bool */
protected $isReadOnly;

/**
* @param string $configDir Path to the config dir, needs to end with '/'
Expand All @@ -67,6 +69,7 @@ public function __construct($configDir, $fileName = 'config.php') {
$this->configFilePath = $this->configDir.$fileName;
$this->configFileName = $fileName;
$this->readData();
$this->isReadOnly = $this->getValue('config_is_read_only', false);
}

/**
Expand Down Expand Up @@ -109,6 +112,7 @@ public function getValue($key, $default = null) {
*
* @param array $configs Associative array with `key => value` pairs
* If value is null, the config key will be deleted
* @throws HintException
*/
public function setValues(array $configs) {
$needsUpdate = false;
Expand All @@ -131,6 +135,7 @@ public function setValues(array $configs) {
*
* @param string $key key
* @param mixed $value value
* @throws HintException
*/
public function setValue($key, $value) {
if ($this->set($key, $value)) {
Expand All @@ -145,8 +150,11 @@ public function setValue($key, $value) {
* @param string $key key
* @param mixed $value value
* @return bool True if the file needs to be updated, false otherwise
* @throws HintException
*/
protected function set($key, $value) {
$this->checkReadOnly();

if (!isset($this->cache[$key]) || $this->cache[$key] !== $value) {
// Add change
$this->cache[$key] = $value;
Expand All @@ -158,7 +166,9 @@ protected function set($key, $value) {

/**
* Removes a key from the config and removes it from config.php if required
*
* @param string $key
* @throws HintException
*/
public function deleteKey($key) {
if ($this->delete($key)) {
Expand All @@ -172,8 +182,11 @@ public function deleteKey($key) {
*
* @param string $key
* @return bool True if the file needs to be updated, false otherwise
* @throws HintException
*/
protected function delete($key) {
$this->checkReadOnly();

if (isset($this->cache[$key])) {
// Delete key from cache
unset($this->cache[$key]);
Expand Down Expand Up @@ -239,6 +252,8 @@ private function readData() {
* @throws \Exception If no file lock can be acquired
*/
private function writeData() {
$this->checkReadOnly();

// Create a php file ...
$content = "<?php\n";
$content .= '$CONFIG = ';
Expand Down Expand Up @@ -274,4 +289,15 @@ private function writeData() {
@opcache_invalidate($this->configFilePath, true);
}
}

/**
* @throws HintException
*/
private function checkReadOnly(): void {
if ($this->isReadOnly) {
throw new HintException(
'Config is set to be read-only via option "config_is_read_only".',
'Unset "config_is_read_only" to allow changes to the config file.');
}
}
}
2 changes: 2 additions & 0 deletions lib/public/IConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface IConfig {
*
* @param array $configs Associative array with `key => value` pairs
* If value is null, the config key will be deleted
* @throws HintException if config file is read-only
* @since 8.0.0
*/
public function setSystemValues(array $configs);
Expand All @@ -56,6 +57,7 @@ public function setSystemValues(array $configs);
*
* @param string $key the key of the value, under which will be saved
* @param mixed $value the value that should be stored
* @throws HintException if config file is read-only
* @since 8.0.0
*/
public function setSystemValue($key, $value);
Expand Down