Skip to content

Instantly share code, notes, and snippets.

@nicolas17
Forked from rubic/gist:1644599
Created May 12, 2012 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicolas17/2663579 to your computer and use it in GitHub Desktop.
Save nicolas17/2663579 to your computer and use it in GitHub Desktop.
setuid via subprocess.Popen
#!/usr/bin/env python
import os, subprocess
def change_identity(uid, gid):
def func():
os.setgid(uid)
os.setuid(gid)
return func
cmd = ['uname', '-a']
process = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
preexec_fn=change_identity(5, 60))
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