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

Show error message if config file is not readable #185

Merged
merged 1 commit into from
Jun 21, 2016

Conversation

MorrisJobke
Copy link
Member

cc @adsworth @Mar1u5 @williambargent @LukasReschke @schiessle

@MorrisJobke MorrisJobke added bug 3. to review Waiting for reviews labels Jun 21, 2016
@MorrisJobke MorrisJobke added this to the Nextcloud Next milestone Jun 21, 2016
@MorrisJobke
Copy link
Member Author

MorrisJobke commented Jun 21, 2016

@adsworth the stable9 patch looks like this (because of some refactoring this patch doesn't apply to stable9)

diff --git a/lib/private/config.php b/lib/private/config.php
index 368dafd..2a21cd6 100644
--- a/lib/private/config.php
+++ b/lib/private/config.php
@@ -184,10 +184,11 @@ class Config {

        // Include file and merge config
        foreach ($configFiles as $file) {
-           $filePointer = file_exists($file) ? fopen($file, 'r') : false;
+           $fileExistsAndIsReadable = file_exists($file) && is_readable($file);
+           $filePointer = $fileExistsAndIsReadable ? fopen($file, 'r') : false;
            if($file === $this->configFilePath &&
-               $filePointer === false &&
-               @!file_exists($this->configFilePath)) {
+               $filePointer === false) {
                // Opening the main config might not be possible, e.g. if the wrong
                // permissions are set (likely on a new installation)
                continue;

if($file === $this->configFilePath &&
$filePointer === false &&
@!file_exists($this->configFilePath)) {
!$fileExistsAndIsReadable) {
Copy link
Member

@schiessle schiessle Jun 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems to be redundant, if $fileExistsAndIsReadable is false, then $filePointer is already false, see https://github.com/nextcloud/server/pull/185/files#diff-e8ccb791da0aa95230141afcf200336dR188

Btw, the old check didn't checked if the config file exists but if the "configFilePath" exists. Don't know in which cases this makes a difference.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, the old check didn't checked if the config file exists but if the "configFilePath" exists.

$file === $this->configFilePath ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested your proposal and also thought about it and you are correct :) I fixed it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, the old check didn't checked if the config file exists but if the "configFilePath" exists.

$file === $this->configFilePath ;)

This just check if $file equals $this->configFilePath.

The old check evaluated the if-statement to false if $this->configFilePath exists but fopen() returned false. The new check would evaluate the if-statement to true.

But I believe that this is just a theoretical difference. I don't see how this should make a difference and also tested it.

* when the config file is not writable there is a error message shown
* same happens now if the config file is not readable
* fixes #180
@MorrisJobke MorrisJobke force-pushed the fix-permission-issue branch from 3409440 to 191a6c6 Compare June 21, 2016 09:25
@LukasReschke
Copy link
Member

LGTM

@schiessle
Copy link
Member

tested, LGTM

@LukasReschke LukasReschke merged commit 097cba8 into master Jun 21, 2016
@LukasReschke LukasReschke deleted the fix-permission-issue branch June 21, 2016 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

white screen if webserver has no read access to config.php
3 participants