From 715f1c8415862360421046de23c670cf0ec36134 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Sun, 2 Aug 2026 13:37:10 +0545 Subject: [PATCH] refactor(password): verify su through run_command --- src/utils/password.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/utils/password.py b/src/utils/password.py index 62f7a83..a18a3b1 100644 --- a/src/utils/password.py +++ b/src/utils/password.py @@ -4,10 +4,10 @@ Provides PAM-based password verification with su fallback, and system keyring integration for caching authenticated passwords. """ -import subprocess - from fabric.utils import logger +from utils.functions import run_command + KEYRING_SERVICE = "sysauth" @@ -42,17 +42,12 @@ def _verify_pam(username: str, password: str) -> bool: def _verify_su(username: str, password: str) -> bool: """Verify password using the su command as fallback.""" - try: - result = subprocess.run( - ["su", "-c", "true", username], - input=password.encode(), - capture_output=True, - timeout=5, - ) - return result.returncode == 0 - except (subprocess.TimeoutExpired, FileNotFoundError, PermissionError) as e: - logger.warning(f"[password] su verification failed: {e}") - return False + result = run_command( + ["su", "-c", "true", username], + input=password, + timeout=5, + ) + return result.returncode == 0 def cache_password(action_id: str, uid: int, password: str) -> None: