[gnome-shell] polkit: return error when authentication dialog is dismissed
- From: David Zeuthen <davidz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] polkit: return error when authentication dialog is dismissed
- Date: Wed, 23 Feb 2011 16:03:02 +0000 (UTC)
commit 697139043f50d4bce58d1b9463c312e3121c5456
Author: David Zeuthen <davidz redhat com>
Date: Tue Feb 22 16:54:08 2011 -0500
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>
js/ui/polkitAuthenticationAgent.js | 26 +++++++++++++-------------
src/shell-polkit-authentication-agent.c | 21 ++++++++++++++++-----
src/shell-polkit-authentication-agent.h | 3 ++-
3 files changed, 31 insertions(+), 19 deletions(-)
---
diff --git a/js/ui/polkitAuthenticationAgent.js b/js/ui/polkitAuthenticationAgent.js
index 294c58d..cc5e591 100644
--- a/js/ui/polkitAuthenticationAgent.js
+++ b/js/ui/polkitAuthenticationAgent.js
@@ -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);
}
}
}
diff --git a/src/shell-polkit-authentication-agent.c b/src/shell-polkit-authentication-agent.c
index 2ac120d..a84d8b6 100644
--- a/src/shell-polkit-authentication-agent.c
+++ b/src/shell-polkit-authentication-agent.c
@@ -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);
}
diff --git a/src/shell-polkit-authentication-agent.h b/src/shell-polkit-authentication-agent.h
index 9dbd215..a8758ae 100644
--- a/src/shell-polkit-authentication-agent.h
+++ b/src/shell-polkit-authentication-agent.h
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]