def check(self):
"""Verify correct permissions and ownership of database files."""
scheme, _, file, _, _ = urlsplit(settings.DB_URI)
if scheme != 'file':
log.warning('DB_URI does not point to a file but %s -- forgot to set "BUILTIN_ZEO = False"?', scheme)
return
try:
st = os.stat(file)
except FileNotFoundError:
# Database not created yet, not an error.
return
error = False
if st.st_uid != os.geteuid():
log.error('Database file %s has wrong owner: %d (file) vs %d (daemon user)', file, st.st_uid, os.geteuid())
error = True
if st.st_gid != os.getegid():
log.error('Database file %s has wrong group: %d (file) vs %d (daemon user)', file, st.st_gid, os.getegid())
# not a critical error, could be, theoretically, on purpose
if error:
sys.exit(1)
# Fix perms, if any
perms = stat.S_IMODE(st.st_mode)
perms_should_be = perms & ~stat.S_IRWXO
if perms != perms_should_be:
try:
os.chmod(file, perms_should_be)
except OSError as ose:
log.debug('Tried to fix permissions on database file, but it didn\'t work: %s', file, ose)
评论列表
文章目录