当前位置: 首页>>代码示例>>Python>>正文


Python os.setregid方法代码示例

本文整理汇总了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']) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:22,代码来源:test_process.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_os.py

示例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)']) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_os.py

示例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) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:7,代码来源:test_os.py

示例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)']) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:8,代码来源:test_os.py

示例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) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:7,代码来源:test_os.py

示例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)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:7,代码来源:test_process.py

示例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 
开发者ID:offlinemark,项目名称:poet,代码行数:32,代码来源:server.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_os.py

示例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) 
开发者ID:rpm-software-management,项目名称:mock,代码行数:7,代码来源:util.py

示例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']) 
开发者ID:rpm-software-management,项目名称:mock,代码行数:12,代码来源:uid.py

示例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) 
开发者ID:rpm-software-management,项目名称:mock,代码行数:6,代码来源:uid.py

示例13: _elevatePrivs

# 需要导入模块: import os [as 别名]
# 或者: from os import setregid [as 别名]
def _elevatePrivs(self):
        setresuid(0, 0, 0)
        os.setregid(0, 0) 
开发者ID:rpm-software-management,项目名称:mock,代码行数:5,代码来源:uid.py

示例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) 
开发者ID:rpm-software-management,项目名称:mock,代码行数:7,代码来源:uid.py

示例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) 
开发者ID:HewlettPackard,项目名称:reconbf,代码行数:12,代码来源:test_binaries.py


注:本文中的os.setregid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。