From 6a4f2025c319f1bb49941f8a13c105afd21dac4d Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Sat, 30 May 2020 09:23:21 -0500 Subject: [PATCH] Check running user lnms (#11726) --- app/Checks.php | 14 ++++++++++++++ lnms | 3 +++ 2 files changed, 17 insertions(+) diff --git a/app/Checks.php b/app/Checks.php index 40f0177a29..d1af6fa5a7 100644 --- a/app/Checks.php +++ b/app/Checks.php @@ -116,6 +116,20 @@ class Checks } } + /** + * Check the script is running as the right user (works before config is available) + */ + public static function runningUser() + { + if (function_exists('posix_getpwuid') && posix_getpwuid(posix_geteuid())['name'] !== get_current_user()) { + self::printMessage( + 'Error: You must run lnms as the user ' . get_current_user(), + null, + true + ); + } + } + private static function printMessage($title, $content, $exit = false) { $content = (array)$content; diff --git a/lnms b/lnms index ea2b9795c7..321b209195 100755 --- a/lnms +++ b/lnms @@ -15,6 +15,9 @@ require __DIR__.'/bootstrap/autoload.php'; +// Check that we don't run this as the wrong user and break the install +\App\Checks::runningUser(); + $app = require_once __DIR__.'/bootstrap/app.php'; /*