Created
January 20, 2012 02:33
-
-
Save rubic/1644599 to your computer and use it in GitHub Desktop.
setuid via subprocess.Popen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os, subprocess | |
uid, gid = 5, 60 | |
def preexec_fn(): | |
os.setgid(uid) | |
os.setuid(gid) | |
cmd = ['uname', '-a'] | |
process = subprocess.Popen(cmd, | |
stdout=subprocess.PIPE, | |
stderr=subprocess.STDOUT, | |
preexec_fn=preexec_fn) | |
outs, errs = process.communicate() | |
print "process return code:", process.returncode | |
print "stderr:", errs | |
print "stdout:", outs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment