本文整理汇总了Python中os.setregid方法的典型用法代码示例。如果您正苦于以下问题:Python os.setregid方法的具体用法?Python os.setregid怎么用?Python os.setregid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.setregid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_mockPTYSetUidInParent
# 需要导入模块: import os [as 别名]
# 或者: from os import setregid [as 别名]
def test_mockPTYSetUidInParent(self):
"""
Try creating a PTY process with setting its uid, in the parent path: it
should switch to root before fork, then restore initial uid/gids.
"""
self.mockos.child = False
cmd = '/mock/ouch'
d = defer.Deferred()
p = TrivialProcessProtocol(d)
oldPTYProcess = process.PTYProcess
try:
process.PTYProcess = DumbPTYProcess
reactor.spawnProcess(p, cmd, ['ouch'], env=None,
usePTY=True, uid=8080)
finally:
process.PTYProcess = oldPTYProcess
self.assertEquals(self.mockos.actions,
[('setuid', 0), ('setgid', 0), ('fork', False),
('setregid', 1235, 1234), ('setreuid', 1237, 1236), 'waitpid'])
示例2: test_setregid
# 需要导入模块: import os [as 别名]
# 或者: from os import setregid [as 别名]
def test_setregid(self):
if os.getuid() != 0:
self.assertRaises(os.error, os.setregid, 0, 0)
self.assertRaises(TypeError, os.setregid, 'not an int', 0)
self.assertRaises(TypeError, os.setregid, 0, 'not an int')
self.assertRaises(OverflowError, os.setregid, 1<<32, 0)
self.assertRaises(OverflowError, os.setregid, 0, 1<<32)
示例3: test_setregid_neg1
# 需要导入模块: import os [as 别名]
# 或者: from os import setregid [as 别名]
def test_setregid_neg1(self):
# Needs to accept -1. We run this in a subprocess to avoid
# altering the test runner's process state (issue8045).
subprocess.check_call([
sys.executable, '-c',
'import os,sys;os.setregid(-1,-1);sys.exit(0)'])
示例4: test_setregid
# 需要导入模块: import os [as 别名]
# 或者: from os import setregid [as 别名]
def test_setregid(self):
if os.getuid() != 0:
self.assertRaises(os.error, os.setregid, 0, 0)
self.assertRaises(OverflowError, os.setregid, 1<<32, 0)
self.assertRaises(OverflowError, os.setregid, 0, 1<<32)
示例5: test_setregid_neg1
# 需要导入模块: import os [as 别名]
# 或者: from os import setregid [as 别名]
def test_setregid_neg1(self):
# Needs to accept -1. We run this in a subprocess to avoid
# altering the test runner's process state (issue8045).
subprocess.check_call([
sys.executable, '-c',
'import os,sys;os.setregid(-1,-1);sys.exit(0)'])
示例6: test_setregid
# 需要导入模块: import os [as 别名]
# 或者: from os import setregid [as 别名]
def test_setregid(self):
if os.getuid() != 0:
self.assertRaises(os.error, os.setregid, 0, 0)
self.assertRaises(OverflowError, os.setregid, 1<<32, 0)
self.assertRaises(OverflowError, os.setregid, 0, 1<<32)
示例7: setregid
# 需要导入模块: import os [as 别名]
# 或者: from os import setregid [as 别名]
def setregid(self, val1, val2):
"""
Override C{os.setregid}. Do nothing.
"""
self.actions.append(('setregid', val1, val2))
示例8: drop_privs
# 需要导入模块: import os [as 别名]
# 或者: from os import setregid [as 别名]
def drop_privs():
try:
new_uid = int(os.getenv('SUDO_UID'))
new_gid = int(os.getenv('SUDO_GID'))
except TypeError:
# they were running directly from a root user and didn't have
# sudo env variables
print """[!] WARNING: Couldn't drop privileges! To avoid this error, run from a non-root user.
You may also use sudo, from a non-root user. Continue? (y/n)""",
if raw_input().lower()[0] == 'y':
return
die()
debug.info('Dropping privileges to uid: {}, gid: {}'.format(new_uid,
new_gid))
# drop group before user, because otherwise you're not privileged enough
# to drop group
os.setgroups([])
os.setregid(new_gid, new_gid)
os.setreuid(new_uid, new_uid)
# check to make sure we can't re-escalate
try:
os.seteuid(0)
print '[!] WARNING: Failed to drop privileges! Continue? (y/n)',
if raw_input().lower()[0] != 'y':
die()
except OSError:
return
示例9: test_setregid
# 需要导入模块: import os [as 别名]
# 或者: from os import setregid [as 别名]
def test_setregid(self):
if os.getuid() != 0 and not HAVE_WHEEL_GROUP:
self.assertRaises(OSError, os.setregid, 0, 0)
self.assertRaises(OverflowError, os.setregid, 1<<32, 0)
self.assertRaises(OverflowError, os.setregid, 0, 1<<32)
示例10: condDropPrivs
# 需要导入模块: import os [as 别名]
# 或者: from os import setregid [as 别名]
def condDropPrivs(uid, gid):
if gid is not None:
os.setregid(gid, gid)
if uid is not None:
os.setreuid(uid, uid)
示例11: restorePrivs
# 需要导入模块: import os [as 别名]
# 或者: from os import setregid [as 别名]
def restorePrivs(self):
# back to root first
self._elevatePrivs()
# then set saved
privs = self.privStack.pop()
os.environ.clear()
os.environ.update(self.privEnviron.pop())
os.setregid(privs['rgid'], privs['egid'])
setresuid(privs['ruid'], privs['euid'])
示例12: dropPrivsForever
# 需要导入模块: import os [as 别名]
# 或者: from os import setregid [as 别名]
def dropPrivsForever(self):
self._elevatePrivs()
os.setregid(self.unprivGid, self.unprivGid)
os.setreuid(self.unprivUid, self.unprivUid)
示例13: _elevatePrivs
# 需要导入模块: import os [as 别名]
# 或者: from os import setregid [as 别名]
def _elevatePrivs(self):
setresuid(0, 0, 0)
os.setregid(0, 0)
示例14: become_user_without_push
# 需要导入模块: import os [as 别名]
# 或者: from os import setregid [as 别名]
def become_user_without_push(self, uid, gid=None):
self._elevatePrivs()
if gid is not None:
os.setregid(gid, gid)
setresuid(uid, uid, 0)
示例15: _safe_child
# 需要导入模块: import os [as 别名]
# 或者: from os import setregid [as 别名]
def _safe_child(to_exec, q, uid, gid):
try:
os.setgroups([])
os.setregid(gid, gid)
os.setreuid(uid, uid)
res = subprocess.check_output(to_exec, stderr=open(os.devnull, 'w'))
q.put(res)
except Exception as e:
q.put(e)