mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-06-03 10:50:20 +00:00
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 <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
d23ceb7050
commit
7d4c5650f4
@ -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():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user