From 6cfa0589a73dd3ac601b166330eeffe6fa133144 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Wed, 16 Feb 2022 11:42:37 -0800 Subject: [PATCH] email: Drop atomic writing to a file Not very critical. Reduce complexity. Re-implement later at framework level. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/email/interproc.py | 30 -------------------------- plinth/modules/email/privileged/tls.py | 18 ++++++++-------- 2 files changed, 9 insertions(+), 39 deletions(-) delete mode 100644 plinth/modules/email/interproc.py diff --git a/plinth/modules/email/interproc.py b/plinth/modules/email/interproc.py deleted file mode 100644 index 45e7399ff..000000000 --- a/plinth/modules/email/interproc.py +++ /dev/null @@ -1,30 +0,0 @@ -# SPDX-License-Identifier: AGPL-3.0-or-later - -import contextlib -import os -import uuid - - -@contextlib.contextmanager -def atomically_rewrite(filepath): - successful = False - tmp = '%s.%s.plinth-tmp' % (filepath, uuid.uuid4().hex) - fd = open(tmp, 'x') - - try: - # Let client write to a temporary file - yield fd - successful = True - finally: - fd.close() - - try: - if successful: - # Invoke rename(2) to atomically replace the original - os.rename(tmp, filepath) - finally: - # Delete temp file - try: - os.unlink(tmp) - except FileNotFoundError: - pass diff --git a/plinth/modules/email/privileged/tls.py b/plinth/modules/email/privileged/tls.py index 56284e9af..a7cdd8bde 100644 --- a/plinth/modules/email/privileged/tls.py +++ b/plinth/modules/email/privileged/tls.py @@ -1,7 +1,9 @@ -"""TLS configuration for postfix and dovecot.""" # SPDX-License-Identifier: AGPL-3.0-or-later +"""TLS configuration for postfix and dovecot.""" -from .. import interproc, postfix +import pathlib + +from .. import postfix # Mozilla Guideline v5.6, Postfix 1.17.7, OpenSSL 1.1.1d, intermediate # Generated 2021-08 @@ -41,11 +43,11 @@ _postfix_config = { def set_postfix_config(primary_domain, all_domains): """Set postfix configuration for TLS certificates.""" - tls_sni_map = '/etc/postfix/freedombox-tls-sni.map' + tls_sni_map = pathlib.Path('/etc/postfix/freedombox-tls-sni.map') config = dict(_postfix_config) config.update({ 'tls_server_sni_maps': - tls_sni_map, + str(tls_sni_map), 'smtpd_tls_chain_files': f'/etc/postfix/letsencrypt/{primary_domain}/chain.pem' }) @@ -54,8 +56,7 @@ def set_postfix_config(primary_domain, all_domains): for domain in all_domains: content += f'{domain} /etc/postfix/letsencrypt/{domain}/chain.pem\n' - with interproc.atomically_rewrite(tls_sni_map) as file_handle: - file_handle.write(content) + tls_sni_map.write_text(content) def set_dovecot_config(primary_domain, all_domains): @@ -71,6 +72,5 @@ local_name {domain} {{ ssl_key =