mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] Synchronize root and admin password
This commit is contained in:
parent
6aef80cd25
commit
2d5077e2ea
3 changed files with 18 additions and 4 deletions
|
@ -1438,7 +1438,7 @@ tools:
|
||||||
|
|
||||||
### tools_adminpw()
|
### tools_adminpw()
|
||||||
adminpw:
|
adminpw:
|
||||||
action_help: Change admin password
|
action_help: Change password of admin and root users
|
||||||
api: PUT /adminpw
|
api: PUT /adminpw
|
||||||
configuration:
|
configuration:
|
||||||
authenticate: all
|
authenticate: all
|
||||||
|
|
|
@ -364,6 +364,7 @@
|
||||||
"restore_running_app_script": "Running restore script of app '{app:s}'...",
|
"restore_running_app_script": "Running restore script of app '{app:s}'...",
|
||||||
"restore_running_hooks": "Running restoration hooks...",
|
"restore_running_hooks": "Running restoration hooks...",
|
||||||
"restore_system_part_failed": "Unable to restore the '{part:s}' system part",
|
"restore_system_part_failed": "Unable to restore the '{part:s}' system part",
|
||||||
|
"root_password_desynchronized": "Password of the user admin has been changed, but Root password has not been synchronized with your new admin password !",
|
||||||
"server_shutdown": "The server will shutdown",
|
"server_shutdown": "The server will shutdown",
|
||||||
"server_shutdown_confirm": "The server will shutdown immediatly, are you sure? [{answers:s}]",
|
"server_shutdown_confirm": "The server will shutdown immediatly, are you sure? [{answers:s}]",
|
||||||
"server_reboot": "The server will reboot",
|
"server_reboot": "The server will reboot",
|
||||||
|
|
|
@ -127,15 +127,28 @@ def tools_adminpw(auth, new_password):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from yunohost.user import _hash_user_password
|
from yunohost.user import _hash_user_password
|
||||||
|
import spwd
|
||||||
|
new_hash = _hash_user_password(new_password)
|
||||||
try:
|
try:
|
||||||
auth.update("cn=admin", {
|
auth.update("cn=admin", { "userPassword": new_hash, })
|
||||||
"userPassword": _hash_user_password(new_password),
|
|
||||||
})
|
|
||||||
except:
|
except:
|
||||||
logger.exception('unable to change admin password')
|
logger.exception('unable to change admin password')
|
||||||
raise MoulinetteError(errno.EPERM,
|
raise MoulinetteError(errno.EPERM,
|
||||||
m18n.n('admin_password_change_failed'))
|
m18n.n('admin_password_change_failed'))
|
||||||
else:
|
else:
|
||||||
|
# Write as root password
|
||||||
|
try:
|
||||||
|
hash_root = spwd.getspnam("root").sp_pwd
|
||||||
|
|
||||||
|
with open('/etc/shadow', 'r') as before_file:
|
||||||
|
before = before_file.read()
|
||||||
|
|
||||||
|
with open('/etc/shadow', 'w') as after_file:
|
||||||
|
after_file.write(before.replace("root:" + hash_root,
|
||||||
|
"root:" + new_hash))
|
||||||
|
except IOError as e:
|
||||||
|
logger.warning(m18n.n('root_password_desynchronized'))
|
||||||
|
return
|
||||||
logger.success(m18n.n('admin_password_changed'))
|
logger.success(m18n.n('admin_password_changed'))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue