PolicyKit: Branch 'master'
David Zeuthen
david at kemper.freedesktop.org
Tue Jan 27 11:11:21 PST 2009
docs/TODO | 3
src/polkitagent/polkitagentauthenticationagent.c | 82 +++++++++++++++++++----
src/polkitagent/polkitagentauthenticationagent.h | 3
3 files changed, 72 insertions(+), 16 deletions(-)
New commits:
commit 091241630b8f48ea9fb6a0976dd6e8e730f6de6d
Author: David Zeuthen <davidz at redhat.com>
Date: Tue Jan 27 14:09:15 2009 -0500
make authentication agents reconnect if polkitd-1 is restarted
diff --git a/docs/TODO b/docs/TODO
index 8211c44..5757d48 100644
--- a/docs/TODO
+++ b/docs/TODO
@@ -77,9 +77,6 @@ polkit-gnome TODO items
- to make it lighter on resource usage
- to work around Metacity focus stealing prevention bugs
- - perhaps it would be nice to re-register the authentication agent if polkitd-1
- jumps off the bus and comes back
-
- port libpolkit-gnome to new API
- port polkit-gnome-authorization to new API
diff --git a/src/polkitagent/polkitagentauthenticationagent.c b/src/polkitagent/polkitagentauthenticationagent.c
index 1be919c..f283a6d 100644
--- a/src/polkitagent/polkitagentauthenticationagent.c
+++ b/src/polkitagent/polkitagentauthenticationagent.c
@@ -40,8 +40,12 @@ struct _PolkitAgentAuthenticationAgent
EggDBusConnection *system_bus;
+ EggDBusObjectProxy *authority_proxy;
+
PolkitAuthority *authority;
+ gboolean is_registered;
+
PolkitAgentAuthenticationAgentBeginFunc begin_func;
PolkitAgentAuthenticationAgentCancelFunc cancel_func;
gpointer user_data;
@@ -61,6 +65,56 @@ G_DEFINE_TYPE_WITH_CODE (PolkitAgentAuthenticationAgent, polkit_agent_authentica
);
static void
+polkit_agent_authentication_agent_register (PolkitAgentAuthenticationAgent *agent)
+{
+ GError *error;
+
+ g_debug ("Attempting to register Authentication Agent with PolicyKit daemon");
+
+ error = NULL;
+ if (!polkit_authority_register_authentication_agent_sync (agent->authority,
+ "/org/freedesktop/PolicyKit1/AuthenticationAgent",
+ NULL,
+ &error))
+ {
+ g_warning ("Unable to register authentication agent: %s", error->message);
+ g_error_free (error);
+ }
+ else
+ {
+ agent->is_registered = TRUE;
+ }
+}
+
+static void
+name_owner_notify (EggDBusObjectProxy *object_proxy,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ PolkitAgentAuthenticationAgent *agent = POLKIT_AGENT_AUTHENTICATION_AGENT (user_data);
+ gchar *owner;
+
+ owner = egg_dbus_object_proxy_get_name_owner (agent->authority_proxy);
+
+ if (owner == NULL)
+ {
+ g_warning ("PolicyKit daemon disconnected from the bus. We are no longer a registered authentication agent.");
+ agent->is_registered = FALSE;
+ }
+ else
+ {
+ /* only register if there is a name owner */
+ if (!agent->is_registered)
+ {
+ g_debug ("PolicyKit daemon connected to bus. Attempting to re-register as an authentication agent.");
+ polkit_agent_authentication_agent_register (agent);
+ }
+ }
+
+ g_free (owner);
+}
+
+static void
polkit_agent_authentication_agent_init (PolkitAgentAuthenticationAgent *agent)
{
agent->system_bus = egg_dbus_connection_get_for_bus (EGG_DBUS_BUS_TYPE_SYSTEM);
@@ -72,6 +126,20 @@ polkit_agent_authentication_agent_init (PolkitAgentAuthenticationAgent *agent)
G_TYPE_INVALID);
agent->authority = polkit_authority_get ();
+
+ /* the only use of this proxy is to re-register with the polkit daemon
+ * if it jumps off the bus and comes back (which is useful for debugging)
+ */
+ agent->authority_proxy = egg_dbus_connection_get_object_proxy (agent->system_bus,
+ "org.freedesktop.PolicyKit1",
+ "/org/freedesktop/PolicyKit1/Authority");
+
+ g_signal_connect (agent->authority_proxy,
+ "notify::name-owner",
+ G_CALLBACK (name_owner_notify),
+ agent);
+
+ polkit_agent_authentication_agent_register (agent);
}
static void
@@ -92,6 +160,8 @@ polkit_agent_authentication_agent_finalize (GObject *object)
g_object_unref (agent->authority);
+ g_object_unref (agent->authority_proxy);
+
g_object_unref (agent->system_bus);
if (G_OBJECT_CLASS (polkit_agent_authentication_agent_parent_class)->finalize != NULL)
@@ -109,8 +179,7 @@ polkit_agent_authentication_agent_class_init (PolkitAgentAuthenticationAgentClas
PolkitAgentAuthenticationAgent *
polkit_agent_authentication_agent_new (PolkitAgentAuthenticationAgentBeginFunc begin_func,
PolkitAgentAuthenticationAgentCancelFunc cancel_func,
- gpointer user_data,
- GError **error)
+ gpointer user_data)
{
PolkitAgentAuthenticationAgent *agent;
@@ -120,15 +189,6 @@ polkit_agent_authentication_agent_new (PolkitAgentAuthenticationAgentBeginFunc b
agent->cancel_func = cancel_func;
agent->user_data = user_data;
- if (!polkit_authority_register_authentication_agent_sync (agent->authority,
- "/org/freedesktop/PolicyKit1/AuthenticationAgent",
- NULL,
- error))
- {
- g_object_unref (agent);
- agent = NULL;
- }
-
return agent;
}
diff --git a/src/polkitagent/polkitagentauthenticationagent.h b/src/polkitagent/polkitagentauthenticationagent.h
index 96d009b..b076f8c 100644
--- a/src/polkitagent/polkitagentauthenticationagent.h
+++ b/src/polkitagent/polkitagentauthenticationagent.h
@@ -55,8 +55,7 @@ GType polkit_agent_authentication_agent_get_type (void
PolkitAgentAuthenticationAgent *polkit_agent_authentication_agent_new (PolkitAgentAuthenticationAgentBeginFunc begin_func,
PolkitAgentAuthenticationAgentCancelFunc cancel_func,
- gpointer user_data,
- GError **error);
+ gpointer user_data);
void polkit_agent_authentication_agent_finish (PolkitAgentAuthenticationAgent *agent,
gpointer pending_call,
More information about the hal-commit
mailing list