mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Change the way username is obtained
Username should be obtained by getting user name for effective UID. Using USERNAME or USER variables is not the right way (when you just "su" and not "su - " it keeps previous username): id : uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel) context=user_u:system_r:unconfined_t ./validate.php: [FAIL] You need to run this script as root echo $USER: <name of user that did su>
This commit is contained in:
committed by
GitHub
co-authored by
GitHub
parent
70ef3dadf0
commit
74675a7b00
+6
-1
@@ -48,7 +48,12 @@ if (strstr(`php -ln config.php`, 'No syntax errors detected')) {
|
||||
}
|
||||
|
||||
// Check we are running this as the root user
|
||||
$username = getenv('USERNAME') ?: getenv('USER');//http://php.net/manual/en/function.get-current-user.php
|
||||
if (function_exists('posix_getpwuid')) {
|
||||
$userinfo = posix_getpwuid( posix_geteuid() );
|
||||
$username = $userinfo['name'];
|
||||
} else {
|
||||
$username = getenv('USERNAME') ?: getenv('USER');//http://php.net/manual/en/function.get-current-user.php
|
||||
}
|
||||
if ($username !== 'root') {
|
||||
print_fail("You need to run this script as root");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user