From 55d6c5ea8f72df17b2928d015644dcd3f31f6b96 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 17 Nov 2011 22:42:37 -0500 Subject: [PATCH] polkit: Find the best user to authenticate as We prefer to ask the user for his own password. If PolicyKit is not configured to accept that, try the root password. If PolicyKit does not accept that either, ask for password of the first user that PolicyKit _will_ accept. The last case is a bit broken, but should rarely occur in real-life configurations. https://bugzilla.gnome.org/show_bug.cgi?id=651547 --- js/ui/polkitAuthenticationAgent.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/js/ui/polkitAuthenticationAgent.js b/js/ui/polkitAuthenticationAgent.js index 2d7063ae8..6f0103975 100644 --- a/js/ui/polkitAuthenticationAgent.js +++ b/js/ui/polkitAuthenticationAgent.js @@ -27,6 +27,7 @@ const AccountsService = imports.gi.AccountsService; const Clutter = imports.gi.Clutter; const St = imports.gi.St; const Pango = imports.gi.Pango; +const GLib = imports.gi.GLib; const Gio = imports.gi.Gio; const Mainloop = imports.mainloop; const Polkit = imports.gi.Polkit; @@ -88,10 +89,14 @@ AuthenticationDialog.prototype = { if (userNames.length > 1) { log('polkitAuthenticationAgent: Received ' + userNames.length + ' identities that can be used for authentication. Only ' + - 'considering the first one.'); + 'considering one.'); } - let userName = userNames[0]; + let userName = GLib.get_user_name(); + if (userNames.indexOf(userName) < 0) + userName = 'root'; + if (userNames.indexOf(userName) < 0) + userName = userNames[0]; this._user = AccountsService.UserManager.get_default().get_user(userName); let userRealName = this._user.get_real_name()