Fix sudo run as another user
EasyOS does not have 'sudo', instead has a light-weight replacement named 'sudo-sh':
https://bkhome.org/news/202510/sudo-sh-reverted-to-simpler-design.html
There is a script /usr/bin/sudo, that is a wrapper for sudo-sh. It is far from implementing everything that sudo is capable of. The guys found when install Zoneminder, that it tries to use sudo to launch an app as user 'www-data':
https://forum.puppylinux.com/viewtopic.php?p=173863#p173863
I have modified 'sudo' script:
#!/bin/ash
C=''
while [ -n "$1" ];do
case "$1" in
-*)
case "$1" in
--user=*)
#ref: https://forum.puppylinux.com/viewtopic.php?p=173863#p173863
USERx="${1/*=/}"
shift
exec /usr/sbin/run-as-user ${USERx} ${@}
;;
-u)
shift
exec /usr/sbin/run-as-user ${@}
;;
-g|-p|-U|-C|-r|-t)
shift
;;
esac
;;
*)
C="$@"
break
;;
esac
shift
done
if [ -n "$C" ];then
#exec sudo-sh ${PPID} ${0} ${C}
exec sudo-sh ${PPID} ${C}
fi
###end###
The 'run-as-user' script was introduced here:
https://bkhome.org/news/202602/enhanced-script-to-run-app-as-any-user.html
If you try and run it, like this for example: run-as-user www-data myapp
It will fail, as folder "/home/www-data" does not exist. I have
modified the 'run-as-user' script to call
/usr/local/clients/create-client-environment if www-data not in
/etc/passwd, or if it is, to not require existence of
/home/www-data.
Tags: easy