Detect the invoking user when running with doas
User detection only checked SUDO_USER, so with doas the user's config file was not found unless -u was given. Fall back to DOAS_USER, as already done for notifications.
This commit is contained in:
@@ -644,14 +644,15 @@ class Backup:
|
||||
return 0
|
||||
|
||||
|
||||
def _detect_user() -> Optional[str]:
|
||||
if os.geteuid() == 0:
|
||||
return os.getenv('SUDO_USER') or os.getenv('DOAS_USER')
|
||||
|
||||
return os.getenv('USER')
|
||||
|
||||
|
||||
def _parse_arguments() -> argparse.Namespace:
|
||||
euid = os.geteuid()
|
||||
|
||||
if euid == 0:
|
||||
user = os.getenv('SUDO_USER')
|
||||
else:
|
||||
user = os.getenv('USER')
|
||||
|
||||
user = _detect_user()
|
||||
homedir = os.path.expanduser(f'~{user}')
|
||||
|
||||
parser = argparse.ArgumentParser(prog='simple_backup',
|
||||
@@ -874,7 +875,7 @@ def simple_backup() -> int:
|
||||
euid = os.geteuid()
|
||||
|
||||
if euid == 0:
|
||||
user = os.getenv('SUDO_USER')
|
||||
user = _detect_user()
|
||||
|
||||
if user is not None:
|
||||
homedir = os.path.expanduser(f'~{user}')
|
||||
|
||||
Reference in New Issue
Block a user