summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2011-02-23 16:45:59 -0500
committerDavid Zeuthen <davidz@redhat.com>2011-02-23 16:45:59 -0500
commit76792accc8c846059b551dfba91ec3cd24d45d71 (patch)
tree77c4ba4614082a256f862adc536491a1c10daf2e
parentf646c32853e775d87aa7147f3ad32e70a627bfce (diff)
Allow overriding message shown in authentication dialog
This is much easier than writing a PolkitBackendActionLookup class and installing an extension. On the downside it requires the caller to be uid 0. Example: http://people.freedesktop.org/~david/polkit-pass-messages.png Signed-off-by: David Zeuthen <davidz@redhat.com>
-rw-r--r--docs/polkit/docbook-interface-org.freedesktop.PolicyKit1.Authority.xml13
-rw-r--r--src/polkit/polkitauthority.c14
-rw-r--r--src/polkitbackend/polkitbackendinteractiveauthority.c9
3 files changed, 36 insertions, 0 deletions
diff --git a/docs/polkit/docbook-interface-org.freedesktop.PolicyKit1.Authority.xml b/docs/polkit/docbook-interface-org.freedesktop.PolicyKit1.Authority.xml
index b67225e..ee29c4c 100644
--- a/docs/polkit/docbook-interface-org.freedesktop.PolicyKit1.Authority.xml
+++ b/docs/polkit/docbook-interface-org.freedesktop.PolicyKit1.Authority.xml
@@ -596,6 +596,19 @@ Identifier for the action that <parameter>subject</parameter> is attempting to d
<para>
Details describing the action. Keys starting with <literal>polkit.</literal> are reserved for internal use and cannot be used.
</para>
+ <para>
+ Known keys include <literal>polkit.message</literal> and
+ <literal>polkit.message.gettext-domain</literal> that can be
+ used to override the message shown to the user (the user might
+ be running an authentication agent in another locale than the
+ calling process so that's why both the message and gettext
+ domain is needed.
+ </para>
+ <para>
+ If non-empty, then the request will fail with
+ <link linkend="eggdbus-constant-Error.org.freedesktop.PolicyKit1.Error.Failed">org.freedesktop.PolicyKit1.Error.Failed</link>
+ unless the process doing the check itsef is sufficiently authorized (e.g. running as uid 0).
+ </para>
</listitem>
</varlistentry>
<varlistentry>
diff --git a/src/polkit/polkitauthority.c b/src/polkit/polkitauthority.c
index cc24e6c..3dc257f 100644
--- a/src/polkit/polkitauthority.c
+++ b/src/polkit/polkitauthority.c
@@ -869,6 +869,17 @@ check_authorization_cb (GDBusProxy *proxy,
* from. You can then call
* polkit_authority_check_authorization_finish() to get the result of
* the operation.
+ *
+ * Known keys in @details include <literal>polkit.message</literal>
+ * and <literal>polkit.message.gettext-domain</literal> that can be
+ * used to override the message shown to the user (the user might be
+ * running an authentication agent in another locale than the calling
+ * process so that's why both the message and gettext domain is
+ * needed).
+ *
+ * If @details is non-empty then the request will fail with
+ * #POLKIT_ERROR_FAILED unless the process doing the check itsef is
+ * sufficiently authorized (e.g. running as uid 0).
**/
void
polkit_authority_check_authorization (PolkitAuthority *authority,
@@ -985,6 +996,9 @@ polkit_authority_check_authorization_finish (PolkitAuthority *authority
* operation to complete because it involves waiting for the user to
* authenticate.
*
+ * See polkit_authority_check_authorization_sync() for how @details is
+ * handled.
+ *
* Returns: (transfer full): A #PolkitAuthorizationResult or %NULL if @error is set. Free with g_object_unref().
*/
PolkitAuthorizationResult *
diff --git a/src/polkitbackend/polkitbackendinteractiveauthority.c b/src/polkitbackend/polkitbackendinteractiveauthority.c
index 59b2fb7..462f334 100644
--- a/src/polkitbackend/polkitbackendinteractiveauthority.c
+++ b/src/polkitbackend/polkitbackendinteractiveauthority.c
@@ -1743,6 +1743,7 @@ get_localized_data_for_challenge (PolkitBackendInteractiveAuthority *authority,
gchar *message;
gchar *icon_name;
PolkitDetails *localized_details;
+ const gchar *message_to_use;
priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (authority);
@@ -1768,6 +1769,14 @@ get_localized_data_for_challenge (PolkitBackendInteractiveAuthority *authority,
}
g_setenv ("LANG", locale, TRUE);
+ message_to_use = polkit_details_lookup (details, "polkit.message");
+ if (message_to_use != NULL)
+ {
+ const gchar *gettext_domain;
+ gettext_domain = polkit_details_lookup (details, "polkit.message.gettext-domain");
+ message = g_strdup (g_dgettext (gettext_domain, message_to_use));
+ }
+
/* call into extension points to get localized auth dialog data - the list is sorted by priority */
action_lookup_list = get_action_lookup_list ();
for (l = action_lookup_list; l != NULL; l = l->next)