Last active
February 4, 2016 13:52
-
-
Save Fi3/d83dba1e1fe7fb1689fd to your computer and use it in GitHub Desktop.
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
import os | |
import pwd | |
def linePrepender(filename, line): | |
with open(filename, 'r+') as f: | |
content = f.read() | |
if content.split('\n')[0] == line: | |
return | |
f.seek(0, 0) | |
f.write(line.rstrip('\r\n') + '\n' + content) | |
def lineSubstitutor(filename, line1, line2): | |
with open(filename, 'r+') as f: | |
content = f.read().split(line1) | |
f.seek(0, 0) | |
f.write(content[0] + line2.rstrip('\r\n') + '\n' + content[1]) | |
def changeUser(user): | |
pwRecord = pwd.getpwnam(user) | |
env = os.environ.copy() | |
env['HOME'] = pwRecord.pw_dir | |
env['LOGNAME'] = pwRecord.pw_name | |
env['PWD'] = pwRecord.pw_dir | |
env['USER'] = user | |
def demote(userUid, userGid): | |
def seyIds(): | |
os.setgid(userGid) | |
os.setuid(userUid) | |
return set_ids | |
return env, pwRecord | |
def demote(userUid, userGid): | |
def setIds(): | |
os.setgid(userGid) | |
os.setuid(userUid) | |
return setIds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment