shell: Remember last admin level per host

Previously, connecting to a remote host and switching around the admin
level on it would change the setting for the next session on the local
host.

Closes #14405
This commit is contained in:
Marius Vollmer 2020-07-24 15:56:34 +03:00 committed by Martin Pitt
parent 1f16657965
commit 2b14c01b2d
1 changed files with 15 additions and 3 deletions

View File

@ -33,6 +33,18 @@ export function can_do_sudo(host) {
(err, out) => !(err.exit_status == 1 && out.match("Sorry, user .+ may not run sudo on .+\\.")));
}
function storage_key(host) {
const local_key = window.localStorage.getItem("superuser-key");
if (!host || host == "localhost")
return local_key;
else if (host.indexOf("@") >= 0)
return "superuser:" + host;
else if (local_key)
return local_key + "@" + host;
else
return null;
}
class UnlockDialog extends React.Component {
render() {
const { state } = this.props;
@ -109,7 +121,7 @@ class LockDialog extends React.Component {
proxy.Stop()
.then(() => {
return cockpit.spawn(["sudo", "-k"], { host: this.props.host }).always(() => {
const key = window.localStorage.getItem("superuser-key");
const key = storage_key(this.props.host);
if (key)
window.localStorage.setItem(key, "none");
onclose();
@ -162,7 +174,7 @@ export class SuperuserDialogs extends React.Component {
this.superuser_connection = cockpit.dbus(null, { bus: "internal", host: host });
this.superuser = this.superuser_connection.proxy("cockpit.Superuser", "/superuser");
this.superuser.addEventListener("changed", () => {
const key = window.localStorage.getItem("superuser-key");
const key = storage_key(host);
if (key) {
// Reset wanted state if we fail to gain admin privs.
// Failing to gain admin privs might take a noticeable
@ -269,7 +281,7 @@ export class SuperuserDialogs extends React.Component {
.then(() => {
this.superuser.removeEventListener("Prompt", onprompt);
const key = window.localStorage.getItem("superuser-key");
const key = storage_key(this.props.host);
if (key)
window.localStorage.setItem(key, method);
if (did_prompt)