Catch stupid error if root is not in /etc/passwd

This commit is contained in:
Alexandre Aubin 2020-11-28 19:13:12 +01:00 committed by GitHub
parent 38bd061b98
commit 63166d05fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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