From 937f26bdaaca64849570c472914e8d8a2e7f1fbf Mon Sep 17 00:00:00 2001 From: opi Date: Thu, 21 Jul 2016 11:43:02 +0200 Subject: [PATCH] [fix] Raise error on malformed SSOwat persistent conf. --- locales/en.json | 1 + src/yunohost/app.py | 3 +++ src/yunohost/tools.py | 3 +++ src/yunohost/user.py | 15 +++++++++------ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/locales/en.json b/locales/en.json index e939b26fa..a91b0c525 100644 --- a/locales/en.json +++ b/locales/en.json @@ -209,6 +209,7 @@ "service_unknown": "Unknown service '{service:s}'", "ssowat_conf_generated": "The SSOwat configuration has been generated", "ssowat_conf_updated": "The SSOwat configuration has been updated", + "ssowat_persistent_conf_error": "Erro while reading SSOwat persistent configuration", "system_upgraded": "The system has been upgraded", "system_username_exists": "Username already exists in the system users", "unbackup_app": "App '{app:s}' will not be saved", diff --git a/src/yunohost/app.py b/src/yunohost/app.py index af61ff63b..27046fd01 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -806,6 +806,9 @@ def app_makedefault(auth, app, domain=None): try: with open('/etc/ssowat/conf.json.persistent') as json_conf: ssowat_conf = json.loads(str(json_conf.read())) + except ValueError: + raise MoulinetteError(errno.EINVAL, + m18n.n('ssowat_persistent_conf_error')) except IOError: ssowat_conf = {} diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index f78e32363..1898e7023 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -226,6 +226,9 @@ def tools_postinstall(domain, password, ignore_dyndns=False): try: with open('/etc/ssowat/conf.json.persistent') as json_conf: ssowat_conf = json.loads(str(json_conf.read())) + except ValueError: + raise MoulinetteError(errno.EINVAL, + m18n.n('ssowat_persistent_conf_error')) except IOError: ssowat_conf = {} diff --git a/src/yunohost/user.py b/src/yunohost/user.py index ec7dd539c..e04ba9883 100644 --- a/src/yunohost/user.py +++ b/src/yunohost/user.py @@ -177,14 +177,17 @@ def user_create(auth, username, firstname, lastname, mail, password, try: with open('/etc/ssowat/conf.json.persistent') as json_conf: ssowat_conf = json.loads(str(json_conf.read())) + except ValueError: + raise MoulinetteError(errno.EINVAL, + m18n.n('ssowat_persistent_conf_error')) + except IOError: + ssowat_conf = {} - if 'redirected_urls' in ssowat_conf and '/' in ssowat_conf['redirected_urls']: - del ssowat_conf['redirected_urls']['/'] + if 'redirected_urls' in ssowat_conf and '/' in ssowat_conf['redirected_urls']: + del ssowat_conf['redirected_urls']['/'] - with open('/etc/ssowat/conf.json.persistent', 'w+') as f: - json.dump(ssowat_conf, f, sort_keys=True, indent=4) - - except IOError: pass + with open('/etc/ssowat/conf.json.persistent', 'w+') as f: + json.dump(ssowat_conf, f, sort_keys=True, indent=4) if auth.add(rdn, attr_dict):