From 7d4c5650f4a0dca06c76c3d804266ed63bc08a88 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Fri, 8 Mar 2024 16:57:54 -0800 Subject: [PATCH] zoph: Restore database password to old value after restore op. Fixes: #2346. Tests: - Without the patch, install zoph, take a backup. Note the db password in /etc/zoph.ini. Uninstall zoph. Install it. Note that db password changed. Restore from previous backup. Note that password has been restored to old value and zoph is unable to connect to database. - With the patch, repeat the test and notice zoph works after restore. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/zoph/privileged.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plinth/modules/zoph/privileged.py b/plinth/modules/zoph/privileged.py index 0c3087cad..2f5655c88 100644 --- a/plinth/modules/zoph/privileged.py +++ b/plinth/modules/zoph/privileged.py @@ -69,8 +69,10 @@ def _get_db_config(): config.read_file(file_handle) return { + 'db_host': config['zoph']['db_host'].strip('"'), 'db_name': config['zoph']['db_name'].strip('"'), 'db_user': config['zoph']['db_user'].strip('"'), + 'db_pass': config['zoph']['db_pass'].strip('"'), } @@ -129,12 +131,19 @@ def restore_database(): """ with action_utils.service_ensure_running('mysql'): db_name = _get_db_config()['db_name'] + db_user = _get_db_config()['db_user'] + db_host = _get_db_config()['db_host'] + db_pass = _get_db_config()['db_pass'] subprocess.run(['mysqladmin', '--force', 'drop', db_name], check=False) subprocess.run(['mysqladmin', 'create', db_name], check=True) with open(DB_BACKUP_FILE, 'r', encoding='utf-8') as db_restore_file: subprocess.run(['mysql', db_name], stdin=db_restore_file, check=True) + # Set the password for user from restored configuration + query = f'ALTER USER {db_user}@{db_host} IDENTIFIED BY "{db_pass}";' + subprocess.run(['mysql'], input=query.encode(), check=True) + @privileged def uninstall():