summaryrefslogtreecommitdiff
path: root/src/polkitbackend
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2011-03-03 13:13:11 -0500
committerDavid Zeuthen <davidz@redhat.com>2011-03-03 13:18:05 -0500
commit02cebdb060e76e6d176f05ef24968e6d17225edb (patch)
treead0bf3810442b299a21e5014364ab6733ead4475 /src/polkitbackend
parent76792accc8c846059b551dfba91ec3cd24d45d71 (diff)
Deprecated PolkitBackendActionLookup
Instead, pass the untranslated message as polkit.message and set the gettext domain on polkit.gettext_domain. For printf()-style messages, occurences of the form $(name_of_key) in the translated version of polkit.message are expanded with the value of the property name_of_key. See the pkexec(1) mechanism for an example of how to use this. Additionally, the property polkit.icon_name can be set to the icon. Note that not all authentication agents use this - in particular, gnome-shell does not. It is no longer possible to set the details to be shown in the authentication dialog. It was never a good idea to hide information there anyway. Instead, the mechanism should format a meaningful message. Signed-off-by: David Zeuthen <davidz@redhat.com>
Diffstat (limited to 'src/polkitbackend')
-rw-r--r--src/polkitbackend/polkitbackendactionlookup.c3
-rw-r--r--src/polkitbackend/polkitbackendactionlookup.h16
-rw-r--r--src/polkitbackend/polkitbackendauthority.c7
-rw-r--r--src/polkitbackend/polkitbackendinteractiveauthority.c145
-rw-r--r--src/polkitbackend/polkitbackendlocalauthority.c1
5 files changed, 104 insertions, 68 deletions
diff --git a/src/polkitbackend/polkitbackendactionlookup.c b/src/polkitbackend/polkitbackendactionlookup.c
index dcc972a..5a1a228 100644
--- a/src/polkitbackend/polkitbackendactionlookup.c
+++ b/src/polkitbackend/polkitbackendactionlookup.c
@@ -23,6 +23,9 @@
#include <errno.h>
#include <pwd.h>
#include <string.h>
+
+#define _POLKIT_BACKEND_ACTION_LOOKUP_NO_DEPRECATED_WARNING
+
#include <polkit/polkit.h>
#include <polkit/polkitprivate.h>
#include "polkitbackendactionlookup.h"
diff --git a/src/polkitbackend/polkitbackendactionlookup.h b/src/polkitbackend/polkitbackendactionlookup.h
index 1fbae16..254507b 100644
--- a/src/polkitbackend/polkitbackendactionlookup.h
+++ b/src/polkitbackend/polkitbackendactionlookup.h
@@ -88,6 +88,7 @@ struct _PolkitBackendActionLookupIface
PolkitActionDescription *action_description);
};
+#ifdef _POLKIT_BACKEND_ACTION_LOOKUP_NO_DEPRECATED_WARNING
GType polkit_backend_action_lookup_get_type (void) G_GNUC_CONST;
gchar *polkit_backend_action_lookup_get_message (PolkitBackendActionLookup *lookup,
const gchar *action_id,
@@ -101,6 +102,21 @@ PolkitDetails *polkit_backend_action_lookup_get_details (PolkitBackendActionLo
const gchar *action_id,
PolkitDetails *details,
PolkitActionDescription *action_description);
+#else
+GType polkit_backend_action_lookup_get_type (void) G_GNUC_CONST G_GNUC_DEPRECATED_FOR (use_PolkitDetails_instead);
+gchar *polkit_backend_action_lookup_get_message (PolkitBackendActionLookup *lookup,
+ const gchar *action_id,
+ PolkitDetails *details,
+ PolkitActionDescription *action_description) G_GNUC_DEPRECATED_FOR (use_PolkitDetails_instead);
+gchar *polkit_backend_action_lookup_get_icon_name (PolkitBackendActionLookup *lookup,
+ const gchar *action_id,
+ PolkitDetails *details,
+ PolkitActionDescription *action_description) G_GNUC_DEPRECATED_FOR (use_PolkitDetails_instead);
+PolkitDetails *polkit_backend_action_lookup_get_details (PolkitBackendActionLookup *lookup,
+ const gchar *action_id,
+ PolkitDetails *details,
+ PolkitActionDescription *action_description) G_GNUC_DEPRECATED_FOR (use_PolkitDetails_instead);
+#endif
G_END_DECLS
diff --git a/src/polkitbackend/polkitbackendauthority.c b/src/polkitbackend/polkitbackendauthority.c
index 9dc8943..44b7493 100644
--- a/src/polkitbackend/polkitbackendauthority.c
+++ b/src/polkitbackend/polkitbackendauthority.c
@@ -30,7 +30,6 @@
#include <polkit/polkitprivate.h>
#include "polkitbackendauthority.h"
-#include "polkitbackendactionlookup.h"
#include "polkitbackendlocalauthority.h"
#include "polkitbackendprivate.h"
@@ -1291,7 +1290,6 @@ PolkitBackendAuthority *
polkit_backend_authority_get (void)
{
static GIOExtensionPoint *ep = NULL;
- static GIOExtensionPoint *ep_action_lookup = NULL;
static volatile GType local_authority_type = G_TYPE_INVALID;
GList *modules;
GList *authority_implementations;
@@ -1305,11 +1303,6 @@ polkit_backend_authority_get (void)
ep = g_io_extension_point_register (POLKIT_BACKEND_AUTHORITY_EXTENSION_POINT_NAME);
g_io_extension_point_set_required_type (ep, POLKIT_BACKEND_TYPE_AUTHORITY);
}
- if (ep_action_lookup == NULL)
- {
- ep_action_lookup = g_io_extension_point_register (POLKIT_BACKEND_ACTION_LOOKUP_EXTENSION_POINT_NAME);
- g_io_extension_point_set_required_type (ep_action_lookup, POLKIT_BACKEND_TYPE_ACTION_LOOKUP);
- }
/* make sure local types are registered */
if (local_authority_type == G_TYPE_INVALID)
diff --git a/src/polkitbackend/polkitbackendinteractiveauthority.c b/src/polkitbackend/polkitbackendinteractiveauthority.c
index 462f334..4f7828a 100644
--- a/src/polkitbackend/polkitbackendinteractiveauthority.c
+++ b/src/polkitbackend/polkitbackendinteractiveauthority.c
@@ -32,7 +32,6 @@
#include "polkitbackendactionpool.h"
#include "polkitbackendsessionmonitor.h"
#include "polkitbackendconfigsource.h"
-#include "polkitbackendactionlookup.h"
#include <polkit/polkitprivate.h>
@@ -1693,35 +1692,81 @@ authentication_agent_begin_cb (GDBusProxy *proxy,
authentication_session_free (session);
}
-static GList *
-get_action_lookup_list (void)
+static void
+append_property (GString *dest,
+ PolkitDetails *details,
+ const gchar *key,
+ PolkitBackendInteractiveAuthority *authority,
+ const gchar *message,
+ const gchar *action_id)
{
- GList *extensions;
- GList *l;
- GIOExtensionPoint *action_lookup_ep;
- static GList *action_lookup_list = NULL;
- static gboolean have_looked_up_extensions = FALSE;
+ const gchar *value;
- if (have_looked_up_extensions)
- goto out;
+ value = polkit_details_lookup (details, key);
+ if (value != NULL)
+ {
+ g_string_append (dest, value);
+ }
+ else
+ {
+ polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority),
+ "Error substituting value for property $(%s) when preparing message `%s' for action-id %s",
+ key,
+ message,
+ action_id);
+ g_string_append (dest, "$(");
+ g_string_append (dest, key);
+ g_string_append (dest, ")");
+ }
+}
+
+static gchar *
+expand_properties (const gchar *message,
+ PolkitDetails *details,
+ PolkitBackendInteractiveAuthority *authority,
+ const gchar *action_id)
+{
+ GString *ret;
+ GString *var;
+ guint n;
+ gboolean in_resolve;
- action_lookup_ep = g_io_extension_point_lookup (POLKIT_BACKEND_ACTION_LOOKUP_EXTENSION_POINT_NAME);
- g_assert (action_lookup_ep != NULL);
+ ret = g_string_new (NULL);
+ var = g_string_new (NULL);
- extensions = g_io_extension_point_get_extensions (action_lookup_ep);
- for (l = extensions; l != NULL; l = l->next)
+ in_resolve = FALSE;
+ for (n = 0; message[n] != '\0'; n++)
{
- GIOExtension *extension = l->data;
- PolkitBackendActionLookup *lookup;
-
- lookup = g_object_new (g_io_extension_get_type (extension), NULL);
- action_lookup_list = g_list_prepend (action_lookup_list, lookup);
+ gint c = message[n];
+ if (c == '$' && message[n+1] == '(')
+ {
+ in_resolve = TRUE;
+ n += 1;
+ }
+ else
+ {
+ if (in_resolve)
+ {
+ if (c == ')')
+ {
+ append_property (ret, details, var->str, authority, message, action_id);
+ g_string_set_size (var, 0);
+ in_resolve = FALSE;
+ }
+ else
+ {
+ g_string_append_c (var, c);
+ }
+ }
+ else
+ {
+ g_string_append_c (ret, c);
+ }
+ }
}
- action_lookup_list = g_list_reverse (action_lookup_list);
+ g_string_free (var, TRUE);
- out:
- have_looked_up_extensions = TRUE;
- return action_lookup_list;
+ return g_string_free (ret, FALSE);
}
static void
@@ -1738,12 +1783,12 @@ get_localized_data_for_challenge (PolkitBackendInteractiveAuthority *authority,
{
PolkitBackendInteractiveAuthorityPrivate *priv;
PolkitActionDescription *action_desc;
- GList *action_lookup_list;
- GList *l;
gchar *message;
gchar *icon_name;
PolkitDetails *localized_details;
const gchar *message_to_use;
+ const gchar *gettext_domain;
+ gchar *s;
priv = POLKIT_BACKEND_INTERACTIVE_AUTHORITY_GET_PRIVATE (authority);
@@ -1762,52 +1807,21 @@ get_localized_data_for_challenge (PolkitBackendInteractiveAuthority *authority,
if (action_desc == NULL)
goto out;
- /* Set LANG and locale so gettext() + friends work when running the code in the extensions */
+ /* Set LANG and locale so g_dgettext() + friends work below */
if (setlocale (LC_ALL, locale) == NULL)
{
g_printerr ("Invalid locale '%s'\n", locale);
}
g_setenv ("LANG", locale, TRUE);
+ gettext_domain = polkit_details_lookup (details, "polkit.gettext_domain");
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));
+ /* g_print ("locale=%s, domain=%s, msg=`%s' -> `%s'\n", locale, gettext_domain, message_to_use, message); */
}
-
- /* 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)
- {
- PolkitBackendActionLookup *lookup = POLKIT_BACKEND_ACTION_LOOKUP (l->data);
-
- if (message != NULL && icon_name != NULL && localized_details != NULL)
- break;
-
- if (message == NULL)
- message = polkit_backend_action_lookup_get_message (lookup,
- action_id,
- details,
- action_desc);
-
- if (icon_name == NULL)
- icon_name = polkit_backend_action_lookup_get_icon_name (lookup,
- action_id,
- details,
- action_desc);
-
- if (localized_details == NULL)
- localized_details = polkit_backend_action_lookup_get_details (lookup,
- action_id,
- details,
- action_desc);
- }
-
- /* Back to C! */
- setlocale (LC_ALL, "C");
- g_setenv ("LANG", "C", TRUE);
+ icon_name = g_strdup (polkit_details_lookup (details, "polkit.icon_name"));
/* fall back to action description */
if (message == NULL)
@@ -1819,6 +1833,15 @@ get_localized_data_for_challenge (PolkitBackendInteractiveAuthority *authority,
icon_name = g_strdup (polkit_action_description_get_icon_name (action_desc));
}
+ /* replace $(property) with values */
+ s = message;
+ message = expand_properties (message, details, authority, action_id);
+ g_free (s);
+
+ /* Back to C! */
+ setlocale (LC_ALL, "C");
+ g_setenv ("LANG", "C", TRUE);
+
out:
if (message == NULL)
message = g_strdup ("");
@@ -1956,6 +1979,8 @@ authentication_agent_initiate_challenge (AuthenticationAgent *agent,
agent->active_sessions = g_list_prepend (agent->active_sessions, session);
+ if (localized_details == NULL)
+ localized_details = polkit_details_new ();
add_pid (localized_details, caller, "polkit.caller-pid");
add_pid (localized_details, subject, "polkit.subject-pid");
diff --git a/src/polkitbackend/polkitbackendlocalauthority.c b/src/polkitbackend/polkitbackendlocalauthority.c
index 23407e9..dc6b36c 100644
--- a/src/polkitbackend/polkitbackendlocalauthority.c
+++ b/src/polkitbackend/polkitbackendlocalauthority.c
@@ -32,7 +32,6 @@
#include "polkitbackendconfigsource.h"
#include "polkitbackendlocalauthority.h"
#include "polkitbackendlocalauthorizationstore.h"
-#include "polkitbackendactionlookup.h"
#include <polkit/polkitprivate.h>