From 7729eec96f4f1787944c54241fd98f86fa52815a Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 13 Feb 2023 12:39:36 -0800 Subject: [PATCH] matrixsynapse: Disable verification to fix public registrations Closes: #2321. - Without verification configuration being set, if public registrations are enabled, matrix-synapse server does not start. Fix this by disabling registration verification. Tests: - Without the patch, install matrix and enable public registrations. Matrix daemon will no longer be running. Apply patches and restart. Matrix app will be updated. 'enable_registration_without_verification: true' will appear in /etc/matrix-synapse/conf.d/freedombox-registration.yaml. Server will be running. - Enabling/disabling the public registration option works. The option will be added and removed. enable_public_registration is set to true/false. - Functional tests for matrix-synapse work. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/matrixsynapse/__init__.py | 5 ++++- plinth/modules/matrixsynapse/privileged.py | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/plinth/modules/matrixsynapse/__init__.py b/plinth/modules/matrixsynapse/__init__.py index b9e377bd9..606f6f47d 100644 --- a/plinth/modules/matrixsynapse/__init__.py +++ b/plinth/modules/matrixsynapse/__init__.py @@ -44,7 +44,7 @@ class MatrixSynapseApp(app_module.App): app_id = 'matrixsynapse' - _version = 7 + _version = 8 def __init__(self): """Create components for the app.""" @@ -114,6 +114,9 @@ class MatrixSynapseApp(app_module.App): else: privileged.post_install() + if old_version and old_version <= 7: + privileged.fix_public_registrations() + if not old_version: self.enable() diff --git a/plinth/modules/matrixsynapse/privileged.py b/plinth/modules/matrixsynapse/privileged.py index 847e4492e..332b0a535 100644 --- a/plinth/modules/matrixsynapse/privileged.py +++ b/plinth/modules/matrixsynapse/privileged.py @@ -79,15 +79,25 @@ def get_config(): with open(ORIG_CONF_PATH, encoding='utf-8') as orig_conf_file: config = yaml.safe_load(orig_conf_file) + if config.get('enable_registration_without_verification'): + registration_verification = 'disabled' + else: + registration_verification = None + return { 'public_registration': bool(config.get('enable_registration', False)), + 'registration_verification': registration_verification, } @privileged -def set_config(public_registration: bool): +def set_config(public_registration: bool, + registration_verification: Optional[str] = None): """Enable/disable public user registration.""" config = {'enable_registration': public_registration} + if public_registration and registration_verification in ('disabled', None): + config['enable_registration_without_verification'] = True + with open(REGISTRATION_CONF_PATH, 'w', encoding='utf-8') as reg_conf_file: yaml.dump(config, reg_conf_file) @@ -135,3 +145,13 @@ def configure_turn(managed: bool, conf: str): _set_turn_config(OVERRIDDEN_TURN_CONF_PATH, conf) action_utils.service_try_restart('matrix-synapse') + + +@privileged +def fix_public_registrations(): + """If public registrations are enabled, set validation mechanism.""" + config = get_config() + if (config['public_registration'] + and config['registration_verification'] is None): + set_config(public_registration=True, + registration_verification='disabled')