From 63166d05fad940db441edf922c4cfaf16120a643 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 28 Nov 2020 19:13:12 +0100 Subject: [PATCH] Catch stupid error if root is not in /etc/passwd --- src/yunohost/tools.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index 132f8c668..8dab6bcff 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -163,7 +163,10 @@ def tools_adminpw(new_password, check_strength=True): with open('/etc/shadow', 'w') as after_file: after_file.write(before.replace("root:" + hash_root, "root:" + new_hash.replace('{CRYPT}', ''))) - except IOError: + # An IOError may be thrown if for some reason we can't read/write /etc/passwd + # A KeyError could also be thrown if 'root' is not in /etc/passwd in the first place (for example because no password defined ?) + # (c.f. the line about getspnam) + except IOError, KeyError: logger.warning(m18n.n('root_password_desynchronized')) return