2020-01-10 18:59:56 +04:00
#
2020-02-11 15:23:09 +04:00
# GPOA - GPO Applier for Linux
#
2021-07-13 03:44:22 +04:00
# Copyright (C) 2019-2021 BaseALT Ltd.
2020-01-10 18:59:56 +04:00
#
2020-02-11 15:23:09 +04:00
# This program is free software: you can redistribute it and/or modify
2020-01-10 18:59:56 +04:00
# it under the terms of the GNU General Public License as published by
2020-02-11 15:23:09 +04:00
# the Free Software Foundation, either version 3 of the License, or
2020-01-10 18:59:56 +04:00
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
2020-02-11 15:23:09 +04:00
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2020-01-10 18:59:56 +04:00
2019-12-20 19:27:24 +04:00
import os
import pwd
2019-12-26 01:08:42 +04:00
2020-07-29 17:33:09 +04:00
from . logging import log
2019-12-20 19:27:24 +04:00
2020-01-17 17:29:54 +04:00
2019-12-20 19:27:24 +04:00
def is_root ( ) :
'''
Check if current process has root permissions .
'''
2020-01-17 17:29:54 +04:00
if os . getuid ( ) == 0 :
2019-12-20 19:27:24 +04:00
return True
return False
2020-01-17 17:29:54 +04:00
2019-12-20 19:27:24 +04:00
def get_process_user ( ) :
'''
Get current process username .
'''
username = None
uid = os . getuid ( )
username = pwd . getpwuid ( uid ) . pw_name
return username
2020-01-17 17:29:54 +04:00
2019-12-20 19:27:24 +04:00
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