diff options
| author | Christian Breunig <christian@breunig.cc> | 2025-12-09 23:15:39 +0100 |
|---|---|---|
| committer | Christian Breunig <christian@breunig.cc> | 2025-12-17 21:27:25 +0100 |
| commit | 197809bf77d841fe57bdcbaeeb3b078145aab140 (patch) | |
| tree | 6e044b10e3fa1648de2b6e8c6a3838da8e4dfa0d | |
| parent | 5566e6035b42e99eb874c3c5a35fe72e8435df38 (diff) | |
| download | vyos-1x-197809bf77d841fe57bdcbaeeb3b078145aab140.tar.gz vyos-1x-197809bf77d841fe57bdcbaeeb3b078145aab140.zip | |
login: T8086: replace getpwnam()/getpwuid() with get_local_passwd_entries()
Switch to our custom implementation to avoid NSS/TACACS timeouts as explained
in commit 4c9eaaa96e06 ("login: replace getpwall() user enumeration to avoid
NSS/TACACS timeouts").
| -rw-r--r-- | python/vyos/utils/auth.py | 7 | ||||
| -rwxr-xr-x | src/conf_mode/system_login.py | 3 |
2 files changed, 5 insertions, 5 deletions
diff --git a/python/vyos/utils/auth.py b/python/vyos/utils/auth.py index 4aa446455..f9551419f 100644 --- a/python/vyos/utils/auth.py +++ b/python/vyos/utils/auth.py @@ -20,7 +20,6 @@ import string from dataclasses import dataclass from decimal import Decimal -from pwd import getpwnam from enum import StrEnum from typing import List from typing import Optional @@ -215,7 +214,9 @@ def get_local_users(min_uid=MIN_USER_UID, max_uid=MAX_USER_UID) -> list: return local_users - def get_user_home_dir(user: str) -> str: """Return user's home directory""" - return getpwnam(user).pw_dir + for u in get_local_passwd_entries(): + if u.pw_name == user: + return u.pw_dir + raise KeyError(f"User '{user}' not found in /etc/passwd") diff --git a/src/conf_mode/system_login.py b/src/conf_mode/system_login.py index 4da1d10ae..3cff7a806 100755 --- a/src/conf_mode/system_login.py +++ b/src/conf_mode/system_login.py @@ -21,7 +21,6 @@ import json from copy import deepcopy from passlib.hosts import linux_context from psutil import users -from pwd import getpwuid from sys import exit from time import sleep @@ -432,7 +431,7 @@ def apply(login): # retrieve current owner of home directory and adjust on demand dir_owner = None try: - dir_owner = getpwuid(os.stat(home_dir).st_uid).pw_name + dir_owner = get_local_passwd_entries(os.stat(home_dir).st_uid).pw_name except: pass |
