cmdmod.py: runas workaround for platforms that don't set a USER env var

Solaris doesn't set a USER env var in its default environment, that is
if you run `su - someuser -c env` you get a HOME, PWD, LOGNAME, etc. env
var, but not a USER. This commit makes sure that the USER env var is set
to the runas user.
This commit is contained in:
Erik Johnson 2018-02-13 11:41:41 -06:00
parent 30fb8f7be0
commit 13cdb52690
No known key found for this signature in database
GPG Key ID: 5E5583C437808F3F

View File

@ -465,6 +465,10 @@ def _run(cmd,
else:
run_env = os.environ.copy()
run_env.update(env)
# Fix platforms like Solaris that don't set a USER env var in the
# user's default environment as obtained above.
if runas is not None and run_env.get('USER') != runas:
run_env['USER'] = runas
if python_shell is None:
python_shell = False