Files
honey-biscuit-workshop/tests/probes/user.py
T
Catty Steve cf317b55c6
CI / ${{ matrix.crate }} (workshop-engine) (push) Failing after 28m8s
CI / ${{ matrix.crate }} (workshop-baker) (push) Failing after 33m39s
feat(pm): add apk/dnf implementations and multi-distro test
infrastructure
2026-04-27 23:01:43 +08:00

42 lines
914 B
Python

"""User existence and attribute probes."""
import pwd
import grp
def user_exists(username: str) -> bool:
"""Check if a system user exists."""
try:
pwd.getpwnam(username)
return True
except KeyError:
return False
def user_uid(username: str) -> int | None:
try:
return pwd.getpwnam(username).pw_uid
except KeyError:
return None
def user_gid(username: str) -> int | None:
try:
return pwd.getpwnam(username).pw_gid
except KeyError:
return None
def user_in_group(username: str, groupname: str) -> bool:
"""Check if a user is a member of a group."""
try:
group = grp.getgrnam(groupname)
return username in group.gr_mem
except KeyError:
return False
def user_shell(username: str) -> str | None:
try:
return pwd.getpwnam(username).pw_shell
except KeyError:
return None