Add hardering
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from datetime import datetime
|
||||
|
||||
@@ -14,6 +15,20 @@ from .storage import ScenarioStore
|
||||
from .system_info import detect_system
|
||||
|
||||
|
||||
def ensure_root() -> None:
|
||||
if os.geteuid() == 0:
|
||||
return
|
||||
if os.environ.get("SECURECHECK_SKIP_SUDO") == "1":
|
||||
return
|
||||
args = sys.argv[1:]
|
||||
if getattr(sys, "frozen", False):
|
||||
target = sys.argv[0]
|
||||
cmd = ["sudo", "-E", target, *args]
|
||||
else:
|
||||
cmd = ["sudo", "-E", sys.executable, "-m", "securecheck", *args]
|
||||
os.execvp("sudo", cmd)
|
||||
|
||||
|
||||
def parse_args() -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(description="SecureCheck - console semi-graphique pour contrôles sécurité Linux")
|
||||
parser.add_argument("--dry-run", action="store_true", help="Simule les commandes sans modifier le système")
|
||||
@@ -66,6 +81,7 @@ def print_summary(results, run_log_path, system) -> None:
|
||||
|
||||
|
||||
def main() -> int:
|
||||
ensure_root()
|
||||
args = parse_args()
|
||||
paths = build_paths()
|
||||
ensure_app_dirs(paths)
|
||||
@@ -77,6 +93,7 @@ def main() -> int:
|
||||
store = ScenarioStore(paths.scenario_file, builtin_scenarios())
|
||||
|
||||
if args.list_scenarios:
|
||||
print(f"Scénarios stockés dans {paths.scenario_file}")
|
||||
for scenario in store.list_all():
|
||||
print(f"{scenario.name}: {scenario.description}")
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user