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

Fix permissions check #8699

Merged
merged 1 commit into from May 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 30 additions & 12 deletions LibreNMS/Validations/User.php
Expand Up @@ -63,14 +63,26 @@ public function validate(Validator $validator)
// Let's test the user configured if we have it
if (Config::has('user')) {
$dir = Config::get('install_dir');

$find_result = rtrim(`find $dir \! -user $lnms_username -o \! -group $lnms_groupname &> /dev/null`);
$find_result = rtrim(`find $dir \! -user $lnms_username -o \! -group $lnms_groupname 2> /dev/null`);
if (!empty($find_result)) {
// Ignore the two logs that may be created by the
$files = array_diff(explode(PHP_EOL, $find_result), array(
// Ignore files created by the webserver
$ignore_files = array(
"$dir/logs/error_log",
"$dir/logs/access_log",
));
"$dir/bootstrap/cache/",
"$dir/storage/framework/cache/",
"$dir/storage/framework/sessions/",
"$dir/storage/framework/views/",
"$dir/storage/debugbar/",
);

$files = array_filter(explode(PHP_EOL, $find_result), function ($file) use ($ignore_files) {
if (starts_with($file, $ignore_files)) {
return false;
}

return true;
});

if (!empty($files)) {
$result = ValidationResult::fail(
Expand All @@ -88,14 +100,20 @@ public function validate(Validator $validator)
}

// check permissions
$rrd_dir = Config::get('rrd_dir');
if (!check_file_permissions($rrd_dir, '660')) {
$validator->fail("The rrd folder has improper permissions.", "chmod ug+rw $rrd_dir");
}
$folders = [
'rrd' => Config::get('rrd_dir'),
'log' => Config::get('log_dir'),
'bootstrap' => "$dir/bootstrap/cache/",
'storage' => "$dir/storage/",
'cache' => "$dir/storage/framework/cache/",
'sessions' => "$dir/storage/framework/sessions/",
'views' => "$dir/storage/framework/views/",
];

$log_dir = Config::get('log_dir');
if (!check_file_permissions($log_dir, '660')) {
$validator->fail("The log folder has improper permissions.", "chmod ug+rw $log_dir");
foreach ($folders as $name => $folder) {
if (!check_file_permissions($folder, '660')) {
$validator->fail("The $name folder has improper permissions.", "chmod ug+rw $folder");
}
}
}
}