Python os 模块,getresuid() 实例源码

我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用os.getresuid()

项目:onedrive-e    作者:tobecontinued    | 项目源码 | 文件源码
def get_current_os_user():
    """
    Find the real user who runs the current process. Return a tuple of uid, username, homedir.
    :rtype: (int, str, str, int)
    """
    user_name = os.getenv('SUDO_USER')
    if not user_name:
        user_name = os.getenv('USER')
    if user_name:
        pw = getpwnam(user_name)
        user_uid = pw.pw_uid
    else:
        # If cannot find the user, use ruid instead.
        user_uid = os.getresuid()[0]
        pw = getpwuid(user_uid)
        user_name = pw.pw_name
    user_gid = pw.pw_gid
    user_home = pw.pw_dir
    return user_uid, user_name, user_home, user_gid
项目:procszoo    作者:procszoo    | 项目源码 | 文件源码
def _accetable_user_map(user_map):
    if not user_map:
        return False

    ruid, euid, suid = getresuid()

    inter_id, outer_id, _range = _covert_map_to_tuple(user_map, 'user')

    if i_am_not_superuser():
        _id = outer_id
        _max_id = outer_id + _range
        if _range > 3:
            return False
        while _id < _max_id:
            if _id not in [ruid, euid, suid]:
                return False
            _id += 1

    return True
项目:procszoo    作者:procszoo    | 项目源码 | 文件源码
def get_current_users_and_groups(displayer=None):
    ruid, euid, suid = getresuid()
    rgid, egid, sgid = getresgid()
    supplementary_groups = os.getgroups()

    _supplementary_groups = []
    for _id in supplementary_groups:
        _name = get_name_by_gid(_id)
        _supplementary_groups.append({'name': _name, 'id': _id})

    return {
        'users': {
            'real user': {'name': get_name_by_uid(ruid), 'id': ruid},
            'effective user': {'name': get_name_by_uid(euid), 'id': euid},
            'saved user': {'name': get_name_by_uid(suid), 'id': suid},},
        'groups': {
            'real group': {'name': get_name_by_gid(rgid), 'id': rgid},
            'effective group': {'name': get_name_by_gid(rgid), 'id': rgid},
            'saved group': {'name': get_name_by_gid(rgid), 'id': rgid},},
        'supplementary_groups': _supplementary_groups,
        }
项目:respeaker_virtualenv    作者:respeaker    | 项目源码 | 文件源码
def test_uids(self):
        p = psutil.Process()
        real, effective, saved = p.uids()
        # os.getuid() refers to "real" uid
        self.assertEqual(real, os.getuid())
        # os.geteuid() refers to "effective" uid
        self.assertEqual(effective, os.geteuid())
        # no such thing as os.getsuid() ("saved" uid), but starting
        # from python 2.7 we have os.getresuid()[2]
        if hasattr(os, "getresuid"):
            self.assertEqual(saved, os.getresuid()[2])
项目:respeaker_virtualenv    作者:respeaker    | 项目源码 | 文件源码
def test_gids(self):
        p = psutil.Process()
        real, effective, saved = p.gids()
        # os.getuid() refers to "real" uid
        self.assertEqual(real, os.getgid())
        # os.geteuid() refers to "effective" uid
        self.assertEqual(effective, os.getegid())
        # no such thing as os.getsgid() ("saved" gid), but starting
        # from python 2.7 we have os.getresgid()[2]
        if hasattr(os, "getresuid"):
            self.assertEqual(saved, os.getresgid()[2])
项目:procszoo    作者:procszoo    | 项目源码 | 文件源码
def getresuid(self):
        try:
            os.getresuid
        except AttributeError:
            pass
        else:
            return os.getresuid()

        ruid = c_int()
        euid = c_int()
        suid = c_int()
        self._c_func_getresuid(ruid, euid, suid)

        return (ruid.value, euid.value, suid.value)
项目:procszoo    作者:procszoo    | 项目源码 | 文件源码
def getresuid():
    return workbench.getresuid()
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def test_uids(self):
        p = psutil.Process()
        real, effective, saved = p.uids()
        # os.getuid() refers to "real" uid
        self.assertEqual(real, os.getuid())
        # os.geteuid() refers to "effective" uid
        self.assertEqual(effective, os.geteuid())
        # no such thing as os.getsuid() ("saved" uid), but starting
        # from python 2.7 we have os.getresuid()[2]
        if hasattr(os, "getresuid"):
            self.assertEqual(saved, os.getresuid()[2])
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def test_gids(self):
        p = psutil.Process()
        real, effective, saved = p.gids()
        # os.getuid() refers to "real" uid
        self.assertEqual(real, os.getgid())
        # os.geteuid() refers to "effective" uid
        self.assertEqual(effective, os.getegid())
        # no such thing as os.getsgid() ("saved" gid), but starting
        # from python 2.7 we have os.getresgid()[2]
        if hasattr(os, "getresuid"):
            self.assertEqual(saved, os.getresgid()[2])
项目:FancyWord    作者:EastonLee    | 项目源码 | 文件源码
def test_uids(self):
        p = psutil.Process()
        real, effective, saved = p.uids()
        # os.getuid() refers to "real" uid
        self.assertEqual(real, os.getuid())
        # os.geteuid() refers to "effective" uid
        self.assertEqual(effective, os.geteuid())
        # No such thing as os.getsuid() ("saved" uid), but starting
        # from python 2.7 we have os.getresuid() which returns all
        # of them.
        if hasattr(os, "getresuid"):
            self.assertEqual(os.getresuid(), p.uids())
项目:FancyWord    作者:EastonLee    | 项目源码 | 文件源码
def test_gids(self):
        p = psutil.Process()
        real, effective, saved = p.gids()
        # os.getuid() refers to "real" uid
        self.assertEqual(real, os.getgid())
        # os.geteuid() refers to "effective" uid
        self.assertEqual(effective, os.getegid())
        # No such thing as os.getsgid() ("saved" gid), but starting
        # from python 2.7 we have os.getresgid() which returns all
        # of them.
        if hasattr(os, "getresuid"):
            self.assertEqual(os.getresgid(), p.gids())