Skip to content

Commit

Permalink
Updated DOIDataBase.create_connection() to ensure group read/write bi…
Browse files Browse the repository at this point in the history
…ts are always set on the db file on disk

This ensures that users other than the installer/maintainer of the service can interact with the service on a fresh install of the database
  • Loading branch information
Scott Collins committed Nov 18, 2021
1 parent 9e7bdf1 commit 015b103
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/pds_doi_service/core/db/doi_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
Contains classes and functions for interfacing with the local transaction
database (SQLite3).
"""
import os
import sqlite3
import stat
from collections import OrderedDict
from datetime import datetime
from datetime import timedelta
Expand Down Expand Up @@ -94,6 +96,14 @@ def create_connection(self):
except Error as my_error:
logger.error("Failed to connect to database, reason: %s", my_error)

# Make sure Database has proper group permissions set
st = os.stat(self.m_database_name)
has_group_rw = bool(st.st_mode & stat.S_IRGRP & stat.S_IWGRP)

if not has_group_rw:
logger.debug("Setting group read/write bits on database %s", self.m_database_name)
os.chmod(self.m_database_name, st.st_mode | stat.S_IRGRP | stat.S_IWGRP)

def get_connection(self, table_name=None):
"""
Returns a connection to the SQLite database. If a connection does
Expand Down

0 comments on commit 015b103

Please sign in to comment.