Skip to content

Commit

Permalink
Try to control access rights over config file
Browse files Browse the repository at this point in the history
  • Loading branch information
sonntam committed Oct 19, 2017
1 parent fd606b6 commit f4d7be6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions classes/ConfigFile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ public function ReadFromFile(string $filename) : bool
return false;
}

// Check access rights
$ac = fileperms($filename);
if( ($ac & 0x07) != 0 ) {
Log::Warning("Config file \"$filename\" is publicly visible (mod=$ac). Trying to change access rights..." );
$newac = $ac & ~0x7;
if( !chmod( $filename, $newac ) ) {
throw new Exception("Could not change access rights of config file. Please try to do it manually. Exiting.");
exit;
} else {
Log::Info("Config file \"$filename\" chmod from $ac to $newac successful.");
}
}

$this->filename = $filename;

$cfg = json_decode( file_get_contents($filename), true ) or Log::Error("Invalid configuration file at \"$filename\"");
Expand Down

0 comments on commit f4d7be6

Please sign in to comment.