Compare commits

...

2 Commits

Author SHA1 Message Date
Florian Müllner
ac3b3533d5 polkitAgent: Indicate which application initiated a request
Now that the ::initiate signal may contain the PID of the initiating
process, we can try to resolve it to an application and use that to
indicate where a request originated. This should work for well-behaved
applications that only ask for permissions in response to a user action,
but unfortunately not when it would be most useful, that is when the
dialog is triggered "out of nowhere" by a background service ...

https://bugzilla.gnome.org/show_bug.cgi?id=688351
2018-07-09 16:18:18 +02:00
Florian Müllner
087f290ff7 polkit-agent: Include subject PID in ::initiate
It is not always clear what triggered a particular polkit request, so
displaying more information to the user is desirable. Unfortunately
the information provided by polkitd is rather sparse, and is usually
limited to subject- and caller PID. Still that's better than nothing,
so include the PID of the initiating process in the signal parameters.

https://bugzilla.gnome.org/show_bug.cgi?id=688351
2018-07-09 16:16:16 +02:00
3 changed files with 17 additions and 6 deletions

View File

@ -374,6 +374,7 @@ StScrollBar {
border: 3px solid $_bubble_borders_color; border: 3px solid $_bubble_borders_color;
.message-dialog-main-layout { spacing: 24px; padding: 10px; } .message-dialog-main-layout { spacing: 24px; padding: 10px; }
.message-dialog-icon { -st-icon-style: symbolic; }
.message-dialog-content { spacing: 16px; } .message-dialog-content { spacing: 16px; }
.message-dialog-title { color: darken($osd_fg_color,25%); } .message-dialog-title { color: darken($osd_fg_color,25%); }
} }

View File

@ -32,7 +32,7 @@ var AuthenticationDialog = new Lang.Class({
Name: 'AuthenticationDialog', Name: 'AuthenticationDialog',
Extends: ModalDialog.ModalDialog, Extends: ModalDialog.ModalDialog,
_init(actionId, body, cookie, userNames) { _init(actionId, body, cookie, app, userNames) {
this.parent({ styleClass: 'prompt-dialog' }); this.parent({ styleClass: 'prompt-dialog' });
this.actionId = actionId; this.actionId = actionId;
@ -44,8 +44,11 @@ var AuthenticationDialog = new Lang.Class({
this._group.visible = !Main.sessionMode.isLocked; this._group.visible = !Main.sessionMode.isLocked;
}); });
let icon = new Gio.ThemedIcon({ name: 'dialog-password-symbolic' }); let appInfo = app ? app.app_info : null;
let title = _("Authentication Required"); let icon = appInfo ? appInfo.get_icon()
: new Gio.ThemedIcon({ name: 'dialog-password' });
let title = appInfo ? _("%s Requires Authentication").format(appInfo.get_name())
: _("Authentication Required");
let content = new Dialog.MessageDialogContent({ icon, title, body }); let content = new Dialog.MessageDialogContent({ icon, title, body });
this.contentLayout.add_actor(content); this.contentLayout.add_actor(content);
@ -362,6 +365,8 @@ var AuthenticationAgent = new Lang.Class({
this._native.connect('initiate', this._onInitiate.bind(this)); this._native.connect('initiate', this._onInitiate.bind(this));
this._native.connect('cancel', this._onCancel.bind(this)); this._native.connect('cancel', this._onCancel.bind(this));
this._sessionUpdatedId = 0; this._sessionUpdatedId = 0;
this._windowTracker = Shell.WindowTracker.get_default();
}, },
enable() { enable() {
@ -380,7 +385,7 @@ var AuthenticationAgent = new Lang.Class({
} }
}, },
_onInitiate(nativeAgent, actionId, message, iconName, cookie, userNames) { _onInitiate(nativeAgent, actionId, message, iconName, cookie, subjectPid, userNames) {
// Don't pop up a dialog while locked // Don't pop up a dialog while locked
if (Main.sessionMode.isLocked) { if (Main.sessionMode.isLocked) {
this._sessionUpdatedId = Main.sessionMode.connect('updated', () => { this._sessionUpdatedId = Main.sessionMode.connect('updated', () => {
@ -392,7 +397,10 @@ var AuthenticationAgent = new Lang.Class({
return; return;
} }
this._currentDialog = new AuthenticationDialog(actionId, message, cookie, userNames); let pid = parseInt(subjectPid);
let app = pid != NaN ? this._windowTracker.get_app_from_pid(pid) : null;
this._currentDialog = new AuthenticationDialog(actionId, message, cookie, app, userNames);
// We actually don't want to open the dialog until we know for // We actually don't want to open the dialog until we know for
// sure that we're going to interact with the user. For // sure that we're going to interact with the user. For

View File

@ -162,7 +162,8 @@ shell_polkit_authentication_agent_class_init (ShellPolkitAuthenticationAgentClas
NULL, /* accumulator data */ NULL, /* accumulator data */
NULL, /* marshaller */ NULL, /* marshaller */
G_TYPE_NONE, G_TYPE_NONE,
5, 6,
G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_STRING,
@ -267,6 +268,7 @@ auth_request_initiate (AuthRequest *request)
request->message, request->message,
request->icon_name, request->icon_name,
request->cookie, request->cookie,
polkit_details_lookup (request->details, "polkit.subject-pid"),
user_names); user_names);
g_strfreev (user_names); g_strfreev (user_names);
} }