Added protection against switching to the server user from non-root users.

This commit is contained in:
Marcus Whybrow 2012-05-30 16:33:37 +01:00
parent ba8a8f14cd
commit 2540c43e8a

10
msm
View File

@ -59,10 +59,16 @@ declare RESTART_COUNTDOWN
# $1: The user to execute the command as
# $2: The command to execute
as_user() {
if [ $(whoami) == $1 ]; then
local user="$(whoami)"
if [ "$user" == "$1" ]; then
bash -c "$2"
else
su - $1 -s /bin/bash -c "$2"
if [ "$user" == "root" ]; then
su - $1 -s /bin/bash -c "$2"
else
echoerr "This command must be executed as the user \"$1\" or \"root\"."
exit 1
fi
fi
}