From 937f26bdaaca64849570c472914e8d8a2e7f1fbf Mon Sep 17 00:00:00 2001 From: opi Date: Thu, 21 Jul 2016 11:43:02 +0200 Subject: [PATCH 1/6] [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): From d95052a9e9a1b26115339bb2ed22e1ed01f7c6ed Mon Sep 17 00:00:00 2001 From: opi Date: Sun, 28 Aug 2016 15:39:45 +0200 Subject: [PATCH 2/6] [enh] Catch SSOwat persistent configuration write error. --- locales/en.json | 3 ++- src/yunohost/app.py | 2 +- src/yunohost/tools.py | 2 +- src/yunohost/user.py | 10 +++++++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/locales/en.json b/locales/en.json index a91b0c525..3a3c8b0b2 100644 --- a/locales/en.json +++ b/locales/en.json @@ -209,7 +209,8 @@ "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", + "ssowat_persistent_conf_read_error": "Error while reading SSOwat persistent configuration", + "ssowat_persistent_conf_write_error": "Error while saving 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 27046fd01..4f4a678d1 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -808,7 +808,7 @@ def app_makedefault(auth, app, domain=None): ssowat_conf = json.loads(str(json_conf.read())) except ValueError: raise MoulinetteError(errno.EINVAL, - m18n.n('ssowat_persistent_conf_error')) + m18n.n('ssowat_persistent_conf_read_error')) except IOError: ssowat_conf = {} diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index 1898e7023..7af818a30 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -228,7 +228,7 @@ def tools_postinstall(domain, password, ignore_dyndns=False): ssowat_conf = json.loads(str(json_conf.read())) except ValueError: raise MoulinetteError(errno.EINVAL, - m18n.n('ssowat_persistent_conf_error')) + m18n.n('ssowat_persistent_conf_read_error')) except IOError: ssowat_conf = {} diff --git a/src/yunohost/user.py b/src/yunohost/user.py index e04ba9883..4cef87429 100644 --- a/src/yunohost/user.py +++ b/src/yunohost/user.py @@ -179,15 +179,19 @@ def user_create(auth, username, firstname, lastname, mail, password, ssowat_conf = json.loads(str(json_conf.read())) except ValueError: raise MoulinetteError(errno.EINVAL, - m18n.n('ssowat_persistent_conf_error')) + m18n.n('ssowat_persistent_conf_read_error')) except IOError: ssowat_conf = {} 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) + try: + with open('/etc/ssowat/conf.json.persistent', 'w+') as f: + json.dump(ssowat_conf, f, sort_keys=True, indent=4) + except IOError: + raise MoulinetteError(errno.EINVAL, + m18n.n('ssowat_persistent_conf_write_error')) if auth.add(rdn, attr_dict): From 6149e6c6deba4664cc2e3fa4008efd1b0d823627 Mon Sep 17 00:00:00 2001 From: opi Date: Sun, 28 Aug 2016 15:42:47 +0200 Subject: [PATCH 3/6] [fix] Write SSOwat configuration file only if needed. --- src/yunohost/user.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/yunohost/user.py b/src/yunohost/user.py index 4cef87429..51c87f59b 100644 --- a/src/yunohost/user.py +++ b/src/yunohost/user.py @@ -185,13 +185,12 @@ def user_create(auth, username, firstname, lastname, mail, password, if 'redirected_urls' in ssowat_conf and '/' in ssowat_conf['redirected_urls']: del ssowat_conf['redirected_urls']['/'] - - try: - with open('/etc/ssowat/conf.json.persistent', 'w+') as f: - json.dump(ssowat_conf, f, sort_keys=True, indent=4) - except IOError: - raise MoulinetteError(errno.EINVAL, - m18n.n('ssowat_persistent_conf_write_error')) + try: + with open('/etc/ssowat/conf.json.persistent', 'w+') as f: + json.dump(ssowat_conf, f, sort_keys=True, indent=4) + except IOError: + raise MoulinetteError(errno.EINVAL, + m18n.n('ssowat_persistent_conf_write_error')) if auth.add(rdn, attr_dict): From 81e464ce1f4031475ed7051712b75a75745629e7 Mon Sep 17 00:00:00 2001 From: opi Date: Sun, 28 Aug 2016 23:36:45 +0200 Subject: [PATCH 4/6] [enh] Display full exception error message. --- locales/en.json | 4 ++-- src/yunohost/app.py | 13 +++++++++---- src/yunohost/tools.py | 13 +++++++++---- src/yunohost/user.py | 10 +++++----- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/locales/en.json b/locales/en.json index 3a3c8b0b2..dc801a908 100644 --- a/locales/en.json +++ b/locales/en.json @@ -209,8 +209,8 @@ "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_read_error": "Error while reading SSOwat persistent configuration", - "ssowat_persistent_conf_write_error": "Error while saving SSOwat persistent configuration", + "ssowat_persistent_conf_read_error": "Error while reading SSOwat persistent configuration: {error:s}", + "ssowat_persistent_conf_write_error": "Error while saving SSOwat persistent configuration: {error:s}", "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 4f4a678d1..b8290f1bb 100644 --- a/src/yunohost/app.py +++ b/src/yunohost/app.py @@ -806,9 +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: + except ValueError as e: raise MoulinetteError(errno.EINVAL, - m18n.n('ssowat_persistent_conf_read_error')) + m18n.n('ssowat_persistent_conf_read_error', error=e.strerror)) except IOError: ssowat_conf = {} @@ -817,8 +817,13 @@ def app_makedefault(auth, app, domain=None): ssowat_conf['redirected_urls'][domain +'/'] = app_domain + app_path - with open('/etc/ssowat/conf.json.persistent', 'w+') as f: - json.dump(ssowat_conf, f, sort_keys=True, indent=4) + try: + with open('/etc/ssowat/conf.json.persistent', 'w+') as f: + json.dump(ssowat_conf, f, sort_keys=True, indent=4) + except IOError as e: + raise MoulinetteError(errno.EPERM, + m18n.n('ssowat_persistent_conf_write_error', error=e.strerror)) + os.system('chmod 644 /etc/ssowat/conf.json.persistent') diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index 7af818a30..906b34e65 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -226,9 +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: + except ValueError as e: raise MoulinetteError(errno.EINVAL, - m18n.n('ssowat_persistent_conf_read_error')) + m18n.n('ssowat_persistent_conf_read_error', error=e.strerror)) except IOError: ssowat_conf = {} @@ -237,8 +237,13 @@ def tools_postinstall(domain, password, ignore_dyndns=False): ssowat_conf['redirected_urls']['/'] = domain +'/yunohost/admin' - with open('/etc/ssowat/conf.json.persistent', 'w+') as f: - json.dump(ssowat_conf, f, sort_keys=True, indent=4) + try: + with open('/etc/ssowat/conf.json.persistent', 'w+') as f: + json.dump(ssowat_conf, f, sort_keys=True, indent=4) + except IOError as e: + raise MoulinetteError(errno.EPERM, + m18n.n('ssowat_persistent_conf_write_error', error=e.strerror)) + os.system('chmod 644 /etc/ssowat/conf.json.persistent') diff --git a/src/yunohost/user.py b/src/yunohost/user.py index 51c87f59b..677ba05d4 100644 --- a/src/yunohost/user.py +++ b/src/yunohost/user.py @@ -177,9 +177,9 @@ 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: + except ValueError as e: raise MoulinetteError(errno.EINVAL, - m18n.n('ssowat_persistent_conf_read_error')) + m18n.n('ssowat_persistent_conf_read_error', error=e.strerror)) except IOError: ssowat_conf = {} @@ -188,9 +188,9 @@ def user_create(auth, username, firstname, lastname, mail, password, try: with open('/etc/ssowat/conf.json.persistent', 'w+') as f: json.dump(ssowat_conf, f, sort_keys=True, indent=4) - except IOError: - raise MoulinetteError(errno.EINVAL, - m18n.n('ssowat_persistent_conf_write_error')) + except IOError as e: + raise MoulinetteError(errno.EPERM, + m18n.n('ssowat_persistent_conf_write_error', error=e.strerror)) if auth.add(rdn, attr_dict): From 952040183e4111374fdf0e3b754425a815632745 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sun, 27 Nov 2016 01:16:22 +0100 Subject: [PATCH 5/6] [mod] give instructions on how to solve the conf.json.persistant parsing error --- locales/en.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/locales/en.json b/locales/en.json index dc801a908..bbb33e937 100644 --- a/locales/en.json +++ b/locales/en.json @@ -209,8 +209,8 @@ "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_read_error": "Error while reading SSOwat persistent configuration: {error:s}", - "ssowat_persistent_conf_write_error": "Error while saving SSOwat persistent configuration: {error:s}", + "ssowat_persistent_conf_read_error": "Error while reading SSOwat persistent configuration: {error:s}. To fix this you need to fix the json syntax error in the SSOwat persistent configuration file which is located there on your filesystem: /etc/ssowat/conf.json.persistent", + "ssowat_persistent_conf_write_error": "Error while saving SSOwat persistent configuration: {error:s}. To fix this you need to fix the json syntax error in the SSOwat persistent configuration file which is located there on your filesystem: /etc/ssowat/conf.json.persistent", "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", From 7ee6ab2fbacf42e19cb2abb5d1b14e6fd0885c9b Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sat, 3 Dec 2016 11:38:37 +0100 Subject: [PATCH 6/6] [mod] implement opi's feedback --- locales/en.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/locales/en.json b/locales/en.json index bbb33e937..700df8db4 100644 --- a/locales/en.json +++ b/locales/en.json @@ -209,8 +209,8 @@ "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_read_error": "Error while reading SSOwat persistent configuration: {error:s}. To fix this you need to fix the json syntax error in the SSOwat persistent configuration file which is located there on your filesystem: /etc/ssowat/conf.json.persistent", - "ssowat_persistent_conf_write_error": "Error while saving SSOwat persistent configuration: {error:s}. To fix this you need to fix the json syntax error in the SSOwat persistent configuration file which is located there on your filesystem: /etc/ssowat/conf.json.persistent", + "ssowat_persistent_conf_read_error": "Error while reading SSOwat persistent configuration: {error:s}. Edit /etc/ssowat/conf.json.persistent file to fix the JSON syntax.", + "ssowat_persistent_conf_write_error": "Error while saving SSOwat persistent configuration: {error:s}. Edit /etc/ssowat/conf.json.persistent file to fix the JSON syntax.", "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",