Python os.getresuid() Examples

The following are code examples for showing how to use os.getresuid(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: onedrive-e   Author: tobecontinued   File: utils.py    (license) View Source Project 6 votes vote down vote up
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 
Example 2
Project: procszoo   Author: procszoo   File: __init__.py    (license) View Source Project 6 votes vote down vote up
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 
Example 3
Project: procszoo   Author: procszoo   File: __init__.py    (license) View Source Project 6 votes vote down vote up
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,
        } 
Example 4
Project: respeaker_virtualenv   Author: respeaker   File: test_process.py    (license) View Source Project 5 votes vote down vote up
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]) 
Example 5
Project: respeaker_virtualenv   Author: respeaker   File: test_process.py    (license) View Source Project 5 votes vote down vote up
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]) 
Example 6
Project: procszoo   Author: procszoo   File: __init__.py    (license) View Source Project 5 votes vote down vote up
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) 
Example 7
Project: procszoo   Author: procszoo   File: __init__.py    (license) View Source Project 5 votes vote down vote up
def getresuid():
    return workbench.getresuid() 
Example 8
Project: zenchmarks   Author: squeaky-pl   File: test_process.py    (license) View Source Project 5 votes vote down vote up
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]) 
Example 9
Project: zenchmarks   Author: squeaky-pl   File: test_process.py    (license) View Source Project 5 votes vote down vote up
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]) 
Example 10
Project: FancyWord   Author: EastonLee   File: test_process.py    (license) View Source Project 5 votes vote down vote up
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()) 
Example 11
Project: FancyWord   Author: EastonLee   File: test_process.py    (license) View Source Project 5 votes vote down vote up
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())