1
0
mirror of https://github.com/altlinux/gpupdate.git synced 2025-03-20 18:50:17 +03:00

util.users: module to work with usernames and UIDs

This commit is contained in:
Игорь Чудов 2019-12-20 19:27:24 +04:00
parent 990ca53f7c
commit 9cc519643b
Signed by untrusted user: nir
GPG Key ID: 0F3883600CAE7AAC

34
gpoa/util/users.py Normal file
View File

@ -0,0 +1,34 @@
import os
import pwd
def is_root():
'''
Check if current process has root permissions.
'''
if 0 == os.getuid():
return True
return False
def get_process_user():
'''
Get current process username.
'''
username = None
uid = os.getuid()
username = pwd.getpwuid(uid).pw_name
return username
def username_match_uid(username):
'''
Check the passed username matches current process UID.
'''
uid = os.getuid()
process_username = get_process_user()
if process_username == username:
return True
return False