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:
parent
990ca53f7c
commit
9cc519643b
34
gpoa/util/users.py
Normal file
34
gpoa/util/users.py
Normal 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user