Fix: unlock database
This commit is contained in:
parent
f664d07c77
commit
63fc1ffd0e
5 changed files with 17 additions and 7 deletions
|
|
@ -7,6 +7,8 @@
|
|||
# Libre comme l’air, stable comme un menhir, et salé comme le beurre.
|
||||
#
|
||||
|
||||
import os
|
||||
import pwd
|
||||
import sqlite3
|
||||
from erminig.config import Config
|
||||
|
||||
|
|
@ -20,6 +22,12 @@ def init_db():
|
|||
conn.executescript(f.read())
|
||||
conn.commit()
|
||||
conn.close()
|
||||
# Attribution au user pak
|
||||
pak_uid = pwd.getpwnam("pak").pw_uid
|
||||
pak_gid = pwd.getpwnam("pak").pw_gid
|
||||
os.chown(Config.DB_PATH, pak_uid, pak_gid)
|
||||
os.chmod(Config.DB_PATH, 0o664)
|
||||
|
||||
print("Base erminig.db initialisée avec succès.")
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ def run_as_user(username):
|
|||
try:
|
||||
pid = os.fork()
|
||||
if pid > 0:
|
||||
# Parent
|
||||
# Parent : attendre le child, ne pas exit, juste return proprement
|
||||
_, status = os.waitpid(pid, 0)
|
||||
return os.WEXITSTATUS(status)
|
||||
return status >> 8 # récupère le code retour du fils (comme exit code)
|
||||
|
||||
# Child
|
||||
pw_record = pwd.getpwnam(username)
|
||||
|
|
@ -51,14 +51,13 @@ def run_as_user(username):
|
|||
os.setgid(user_gid)
|
||||
os.setuid(user_uid)
|
||||
|
||||
# Exécuter la fonction sous l'utilisateur demandé
|
||||
result = func(*args, **kwargs)
|
||||
sys.exit(0 if result is None else int(bool(result)))
|
||||
os._exit(0 if result is None else int(bool(result)))
|
||||
|
||||
except OSError as e:
|
||||
print(f"[SECURITY] Fork échoué : {e}")
|
||||
sys.exit(1)
|
||||
os._exit(1)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
return decorator
|
||||
Loading…
Add table
Add a link
Reference in a new issue