infinoted: Always check ownership of cert files in setup

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2018-03-05 18:53:02 +01:00 committed by Sunil Mohan Adapa
parent 943142a0a5
commit 474b363f0b
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2

View File

@ -15,7 +15,6 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
""" """
Configuration helper for infinoted. Configuration helper for infinoted.
""" """
@ -29,7 +28,6 @@ import subprocess
from plinth import action_utils from plinth import action_utils
DATA_DIR = '/var/lib/infinoted' DATA_DIR = '/var/lib/infinoted'
KEY_DIR = '/etc/infinoted' KEY_DIR = '/etc/infinoted'
@ -134,10 +132,11 @@ def subcommand_setup(_):
try: try:
pwd.getpwnam('infinoted') pwd.getpwnam('infinoted')
except KeyError: except KeyError:
subprocess.run(['adduser', '--system', '--ingroup', 'infinoted', subprocess.run([
'--home', DATA_DIR, 'adduser', '--system', '--ingroup', 'infinoted', '--home',
'--gecos', 'Infinoted collaborative editing server', DATA_DIR, '--gecos', 'Infinoted collaborative editing server',
'infinoted'], check=True) 'infinoted'
], check=True)
if not os.path.exists(DATA_DIR): if not os.path.exists(DATA_DIR):
os.makedirs(DATA_DIR, mode=0o750) os.makedirs(DATA_DIR, mode=0o750)
@ -152,16 +151,20 @@ def subcommand_setup(_):
try: try:
# infinoted doesn't have a "create key and exit" mode. Run as # infinoted doesn't have a "create key and exit" mode. Run as
# daemon so we can stop after. # daemon so we can stop after.
subprocess.run(['infinoted', '--create-key', subprocess.run([
'--create-certificate', '--daemonize'], check=True) 'infinoted', '--create-key', '--create-certificate',
'--daemonize'
], check=True)
subprocess.run(['infinoted', '--kill-daemon'], check=True) subprocess.run(['infinoted', '--kill-daemon'], check=True)
finally: finally:
os.umask(old_umask) os.umask(old_umask)
shutil.chown(KEY_DIR + '/infinoted-cert.pem', # Always check the ownership of certificate files, in case setup
user='infinoted', group='infinoted') # failed previously.
shutil.chown(KEY_DIR + '/infinoted-key.pem', shutil.chown(KEY_DIR + '/infinoted-cert.pem', user='infinoted',
user='infinoted', group='infinoted') group='infinoted')
shutil.chown(KEY_DIR + '/infinoted-key.pem', user='infinoted',
group='infinoted')
action_utils.service_enable('infinoted') action_utils.service_enable('infinoted')