polkit: return error when authentication dialog is dismissed
This allows PolicyKit applications to disambiguate between when the authentication dialog is dismissed versus when authentication fails (e.g. the wrong password has been entered). See https://bugs.freedesktop.org/show_bug.cgi?id=30653 for more information. Signed-off-by: David Zeuthen <davidz@redhat.com>
This commit is contained in:
parent
29ce02b1d2
commit
697139043f
@ -192,10 +192,10 @@ AuthenticationDialog.prototype = {
|
||||
}));
|
||||
},
|
||||
|
||||
_emitDone: function(keepVisible) {
|
||||
_emitDone: function(keepVisible, dismissed) {
|
||||
if (!this._doneEmitted) {
|
||||
this._doneEmitted = true;
|
||||
this.emit('done', keepVisible);
|
||||
this.emit('done', keepVisible, dismissed);
|
||||
}
|
||||
},
|
||||
|
||||
@ -214,7 +214,7 @@ AuthenticationDialog.prototype = {
|
||||
|
||||
_onSessionCompleted: function(session, gainedAuthorization) {
|
||||
this._passwordBox.hide();
|
||||
this._emitDone(!gainedAuthorization);
|
||||
this._emitDone(!gainedAuthorization, false);
|
||||
},
|
||||
|
||||
_onSessionRequest: function(session, request, echo_on) {
|
||||
@ -270,7 +270,7 @@ AuthenticationDialog.prototype = {
|
||||
|
||||
cancel: function() {
|
||||
this.close(global.get_current_time());
|
||||
this._emitDone(false);
|
||||
this._emitDone(false, true);
|
||||
},
|
||||
|
||||
};
|
||||
@ -302,30 +302,30 @@ AuthenticationAgent.prototype = {
|
||||
log('polkitAuthenticationAgent: Failed to show modal dialog');
|
||||
this._currentDialog.destroySession();
|
||||
this._currentDialog = null;
|
||||
this._native.complete()
|
||||
this._native.complete(false)
|
||||
} else {
|
||||
this._currentDialog.connect('done', Lang.bind(this, this._onDialogDone));
|
||||
}
|
||||
},
|
||||
|
||||
_onCancel: function(nativeAgent) {
|
||||
this._completeRequest(false);
|
||||
this._completeRequest(false, false);
|
||||
},
|
||||
|
||||
_onDialogDone: function(dialog, keepVisible) {
|
||||
this._completeRequest(keepVisible);
|
||||
_onDialogDone: function(dialog, keepVisible, dismissed) {
|
||||
this._completeRequest(keepVisible, dismissed);
|
||||
},
|
||||
|
||||
_reallyCompleteRequest: function() {
|
||||
_reallyCompleteRequest: function(dismissed) {
|
||||
this._currentDialog.close();
|
||||
this._currentDialog.destroySession();
|
||||
this._currentDialog = null;
|
||||
this._isCompleting = false;
|
||||
|
||||
this._native.complete()
|
||||
this._native.complete(dismissed)
|
||||
},
|
||||
|
||||
_completeRequest: function(keepVisible) {
|
||||
_completeRequest: function(keepVisible, wasDismissed) {
|
||||
if (this._isCompleting)
|
||||
return;
|
||||
|
||||
@ -337,10 +337,10 @@ AuthenticationAgent.prototype = {
|
||||
Mainloop.timeout_add(2000,
|
||||
Lang.bind(this,
|
||||
function() {
|
||||
this._reallyCompleteRequest();
|
||||
this._reallyCompleteRequest(wasDismissed);
|
||||
}));
|
||||
} else {
|
||||
this._reallyCompleteRequest();
|
||||
this._reallyCompleteRequest(wasDismissed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include <polkitagent/polkitagent.h>
|
||||
#include "shell-polkit-authentication-agent.h"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
/* uncomment for useful debug output */
|
||||
/* #define SHOW_DEBUG */
|
||||
|
||||
@ -282,7 +284,8 @@ auth_request_initiate (AuthRequest *request)
|
||||
g_strfreev (user_names);
|
||||
}
|
||||
|
||||
static void auth_request_complete (AuthRequest *request);
|
||||
static void auth_request_complete (AuthRequest *request,
|
||||
gboolean dismissed);
|
||||
|
||||
static gboolean
|
||||
handle_cancelled_in_idle (gpointer user_data)
|
||||
@ -298,7 +301,7 @@ handle_cancelled_in_idle (gpointer user_data)
|
||||
}
|
||||
else
|
||||
{
|
||||
auth_request_complete (request);
|
||||
auth_request_complete (request, FALSE);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
@ -319,10 +322,17 @@ on_request_cancelled (GCancellable *cancellable,
|
||||
static void maybe_process_next_request (ShellPolkitAuthenticationAgent *agent);
|
||||
|
||||
static void
|
||||
auth_request_complete (AuthRequest *request)
|
||||
auth_request_complete (AuthRequest *request,
|
||||
gboolean dismissed)
|
||||
{
|
||||
ShellPolkitAuthenticationAgent *agent = request->agent;
|
||||
|
||||
if (dismissed)
|
||||
g_simple_async_result_set_error (request->simple,
|
||||
POLKIT_ERROR,
|
||||
POLKIT_ERROR_CANCELLED,
|
||||
_("Authentation dialog was dismissed by the user"));
|
||||
|
||||
if (agent->current_request == request)
|
||||
{
|
||||
print_debug ("COMPLETING CURRENT %s cookie %s", request->action_id, request->cookie);
|
||||
@ -415,10 +425,11 @@ initiate_authentication_finish (PolkitAgentListener *listener,
|
||||
}
|
||||
|
||||
void
|
||||
shell_polkit_authentication_agent_complete (ShellPolkitAuthenticationAgent *agent)
|
||||
shell_polkit_authentication_agent_complete (ShellPolkitAuthenticationAgent *agent,
|
||||
gboolean dismissed)
|
||||
{
|
||||
g_return_if_fail (SHELL_IS_POLKIT_AUTHENTICATION_AGENT (agent));
|
||||
g_return_if_fail (agent->current_request != NULL);
|
||||
|
||||
auth_request_complete (agent->current_request);
|
||||
auth_request_complete (agent->current_request, dismissed);
|
||||
}
|
||||
|
@ -25,7 +25,8 @@ typedef struct _ShellPolkitAuthenticationAgentClass ShellPolkitAuthenticationAge
|
||||
|
||||
GType shell_polkit_authentication_agent_get_type (void) G_GNUC_CONST;
|
||||
ShellPolkitAuthenticationAgent *shell_polkit_authentication_agent_new (void);
|
||||
void shell_polkit_authentication_agent_complete (ShellPolkitAuthenticationAgent *agent);
|
||||
void shell_polkit_authentication_agent_complete (ShellPolkitAuthenticationAgent *agent,
|
||||
gboolean dismissed);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user