mirror of
https://github.com/eliasstepanik/ark-ac-server-tools.git
synced 2026-01-25 15:58:27 +00:00
Add additional checks when running as root
This commit is contained in:
parent
86b22b4dea
commit
7c86d40eff
@ -229,18 +229,26 @@ runAsRoot(){
|
|||||||
elif [ "$1" == "uninstall-tools" ]; then
|
elif [ "$1" == "uninstall-tools" ]; then
|
||||||
doUninstallTools
|
doUninstallTools
|
||||||
elif [ "$steamcmd_user" = "$USERNAME" ]; then
|
elif [ "$steamcmd_user" = "$USERNAME" ]; then
|
||||||
echo "Error: steamcmd_user is root; aborting"
|
echo "Error: steamcmd_user is root; aborting" >&2
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
exec /sbin/runuser "$steamcmd_user" -s "$steamcmd_user_shellexec" -c "$(printf "%q" "$0")$(printf " %q" "$@")"
|
echo "Attempting to drop privileges; re-running as $steamcmd_user" >&2
|
||||||
|
exec /sbin/runuser "$steamcmd_user" -s "$steamcmd_user_shellexec" -c "$(printf "%q" "$0") --runfromroot$(printf " %q" "$@")"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check the user is not currently running this script as root
|
# Check the user is not currently running this script as root
|
||||||
if [ "$(id -u)" == "0" ]; then
|
if [ "$(id -u)" == "0" ]; then
|
||||||
runAsRoot "$@"
|
if [ "$1" != "--run-as-root-i-know-what-im-doing" ]; then
|
||||||
exit 0
|
echo "Warning: running as root is dangerous" >&2
|
||||||
|
elif [ "$1" = "--runfromroot" ]; then
|
||||||
|
echo "Error: still running as root after attempting to drop privileges; aborting" >&2
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
runAsRoot "$@"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#---------------------
|
#---------------------
|
||||||
@ -259,6 +267,7 @@ if [ -f "${HOME}/${arkstUserCfgFile}" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -n "${steamcmd_user}" && "${steamcmd_user}" != "--me" && "$USERNAME" != "${steamcmd_user}" && -n "$usesudo" ]]; then
|
if [[ -n "${steamcmd_user}" && "${steamcmd_user}" != "--me" && "$USERNAME" != "${steamcmd_user}" && -n "$usesudo" ]]; then
|
||||||
|
echo "Attempting to run as $steamcmd_user" >&2
|
||||||
exec sudo --user="${steamcmd_user}" "$0" "$@"
|
exec sudo --user="${steamcmd_user}" "$0" "$@"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -3791,6 +3800,12 @@ main(){
|
|||||||
inCronJob=true
|
inCronJob=true
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
|
--runfromroot)
|
||||||
|
continue
|
||||||
|
;;
|
||||||
|
--run-as-root-i-know-what-im-doing)
|
||||||
|
continue
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# get the number of arguments for commands that take arguments
|
# get the number of arguments for commands that take arguments
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user