From 070c784412177c7264c46ccecf039824ffedbc9d Mon Sep 17 00:00:00 2001 From: Joaquim Rocha Date: Sun, 23 Jun 2019 12:32:35 +0200 Subject: [PATCH] polkitAgent: Use dialog as confirmation when the user has no password When a user has no password and a polkit authentication is started, instead of blindly initiating the admin session, show the regular "Authentication Requested" dialog (but without the password entry). This makes sure that the user's admin session is only effectively started after the user chooses to proceed with the authentication, which provides an extra confirmation step that can be vital for critical tasks. To do this, we show the dialog inside `_onUserChanged()` right after the dialog was created instead of calling `performAuthentication()` from `_onInitiate()`. The bug mentioned in `_onInitiate()` is no longer an issue since we show the dialog in all cases now anyway. Ideally we should use a different wording than "authentication" when the user has no password set, and use "confirmation" instead. However polkit already sends the requests with such messages (e.g. "Authentication is required to configure software repositories"), and it's important to show those to the user, so this patch keeps the regular wording. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/829 --- js/ui/components/polkitAgent.js | 63 ++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/js/ui/components/polkitAgent.js b/js/ui/components/polkitAgent.js index 0896cab5e..bd05526d6 100644 --- a/js/ui/components/polkitAgent.js +++ b/js/ui/components/polkitAgent.js @@ -11,6 +11,11 @@ const ModalDialog = imports.ui.modalDialog; const ShellEntry = imports.ui.shellEntry; const UserWidget = imports.ui.userWidget; +const DialogMode = { + AUTH: 0, + CONFIRM: 1, +}; + var DIALOG_ICON_SIZE = 48; var WORK_SPINNER_ICON_SIZE = 16; @@ -78,12 +83,6 @@ var AuthenticationDialog = GObject.registerClass({ userBox.add_child(this._userLabel); - this._userLoadedId = this._user.connect('notify::is-loaded', - this._onUserChanged.bind(this)); - this._userChangedId = this._user.connect('changed', - this._onUserChanged.bind(this)); - this._onUserChanged(); - this._passwordBox = new St.BoxLayout({ vertical: false, style_class: 'prompt-dialog-password-box' }); content.messageBox.add(this._passwordBox); this._passwordLabel = new St.Label(({ style_class: 'prompt-dialog-password-label' })); @@ -137,8 +136,16 @@ var AuthenticationDialog = GObject.registerClass({ this._doneEmitted = false; + this._mode = -1; + this._identityToAuth = Polkit.UnixUser.new_for_name(userName); this._cookie = cookie; + + this._userLoadedId = this._user.connect('notify::is-loaded', + this._onUserChanged.bind(this)); + this._userChangedId = this._user.connect('changed', + this._onUserChanged.bind(this)); + this._onUserChanged(); } _setWorking(working) { @@ -148,8 +155,9 @@ var AuthenticationDialog = GObject.registerClass({ this._workSpinner.stop(); } - performAuthentication() { + _initiateSession() { this._destroySession(); + this._session = new PolkitAgent.Session({ identity: this._identityToAuth, cookie: this._cookie }); this._sessionCompletedId = this._session.connect('completed', this._onSessionCompleted.bind(this)); @@ -209,7 +217,10 @@ var AuthenticationDialog = GObject.registerClass({ } _onAuthenticateButtonPressed() { - this._onEntryActivate(); + if (this._mode === DialogMode.CONFIRM) + this._initiateSession(); + else + this._onEntryActivate(); } _onSessionCompleted(session, gainedAuthorization) { @@ -240,7 +251,7 @@ var AuthenticationDialog = GObject.registerClass({ } /* Try and authenticate again */ - this.performAuthentication(); + this._initiateSession(); } } @@ -308,6 +319,28 @@ var AuthenticationDialog = GObject.registerClass({ this._userAvatar.update(); this._userAvatar.actor.show(); } + + if (this._user.get_password_mode() === AccountsService.UserPasswordMode.NONE) { + if (this._mode === DialogMode.CONFIRM) + return; + + this._mode = DialogMode.CONFIRM; + this._destroySession(); + + this._okButton.reactive = true; + + /* We normally open the dialog when we get a "request" signal, but + * since in this case initiating a session would perform the + * authentication, only open the dialog and initiate the session + * when the user confirmed. */ + this._ensureOpen(); + } else { + if (this._mode === DialogMode.AUTH) + return; + + this._mode = DialogMode.AUTH; + this._initiateSession(); + } } cancel() { @@ -370,19 +403,7 @@ var AuthenticationAgent = class { } this._currentDialog = new AuthenticationDialog(actionId, message, cookie, userNames); - - // We actually don't want to open the dialog until we know for - // sure that we're going to interact with the user. For - // example, if the password for the identity to auth is blank - // (which it will be on a live CD) then there will be no - // conversation at all... of course, we don't *know* that - // until we actually try it. - // - // See https://bugzilla.gnome.org/show_bug.cgi?id=643062 for more - // discussion. - this._currentDialog.connect('done', this._onDialogDone.bind(this)); - this._currentDialog.performAuthentication(); } _onCancel(_nativeAgent) {