mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
email: Fix enabling SMTPS; check return value
- master.cf: Enable SMTPS - lock.Mutex: check the return value of lock.acquire - Write debug logs
This commit is contained in:
parent
10c3a667b6
commit
f20929c23f
@ -1,6 +1,8 @@
|
|||||||
"""Audit of LDAP and mail submission settings"""
|
"""Audit of LDAP and mail submission settings"""
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
|
|
||||||
import plinth.modules.email_server.postconf as postconf
|
import plinth.modules.email_server.postconf as postconf
|
||||||
@ -26,6 +28,20 @@ default_submission_options = {
|
|||||||
'smtpd_relay_restrictions': 'permit_sasl_authenticated,reject'
|
'smtpd_relay_restrictions': 'permit_sasl_authenticated,reject'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
smtps_flags = postconf.ServiceFlags(
|
||||||
|
service='smtps', type='inet', private='n', unpriv='-', chroot='y',
|
||||||
|
wakeup='-', maxproc='-', command_args='smtpd'
|
||||||
|
)
|
||||||
|
|
||||||
|
default_smtps_options = {
|
||||||
|
'syslog_name': 'postfix/smtps',
|
||||||
|
'smtpd_tls_wrappermode': 'yes',
|
||||||
|
'smtpd_sasl_auth_enable': 'yes',
|
||||||
|
'smtpd_relay_restrictions': 'permit_sasl_authenticated,reject'
|
||||||
|
}
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def get():
|
def get():
|
||||||
"""Compare current values with the default. Generate an audit report
|
"""Compare current values with the default. Generate an audit report
|
||||||
@ -47,7 +63,13 @@ def repair():
|
|||||||
Recommended endpoint name:
|
Recommended endpoint name:
|
||||||
POST /audit/ldap/repair
|
POST /audit/ldap/repair
|
||||||
"""
|
"""
|
||||||
|
logger.debug('Updating postconf: %r', default_config)
|
||||||
actions.superuser_run('email_server', ['ipc', 'set_sasl'])
|
actions.superuser_run('email_server', ['ipc', 'set_sasl'])
|
||||||
|
|
||||||
|
logger.debug('Setting up postfix %s service in master.cf: %r',
|
||||||
|
submission_flags.service, default_submission_options)
|
||||||
|
logger.debug('And postfix %s service: %r', smtps_flags.service,
|
||||||
|
default_smtps_options)
|
||||||
actions.superuser_run('email_server', ['ipc', 'set_submission'])
|
actions.superuser_run('email_server', ['ipc', 'set_submission'])
|
||||||
|
|
||||||
|
|
||||||
@ -60,3 +82,5 @@ def action_set_submission():
|
|||||||
"""Called by email_server ipc set_submission"""
|
"""Called by email_server ipc set_submission"""
|
||||||
postconf.set_master_cf_options(service_flags=submission_flags,
|
postconf.set_master_cf_options(service_flags=submission_flags,
|
||||||
options=default_submission_options)
|
options=default_submission_options)
|
||||||
|
postconf.set_master_cf_options(service_flags=smtps_flags,
|
||||||
|
options=default_smtps_options)
|
||||||
|
|||||||
@ -25,7 +25,7 @@ class Result:
|
|||||||
|
|
||||||
def write_logs(self):
|
def write_logs(self):
|
||||||
"""Log errors and failures"""
|
"""Log errors and failures"""
|
||||||
logger.debug('Ran audit: ' + self.title)
|
logger.debug('Ran audit: %s', self.title)
|
||||||
for message in self.errors:
|
for message in self.errors:
|
||||||
logger.critical(message)
|
logger.critical(message)
|
||||||
for message in self.fails:
|
for message in self.fails:
|
||||||
|
|||||||
@ -2,11 +2,14 @@
|
|||||||
import contextlib
|
import contextlib
|
||||||
import errno
|
import errno
|
||||||
import fcntl
|
import fcntl
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import pwd
|
import pwd
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Mutex:
|
class Mutex:
|
||||||
"""File and pthread lock based resource mutex"""
|
"""File and pthread lock based resource mutex"""
|
||||||
@ -18,7 +21,8 @@ class Mutex:
|
|||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def lock_threads_only(self):
|
def lock_threads_only(self):
|
||||||
"""Acquire the thread lock but not the file lock"""
|
"""Acquire the thread lock but not the file lock"""
|
||||||
self.thread_mutex.acquire(timeout=5)
|
if not self.thread_mutex.acquire(timeout=5):
|
||||||
|
raise RuntimeError('Could not acquire thread lock')
|
||||||
try:
|
try:
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
@ -65,7 +69,10 @@ class Mutex:
|
|||||||
fd.truncate(0)
|
fd.truncate(0)
|
||||||
os.fchown(fd.fileno(), user_info.pw_uid, user_info.pw_gid)
|
os.fchown(fd.fileno(), user_info.pw_uid, user_info.pw_gid)
|
||||||
else:
|
else:
|
||||||
self._try(lambda: os.fchmod(fd.fileno(), 0o660)) # rw-rw----
|
errno, _ = self._try(lambda: os.fchmod(fd.fileno(), 0o660))
|
||||||
|
if errno != 0:
|
||||||
|
logger.warning('chmod failed, lock path %s, errno %d',
|
||||||
|
self.lock_path, errno)
|
||||||
|
|
||||||
def _try(self, function):
|
def _try(self, function):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user