diff options
author | Helmut Grohne <helmut@subdivi.de> | 2025-07-11 14:47:37 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2025-07-11 14:47:37 +0200 |
commit | c97c6de178e727efdad42f08f6354d958fdb6b0d (patch) | |
tree | 8cb307b0290b5cf5c50ce1dbb56800e22dc127dc | |
parent | 58dca9beea23e4e18c67f6f13838f5a895ca150f (diff) | |
download | python-linuxnamespaces-c97c6de178e727efdad42f08f6354d958fdb6b0d.tar.gz |
prefer getpass.getuser() over os.getlogin()
os.getlogin() returns an undesired value in a runuser environment and is
not overridable with environment.
-rwxr-xr-x | examples/unschroot_fs.py | 5 | ||||
-rwxr-xr-x | examples/unschroot_proc.py | 5 | ||||
-rw-r--r-- | linuxnamespaces/idmap.py | 3 |
3 files changed, 10 insertions, 3 deletions
diff --git a/examples/unschroot_fs.py b/examples/unschroot_fs.py index 68e2320..a07f32d 100755 --- a/examples/unschroot_fs.py +++ b/examples/unschroot_fs.py @@ -18,6 +18,7 @@ between calls with no background processes or persistent namespaces. import argparse import grp +import getpass import os import pathlib import pwd @@ -474,7 +475,9 @@ def main() -> None: parser.add_argument("-d", "--directory", action="store") parser.add_argument("-p", "--preserve-environment", action="store_true") parser.add_argument("-q", "--quiet", action="store_true") - parser.add_argument("-u", "--user", action="store", default=os.getlogin()) + parser.add_argument( + "-u", "--user", action="store", default=getpass.getuser() + ) parser.add_argument("--isolate-network", action="store_true") parser.add_argument("command", nargs="*") args = parser.parse_args() diff --git a/examples/unschroot_proc.py b/examples/unschroot_proc.py index dc5cc94..31cb1e8 100755 --- a/examples/unschroot_proc.py +++ b/examples/unschroot_proc.py @@ -24,6 +24,7 @@ import configparser import contextlib import errno import functools +import getpass import itertools import os import pathlib @@ -1020,7 +1021,9 @@ def main() -> None: parser.add_argument("-n", "--session-name", action="store", default=None) parser.add_argument("-p", "--preserve-environment", action="store_true") parser.add_argument("-q", "--quiet", action="store_true") - parser.add_argument("-u", "--user", action="store", default=os.getlogin()) + parser.add_argument( + "-u", "--user", action="store", default=getpass.getuser() + ) parser.add_argument("--isolate-network", action="store_true") parser.add_argument("command", nargs="*") args = parser.parse_args() diff --git a/linuxnamespaces/idmap.py b/linuxnamespaces/idmap.py index a10ec12..8f33d70 100644 --- a/linuxnamespaces/idmap.py +++ b/linuxnamespaces/idmap.py @@ -7,6 +7,7 @@ namespace. import bisect import dataclasses +import getpass import os import subprocess import typing @@ -21,7 +22,7 @@ def subidranges( user. Return all ranges as (start, count) pairs. """ if login is None: - login = os.getlogin() + login = getpass.getuser() with open(f"/etc/sub{kind}") as filelike: for line in filelike: parts = line.strip().split(":") |