audit _run: retry sans sudo accepte sortie vide (pas containers/failed = OK, pas erreur)

This commit is contained in:
Pierre & Lumière 2026-04-15 12:18:35 +02:00
parent 1a1af9e28a
commit 0dc9b07edd

View File

@ -246,19 +246,23 @@ def _run(client, cmd):
err = stderr.read().decode("utf-8", errors="replace").strip() err = stderr.read().decode("utf-8", errors="replace").strip()
# Fallback sans sudo si sudoers refuse (detection robuste case/accent insensible) # Fallback sans sudo si sudoers refuse (detection robuste case/accent insensible)
SUDO_KW = ["pas autoris", "non autoris", "not allowed to execute",
"is not allowed", "no tty present", "sudo:"]
err_low = err.lower() err_low = err.lower()
sudo_refused = any(kw in err_low for kw in [ sudo_refused = any(kw in err_low for kw in SUDO_KW)
"pas autoris", "non autoris", "not allowed to execute",
"is not allowed", "no tty present", "sudo:",
])
if (not out) and err and sudo_refused: if (not out) and err and sudo_refused:
_, stdout, stderr = client.exec_command(cmd, timeout=15) _, stdout, stderr = client.exec_command(cmd, timeout=15)
out = stdout.read().decode("utf-8", errors="replace").strip() out = stdout.read().decode("utf-8", errors="replace").strip()
err2 = stderr.read().decode("utf-8", errors="replace").strip() err2 = stderr.read().decode("utf-8", errors="replace").strip()
if out: err2_low = err2.lower()
err = "" still_sudo_err = any(kw in err2_low for kw in SUDO_KW)
if still_sudo_err:
err = err2
else: else:
err = err2 or err # Retry sans sudo a abouti (sortie vide acceptable)
err = err2 if err2 else ""
if not out and not err:
out = "" # explicite : pas de containers / pas de services failed = OK
result = out if out else err result = out if out else err
lines = [l for l in result.splitlines() if not any(b in l for b in BANNER_FILTERS) and l.strip()] lines = [l for l in result.splitlines() if not any(b in l for b in BANNER_FILTERS) and l.strip()]