Prerequisites:
- python2.6
- GNU Linux
I have some questions regarding the 'subprocess.call' behavior and securing http server.
The following code examples differ in not using/using shell:
1
sudo python -c "from subprocess import call; from os import setreuid, setregid; setreuid(1000,0); setregid(1000,0); call(['touch','./aaa'])"
produces a file owned by 'root'.
2
sudo python -c "from subprocess import call; from os import setreuid, setregid; setreuid(1000,0); setregid(1000,0); call('touch ./aaa', shell=True)"
produces a file owned by user 1000.
Questions:
What is the reason to produce a file owned by effective user in the first case and real user in the second case?
Is there a way in python2.6 (no 'setresuid') to temporarily (and safely) change user within a python code?
Is it safe to use privileged effective user for temporal real user changes to raise/lower privileges?