Corrected permissions on database file (and parent folder for #48)

This commit is contained in:
Simonmicro 2021-12-23 17:28:24 +01:00
parent 476f7faf4e
commit bc3c504fe3
No known key found for this signature in database
GPG key ID: 033A4D4CE4E063D6

View file

@ -10,7 +10,7 @@ import subprocess
import sys
PYTHON3 = '/usr/bin/python3'
dbPath = os.path.join(os.sep, 'home', 'py-kms', 'db', 'pykms_database.db')
dbPath = os.path.join(os.sep, 'home', 'py-kms', 'db') # Do not include the database file name, as we must correct the folder permissions (the db file is recursively reachable)
log_level_bootstrap = log_level = os.getenv('LOGLEVEL', 'INFO')
if log_level_bootstrap == "MININFO":
log_level_bootstrap = "INFO"
@ -34,8 +34,13 @@ def change_uid_grp():
os.chown("/home/py-kms", new_uid, new_gid)
os.chown("/usr/bin/start.py", new_uid, new_gid)
if os.path.isfile(dbPath):
os.chown(dbPath, new_uid, new_gid)
loggersrv.debug("%s" %str(subprocess.check_output("ls -al " + dbPath, shell=True)))
# Corret permissions recursively, as to access the database file, also its parent folder must be accessible
for root, dirs, files in os.walk(dbPath):
for dName in dirs:
os.chown(os.path.join(root, dName), new_uid, new_gid)
for fName in files:
os.chown(os.path.join(root, fName), new_uid, new_gid)
loggersrv.debug(str(subprocess.check_output(['ls', '-la', dbPath])))
loggersrv.info("Setting gid to '%s'." % str(new_gid))
os.setgid(new_gid)