PolicyKit: Branch 'gdbus'
David Zeuthen
david at kemper.freedesktop.org
Wed Jul 28 09:17:22 PDT 2010
src/examples/cancel.c | 18
src/polkit/polkitactiondescription.c | 88 ++
src/polkit/polkitauthority.c | 1185 +++++++++++------------------
src/polkit/polkitauthorizationresult.c | 40
src/polkit/polkitdetails.c | 40
src/polkit/polkiterror.c | 17
src/polkit/polkitidentity.c | 122 ++
src/polkit/polkitprivate.h | 14
src/polkit/polkitsubject.c | 190 ++++
src/polkit/polkittemporaryauthorization.c | 40
src/polkitbackend/polkitbackendauthority.c | 1015 +++++++++++++-----------
src/polkitd/main.c | 2
12 files changed, 1570 insertions(+), 1201 deletions(-)
New commits:
commit 3fee22546b76d377c6238943f2f0bcfb00c8f79c
Author: David Zeuthen <davidz at redhat.com>
Date: Wed Jul 28 12:16:42 2010 -0400
Port core bits to gdbus
Signed-off-by: David Zeuthen <davidz at redhat.com>
diff --git a/src/examples/cancel.c b/src/examples/cancel.c
index 2c6224c..fd94b0e 100644
--- a/src/examples/cancel.c
+++ b/src/examples/cancel.c
@@ -34,13 +34,23 @@
#include <polkit/polkit.h>
+static gboolean
+on_tensec_timeout (gpointer user_data)
+{
+ GMainLoop *loop = user_data;
+ g_print ("Ten seconds has passed. Now exiting.\n");
+ g_main_loop_quit (loop);
+ return FALSE;
+}
+
static void
check_authorization_cb (PolkitAuthority *authority,
GAsyncResult *res,
- GMainLoop *loop)
+ gpointer user_data)
{
- GError *error;
+ GMainLoop *loop = user_data;
PolkitAuthorizationResult *result;
+ GError *error;
error = NULL;
result = polkit_authority_check_authorization_finish (authority, res, &error);
@@ -68,7 +78,9 @@ check_authorization_cb (PolkitAuthority *authority,
g_print ("Authorization result: %s\n", result_str);
}
- g_main_loop_quit (loop);
+ g_print ("Authorization check has been cancelled and the dialog should now be hidden.\n"
+ "This process will exit in ten seconds.\n");
+ g_timeout_add (10000, on_tensec_timeout, loop);
}
static gboolean
diff --git a/src/polkit/polkitactiondescription.c b/src/polkit/polkitactiondescription.c
index cc1a8b5..222f7af 100644
--- a/src/polkit/polkitactiondescription.c
+++ b/src/polkit/polkitactiondescription.c
@@ -71,7 +71,8 @@ polkit_action_description_finalize (GObject *object)
action_description = POLKIT_ACTION_DESCRIPTION (object);
- g_object_unref (action_description->real);
+ if (action_description->real != NULL)
+ g_object_unref (action_description->real);
g_strfreev (action_description->annotation_keys);
@@ -302,3 +303,88 @@ polkit_action_description_get_annotation_keys (PolkitActionDescription *action_d
out:
return (const gchar * const *) action_description->annotation_keys;
}
+
+PolkitActionDescription *
+polkit_action_description_new_for_gvariant (GVariant *value)
+{
+ PolkitActionDescription *action_description;
+ GVariantIter iter;
+ const gchar *action_id;
+ const gchar *description;
+ const gchar *message;
+ const gchar *vendor_name;
+ const gchar *vendor_url;
+ const gchar *icon_name;
+ PolkitImplicitAuthorization implicit_any;
+ PolkitImplicitAuthorization implicit_inactive;
+ PolkitImplicitAuthorization implicit_active;
+ GVariant *annotations_dict;
+ gchar *a_key;
+ gchar *a_value;
+ EggDBusHashMap *hm;
+
+ action_description = POLKIT_ACTION_DESCRIPTION (g_object_new (POLKIT_TYPE_ACTION_DESCRIPTION, NULL));
+ g_variant_get (value,
+ "(&s&s&s&s&s&suuu at a{ss})",
+ &action_id,
+ &description,
+ &message,
+ &vendor_name,
+ &vendor_url,
+ &icon_name,
+ &implicit_any,
+ &implicit_inactive,
+ &implicit_active,
+ &annotations_dict);
+ hm = egg_dbus_hash_map_new (G_TYPE_STRING, g_free, G_TYPE_STRING, g_free);
+ g_variant_iter_init (&iter, annotations_dict);
+ while (g_variant_iter_next (&iter, "{ss}", &a_key, &a_value))
+ egg_dbus_hash_map_insert (hm, a_key, a_value);
+ g_variant_unref (annotations_dict);
+
+ action_description->real = _polkit_action_description_new (action_id, description, message, vendor_name, vendor_url, icon_name, implicit_any, implicit_inactive, implicit_active, hm);
+ g_object_unref (hm);
+
+ return action_description;
+}
+
+static gboolean
+add_annotation (EggDBusHashMap *hash_map,
+ gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ GVariantBuilder *builder = user_data;
+
+ g_variant_builder_add (builder, "{ss}", key, value);
+
+ return FALSE;
+}
+
+GVariant *
+polkit_action_description_to_gvariant (PolkitActionDescription *action_description)
+{
+ GVariant *value;
+ GVariantBuilder builder;
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
+
+ egg_dbus_hash_map_foreach (_polkit_action_description_get_annotations (action_description->real),
+ add_annotation,
+ &builder);
+
+ /* TODO: note 'foo ? : ""' is a gcc specific extension (it's a short-hand for 'foo ? foo : ""') */
+ value = g_variant_new ("(ssssssuuua{ss})",
+ _polkit_action_description_get_action_id (action_description->real) ? : "",
+ _polkit_action_description_get_description (action_description->real) ? : "",
+ _polkit_action_description_get_message (action_description->real) ? : "",
+ _polkit_action_description_get_vendor_name (action_description->real) ? : "",
+ _polkit_action_description_get_vendor_url (action_description->real) ? : "",
+ _polkit_action_description_get_icon_name (action_description->real) ? : "",
+ _polkit_action_description_get_implicit_any (action_description->real),
+ _polkit_action_description_get_implicit_inactive (action_description->real),
+ _polkit_action_description_get_implicit_active (action_description->real),
+ &builder);
+
+ return value;
+}
diff --git a/src/polkit/polkitauthority.c b/src/polkit/polkitauthority.c
index f29be09..11ebed8 100644
--- a/src/polkit/polkitauthority.c
+++ b/src/polkit/polkitauthority.c
@@ -59,13 +59,10 @@ struct _PolkitAuthority
/*< private >*/
GObject parent_instance;
- EggDBusConnection *system_bus;
- EggDBusObjectProxy *authority_object_proxy;
-
- _PolkitAuthority *real;
gchar *name;
gchar *version;
+ GDBusProxy *proxy;
guint cancellation_id_counter;
};
@@ -75,7 +72,7 @@ struct _PolkitAuthorityClass
};
-/* TODO: locking */
+/* TODO: fix up locking */
static PolkitAuthority *the_authority = NULL;
@@ -98,44 +95,56 @@ static guint signals[LAST_SIGNAL] = {0};
G_DEFINE_TYPE (PolkitAuthority, polkit_authority, G_TYPE_OBJECT);
static void
-real_authority_changed (_PolkitAuthority *real_authority,
- gpointer user_data)
+on_proxy_signal (GDBusProxy *proxy,
+ const gchar *sender_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
PolkitAuthority *authority = POLKIT_AUTHORITY (user_data);
-
- g_signal_emit_by_name (authority, "changed");
+ if (g_strcmp0 (signal_name, "Changed") == 0)
+ {
+ g_signal_emit_by_name (authority, "changed");
+ }
}
static void
polkit_authority_init (PolkitAuthority *authority)
{
- authority->system_bus = egg_dbus_connection_get_for_bus (EGG_DBUS_BUS_TYPE_SYSTEM);
-
- authority->authority_object_proxy = egg_dbus_connection_get_object_proxy (authority->system_bus,
- "org.freedesktop.PolicyKit1",
- "/org/freedesktop/PolicyKit1/Authority");
-
- authority->real = _POLKIT_QUERY_INTERFACE_AUTHORITY (authority->authority_object_proxy);
+ GError *error;
- g_signal_connect (authority->real,
- "changed",
- (GCallback) real_authority_changed,
+ /* TODO: do this instead in GInitable and GAsyncInitable implementations */
+ error = NULL;
+ authority->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL, /* GDBusInterfaceInfo* */
+ "org.freedesktop.PolicyKit1", /* name */
+ "/org/freedesktop/PolicyKit1/Authority", /* path */
+ "org.freedesktop.PolicyKit1.Authority", /* interface */
+ NULL, /* GCancellable */
+ &error);
+ if (authority->proxy == NULL)
+ {
+ g_warning ("Error initializing authority: %s", error->message);
+ g_error_free (error);
+ }
+ g_signal_connect (authority->proxy,
+ "g-signal",
+ G_CALLBACK (on_proxy_signal),
authority);
}
static void
polkit_authority_finalize (GObject *object)
{
- PolkitAuthority *authority;
+ PolkitAuthority *authority = POLKIT_AUTHORITY (object);
- authority = POLKIT_AUTHORITY (object);
+ the_authority = NULL;
- g_object_unref (authority->authority_object_proxy);
- g_object_unref (authority->system_bus);
g_free (authority->name);
g_free (authority->version);
-
- the_authority = NULL;
+ if (authority->proxy != NULL)
+ g_object_unref (authority->proxy);
if (G_OBJECT_CLASS (polkit_authority_parent_class)->finalize != NULL)
G_OBJECT_CLASS (polkit_authority_parent_class)->finalize (object);
@@ -253,10 +262,11 @@ polkit_authority_class_init (PolkitAuthorityClass *klass)
PolkitAuthority *
polkit_authority_get (void)
{
- if (the_authority != NULL) {
- g_object_ref (the_authority);
- goto out;
- }
+ if (the_authority != NULL)
+ {
+ g_object_ref (the_authority);
+ goto out;
+ }
the_authority = POLKIT_AUTHORITY (g_object_new (POLKIT_TYPE_AUTHORITY, NULL));
@@ -264,53 +274,54 @@ polkit_authority_get (void)
return the_authority;
}
-static void
-generic_cb (GObject *source_obj,
- GAsyncResult *res,
- gpointer user_data)
+/* ---------------------------------------------------------------------------------------------------- */
+
+typedef struct
{
- GAsyncResult **target_res = user_data;
+ GAsyncResult *res;
+ GMainContext *context;
+ GMainLoop *loop;
+} CallSyncData;
- *target_res = g_object_ref (res);
+static CallSyncData *
+call_sync_new (void)
+{
+ CallSyncData *data;
+ data = g_new0 (CallSyncData, 1);
+ data->context = g_main_context_new ();
+ data->loop = g_main_loop_new (data->context, FALSE);
+ g_main_context_push_thread_default (data->context);
+ return data;
}
static void
-generic_async_cb (GObject *source_obj,
- GAsyncResult *res,
- gpointer user_data)
+call_sync_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
-
- g_simple_async_result_set_op_res_gpointer (simple, g_object_ref (res), g_object_unref);
- g_simple_async_result_complete (simple);
+ CallSyncData *data = user_data;
+ data->res = g_object_ref (res);
+ g_main_loop_quit (data->loop);
}
-/* ---------------------------------------------------------------------------------------------------- */
-
-static guint
-polkit_authority_enumerate_actions_async (PolkitAuthority *authority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+static void
+call_sync_block (CallSyncData *data)
{
- guint call_id;
- GSimpleAsyncResult *simple;
-
- simple = g_simple_async_result_new (G_OBJECT (authority),
- callback,
- user_data,
- polkit_authority_enumerate_actions_async);
-
- call_id = _polkit_authority_enumerate_actions (authority->real,
- EGG_DBUS_CALL_FLAGS_NONE,
- "", /* TODO: use current locale */
- cancellable,
- generic_async_cb,
- simple);
+ g_main_loop_run (data->loop);
+}
- return call_id;
+static void
+call_sync_free (CallSyncData *data)
+{
+ g_main_context_pop_thread_default (data->context);
+ g_main_context_unref (data->context);
+ g_main_loop_unref (data->loop);
+ g_object_unref (data->res);
+ g_free (data);
}
+/* ---------------------------------------------------------------------------------------------------- */
+
/**
* polkit_authority_enumerate_actions:
* @authority: A #PolkitAuthority.
@@ -330,7 +341,15 @@ polkit_authority_enumerate_actions (PolkitAuthority *authority,
GAsyncReadyCallback callback,
gpointer user_data)
{
- polkit_authority_enumerate_actions_async (authority, cancellable, callback, user_data);
+ g_dbus_proxy_call (authority->proxy,
+ "EnumerateActions",
+ g_variant_new ("(s)",
+ ""), /* TODO: use system locale */
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ cancellable,
+ callback,
+ user_data);
}
/**
@@ -349,44 +368,34 @@ polkit_authority_enumerate_actions_finish (PolkitAuthority *authority,
GAsyncResult *res,
GError **error)
{
- EggDBusArraySeq *array_seq;
- GList *result;
- guint n;
- GSimpleAsyncResult *simple;
- GAsyncResult *real_res;
+ GList *ret;
+ GVariant *value;
+ GVariantIter iter;
+ GVariant *child;
+ GVariant *array;
- simple = G_SIMPLE_ASYNC_RESULT (res);
- real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));
+ ret = NULL;
- g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_enumerate_actions_async);
-
- result = NULL;
-
- if (!_polkit_authority_enumerate_actions_finish (authority->real,
- &array_seq,
- real_res,
- error))
+ value = g_dbus_proxy_call_finish (authority->proxy, res, error);
+ if (value == NULL)
goto out;
- for (n = 0; n < array_seq->size; n++)
+ array = g_variant_get_child_value (value, 0);
+ g_variant_iter_init (&iter, array);
+ while ((child = g_variant_iter_next_value (&iter)) != NULL)
{
- _PolkitActionDescription *real_ad;
-
- real_ad = array_seq->data.v_ptr[n];
-
- result = g_list_prepend (result, polkit_action_description_new_for_real (real_ad));
+ ret = g_list_prepend (ret, polkit_action_description_new_for_gvariant (child));
+ g_variant_ref_sink (child);
+ g_variant_unref (child);
}
-
- result = g_list_reverse (result);
-
- g_object_unref (array_seq);
+ ret = g_list_reverse (ret);
+ g_variant_unref (array);
+ g_variant_unref (value);
out:
- g_object_unref (real_res);
- return result;
+ return ret;
}
-
/**
* polkit_authority_enumerate_actions_sync:
* @authority: A #PolkitAuthority.
@@ -403,85 +412,95 @@ polkit_authority_enumerate_actions_sync (PolkitAuthority *authority,
GCancellable *cancellable,
GError **error)
{
- guint call_id;
- GAsyncResult *res;
- GList *result;
-
- call_id = polkit_authority_enumerate_actions_async (authority, cancellable, generic_cb, &res);
-
- egg_dbus_connection_pending_call_block (authority->system_bus, call_id);
-
- result = polkit_authority_enumerate_actions_finish (authority, res, error);
+ GList *ret;
+ CallSyncData *data;
- g_object_unref (res);
+ data = call_sync_new ();
+ polkit_authority_enumerate_actions (authority, cancellable, call_sync_cb, data);
+ call_sync_block (data);
+ ret = polkit_authority_enumerate_actions_finish (authority, data->res, error);
+ call_sync_free (data);
- return result;
+ return ret;
}
/* ---------------------------------------------------------------------------------------------------- */
-static guint
-polkit_authority_check_authorization_async (PolkitAuthority *authority,
- PolkitSubject *subject,
- const gchar *action_id,
- PolkitDetails *details,
- PolkitCheckAuthorizationFlags flags,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+typedef struct
{
- _PolkitSubject *real_subject;
- guint call_id;
+ PolkitAuthority *authority;
GSimpleAsyncResult *simple;
gchar *cancellation_id;
- EggDBusHashMap *real_details;
+} CheckAuthData;
- real_subject = polkit_subject_get_real (subject);
-
- simple = g_simple_async_result_new (G_OBJECT (authority),
- callback,
- user_data,
- polkit_authority_check_authorization_async);
+static void
+cancel_check_authorization_cb (GDBusProxy *proxy,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GVariant *value;
+ GError *error;
- cancellation_id = NULL;
- if (cancellable != NULL)
+ error = NULL;
+ value = g_dbus_proxy_call_finish (proxy, res, &error);
+ if (value == NULL)
{
- cancellation_id = g_strdup_printf ("cancellation-id-%d", authority->cancellation_id_counter++);
- g_object_set_data_full (G_OBJECT (simple), "polkit-1-cancellation-id", cancellation_id, g_free);
+ g_warning ("Error cancelling authorization check: %s", error->message);
+ g_error_free (error);
}
-
- real_details = egg_dbus_hash_map_new (G_TYPE_STRING, NULL,
- G_TYPE_STRING, NULL);
- if (details != NULL)
+ else
{
- GHashTable *hash;
- GHashTableIter iter;
- const gchar *key;
- const gchar *value;
+ g_variant_unref (value);
+ }
+}
+
+static void
+check_authorization_cb (GDBusProxy *proxy,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ CheckAuthData *data = user_data;
+ GVariant *value;
+ GError *error;
- hash = polkit_details_get_hash (details);
- if (hash != NULL)
+ error = NULL;
+ value = g_dbus_proxy_call_finish (proxy, res, &error);
+ if (value == NULL)
+ {
+ if (data->cancellation_id != NULL &&
+ (!g_dbus_error_is_remote_error (error) &&
+ error->domain == G_IO_ERROR &&
+ error->code == G_IO_ERROR_CANCELLED))
{
- g_hash_table_iter_init (&iter, hash);
- while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value))
- egg_dbus_hash_map_insert (real_details, key, value);
+ g_dbus_proxy_call (data->authority->proxy,
+ "CancelCheckAuthorization",
+ g_variant_new ("(s)", data->cancellation_id),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL, /* GCancellable */
+ (GAsyncReadyCallback) cancel_check_authorization_cb,
+ NULL);
}
+ g_simple_async_result_set_from_error (data->simple, error);
+ g_error_free (error);
+ }
+ else
+ {
+ GVariant *result_value;
+ PolkitAuthorizationResult *result;
+ result_value = g_variant_get_child_value (value, 0);
+ result = polkit_authorization_result_new_for_gvariant (result_value);
+ g_variant_unref (result_value);
+ g_variant_unref (value);
+ g_simple_async_result_set_op_res_gpointer (data->simple, result, g_object_unref);
}
- call_id = _polkit_authority_check_authorization (authority->real,
- EGG_DBUS_CALL_FLAGS_TIMEOUT_NONE,
- real_subject,
- action_id,
- real_details,
- flags,
- cancellation_id,
- cancellable,
- generic_async_cb,
- simple);
-
- g_object_unref (real_subject);
+ g_simple_async_result_complete (data->simple);
- return call_id;
+ g_object_unref (data->authority);
+ g_object_unref (data->simple);
+ g_free (data->cancellation_id);
+ g_free (data);
}
/**
@@ -518,31 +537,39 @@ polkit_authority_check_authorization (PolkitAuthority *authority,
GAsyncReadyCallback callback,
gpointer user_data)
{
- polkit_authority_check_authorization_async (authority,
- subject,
- action_id,
- details,
- flags,
- cancellable,
- callback,
- user_data);
-}
-
-static void
-authorization_check_cancelled_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- GError *error;
-
- error = NULL;
- if (!_polkit_authority_cancel_check_authorization_finish (_POLKIT_AUTHORITY (source_object),
- res,
- &error))
- {
- g_warning ("Error cancelling authorization check: %s", error->message);
- g_error_free (error);
- }
+ GVariant *subject_value;
+ GVariant *details_value;
+ CheckAuthData *data;
+
+ subject_value = polkit_subject_to_gvariant (subject);
+ details_value = polkit_details_to_gvariant (details);
+ g_variant_ref_sink (subject_value);
+ g_variant_ref_sink (details_value);
+
+ data = g_new0 (CheckAuthData, 1);
+ data->authority = g_object_ref (authority);
+ data->simple = g_simple_async_result_new (G_OBJECT (authority),
+ callback,
+ user_data,
+ polkit_authority_check_authorization);
+ if (cancellable != NULL)
+ data->cancellation_id = g_strdup_printf ("cancellation-id-%d", authority->cancellation_id_counter++);
+
+ g_dbus_proxy_call (authority->proxy,
+ "CheckAuthorization",
+ g_variant_new ("(@(sa{sv})s at a{ss}us)",
+ subject_value,
+ action_id,
+ details_value,
+ flags,
+ data->cancellation_id != NULL ? data->cancellation_id : ""),
+ G_DBUS_CALL_FLAGS_NONE,
+ G_MAXINT, /* no timeout */
+ cancellable,
+ (GAsyncReadyCallback) check_authorization_cb,
+ data);
+ g_variant_unref (subject_value);
+ g_variant_unref (details_value);
}
/**
@@ -560,66 +587,18 @@ polkit_authority_check_authorization_finish (PolkitAuthority *authority
GAsyncResult *res,
GError **error)
{
- PolkitAuthorizationResult *result;
- _PolkitAuthorizationResult *real_result;
- GSimpleAsyncResult *simple;
- GAsyncResult *real_res;
- GError *local_error;
+ GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
+ PolkitAuthorizationResult *ret;
- simple = G_SIMPLE_ASYNC_RESULT (res);
- real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));
+ ret = NULL;
- g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_check_authorization_async);
-
- result = NULL;
- real_result = NULL;
-
- local_error = NULL;
- _polkit_authority_check_authorization_finish (authority->real,
- &real_result,
- real_res,
- &local_error);
-
- if (local_error != NULL)
- {
- if (local_error->domain == EGG_DBUS_ERROR && local_error->code == EGG_DBUS_ERROR_CANCELLED)
- {
- const gchar *cancellation_id;
-
- /* if the operation was cancelled locally, make sure to tell the daemon so the authentication
- * dialog etc. can be removed
- */
- cancellation_id = g_object_get_data (G_OBJECT (simple), "polkit-1-cancellation-id");
- if (cancellation_id != NULL)
- {
- _polkit_authority_cancel_check_authorization (authority->real,
- EGG_DBUS_CALL_FLAGS_NONE,
- cancellation_id,
- NULL,
- authorization_check_cancelled_cb,
- NULL);
- }
-
- g_set_error (error,
- POLKIT_ERROR,
- POLKIT_ERROR_CANCELLED,
- "The operation was cancelled");
- g_error_free (local_error);
- }
- else
- {
- g_propagate_error (error, local_error);
- }
- }
- g_object_unref (real_res);
+ if (g_simple_async_result_propagate_error (simple, error))
+ goto out;
- if (real_result != NULL)
- {
- result = polkit_authorization_result_new_for_real (real_result);
- g_object_unref (real_result);
- }
+ ret = g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
- return result;
+ out:
+ return ret;
}
/**
@@ -651,63 +630,20 @@ polkit_authority_check_authorization_sync (PolkitAuthority *author
GCancellable *cancellable,
GError **error)
{
- guint call_id;
- GAsyncResult *res;
- PolkitAuthorizationResult *result;
-
- call_id = polkit_authority_check_authorization_async (authority,
- subject,
- action_id,
- details,
- flags,
- cancellable,
- generic_cb,
- &res);
+ PolkitAuthorizationResult *ret;
+ CallSyncData *data;
- egg_dbus_connection_pending_call_block (authority->system_bus, call_id);
+ data = call_sync_new ();
+ polkit_authority_check_authorization (authority, subject, action_id, details, flags, cancellable, call_sync_cb, data);
+ call_sync_block (data);
+ ret = polkit_authority_check_authorization_finish (authority, data->res, error);
+ call_sync_free (data);
- result = polkit_authority_check_authorization_finish (authority, res, error);
-
- g_object_unref (res);
-
- return result;
+ return ret;
}
/* ---------------------------------------------------------------------------------------------------- */
-static guint
-polkit_authority_register_authentication_agent_async (PolkitAuthority *authority,
- PolkitSubject *subject,
- const gchar *locale,
- const gchar *object_path,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- guint call_id;
- GSimpleAsyncResult *simple;
- _PolkitSubject *real_subject;
-
- simple = g_simple_async_result_new (G_OBJECT (authority),
- callback,
- user_data,
- polkit_authority_register_authentication_agent_async);
-
- real_subject = polkit_subject_get_real (subject);
-
- call_id = _polkit_authority_register_authentication_agent (authority->real,
- EGG_DBUS_CALL_FLAGS_NONE,
- real_subject,
- locale,
- object_path,
- cancellable,
- generic_async_cb,
- simple);
- g_object_unref (real_subject);
-
- return call_id;
-}
-
/**
* polkit_authority_register_authentication_agent:
* @authority: A #PolkitAuthority.
@@ -733,13 +669,21 @@ polkit_authority_register_authentication_agent (PolkitAuthority *authority,
GAsyncReadyCallback callback,
gpointer user_data)
{
- polkit_authority_register_authentication_agent_async (authority,
- subject,
- locale,
- object_path,
- cancellable,
- callback,
- user_data);
+ GVariant *subject_value;
+ subject_value = polkit_subject_to_gvariant (subject);
+ g_variant_ref_sink (subject_value);
+ g_dbus_proxy_call (authority->proxy,
+ "RegisterAuthenticationAgent",
+ g_variant_new ("(@(sa{sv})ss)",
+ subject_value,
+ locale,
+ object_path),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ cancellable,
+ callback,
+ user_data);
+ g_variant_unref (subject_value);
}
/**
@@ -757,24 +701,18 @@ polkit_authority_register_authentication_agent_finish (PolkitAuthority *authorit
GAsyncResult *res,
GError **error)
{
- GSimpleAsyncResult *simple;
- GAsyncResult *real_res;
gboolean ret;
+ GVariant *value;
- simple = G_SIMPLE_ASYNC_RESULT (res);
- real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));
+ ret = FALSE;
- g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_register_authentication_agent_async);
-
- ret = _polkit_authority_register_authentication_agent_finish (authority->real,
- real_res,
- error);
-
- if (!ret)
+ value = g_dbus_proxy_call_finish (authority->proxy, res, error);
+ if (value == NULL)
goto out;
+ ret = TRUE;
+ g_variant_unref (value);
out:
- g_object_unref (real_res);
return ret;
}
@@ -800,66 +738,26 @@ polkit_authority_register_authentication_agent_sync (PolkitAuthority *author
GCancellable *cancellable,
GError **error)
{
- guint call_id;
- GAsyncResult *res;
gboolean ret;
+ CallSyncData *data;
- call_id = polkit_authority_register_authentication_agent_async (authority,
- subject,
- locale,
- object_path,
- cancellable,
- generic_cb,
- &res);
-
- egg_dbus_connection_pending_call_block (authority->system_bus, call_id);
-
- ret = polkit_authority_register_authentication_agent_finish (authority, res, error);
-
- g_object_unref (res);
+ data = call_sync_new ();
+ polkit_authority_register_authentication_agent (authority, subject, locale, object_path, cancellable, call_sync_cb, data);
+ call_sync_block (data);
+ ret = polkit_authority_register_authentication_agent_finish (authority, data->res, error);
+ call_sync_free (data);
return ret;
}
/* ---------------------------------------------------------------------------------------------------- */
-static guint
-polkit_authority_unregister_authentication_agent_async (PolkitAuthority *authority,
- PolkitSubject *subject,
- const gchar *object_path,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- guint call_id;
- GSimpleAsyncResult *simple;
- _PolkitSubject *real_subject;
-
- simple = g_simple_async_result_new (G_OBJECT (authority),
- callback,
- user_data,
- polkit_authority_unregister_authentication_agent_async);
-
- real_subject = polkit_subject_get_real (subject);
-
- call_id = _polkit_authority_unregister_authentication_agent (authority->real,
- EGG_DBUS_CALL_FLAGS_NONE,
- real_subject,
- object_path,
- cancellable,
- generic_async_cb,
- simple);
-
- g_object_unref (real_subject);
-
- return call_id;
-}
-
/**
* polkit_authority_unregister_authentication_agent:
* @authority: A #PolkitAuthority.
- * @subject: The #PolkitSubject passed when registering the agent.
- * @object_path: The object path that the authentication agent is registered at.
+ * @subject: The subject the authentication agent is for, typically a #PolkitUnixSession object.
+ * @locale: The locale of the authentication agent.
+ * @object_path: The object path for the authentication agent.
* @cancellable: A #GCancellable or %NULL.
* @callback: A #GAsyncReadyCallback to call when the request is satisfied.
* @user_data: The data to pass to @callback.
@@ -878,12 +776,20 @@ polkit_authority_unregister_authentication_agent (PolkitAuthority *authorit
GAsyncReadyCallback callback,
gpointer user_data)
{
- polkit_authority_unregister_authentication_agent_async (authority,
- subject,
- object_path,
- cancellable,
- callback,
- user_data);
+ GVariant *subject_value;
+ subject_value = polkit_subject_to_gvariant (subject);
+ g_variant_ref_sink (subject_value);
+ g_dbus_proxy_call (authority->proxy,
+ "UnregisterAuthenticationAgent",
+ g_variant_new ("(@(sa{sv})s)",
+ subject_value,
+ object_path),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ cancellable,
+ callback,
+ user_data);
+ g_variant_unref (subject_value);
}
/**
@@ -901,32 +807,28 @@ polkit_authority_unregister_authentication_agent_finish (PolkitAuthority *author
GAsyncResult *res,
GError **error)
{
- GSimpleAsyncResult *simple;
- GAsyncResult *real_res;
gboolean ret;
+ GVariant *value;
- simple = G_SIMPLE_ASYNC_RESULT (res);
- real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));
+ ret = FALSE;
- g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_unregister_authentication_agent_async);
-
- ret = _polkit_authority_unregister_authentication_agent_finish (authority->real,
- real_res,
- error);
-
- if (!ret)
+ value = g_dbus_proxy_call_finish (authority->proxy, res, error);
+ if (value == NULL)
goto out;
+ ret = TRUE;
+ g_variant_unref (value);
out:
- g_object_unref (real_res);
return ret;
}
+
/**
* polkit_authority_unregister_authentication_agent_sync:
* @authority: A #PolkitAuthority.
- * @subject: The #PolkitSubject passed when registering the agent.
- * @object_path: The object path that the authentication agent is registered at.
+ * @subject: The subject the authentication agent is for, typically a #PolkitUnixSession object.
+ * @locale: The locale of the authentication agent.
+ * @object_path: The object path for the authentication agent.
* @cancellable: A #GCancellable or %NULL.
* @error: Return location for error or %NULL.
*
@@ -941,60 +843,20 @@ polkit_authority_unregister_authentication_agent_sync (PolkitAuthority *auth
GCancellable *cancellable,
GError **error)
{
- guint call_id;
- GAsyncResult *res;
gboolean ret;
+ CallSyncData *data;
- call_id = polkit_authority_unregister_authentication_agent_async (authority,
- subject,
- object_path,
- cancellable,
- generic_cb,
- &res);
-
- egg_dbus_connection_pending_call_block (authority->system_bus, call_id);
-
- ret = polkit_authority_unregister_authentication_agent_finish (authority, res, error);
-
- g_object_unref (res);
+ data = call_sync_new ();
+ polkit_authority_unregister_authentication_agent (authority, subject, object_path, cancellable, call_sync_cb, data);
+ call_sync_block (data);
+ ret = polkit_authority_unregister_authentication_agent_finish (authority, data->res, error);
+ call_sync_free (data);
return ret;
}
/* ---------------------------------------------------------------------------------------------------- */
-static guint
-polkit_authority_authentication_agent_response_async (PolkitAuthority *authority,
- const gchar *cookie,
- PolkitIdentity *identity,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- guint call_id;
- GSimpleAsyncResult *simple;
- _PolkitIdentity *real_identity;
-
- simple = g_simple_async_result_new (G_OBJECT (authority),
- callback,
- user_data,
- polkit_authority_authentication_agent_response_async);
-
- real_identity = polkit_identity_get_real (identity);
-
- call_id = _polkit_authority_authentication_agent_response (authority->real,
- EGG_DBUS_CALL_FLAGS_NONE,
- cookie,
- real_identity,
- cancellable,
- generic_async_cb,
- simple);
-
- g_object_unref (real_identity);
-
- return call_id;
-}
-
/**
* polkit_authority_authentication_agent_response:
* @authority: A #PolkitAuthority.
@@ -1022,12 +884,20 @@ polkit_authority_authentication_agent_response (PolkitAuthority *authority,
GAsyncReadyCallback callback,
gpointer user_data)
{
- polkit_authority_authentication_agent_response_async (authority,
- cookie,
- identity,
- cancellable,
- callback,
- user_data);
+ GVariant *identity_value;
+ identity_value = polkit_identity_to_gvariant (identity);
+ g_variant_ref_sink (identity_value);
+ g_dbus_proxy_call (authority->proxy,
+ "AuthenticationAgentResponse",
+ g_variant_new ("(s@(sa{sv}))",
+ cookie,
+ identity_value),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ cancellable,
+ callback,
+ user_data);
+ g_variant_unref (identity_value);
}
/**
@@ -1045,24 +915,18 @@ polkit_authority_authentication_agent_response_finish (PolkitAuthority *authorit
GAsyncResult *res,
GError **error)
{
- GSimpleAsyncResult *simple;
- GAsyncResult *real_res;
gboolean ret;
+ GVariant *value;
- simple = G_SIMPLE_ASYNC_RESULT (res);
- real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));
+ ret = FALSE;
- g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_authentication_agent_response_async);
-
- ret = _polkit_authority_authentication_agent_response_finish (authority->real,
- real_res,
- error);
-
- if (!ret)
+ value = g_dbus_proxy_call_finish (authority->proxy, res, error);
+ if (value == NULL)
goto out;
+ ret = TRUE;
+ g_variant_unref (value);
out:
- g_object_unref (real_res);
return ret;
}
@@ -1088,58 +952,20 @@ polkit_authority_authentication_agent_response_sync (PolkitAuthority *author
GCancellable *cancellable,
GError **error)
{
- guint call_id;
- GAsyncResult *res;
gboolean ret;
+ CallSyncData *data;
- call_id = polkit_authority_authentication_agent_response_async (authority,
- cookie,
- identity,
- cancellable,
- generic_cb,
- &res);
-
- egg_dbus_connection_pending_call_block (authority->system_bus, call_id);
-
- ret = polkit_authority_authentication_agent_response_finish (authority, res, error);
-
- g_object_unref (res);
+ data = call_sync_new ();
+ polkit_authority_authentication_agent_response (authority, cookie, identity, cancellable, call_sync_cb, data);
+ call_sync_block (data);
+ ret = polkit_authority_authentication_agent_response_finish (authority, data->res, error);
+ call_sync_free (data);
return ret;
}
/* ---------------------------------------------------------------------------------------------------- */
-static guint
-polkit_authority_enumerate_temporary_authorizations_async (PolkitAuthority *authority,
- PolkitSubject *subject,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- guint call_id;
- GSimpleAsyncResult *simple;
- _PolkitSubject *real_subject;
-
- simple = g_simple_async_result_new (G_OBJECT (authority),
- callback,
- user_data,
- polkit_authority_enumerate_temporary_authorizations_async);
-
- real_subject = polkit_subject_get_real (subject);
-
- call_id = _polkit_authority_enumerate_temporary_authorizations (authority->real,
- EGG_DBUS_CALL_FLAGS_NONE,
- real_subject,
- cancellable,
- generic_async_cb,
- simple);
-
- g_object_unref (real_subject);
-
- return call_id;
-}
-
/**
* polkit_authority_enumerate_temporary_authorizations:
* @authority: A #PolkitAuthority.
@@ -1161,7 +987,19 @@ polkit_authority_enumerate_temporary_authorizations (PolkitAuthority *author
GAsyncReadyCallback callback,
gpointer user_data)
{
- polkit_authority_enumerate_temporary_authorizations_async (authority, subject, cancellable, callback, user_data);
+ GVariant *subject_value;
+ subject_value = polkit_subject_to_gvariant (subject);
+ g_variant_ref_sink (subject_value);
+ g_dbus_proxy_call (authority->proxy,
+ "EnumerateTemporaryAuthorizations",
+ g_variant_new ("(@(sa{sv}))",
+ subject_value),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ cancellable,
+ callback,
+ user_data);
+ g_variant_unref (subject_value);
}
/**
@@ -1180,41 +1018,31 @@ polkit_authority_enumerate_temporary_authorizations_finish (PolkitAuthority *aut
GAsyncResult *res,
GError **error)
{
- EggDBusArraySeq *array_seq;
- GList *result;
- guint n;
- GSimpleAsyncResult *simple;
- GAsyncResult *real_res;
+ GList *ret;
+ GVariant *value;
+ GVariantIter iter;
+ GVariant *child;
+ GVariant *array;
- simple = G_SIMPLE_ASYNC_RESULT (res);
- real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));
+ ret = NULL;
- g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_enumerate_temporary_authorizations_async);
-
- result = NULL;
-
- if (!_polkit_authority_enumerate_temporary_authorizations_finish (authority->real,
- &array_seq,
- real_res,
- error))
+ value = g_dbus_proxy_call_finish (authority->proxy, res, error);
+ if (value == NULL)
goto out;
- for (n = 0; n < array_seq->size; n++)
+ array = g_variant_get_child_value (value, 0);
+ g_variant_iter_init (&iter, array);
+ while ((child = g_variant_iter_next_value (&iter)) != NULL)
{
- _PolkitTemporaryAuthorization *real_ta;
-
- real_ta = array_seq->data.v_ptr[n];
-
- result = g_list_prepend (result, polkit_temporary_authorization_new_for_real (real_ta));
+ ret = g_list_prepend (ret, polkit_temporary_authorization_new_for_gvariant (child));
+ g_variant_unref (child);
}
-
- result = g_list_reverse (result);
-
- g_object_unref (array_seq);
+ ret = g_list_reverse (ret);
+ g_variant_unref (array);
+ g_variant_unref (value);
out:
- g_object_unref (real_res);
- return result;
+ return ret;
}
/**
@@ -1235,53 +1063,20 @@ polkit_authority_enumerate_temporary_authorizations_sync (PolkitAuthority *a
GCancellable *cancellable,
GError **error)
{
- guint call_id;
- GAsyncResult *res;
- GList *result;
+ GList *ret;
+ CallSyncData *data;
- call_id = polkit_authority_enumerate_temporary_authorizations_async (authority, subject, cancellable, generic_cb, &res);
+ data = call_sync_new ();
+ polkit_authority_enumerate_temporary_authorizations (authority, subject, cancellable, call_sync_cb, data);
+ call_sync_block (data);
+ ret = polkit_authority_enumerate_temporary_authorizations_finish (authority, data->res, error);
+ call_sync_free (data);
- egg_dbus_connection_pending_call_block (authority->system_bus, call_id);
-
- result = polkit_authority_enumerate_temporary_authorizations_finish (authority, res, error);
-
- g_object_unref (res);
-
- return result;
+ return ret;
}
/* ---------------------------------------------------------------------------------------------------- */
-static guint
-polkit_authority_revoke_temporary_authorizations_async (PolkitAuthority *authority,
- PolkitSubject *subject,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- guint call_id;
- GSimpleAsyncResult *simple;
- _PolkitSubject *real_subject;
-
- simple = g_simple_async_result_new (G_OBJECT (authority),
- callback,
- user_data,
- polkit_authority_revoke_temporary_authorizations_async);
-
- real_subject = polkit_subject_get_real (subject);
-
- call_id = _polkit_authority_revoke_temporary_authorizations (authority->real,
- EGG_DBUS_CALL_FLAGS_NONE,
- real_subject,
- cancellable,
- generic_async_cb,
- simple);
-
- g_object_unref (real_subject);
-
- return call_id;
-}
-
/**
* polkit_authority_revoke_temporary_authorizations:
* @authority: A #PolkitAuthority.
@@ -1303,7 +1098,19 @@ polkit_authority_revoke_temporary_authorizations (PolkitAuthority *authority
GAsyncReadyCallback callback,
gpointer user_data)
{
- polkit_authority_revoke_temporary_authorizations_async (authority, subject, cancellable, callback, user_data);
+ GVariant *subject_value;
+ subject_value = polkit_subject_to_gvariant (subject);
+ g_variant_ref_sink (subject_value);
+ g_dbus_proxy_call (authority->proxy,
+ "RevokeTemporaryAuthorizations",
+ g_variant_new ("(@(sa{sv}))",
+ subject_value),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ cancellable,
+ callback,
+ user_data);
+ g_variant_unref (subject_value);
}
/**
@@ -1321,24 +1128,18 @@ polkit_authority_revoke_temporary_authorizations_finish (PolkitAuthority *author
GAsyncResult *res,
GError **error)
{
- GSimpleAsyncResult *simple;
- GAsyncResult *real_res;
gboolean ret;
+ GVariant *value;
- simple = G_SIMPLE_ASYNC_RESULT (res);
- real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));
-
- g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_revoke_temporary_authorizations_async);
+ ret = FALSE;
- ret = _polkit_authority_revoke_temporary_authorizations_finish (authority->real,
- real_res,
- error);
-
- if (!ret)
+ value = g_dbus_proxy_call_finish (authority->proxy, res, error);
+ if (value == NULL)
goto out;
+ ret = TRUE;
+ g_variant_unref (value);
out:
- g_object_unref (real_res);
return ret;
}
@@ -1359,48 +1160,20 @@ polkit_authority_revoke_temporary_authorizations_sync (PolkitAuthority *auth
GCancellable *cancellable,
GError **error)
{
- guint call_id;
- GAsyncResult *res;
- gboolean result;
-
- call_id = polkit_authority_revoke_temporary_authorizations_async (authority, subject, cancellable, generic_cb, &res);
-
- egg_dbus_connection_pending_call_block (authority->system_bus, call_id);
-
- result = polkit_authority_revoke_temporary_authorizations_finish (authority, res, error);
+ gboolean ret;
+ CallSyncData *data;
- g_object_unref (res);
+ data = call_sync_new ();
+ polkit_authority_revoke_temporary_authorizations (authority, subject, cancellable, call_sync_cb, data);
+ call_sync_block (data);
+ ret = polkit_authority_revoke_temporary_authorizations_finish (authority, data->res, error);
+ call_sync_free (data);
- return result;
+ return ret;
}
/* ---------------------------------------------------------------------------------------------------- */
-static guint
-polkit_authority_revoke_temporary_authorization_by_id_async (PolkitAuthority *authority,
- const gchar *id,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- guint call_id;
- GSimpleAsyncResult *simple;
-
- simple = g_simple_async_result_new (G_OBJECT (authority),
- callback,
- user_data,
- polkit_authority_revoke_temporary_authorizations_async);
-
- call_id = _polkit_authority_revoke_temporary_authorization_by_id (authority->real,
- EGG_DBUS_CALL_FLAGS_NONE,
- id,
- cancellable,
- generic_async_cb,
- simple);
-
- return call_id;
-}
-
/**
* polkit_authority_revoke_temporary_authorization_by_id:
* @authority: A #PolkitAuthority.
@@ -1422,7 +1195,15 @@ polkit_authority_revoke_temporary_authorization_by_id (PolkitAuthority *auth
GAsyncReadyCallback callback,
gpointer user_data)
{
- polkit_authority_revoke_temporary_authorization_by_id_async (authority, id, cancellable, callback, user_data);
+ g_dbus_proxy_call (authority->proxy,
+ "RevokeTemporaryAuthorizationById",
+ g_variant_new ("(s)",
+ id),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ cancellable,
+ callback,
+ user_data);
}
/**
@@ -1440,24 +1221,18 @@ polkit_authority_revoke_temporary_authorization_by_id_finish (PolkitAuthority *a
GAsyncResult *res,
GError **error)
{
- GSimpleAsyncResult *simple;
- GAsyncResult *real_res;
gboolean ret;
+ GVariant *value;
- simple = G_SIMPLE_ASYNC_RESULT (res);
- real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));
-
- g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_revoke_temporary_authorizations_async);
+ ret = FALSE;
- ret = _polkit_authority_revoke_temporary_authorization_by_id_finish (authority->real,
- real_res,
- error);
-
- if (!ret)
+ value = g_dbus_proxy_call_finish (authority->proxy, res, error);
+ if (value == NULL)
goto out;
+ ret = TRUE;
+ g_variant_unref (value);
out:
- g_object_unref (real_res);
return ret;
}
@@ -1478,48 +1253,20 @@ polkit_authority_revoke_temporary_authorization_by_id_sync (PolkitAuthority
GCancellable *cancellable,
GError **error)
{
- guint call_id;
- GAsyncResult *res;
- gboolean result;
-
- call_id = polkit_authority_revoke_temporary_authorization_by_id_async (authority, id, cancellable, generic_cb, &res);
-
- egg_dbus_connection_pending_call_block (authority->system_bus, call_id);
-
- result = polkit_authority_revoke_temporary_authorization_by_id_finish (authority, res, error);
+ gboolean ret;
+ CallSyncData *data;
- g_object_unref (res);
+ data = call_sync_new ();
+ polkit_authority_revoke_temporary_authorization_by_id (authority, id, cancellable, call_sync_cb, data);
+ call_sync_block (data);
+ ret = polkit_authority_revoke_temporary_authorization_by_id_finish (authority, data->res, error);
+ call_sync_free (data);
- return result;
+ return ret;
}
/* ---------------------------------------------------------------------------------------------------- */
-static guint
-polkit_authority_add_lockdown_for_action_async (PolkitAuthority *authority,
- const gchar *action_id,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- guint call_id;
- GSimpleAsyncResult *simple;
-
- simple = g_simple_async_result_new (G_OBJECT (authority),
- callback,
- user_data,
- polkit_authority_add_lockdown_for_action_async);
-
- call_id = _polkit_authority_add_lockdown_for_action (authority->real,
- EGG_DBUS_CALL_FLAGS_NONE,
- action_id,
- cancellable,
- generic_async_cb,
- simple);
-
- return call_id;
-}
-
/**
* polkit_authority_add_lockdown_for_action:
* @authority: A #PolkitAuthority.
@@ -1541,7 +1288,15 @@ polkit_authority_add_lockdown_for_action (PolkitAuthority *authority,
GAsyncReadyCallback callback,
gpointer user_data)
{
- polkit_authority_add_lockdown_for_action_async (authority, action_id, cancellable, callback, user_data);
+ g_dbus_proxy_call (authority->proxy,
+ "AddLockdownForAction",
+ g_variant_new ("(s)",
+ action_id),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ cancellable,
+ callback,
+ user_data);
}
/**
@@ -1559,24 +1314,18 @@ polkit_authority_add_lockdown_for_action_finish (PolkitAuthority *authority,
GAsyncResult *res,
GError **error)
{
- GSimpleAsyncResult *simple;
- GAsyncResult *real_res;
gboolean ret;
+ GVariant *value;
- simple = G_SIMPLE_ASYNC_RESULT (res);
- real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));
-
- g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_add_lockdown_for_action_async);
+ ret = FALSE;
- ret = _polkit_authority_add_lockdown_for_action_finish (authority->real,
- real_res,
- error);
-
- if (!ret)
+ value = g_dbus_proxy_call_finish (authority->proxy, res, error);
+ if (value == NULL)
goto out;
+ ret = TRUE;
+ g_variant_unref (value);
out:
- g_object_unref (real_res);
return ret;
}
@@ -1597,48 +1346,20 @@ polkit_authority_add_lockdown_for_action_sync (PolkitAuthority *authority,
GCancellable *cancellable,
GError **error)
{
- guint call_id;
- GAsyncResult *res;
- gboolean result;
-
- call_id = polkit_authority_add_lockdown_for_action_async (authority, action_id, cancellable, generic_cb, &res);
-
- egg_dbus_connection_pending_call_block (authority->system_bus, call_id);
-
- result = polkit_authority_add_lockdown_for_action_finish (authority, res, error);
+ gboolean ret;
+ CallSyncData *data;
- g_object_unref (res);
+ data = call_sync_new ();
+ polkit_authority_add_lockdown_for_action (authority, action_id, cancellable, call_sync_cb, data);
+ call_sync_block (data);
+ ret = polkit_authority_add_lockdown_for_action_finish (authority, data->res, error);
+ call_sync_free (data);
- return result;
+ return ret;
}
/* ---------------------------------------------------------------------------------------------------- */
-static guint
-polkit_authority_remove_lockdown_for_action_async (PolkitAuthority *authority,
- const gchar *action_id,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- guint call_id;
- GSimpleAsyncResult *simple;
-
- simple = g_simple_async_result_new (G_OBJECT (authority),
- callback,
- user_data,
- polkit_authority_remove_lockdown_for_action_async);
-
- call_id = _polkit_authority_remove_lockdown_for_action (authority->real,
- EGG_DBUS_CALL_FLAGS_NONE,
- action_id,
- cancellable,
- generic_async_cb,
- simple);
-
- return call_id;
-}
-
/**
* polkit_authority_remove_lockdown_for_action:
* @authority: A #PolkitAuthority.
@@ -1660,7 +1381,15 @@ polkit_authority_remove_lockdown_for_action (PolkitAuthority *authority,
GAsyncReadyCallback callback,
gpointer user_data)
{
- polkit_authority_remove_lockdown_for_action_async (authority, action_id, cancellable, callback, user_data);
+ g_dbus_proxy_call (authority->proxy,
+ "RemoveLockdownForAction",
+ g_variant_new ("(s)",
+ action_id),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ cancellable,
+ callback,
+ user_data);
}
/**
@@ -1678,24 +1407,18 @@ polkit_authority_remove_lockdown_for_action_finish (PolkitAuthority *authority,
GAsyncResult *res,
GError **error)
{
- GSimpleAsyncResult *simple;
- GAsyncResult *real_res;
gboolean ret;
+ GVariant *value;
- simple = G_SIMPLE_ASYNC_RESULT (res);
- real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));
-
- g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_remove_lockdown_for_action_async);
+ ret = FALSE;
- ret = _polkit_authority_remove_lockdown_for_action_finish (authority->real,
- real_res,
- error);
-
- if (!ret)
+ value = g_dbus_proxy_call_finish (authority->proxy, res, error);
+ if (value == NULL)
goto out;
+ ret = TRUE;
+ g_variant_unref (value);
out:
- g_object_unref (real_res);
return ret;
}
@@ -1716,19 +1439,16 @@ polkit_authority_remove_lockdown_for_action_sync (PolkitAuthority *authority
GCancellable *cancellable,
GError **error)
{
- guint call_id;
- GAsyncResult *res;
- gboolean result;
-
- call_id = polkit_authority_remove_lockdown_for_action_async (authority, action_id, cancellable, generic_cb, &res);
-
- egg_dbus_connection_pending_call_block (authority->system_bus, call_id);
-
- result = polkit_authority_remove_lockdown_for_action_finish (authority, res, error);
+ gboolean ret;
+ CallSyncData *data;
- g_object_unref (res);
+ data = call_sync_new ();
+ polkit_authority_remove_lockdown_for_action (authority, action_id, cancellable, call_sync_cb, data);
+ call_sync_block (data);
+ ret = polkit_authority_remove_lockdown_for_action_finish (authority, data->res, error);
+ call_sync_free (data);
- return result;
+ return ret;
}
/* ---------------------------------------------------------------------------------------------------- */
@@ -1745,7 +1465,12 @@ const gchar *
polkit_authority_get_backend_name (PolkitAuthority *authority)
{
if (authority->name == NULL)
- authority->name = _polkit_authority_get_backend_name (authority->real);
+ {
+ GVariant *value;
+ value = g_dbus_proxy_get_cached_property (authority->proxy, "BackendName");
+ authority->name = g_variant_dup_string (value, NULL);
+ g_variant_unref (value);
+ }
return authority->name;
}
@@ -1755,13 +1480,18 @@ polkit_authority_get_backend_name (PolkitAuthority *authority)
*
* Gets the version of the authority backend.
*
- * Returns: The name of the backend.
+ * Returns: The version string for the backend.
*/
const gchar *
polkit_authority_get_backend_version (PolkitAuthority *authority)
{
if (authority->version == NULL)
- authority->version = _polkit_authority_get_backend_version (authority->real);
+ {
+ GVariant *value;
+ value = g_dbus_proxy_get_cached_property (authority->proxy, "BackendVersion");
+ authority->version = g_variant_dup_string (value, NULL);
+ g_variant_unref (value);
+ }
return authority->version;
}
@@ -1776,5 +1506,12 @@ polkit_authority_get_backend_version (PolkitAuthority *authority)
PolkitAuthorityFeatures
polkit_authority_get_backend_features (PolkitAuthority *authority)
{
- return _polkit_authority_get_backend_features (authority->real);
+ PolkitAuthorityFeatures ret;
+ GVariant *value;
+
+ value = g_dbus_proxy_get_cached_property (authority->proxy, "BackendFeatures");
+ ret = (PolkitAuthorityFeatures) g_variant_get_uint32 (value);
+ g_variant_unref (value);
+
+ return ret;
}
diff --git a/src/polkit/polkitauthorizationresult.c b/src/polkit/polkitauthorizationresult.c
index 20c1434..334a6f3 100644
--- a/src/polkit/polkitauthorizationresult.c
+++ b/src/polkit/polkitauthorizationresult.c
@@ -302,3 +302,43 @@ polkit_authorization_result_get_locked_down (PolkitAuthorizationResult *result)
return ret;
}
+
+PolkitAuthorizationResult *
+polkit_authorization_result_new_for_gvariant (GVariant *value)
+{
+ gboolean is_authorized;
+ gboolean is_challenge;
+ GVariant *dict;
+ PolkitDetails *details;
+ PolkitAuthorizationResult *ret;
+
+ g_variant_get (value,
+ "(bb at a{ss})",
+ &is_authorized,
+ &is_challenge,
+ &dict);
+ details = polkit_details_new_for_gvariant (dict);
+ g_variant_unref (dict);
+
+ ret = polkit_authorization_result_new (is_authorized, is_challenge, details);
+ g_object_unref (details);
+
+ return ret;
+}
+
+GVariant *
+polkit_authorization_result_to_gvariant (PolkitAuthorizationResult *authorization_result)
+{
+ GVariant *ret;
+ GVariant *details_gvariant;
+
+ details_gvariant = polkit_details_to_gvariant (polkit_authorization_result_get_details (authorization_result));
+ g_variant_ref_sink (details_gvariant);
+ ret = g_variant_new ("(bb at a{ss})",
+ polkit_authorization_result_get_is_authorized (authorization_result),
+ polkit_authorization_result_get_is_challenge (authorization_result),
+ details_gvariant);
+ g_variant_unref (details_gvariant);
+
+ return ret;
+}
diff --git a/src/polkit/polkitdetails.c b/src/polkit/polkitdetails.c
index 2ef9e78..3490a71 100644
--- a/src/polkit/polkitdetails.c
+++ b/src/polkit/polkitdetails.c
@@ -188,3 +188,43 @@ polkit_details_get_keys (PolkitDetails *details)
return ret;
}
+
+GVariant *
+polkit_details_to_gvariant (PolkitDetails *details)
+{
+ GVariant *ret;
+ GVariantBuilder builder;
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
+ if (details != NULL && details->hash != NULL)
+ {
+ GHashTableIter hash_iter;
+ const gchar *key;
+ const gchar *value;
+
+ g_hash_table_iter_init (&hash_iter, details->hash);
+ while (g_hash_table_iter_next (&hash_iter, (gpointer) &key, (gpointer) &value))
+ g_variant_builder_add (&builder, "{ss}", key, value);
+ }
+ ret = g_variant_builder_end (&builder);
+ return ret;
+}
+
+PolkitDetails *
+polkit_details_new_for_gvariant (GVariant *value)
+{
+ PolkitDetails *ret;
+ GHashTable *hash;
+ GVariantIter iter;
+ gchar *hash_key;
+ gchar *hash_value;
+
+ hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ g_variant_iter_init (&iter, value);
+ while (g_variant_iter_next (&iter, "{ss}", &hash_key, &hash_value))
+ g_hash_table_insert (hash, hash_key, hash_value);
+ ret = polkit_details_new_for_hash (hash);
+ g_hash_table_unref (hash);
+ return ret;
+}
+
diff --git a/src/polkit/polkiterror.c b/src/polkit/polkiterror.c
index 9a50d10..89b9007 100644
--- a/src/polkit/polkiterror.c
+++ b/src/polkit/polkiterror.c
@@ -34,9 +34,22 @@
* Error codes.
*/
+static const GDBusErrorEntry polkit_error_entries[] =
+{
+ {POLKIT_ERROR_FAILED, "org.freedesktop.PolicyKit1.Error.Failed"},
+ {POLKIT_ERROR_CANCELLED, "org.freedesktop.PolicyKit1.Error.Cancelled"},
+ {POLKIT_ERROR_NOT_SUPPORTED, "org.freedesktop.PolicyKit1.Error.NotSupported"},
+ {POLKIT_ERROR_NOT_AUTHORIZED, "org.freedesktop.PolicyKit1.Error.NotAuthorized"},
+};
+
GQuark
polkit_error_quark (void)
{
- return _polkit_error_quark ();
+ static volatile gsize quark_volatile = 0;
+ g_dbus_error_register_error_domain ("polkit-error-quark",
+ &quark_volatile,
+ polkit_error_entries,
+ G_N_ELEMENTS (polkit_error_entries));
+ G_STATIC_ASSERT (G_N_ELEMENTS (polkit_error_entries) - 1 == POLKIT_ERROR_NOT_AUTHORIZED);
+ return (GQuark) quark_volatile;
}
-
diff --git a/src/polkit/polkitidentity.c b/src/polkit/polkitidentity.c
index 6e33136..b80c57f 100644
--- a/src/polkit/polkitidentity.c
+++ b/src/polkit/polkitidentity.c
@@ -259,3 +259,125 @@ polkit_identity_get_real (PolkitIdentity *identity)
return real;
}
+GVariant *
+polkit_identity_to_gvariant (PolkitIdentity *identity)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
+
+static GVariant *
+lookup_asv (GVariant *dict,
+ const gchar *given_key,
+ const GVariantType *given_type,
+ GError **error)
+{
+ GVariantIter iter;
+ const gchar *key;
+ GVariant *value;
+ GVariant *ret;
+
+ ret = NULL;
+
+ g_variant_iter_init (&iter, dict);
+ while (g_variant_iter_next (&iter, "{&sv}", &key, &value))
+ {
+ if (g_strcmp0 (key, given_key) == 0)
+ {
+ if (!g_variant_is_of_type (value, given_type))
+ {
+ gchar *type_string;
+ type_string = g_variant_type_dup_string (given_type);
+ g_set_error (error,
+ POLKIT_ERROR,
+ POLKIT_ERROR_FAILED,
+ "Value for key `%s' found but is of type %s and type %s was expected",
+ given_key,
+ g_variant_get_type_string (value),
+ type_string);
+ g_free (type_string);
+ goto out;
+ }
+ ret = value;
+ goto out;
+ }
+ g_variant_unref (value);
+ }
+
+ out:
+ if (ret == NULL)
+ {
+ gchar *type_string;
+ type_string = g_variant_type_dup_string (given_type);
+ g_set_error (error,
+ POLKIT_ERROR,
+ POLKIT_ERROR_FAILED,
+ "Didn't find value for key `%s' of type %s",
+ given_key,
+ type_string);
+ g_free (type_string);
+ }
+
+ return ret;
+}
+
+PolkitIdentity *
+polkit_identity_new_for_gvariant (GVariant *variant,
+ GError **error)
+{
+ PolkitIdentity *ret;
+ const gchar *kind;
+ GVariant *details_gvariant;
+
+ ret = NULL;
+
+ g_variant_get (variant,
+ "(&s at a{sv})",
+ &kind,
+ &details_gvariant);
+
+ if (g_strcmp0 (kind, "unix-user") == 0)
+ {
+ GVariant *v;
+ guint32 uid;
+
+ v = lookup_asv (details_gvariant, "uid", G_VARIANT_TYPE_UINT32, error);
+ if (v == NULL)
+ {
+ g_prefix_error (error, "Error parsing unix-user identity: ");
+ goto out;
+ }
+ uid = g_variant_get_uint32 (v);
+ g_variant_unref (v);
+
+ ret = polkit_unix_user_new (uid);
+ }
+ else if (g_strcmp0 (kind, "unix-group") == 0)
+ {
+ GVariant *v;
+ guint32 gid;
+
+ v = lookup_asv (details_gvariant, "gid", G_VARIANT_TYPE_UINT32, error);
+ if (v == NULL)
+ {
+ g_prefix_error (error, "Error parsing unix-user identity: ");
+ goto out;
+ }
+ gid = g_variant_get_uint32 (v);
+ g_variant_unref (v);
+
+ ret = polkit_unix_group_new (gid);
+ }
+ else
+ {
+ g_set_error (error,
+ POLKIT_ERROR,
+ POLKIT_ERROR_FAILED,
+ "Unknown identity of kind `%s'",
+ kind);
+ }
+
+ out:
+ g_variant_unref (details_gvariant);
+ return ret;
+}
diff --git a/src/polkit/polkitprivate.h b/src/polkit/polkitprivate.h
index 3d4ed16..d52f628 100644
--- a/src/polkit/polkitprivate.h
+++ b/src/polkit/polkitprivate.h
@@ -38,6 +38,14 @@
PolkitActionDescription *polkit_action_description_new_for_real (_PolkitActionDescription *real);
_PolkitActionDescription *polkit_action_description_get_real (PolkitActionDescription *action_description);
+PolkitActionDescription *polkit_action_description_new_for_gvariant (GVariant *value);
+GVariant *polkit_action_description_to_gvariant (PolkitActionDescription *action_description);
+
+GVariant *polkit_subject_to_gvariant (PolkitSubject *subject);
+GVariant *polkit_identity_to_gvariant (PolkitIdentity *identity);
+
+PolkitSubject *polkit_subject_new_for_gvariant (GVariant *variant, GError **error);
+PolkitIdentity *polkit_identity_new_for_gvariant (GVariant *variant, GError **error);
PolkitSubject *polkit_subject_new_for_real (_PolkitSubject *real);
_PolkitSubject *polkit_subject_get_real (PolkitSubject *subject);
@@ -47,11 +55,17 @@ _PolkitIdentity *polkit_identity_get_real (PolkitIdentity *identity);
PolkitAuthorizationResult *polkit_authorization_result_new_for_real (_PolkitAuthorizationResult *real);
_PolkitAuthorizationResult *polkit_authorization_result_get_real (PolkitAuthorizationResult *authorization_result);
+PolkitAuthorizationResult *polkit_authorization_result_new_for_gvariant (GVariant *value);
+GVariant *polkit_authorization_result_to_gvariant (PolkitAuthorizationResult *authorization_result);
_PolkitTemporaryAuthorization *polkit_temporary_authorization_get_real (PolkitTemporaryAuthorization *authorization);
PolkitTemporaryAuthorization *polkit_temporary_authorization_new_for_real (_PolkitTemporaryAuthorization *real);
+PolkitTemporaryAuthorization *polkit_temporary_authorization_new_for_gvariant (GVariant *value);
+GVariant *polkit_temporary_authorization_to_gvariant (PolkitTemporaryAuthorization *authorization);
PolkitDetails *polkit_details_new_for_hash (GHashTable *hash);
GHashTable *polkit_details_get_hash (PolkitDetails *details);
+GVariant *polkit_details_to_gvariant (PolkitDetails *details);
+PolkitDetails *polkit_details_new_for_gvariant (GVariant *value);
#endif /* __POLKIT_PRIVATE_H */
diff --git a/src/polkit/polkitsubject.c b/src/polkit/polkitsubject.c
index d5039a5..0fab0d9 100644
--- a/src/polkit/polkitsubject.c
+++ b/src/polkit/polkitsubject.c
@@ -360,3 +360,193 @@ polkit_subject_get_real (PolkitSubject *subject)
return real;
}
+
+GVariant *
+polkit_subject_to_gvariant (PolkitSubject *subject)
+{
+ GVariantBuilder builder;
+ GVariant *dict;
+ GVariant *ret;
+ const gchar *kind;
+
+ kind = "";
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
+ if (POLKIT_IS_UNIX_PROCESS (subject))
+ {
+ kind = "unix-process";
+ g_variant_builder_add (&builder, "{sv}", "pid",
+ g_variant_new_uint32 (polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (subject))));
+ g_variant_builder_add (&builder, "{sv}", "start-time",
+ g_variant_new_uint64 (polkit_unix_process_get_start_time (POLKIT_UNIX_PROCESS (subject))));
+ }
+ else if (POLKIT_IS_UNIX_SESSION (subject))
+ {
+ kind = "unix-process";
+ g_variant_builder_add (&builder, "{sv}", "session-id",
+ g_variant_new_string (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject))));
+ }
+ else if (POLKIT_IS_SYSTEM_BUS_NAME (subject))
+ {
+ kind = "system-bus-name";
+ g_variant_builder_add (&builder, "{sv}", "name",
+ g_variant_new_string (polkit_system_bus_name_get_name (POLKIT_SYSTEM_BUS_NAME (subject))));
+ }
+ else
+ {
+ g_warning ("Unknown class %s implementing PolkitSubject", g_type_name (G_TYPE_FROM_INSTANCE (subject)));
+ }
+
+ dict = g_variant_builder_end (&builder);
+ ret = g_variant_new ("(s at a{sv})", kind, dict);
+ return ret;
+}
+
+static GVariant *
+lookup_asv (GVariant *dict,
+ const gchar *given_key,
+ const GVariantType *given_type,
+ GError **error)
+{
+ GVariantIter iter;
+ const gchar *key;
+ GVariant *value;
+ GVariant *ret;
+
+ ret = NULL;
+
+ g_variant_iter_init (&iter, dict);
+ while (g_variant_iter_next (&iter, "{&sv}", &key, &value))
+ {
+ if (g_strcmp0 (key, given_key) == 0)
+ {
+ if (!g_variant_is_of_type (value, given_type))
+ {
+ gchar *type_string;
+ type_string = g_variant_type_dup_string (given_type);
+ g_set_error (error,
+ POLKIT_ERROR,
+ POLKIT_ERROR_FAILED,
+ "Value for key `%s' found but is of type %s and type %s was expected",
+ given_key,
+ g_variant_get_type_string (value),
+ type_string);
+ g_free (type_string);
+ goto out;
+ }
+ ret = value;
+ goto out;
+ }
+ g_variant_unref (value);
+ }
+
+ out:
+ if (ret == NULL)
+ {
+ gchar *type_string;
+ type_string = g_variant_type_dup_string (given_type);
+ g_set_error (error,
+ POLKIT_ERROR,
+ POLKIT_ERROR_FAILED,
+ "Didn't find value for key `%s' of type %s",
+ given_key,
+ type_string);
+ g_free (type_string);
+ }
+
+ return ret;
+}
+
+PolkitSubject *
+polkit_subject_new_for_gvariant (GVariant *variant,
+ GError **error)
+{
+ PolkitSubject *ret;
+ const gchar *kind;
+ GVariant *details_gvariant;
+
+ ret = NULL;
+
+ g_variant_get (variant,
+ "(&s at a{sv})",
+ &kind,
+ &details_gvariant);
+
+ if (g_strcmp0 (kind, "unix-process") == 0)
+ {
+ GVariant *v;
+ guint32 pid;
+ guint64 start_time;
+
+ v = lookup_asv (details_gvariant, "pid", G_VARIANT_TYPE_UINT32, error);
+ if (v == NULL)
+ {
+ g_prefix_error (error, "Error parsing unix-process subject: ");
+ goto out;
+ }
+ pid = g_variant_get_uint32 (v);
+ g_variant_unref (v);
+
+ v = lookup_asv (details_gvariant, "start-time", G_VARIANT_TYPE_UINT64, error);
+ if (v == NULL)
+ {
+ g_prefix_error (error, "Error parsing unix-process subject: ");
+ goto out;
+ }
+ start_time = g_variant_get_uint64 (v);
+ g_variant_unref (v);
+
+ ret = polkit_unix_process_new_full (pid, start_time);
+ }
+ else if (g_strcmp0 (kind, "unix-session") == 0)
+ {
+ GVariant *v;
+ const gchar *session_id;
+
+ v = lookup_asv (details_gvariant, "session-id", G_VARIANT_TYPE_STRING, error);
+ if (v == NULL)
+ {
+ g_prefix_error (error, "Error parsing unix-session subject: ");
+ goto out;
+ }
+ session_id = g_variant_get_string (v, NULL);
+ ret = polkit_unix_session_new (session_id);
+ g_variant_unref (v);
+ }
+ else if (g_strcmp0 (kind, "system-bus-name") == 0)
+ {
+ GVariant *v;
+ const gchar *name;
+
+ v = lookup_asv (details_gvariant, "name", G_VARIANT_TYPE_STRING, error);
+ if (v == NULL)
+ {
+ g_prefix_error (error, "Error parsing system-bus-name subject: ");
+ goto out;
+ }
+ name = g_variant_get_string (v, NULL);
+ if (!g_dbus_is_unique_name (name))
+ {
+ g_set_error (error,
+ POLKIT_ERROR,
+ POLKIT_ERROR_FAILED,
+ "Error parsing system-bus-name subject: `%s' is not a valid unique name",
+ name);
+ goto out;
+ }
+ ret = polkit_system_bus_name_new (name);
+ g_variant_unref (v);
+ }
+ else
+ {
+ g_set_error (error,
+ POLKIT_ERROR,
+ POLKIT_ERROR_FAILED,
+ "Unknown subject of kind `%s'",
+ kind);
+ }
+
+ out:
+ g_variant_unref (details_gvariant);
+ return ret;
+}
diff --git a/src/polkit/polkittemporaryauthorization.c b/src/polkit/polkittemporaryauthorization.c
index 409a5ec..3126b18 100644
--- a/src/polkit/polkittemporaryauthorization.c
+++ b/src/polkit/polkittemporaryauthorization.c
@@ -209,3 +209,43 @@ polkit_temporary_authorization_get_time_expires (PolkitTemporaryAuthorization *a
{
return _polkit_temporary_authorization_get_time_expires (authorization->real);
}
+
+PolkitTemporaryAuthorization *
+polkit_temporary_authorization_new_for_gvariant (GVariant *value)
+{
+ g_assert_not_reached ();
+ return NULL;
+}
+
+GVariant *
+polkit_temporary_authorization_to_gvariant (PolkitTemporaryAuthorization *authorization)
+{
+ const gchar *id;
+ const gchar *action_id;
+ PolkitSubject *subject;
+ guint64 time_obtained;
+ guint64 time_expires;
+ GVariant *ret;
+ GVariant *subject_gvariant;
+
+ id = polkit_temporary_authorization_get_id (authorization);
+ action_id = polkit_temporary_authorization_get_action_id (authorization);
+ subject = polkit_temporary_authorization_get_subject (authorization);
+ time_obtained = polkit_temporary_authorization_get_time_obtained (authorization);
+ time_expires = polkit_temporary_authorization_get_time_expires (authorization);
+
+ subject_gvariant = polkit_subject_to_gvariant (subject);
+ g_variant_ref_sink (subject_gvariant);
+ ret = g_variant_new ("(ss@(sa{sv})tt)",
+ id,
+ action_id,
+ subject_gvariant,
+ time_obtained,
+ time_expires);
+
+ g_variant_unref (subject_gvariant);
+ g_object_unref (subject);
+
+ return ret;
+}
+
diff --git a/src/polkitbackend/polkitbackendauthority.c b/src/polkitbackend/polkitbackendauthority.c
index 44de079..4373315 100644
--- a/src/polkitbackend/polkitbackendauthority.c
+++ b/src/polkitbackend/polkitbackendauthority.c
@@ -648,212 +648,219 @@ polkit_backend_authority_remove_lockdown_for_action_finish (PolkitBackendAuthori
/* ---------------------------------------------------------------------------------------------------- */
-#define TYPE_SERVER (server_get_type ())
-#define SERVER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_SERVER, Server))
-#define SERVER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TYPE_SERVER, ServerClass))
-#define SERVER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TYPE_SERVER,ServerClass))
-#define IS_SERVER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_SERVER))
-#define IS_SERVER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TYPE_SERVER))
-
-typedef struct _Server Server;
-typedef struct _ServerClass ServerClass;
-
-GType server_get_type (void) G_GNUC_CONST;
-
-struct _Server
+typedef struct
{
- GObject parent_instance;
-
- PolkitBackendAuthority *authority;
-
- EggDBusConnection *system_bus;
+ guint authority_registration_id;
+ guint name_owner_changed_signal_id;
- EggDBusObjectProxy *bus_proxy;
+ GDBusNodeInfo *introspection_info;
- EggDBusBus *bus;
+ PolkitBackendAuthority *authority;
- gulong name_owner_changed_id;
+ GDBusConnection *system_bus;
gulong authority_changed_id;
gchar *well_known_name;
+ gchar *object_path;
- GHashTable *cancellation_id_to_cancellable;
-};
-
-struct _ServerClass
-{
- GObjectClass parent_class;
-};
-
-enum
-{
- PROP_0,
- PROP_BACKEND_NAME,
- PROP_BACKEND_VERSION,
- PROP_BACKEND_FEATURES
-};
-
-static void authority_iface_init (_PolkitAuthorityIface *authority_iface);
-
-G_DEFINE_TYPE_WITH_CODE (Server, server, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (_POLKIT_TYPE_AUTHORITY, authority_iface_init)
- );
+ GHashTable *cancellation_id_to_check_auth_data;
+} Server;
static void
-server_init (Server *server)
+server_free (Server *server)
{
- server->cancellation_id_to_cancellable = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- g_object_unref);
-}
-
-static void
-server_finalize (GObject *object)
-{
- Server *server;
-
- server = SERVER (object);
-
g_free (server->well_known_name);
+ g_free (server->object_path);
/* TODO: release well_known_name if not NULL */
- g_signal_handler_disconnect (server->bus, server->name_owner_changed_id);
-
- g_object_unref (server->bus_proxy);
-
- g_object_unref (server->system_bus);
+ //g_signal_handler_disconnect (server->bus, server->name_owner_changed_id);
- g_signal_handler_disconnect (server->authority, server->authority_changed_id);
+ if (server->authority_registration_id > 0)
+ g_dbus_connection_unregister_object (server->system_bus, server->authority_registration_id);
- g_hash_table_unref (server->cancellation_id_to_cancellable);
-}
+ if (server->name_owner_changed_signal_id > 0)
+ g_dbus_connection_signal_unsubscribe (server->system_bus, server->name_owner_changed_signal_id);
-static void
-server_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- Server *server = SERVER (object);
+ if (server->system_bus != NULL)
+ g_object_unref (server->system_bus);
- switch (prop_id)
- {
- case PROP_BACKEND_NAME:
- g_value_set_string (value, polkit_backend_authority_get_name (server->authority));
- break;
+ if (server->introspection_info != NULL)
+ g_dbus_node_info_unref (server->introspection_info);
- case PROP_BACKEND_VERSION:
- g_value_set_string (value, polkit_backend_authority_get_version (server->authority));
- break;
+ if (server->authority != NULL && server->authority_changed_id > 0)
+ g_signal_handler_disconnect (server->authority, server->authority_changed_id);
- case PROP_BACKEND_FEATURES:
- g_value_set_flags (value, polkit_backend_authority_get_features (server->authority));
- break;
+ if (server->cancellation_id_to_check_auth_data != NULL)
+ g_hash_table_unref (server->cancellation_id_to_check_auth_data);
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ g_free (server);
}
-
static void
-server_class_init (ServerClass *klass)
+on_authority_changed (PolkitBackendAuthority *authority,
+ gpointer user_data)
{
- GObjectClass *gobject_class;
-
- gobject_class = G_OBJECT_CLASS (klass);
-
- gobject_class->finalize = server_finalize;
- gobject_class->get_property = server_get_property;
+ Server *server = user_data;
+ GError *error;
- g_assert (_polkit_authority_override_properties (gobject_class, PROP_BACKEND_NAME) == PROP_BACKEND_FEATURES);
+ error = NULL;
+ if (!g_dbus_connection_emit_signal (server->system_bus,
+ NULL, /* destination bus name */
+ server->object_path,
+ "org.freedesktop.PolicyKit1.Authority",
+ "Changed",
+ NULL,
+ &error))
+ {
+ g_warning ("Error emitting Changed() signal: %s", error->message);
+ g_error_free (error);
+ }
}
static void
-name_owner_changed (EggDBusBus *instance,
- gchar *name,
- gchar *old_owner,
- gchar *new_owner,
- Server *server)
+authority_died (gpointer user_data,
+ GObject *where_the_object_was)
{
- polkit_backend_authority_system_bus_name_owner_changed (server->authority, name, old_owner, new_owner);
+ Server *server = user_data;
+ server_free (server);
}
-static void
-authority_changed (PolkitBackendAuthority *authority,
- Server *server)
-{
- _polkit_authority_emit_signal_changed (_POLKIT_AUTHORITY (server), NULL);
-}
+static const gchar *server_introspection_data =
+ "<node>"
+ " <interface name='org.freedesktop.PolicyKit1.Authority'>"
+ " <method name='EnumerateActions'>"
+ " <arg type='s' name='locale' direction='in'/>"
+ " <arg type='a(ssssssuuua{ss})' name='action_descriptions' direction='out'/>"
+ " </method>"
+ " <method name='CheckAuthorization'>"
+ " <arg type='(sa{sv})' name='subject' direction='in'/>"
+ " <arg type='s' name='action_id' direction='in'/>"
+ " <arg type='a{ss}' name='details' direction='in'/>"
+ " <arg type='u' name='flags' direction='in'/>"
+ " <arg type='s' name='cancellation_id' direction='in'/>"
+ " <arg type='(bba{ss})' name='result' direction='out'/>"
+ " </method>"
+ " <method name='CancelCheckAuthorization'>"
+ " <arg type='s' name='cancellation_id' direction='in'/>"
+ " </method>"
+ " <method name='RegisterAuthenticationAgent'>"
+ " <arg type='(sa{sv})' name='subject' direction='in'/>"
+ " <arg type='s' name='locale' direction='in'/>"
+ " <arg type='s' name='object_path' direction='in'/>"
+ " </method>"
+ " <method name='UnregisterAuthenticationAgent'>"
+ " <arg type='(sa{sv})' name='subject' direction='in'/>"
+ " <arg type='s' name='object_path' direction='in'/>"
+ " </method>"
+ " <method name='AuthenticationAgentResponse'>"
+ " <arg type='s' name='cookie' direction='in'/>"
+ " <arg type='(sa{sv})' name='identity' direction='in'/>"
+ " </method>"
+ " <method name='EnumerateTemporaryAuthorizations'>"
+ " <arg type='(sa{sv})' name='subject' direction='in'/>"
+ " <arg type='a(ss(sa{sv})tt)' name='temporary_authorizations' direction='out'/>"
+ " </method>"
+ " <method name='RevokeTemporaryAuthorizations'>"
+ " <arg type='(sa{sv})' name='subject' direction='in'/>"
+ " </method>"
+ " <method name='RevokeTemporaryAuthorizationById'>"
+ " <arg type='s' name='id' direction='in'/>"
+ " </method>"
+ " <method name='AddLockdownForAction'>"
+ " <arg type='s' name='action_id' direction='in'/>"
+ " </method>"
+ " <method name='RemoveLockdownForAction'>"
+ " <arg type='s' name='action_id' direction='in'/>"
+ " </method>"
+ " <signal name='Changed'/>"
+ " <property type='s' name='BackendName' access='read'/>"
+ " <property type='s' name='BackendVersion' access='read'/>"
+ " <property type='u' name='BackendFeatures' access='read'/>"
+ " </interface>"
+ "</node>";
/* ---------------------------------------------------------------------------------------------------- */
static void
-authority_handle_enumerate_actions (_PolkitAuthority *instance,
- const gchar *locale,
- EggDBusMethodInvocation *method_invocation)
+server_handle_enumerate_actions (Server *server,
+ GVariant *parameters,
+ PolkitSubject *caller,
+ GDBusMethodInvocation *invocation)
{
- Server *server = SERVER (instance);
- PolkitSubject *caller;
- EggDBusArraySeq *array;
+ GVariantBuilder builder;
GError *error;
GList *actions;
GList *l;
+ const gchar *locale;
- error = NULL;
- caller = NULL;
actions = NULL;
- caller = polkit_system_bus_name_new (egg_dbus_method_invocation_get_caller (method_invocation));
+ g_variant_get (parameters, "(&s)", &locale);
+ error = NULL;
actions = polkit_backend_authority_enumerate_actions (server->authority,
caller,
locale,
&error);
if (error != NULL)
{
- egg_dbus_method_invocation_return_gerror (method_invocation, error);
+ g_dbus_method_invocation_return_gerror (invocation, error);
g_error_free (error);
goto out;
}
- array = egg_dbus_array_seq_new (G_TYPE_OBJECT, //_POLKIT_TYPE_ACTION_DESCRIPTION,
- (GDestroyNotify) g_object_unref,
- NULL,
- NULL);
-
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ssssssuuua{ss})"));
for (l = actions; l != NULL; l = l->next)
{
PolkitActionDescription *ad = POLKIT_ACTION_DESCRIPTION (l->data);
- _PolkitActionDescription *real;
-
- real = polkit_action_description_get_real (ad);
- egg_dbus_array_seq_add (array, real);
+ GVariant *value;
+ value = polkit_action_description_to_gvariant (ad);
+ g_variant_ref_sink (value);
+ g_variant_builder_add_value (&builder, value);
+ g_variant_unref (value);
}
-
- _polkit_authority_handle_enumerate_actions_finish (method_invocation, array);
-
- g_object_unref (array);
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(a(ssssssuuua{ss}))", &builder));
out:
g_list_foreach (actions, (GFunc) g_object_unref, NULL);
g_list_free (actions);
- g_object_unref (caller);
}
/* ---------------------------------------------------------------------------------------------------- */
+typedef struct
+{
+ GDBusMethodInvocation *invocation;
+ Server *server;
+ PolkitSubject *caller;
+ PolkitSubject *subject;
+ GCancellable *cancellable;
+ gchar *cancellation_id;
+} CheckAuthData;
+
+static void
+check_auth_data_free (CheckAuthData *data)
+{
+ if (data->invocation != NULL)
+ g_object_unref (data->invocation);
+ if (data->caller != NULL)
+ g_object_unref (data->caller);
+ if (data->subject != NULL)
+ g_object_unref (data->subject);
+ if (data->cancellable != NULL)
+ g_object_unref (data->cancellable);
+ g_free (data->cancellation_id);
+ g_free (data);
+}
+
static void
check_auth_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- EggDBusMethodInvocation *method_invocation = EGG_DBUS_METHOD_INVOCATION (user_data);
- const gchar *full_cancellation_id;
+ CheckAuthData *data = user_data;
PolkitAuthorizationResult *result;
GError *error;
@@ -862,92 +869,96 @@ check_auth_cb (GObject *source_object,
res,
&error);
- full_cancellation_id = g_object_get_data (G_OBJECT (method_invocation), "cancellation-id");
- if (full_cancellation_id != NULL)
- {
- Server *server;
- server = SERVER (g_object_get_data (G_OBJECT (method_invocation), "server"));
- g_hash_table_remove (server->cancellation_id_to_cancellable, full_cancellation_id);
- }
+ if (data->cancellation_id != NULL)
+ g_hash_table_remove (data->server->cancellation_id_to_check_auth_data, data->cancellation_id);
if (error != NULL)
{
- egg_dbus_method_invocation_return_gerror (method_invocation, error);
+ g_dbus_method_invocation_return_gerror (data->invocation, error);
g_error_free (error);
}
else
{
- _PolkitAuthorizationResult *real_result;
- real_result = polkit_authorization_result_get_real (result);
- _polkit_authority_handle_check_authorization_finish (method_invocation, real_result);
- g_object_unref (real_result);
- g_object_unref (result);
+ GVariant *value;
+ value = polkit_authorization_result_to_gvariant (result);
+ g_variant_ref_sink (value);
+ g_dbus_method_invocation_return_value (data->invocation, g_variant_new ("(@(bba{ss}))", value));
+ g_variant_unref (value);
}
+
+ check_auth_data_free (data);
}
static void
-authority_handle_check_authorization (_PolkitAuthority *instance,
- _PolkitSubject *real_subject,
- const gchar *action_id,
- EggDBusHashMap *real_details,
- _PolkitCheckAuthorizationFlags flags,
- const gchar *cancellation_id,
- EggDBusMethodInvocation *method_invocation)
+server_handle_check_authorization (Server *server,
+ GVariant *parameters,
+ PolkitSubject *caller,
+ GDBusMethodInvocation *invocation)
{
- Server *server = SERVER (instance);
- const gchar *caller_name;
+ GVariant *subject_gvariant;
+ const gchar *action_id;
+ GVariant *details_gvariant;
+ guint32 flags;
+ const gchar *cancellation_id;
+ GError *error;
PolkitSubject *subject;
- PolkitSubject *caller;
- GCancellable *cancellable;
PolkitDetails *details;
+ subject = NULL;
details = NULL;
- subject = polkit_subject_new_for_real (real_subject);
+ g_variant_get (parameters,
+ "(@(sa{sv})&s at a{ss}u&s)",
+ &subject_gvariant,
+ &action_id,
+ &details_gvariant,
+ &flags,
+ &cancellation_id);
+
+ error = NULL;
+ subject = polkit_subject_new_for_gvariant (subject_gvariant, &error);
if (subject == NULL)
{
- egg_dbus_method_invocation_return_error_literal (method_invocation,
- _POLKIT_ERROR,
- _POLKIT_ERROR_FAILED,
- "Error parsing subject struct");
+ g_prefix_error (&error, "Error getting subject: ");
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ g_error_free (error);
goto out;
}
- caller_name = egg_dbus_method_invocation_get_caller (method_invocation);
- caller = polkit_system_bus_name_new (caller_name);
+ details = polkit_details_new_for_gvariant (details_gvariant);
- details = polkit_details_new_for_hash (real_details->data);
+ CheckAuthData *data;
+ data = g_new0 (CheckAuthData, 1);
- g_object_set_data_full (G_OBJECT (method_invocation), "caller", caller, (GDestroyNotify) g_object_unref);
- g_object_set_data_full (G_OBJECT (method_invocation), "subject", subject, (GDestroyNotify) g_object_unref);
+ data->server = server;
+ data->caller = g_object_ref (caller);
+ data->subject = g_object_ref (subject);
+ data->invocation = g_object_ref (invocation);
- cancellable = NULL;
- if (cancellation_id != NULL && strlen (cancellation_id) > 0)
+ if (strlen (cancellation_id) > 0)
{
- gchar *full_cancellation_id;
-
- full_cancellation_id = g_strdup_printf ("%s-%s", caller_name, cancellation_id);
-
- if (g_hash_table_lookup (server->cancellation_id_to_cancellable, full_cancellation_id) != NULL)
+ data->cancellation_id = g_strdup_printf ("%s-%s",
+ g_dbus_method_invocation_get_sender (invocation),
+ cancellation_id);
+ if (g_hash_table_lookup (server->cancellation_id_to_check_auth_data, data->cancellation_id) != NULL)
{
- egg_dbus_method_invocation_return_error (method_invocation,
- _POLKIT_ERROR,
- _POLKIT_ERROR_CANCELLATION_ID_NOT_UNIQUE,
- "Given cancellation_id %s is already in use for name %s",
- cancellation_id,
- caller_name);
- g_free (full_cancellation_id);
+ gchar *message;
+ message = g_strdup_printf ("Given cancellation_id %s is already in use for name %s",
+ cancellation_id,
+ g_dbus_method_invocation_get_sender (invocation));
+ /* Don't want this error in our GError enum since libpolkit-gobject-1 users will never see it */
+ g_dbus_method_invocation_return_dbus_error (invocation,
+ "org.freedesktop.PolicyKit1.Error.CancellationIdNotUnique",
+ message);
+ g_free (message);
+ check_auth_data_free (data);
goto out;
}
- cancellable = g_cancellable_new ();
-
- g_hash_table_insert (server->cancellation_id_to_cancellable,
- full_cancellation_id,
- cancellable);
-
- g_object_set_data (G_OBJECT (method_invocation), "server", server);
- g_object_set_data (G_OBJECT (method_invocation), "cancellation-id", full_cancellation_id);
+ data->cancellable = g_cancellable_new ();
+ g_hash_table_insert (server->cancellation_id_to_check_auth_data,
+ data->cancellation_id,
+ data);
}
polkit_backend_authority_check_authorization (server->authority,
@@ -956,43 +967,54 @@ authority_handle_check_authorization (_PolkitAuthority *instance,
action_id,
details,
flags,
- cancellable,
+ data->cancellable,
check_auth_cb,
- method_invocation);
+ data);
+
out:
+
+ g_variant_unref (subject_gvariant);
+ g_variant_unref (details_gvariant);
+
if (details != NULL)
g_object_unref (details);
+ if (subject != NULL)
+ g_object_unref (subject);
}
+/* ---------------------------------------------------------------------------------------------------- */
+
static void
-authority_handle_cancel_check_authorization (_PolkitAuthority *instance,
- const gchar *cancellation_id,
- EggDBusMethodInvocation *method_invocation)
+server_handle_cancel_check_authorization (Server *server,
+ GVariant *parameters,
+ PolkitSubject *caller,
+ GDBusMethodInvocation *invocation)
{
- Server *server = SERVER (instance);
- GCancellable *cancellable;
- const gchar *caller_name;
+ CheckAuthData *data;
+ const gchar *cancellation_id;
gchar *full_cancellation_id;
- caller_name = egg_dbus_method_invocation_get_caller (method_invocation);
+ g_variant_get (parameters, "(&s)", &cancellation_id);
- full_cancellation_id = g_strdup_printf ("%s-%s", caller_name, cancellation_id);
+ full_cancellation_id = g_strdup_printf ("%s-%s",
+ g_dbus_method_invocation_get_sender (invocation),
+ cancellation_id);
- cancellable = g_hash_table_lookup (server->cancellation_id_to_cancellable, full_cancellation_id);
- if (cancellable == NULL)
+ data = g_hash_table_lookup (server->cancellation_id_to_check_auth_data, full_cancellation_id);
+ if (data == NULL)
{
- egg_dbus_method_invocation_return_error (method_invocation,
- _POLKIT_ERROR,
- _POLKIT_ERROR_FAILED,
- "No such cancellation_id %s for name %s",
- cancellation_id,
- caller_name);
+ g_dbus_method_invocation_return_error (invocation,
+ POLKIT_ERROR,
+ POLKIT_ERROR_FAILED,
+ "No such cancellation_id `%s' for name %s",
+ cancellation_id,
+ g_dbus_method_invocation_get_sender (invocation));
goto out;
}
- g_cancellable_cancel (cancellable);
+ g_cancellable_cancel (data->cancellable);
- _polkit_authority_handle_cancel_check_authorization_finish (method_invocation);
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
out:
g_free (full_cancellation_id);
@@ -1001,31 +1023,34 @@ authority_handle_cancel_check_authorization (_PolkitAuthority *ins
/* ---------------------------------------------------------------------------------------------------- */
static void
-authority_handle_register_authentication_agent (_PolkitAuthority *instance,
- _PolkitSubject *real_subject,
- const gchar *locale,
- const gchar *object_path,
- EggDBusMethodInvocation *method_invocation)
+server_handle_register_authentication_agent (Server *server,
+ GVariant *parameters,
+ PolkitSubject *caller,
+ GDBusMethodInvocation *invocation)
{
- Server *server = SERVER (instance);
- PolkitSubject *caller;
- PolkitSubject *subject;
+ GVariant *subject_gvariant;
GError *error;
+ PolkitSubject *subject;
+ const gchar *locale;
+ const gchar *object_path;
- caller = NULL;
+ subject = NULL;
- subject = polkit_subject_new_for_real (real_subject);
+ g_variant_get (parameters,
+ "(@(sa{sv})&s&s)",
+ &subject_gvariant,
+ &locale,
+ &object_path);
+
+ error = NULL;
+ subject = polkit_subject_new_for_gvariant (subject_gvariant, &error);
if (subject == NULL)
{
- egg_dbus_method_invocation_return_error_literal (method_invocation,
- _POLKIT_ERROR,
- _POLKIT_ERROR_FAILED,
- "Error parsing subject struct");
+ g_prefix_error (&error, "Error getting subject: ");
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ g_error_free (error);
goto out;
}
- g_object_set_data_full (G_OBJECT (method_invocation), "subject", subject, (GDestroyNotify) g_object_unref);
-
- caller = polkit_system_bus_name_new (egg_dbus_method_invocation_get_caller (method_invocation));
error = NULL;
if (!polkit_backend_authority_register_authentication_agent (server->authority,
@@ -1035,45 +1060,47 @@ authority_handle_register_authentication_agent (_PolkitAuthority *
object_path,
&error))
{
- egg_dbus_method_invocation_return_gerror (method_invocation, error);
+ g_dbus_method_invocation_return_gerror (invocation, error);
g_error_free (error);
goto out;
}
- _polkit_authority_handle_register_authentication_agent_finish (method_invocation);
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
out:
- if (caller != NULL)
- g_object_unref (caller);
+ if (subject != NULL)
+ g_object_unref (subject);
}
/* ---------------------------------------------------------------------------------------------------- */
static void
-authority_handle_unregister_authentication_agent (_PolkitAuthority *instance,
- _PolkitSubject *real_subject,
- const gchar *object_path,
- EggDBusMethodInvocation *method_invocation)
+server_handle_unregister_authentication_agent (Server *server,
+ GVariant *parameters,
+ PolkitSubject *caller,
+ GDBusMethodInvocation *invocation)
{
- Server *server = SERVER (instance);
- PolkitSubject *caller;
- PolkitSubject *subject;
+ GVariant *subject_gvariant;
GError *error;
+ PolkitSubject *subject;
+ const gchar *object_path;
+
+ subject = NULL;
- caller = NULL;
+ g_variant_get (parameters,
+ "(@(sa{sv})&s)",
+ &subject_gvariant,
+ &object_path);
- subject = polkit_subject_new_for_real (real_subject);
+ error = NULL;
+ subject = polkit_subject_new_for_gvariant (subject_gvariant, &error);
if (subject == NULL)
{
- egg_dbus_method_invocation_return_error_literal (method_invocation,
- _POLKIT_ERROR,
- _POLKIT_ERROR_FAILED,
- "Error parsing subject struct");
+ g_prefix_error (&error, "Error getting subject: ");
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ g_error_free (error);
goto out;
}
- g_object_set_data_full (G_OBJECT (method_invocation), "subject", subject, (GDestroyNotify) g_object_unref);
-
- caller = polkit_system_bus_name_new (egg_dbus_method_invocation_get_caller (method_invocation));
error = NULL;
if (!polkit_backend_authority_unregister_authentication_agent (server->authority,
@@ -1082,46 +1109,48 @@ authority_handle_unregister_authentication_agent (_PolkitAuthority
object_path,
&error))
{
- egg_dbus_method_invocation_return_gerror (method_invocation, error);
+ g_dbus_method_invocation_return_gerror (invocation, error);
g_error_free (error);
goto out;
}
- _polkit_authority_handle_unregister_authentication_agent_finish (method_invocation);
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
out:
- if (caller != NULL)
- g_object_unref (caller);
+ if (subject != NULL)
+ g_object_unref (subject);
}
/* ---------------------------------------------------------------------------------------------------- */
static void
-authority_handle_authentication_agent_response (_PolkitAuthority *instance,
- const gchar *cookie,
- _PolkitIdentity *real_identity,
- EggDBusMethodInvocation *method_invocation)
+server_handle_authentication_agent_response (Server *server,
+ GVariant *parameters,
+ PolkitSubject *caller,
+ GDBusMethodInvocation *invocation)
{
- Server *server = SERVER (instance);
- PolkitSubject *caller;
+ const gchar *cookie;
+ GVariant *identity_gvariant;
PolkitIdentity *identity;
GError *error;
- caller = NULL;
identity = NULL;
- identity = polkit_identity_new_for_real (real_identity);
+ g_variant_get (parameters,
+ "(&s@(sa{sv}))",
+ &cookie,
+ &identity_gvariant);
+
+ error = NULL;
+ identity = polkit_identity_new_for_gvariant (identity_gvariant, &error);
if (identity == NULL)
{
- egg_dbus_method_invocation_return_error_literal (method_invocation,
- _POLKIT_ERROR,
- _POLKIT_ERROR_FAILED,
- "Error parsing identity struct");
+ g_prefix_error (&error, "Error getting identity: ");
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ g_error_free (error);
goto out;
}
- caller = polkit_system_bus_name_new (egg_dbus_method_invocation_get_caller (method_invocation));
-
error = NULL;
if (!polkit_backend_authority_authentication_agent_response (server->authority,
caller,
@@ -1129,17 +1158,14 @@ authority_handle_authentication_agent_response (_PolkitAuthority *
identity,
&error))
{
- egg_dbus_method_invocation_return_gerror (method_invocation, error);
+ g_dbus_method_invocation_return_gerror (invocation, error);
g_error_free (error);
goto out;
}
- _polkit_authority_handle_authentication_agent_response_finish (method_invocation);
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
out:
- if (caller != NULL)
- g_object_unref (caller);
-
if (identity != NULL)
g_object_unref (identity);
}
@@ -1147,265 +1173,286 @@ authority_handle_authentication_agent_response (_PolkitAuthority *
/* ---------------------------------------------------------------------------------------------------- */
static void
-authority_handle_enumerate_temporary_authorizations (_PolkitAuthority *instance,
- _PolkitSubject *real_subject,
- EggDBusMethodInvocation *method_invocation)
+server_handle_enumerate_temporary_authorizations (Server *server,
+ GVariant *parameters,
+ PolkitSubject *caller,
+ GDBusMethodInvocation *invocation)
{
- Server *server = SERVER (instance);
- PolkitSubject *caller;
- EggDBusArraySeq *array;
+ GVariant *subject_gvariant;
GError *error;
- GList *temporary_authorizations;
- GList *l;
PolkitSubject *subject;
+ GList *authorizations;
+ GList *l;
+ GVariantBuilder builder;
- error = NULL;
- caller = NULL;
- temporary_authorizations = NULL;
+ subject = NULL;
+
+ g_variant_get (parameters,
+ "(@(sa{sv}))",
+ &subject_gvariant);
- subject = polkit_subject_new_for_real (real_subject);
+ error = NULL;
+ subject = polkit_subject_new_for_gvariant (subject_gvariant, &error);
if (subject == NULL)
{
- egg_dbus_method_invocation_return_error_literal (method_invocation,
- _POLKIT_ERROR,
- _POLKIT_ERROR_FAILED,
- "Error parsing subject struct");
+ g_prefix_error (&error, "Error getting subject: ");
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ g_error_free (error);
goto out;
}
- g_object_set_data_full (G_OBJECT (method_invocation), "subject", subject, (GDestroyNotify) g_object_unref);
-
- caller = polkit_system_bus_name_new (egg_dbus_method_invocation_get_caller (method_invocation));
- temporary_authorizations = polkit_backend_authority_enumerate_temporary_authorizations (server->authority,
- caller,
- subject,
- &error);
+ error = NULL;
+ authorizations = polkit_backend_authority_enumerate_temporary_authorizations (server->authority,
+ caller,
+ subject,
+ &error);
if (error != NULL)
{
- egg_dbus_method_invocation_return_gerror (method_invocation, error);
+ g_dbus_method_invocation_return_gerror (invocation, error);
g_error_free (error);
goto out;
}
- array = egg_dbus_array_seq_new (G_TYPE_OBJECT, //_POLKIT_TYPE_TEMPORARY_AUTHORIZATION,
- (GDestroyNotify) g_object_unref,
- NULL,
- NULL);
-
- for (l = temporary_authorizations; l != NULL; l = l->next)
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ss(sa{sv})tt)"));
+ for (l = authorizations; l != NULL; l = l->next)
{
- PolkitTemporaryAuthorization *ta = POLKIT_TEMPORARY_AUTHORIZATION (l->data);
- _PolkitTemporaryAuthorization *real;
-
- real = polkit_temporary_authorization_get_real (ta);
- egg_dbus_array_seq_add (array, real);
+ PolkitTemporaryAuthorization *a = POLKIT_TEMPORARY_AUTHORIZATION (l->data);
+ GVariant *value;
+ value = polkit_temporary_authorization_to_gvariant (a);
+ g_variant_ref_sink (value);
+ g_variant_builder_add_value (&builder, value);
+ g_variant_unref (value);
}
-
- _polkit_authority_handle_enumerate_temporary_authorizations_finish (method_invocation, array);
-
- g_object_unref (array);
+ g_list_foreach (authorizations, (GFunc) g_object_unref, NULL);
+ g_list_free (authorizations);
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(a(ss(sa{sv})tt))", &builder));
out:
- g_list_foreach (temporary_authorizations, (GFunc) g_object_unref, NULL);
- g_list_free (temporary_authorizations);
- if (caller != NULL)
- g_object_unref (caller);
+ if (subject != NULL)
+ g_object_unref (subject);
}
/* ---------------------------------------------------------------------------------------------------- */
static void
-authority_handle_revoke_temporary_authorizations (_PolkitAuthority *instance,
- _PolkitSubject *real_subject,
- EggDBusMethodInvocation *method_invocation)
+server_handle_revoke_temporary_authorizations (Server *server,
+ GVariant *parameters,
+ PolkitSubject *caller,
+ GDBusMethodInvocation *invocation)
{
- Server *server = SERVER (instance);
- PolkitSubject *caller;
+ GVariant *subject_gvariant;
GError *error;
PolkitSubject *subject;
- error = NULL;
- caller = NULL;
+ subject = NULL;
+
+ g_variant_get (parameters,
+ "(@(sa{sv}))",
+ &subject_gvariant);
- subject = polkit_subject_new_for_real (real_subject);
+ error = NULL;
+ subject = polkit_subject_new_for_gvariant (subject_gvariant, &error);
if (subject == NULL)
{
- egg_dbus_method_invocation_return_error_literal (method_invocation,
- _POLKIT_ERROR,
- _POLKIT_ERROR_FAILED,
- "Error parsing subject struct");
+ g_prefix_error (&error, "Error getting subject: ");
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ g_error_free (error);
goto out;
}
- g_object_set_data_full (G_OBJECT (method_invocation), "subject", subject, (GDestroyNotify) g_object_unref);
-
- caller = polkit_system_bus_name_new (egg_dbus_method_invocation_get_caller (method_invocation));
- polkit_backend_authority_revoke_temporary_authorizations (server->authority,
- caller,
- subject,
- &error);
- if (error != NULL)
+ error = NULL;
+ if (!polkit_backend_authority_revoke_temporary_authorizations (server->authority,
+ caller,
+ subject,
+ &error))
{
- egg_dbus_method_invocation_return_gerror (method_invocation, error);
+ g_dbus_method_invocation_return_gerror (invocation, error);
g_error_free (error);
goto out;
}
- _polkit_authority_handle_revoke_temporary_authorizations_finish (method_invocation);
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
out:
- if (caller != NULL)
- g_object_unref (caller);
+ if (subject != NULL)
+ g_object_unref (subject);
}
/* ---------------------------------------------------------------------------------------------------- */
static void
-authority_handle_revoke_temporary_authorization_by_id (_PolkitAuthority *instance,
- const gchar *id,
- EggDBusMethodInvocation *method_invocation)
+server_handle_revoke_temporary_authorization_by_id (Server *server,
+ GVariant *parameters,
+ PolkitSubject *caller,
+ GDBusMethodInvocation *invocation)
{
- Server *server = SERVER (instance);
GError *error;
- PolkitSubject *caller;
+ const gchar *id;
- error = NULL;
+ g_variant_get (parameters,
+ "(@s)",
+ &id);
- caller = polkit_system_bus_name_new (egg_dbus_method_invocation_get_caller (method_invocation));
-
- polkit_backend_authority_revoke_temporary_authorization_by_id (server->authority,
- caller,
- id,
- &error);
- if (error != NULL)
+ error = NULL;
+ if (!polkit_backend_authority_revoke_temporary_authorization_by_id (server->authority,
+ caller,
+ id,
+ &error))
{
- egg_dbus_method_invocation_return_gerror (method_invocation, error);
+ g_dbus_method_invocation_return_gerror (invocation, error);
g_error_free (error);
goto out;
}
- _polkit_authority_handle_revoke_temporary_authorization_by_id_finish (method_invocation);
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
out:
- g_object_unref (caller);
+ ;
}
/* ---------------------------------------------------------------------------------------------------- */
static void
-add_lockdown_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
+server_handle_add_lockdown_for_action (Server *server,
+ GVariant *parameters,
+ PolkitSubject *caller,
+ GDBusMethodInvocation *invocation)
{
- EggDBusMethodInvocation *method_invocation = EGG_DBUS_METHOD_INVOCATION (user_data);
- GError *error;
+ /* TODO: probably want to nuke this method so don't implement now */
+ g_dbus_method_invocation_return_error (invocation,
+ POLKIT_ERROR,
+ POLKIT_ERROR_NOT_SUPPORTED,
+ "Operation is not supported");
+}
- error = NULL;
- polkit_backend_authority_add_lockdown_for_action_finish (POLKIT_BACKEND_AUTHORITY (source_object),
- res,
- &error);
+/* ---------------------------------------------------------------------------------------------------- */
- if (error != NULL)
- {
- egg_dbus_method_invocation_return_gerror (method_invocation, error);
- g_error_free (error);
- }
- else
- {
- _polkit_authority_handle_add_lockdown_for_action_finish (method_invocation);
- }
+static void
+server_handle_remove_lockdown_for_action (Server *server,
+ GVariant *parameters,
+ PolkitSubject *caller,
+ GDBusMethodInvocation *invocation)
+{
+ /* TODO: probably want to nuke this method so don't implement now */
+ g_dbus_method_invocation_return_error (invocation,
+ POLKIT_ERROR,
+ POLKIT_ERROR_NOT_SUPPORTED,
+ "Operation is not supported");
}
+/* ---------------------------------------------------------------------------------------------------- */
+
static void
-authority_handle_add_lockdown_for_action (_PolkitAuthority *instance,
- const gchar *action_id,
- EggDBusMethodInvocation *method_invocation)
+server_handle_method_call (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- Server *server = SERVER (instance);
- const gchar *caller_name;
+ Server *server = user_data;
PolkitSubject *caller;
- caller_name = egg_dbus_method_invocation_get_caller (method_invocation);
- caller = polkit_system_bus_name_new (caller_name);
+ caller = polkit_system_bus_name_new (g_dbus_method_invocation_get_sender (invocation));
+
+ if (g_strcmp0 (method_name, "EnumerateActions") == 0)
+ server_handle_enumerate_actions (server, parameters, caller, invocation);
+ else if (g_strcmp0 (method_name, "CheckAuthorization") == 0)
+ server_handle_check_authorization (server, parameters, caller, invocation);
+ else if (g_strcmp0 (method_name, "CancelCheckAuthorization") == 0)
+ server_handle_cancel_check_authorization (server, parameters, caller, invocation);
+ else if (g_strcmp0 (method_name, "RegisterAuthenticationAgent") == 0)
+ server_handle_register_authentication_agent (server, parameters, caller, invocation);
+ else if (g_strcmp0 (method_name, "UnregisterAuthenticationAgent") == 0)
+ server_handle_unregister_authentication_agent (server, parameters, caller, invocation);
+ else if (g_strcmp0 (method_name, "AuthenticationAgentResponse") == 0)
+ server_handle_authentication_agent_response (server, parameters, caller, invocation);
+ else if (g_strcmp0 (method_name, "EnumerateTemporaryAuthorizations") == 0)
+ server_handle_enumerate_temporary_authorizations (server, parameters, caller, invocation);
+ else if (g_strcmp0 (method_name, "RevokeTemporaryAuthorizations") == 0)
+ server_handle_revoke_temporary_authorizations (server, parameters, caller, invocation);
+ else if (g_strcmp0 (method_name, "RevokeTemporaryAuthorizationById") == 0)
+ server_handle_revoke_temporary_authorization_by_id (server, parameters, caller, invocation);
+ else if (g_strcmp0 (method_name, "AddLockdownForAction") == 0)
+ server_handle_add_lockdown_for_action (server, parameters, caller, invocation);
+ else if (g_strcmp0 (method_name, "RemoveLockdownForAction") == 0)
+ server_handle_remove_lockdown_for_action (server, parameters, caller, invocation);
+ else
+ g_assert_not_reached ();
- polkit_backend_authority_add_lockdown_for_action (server->authority,
- caller,
- action_id,
- add_lockdown_cb,
- method_invocation);
+ g_object_unref (caller);
}
-/* ---------------------------------------------------------------------------------------------------- */
-
-static void
-remove_lockdown_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
+static GVariant *
+server_handle_get_property (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *property_name,
+ GError **error,
+ gpointer user_data)
{
- EggDBusMethodInvocation *method_invocation = EGG_DBUS_METHOD_INVOCATION (user_data);
- GError *error;
+ Server *server = user_data;
+ GVariant *result;
- error = NULL;
- polkit_backend_authority_remove_lockdown_for_action_finish (POLKIT_BACKEND_AUTHORITY (source_object),
- res,
- &error);
+ result = NULL;
- if (error != NULL)
+ if (g_strcmp0 (property_name, "BackendName") == 0)
{
- egg_dbus_method_invocation_return_gerror (method_invocation, error);
- g_error_free (error);
+ result = g_variant_new_string (polkit_backend_authority_get_name (server->authority));
}
- else
+ else if (g_strcmp0 (property_name, "BackendVersion") == 0)
{
- _polkit_authority_handle_remove_lockdown_for_action_finish (method_invocation);
+ result = g_variant_new_string (polkit_backend_authority_get_version (server->authority));
}
-}
-
-static void
-authority_handle_remove_lockdown_for_action (_PolkitAuthority *instance,
- const gchar *action_id,
- EggDBusMethodInvocation *method_invocation)
-{
- Server *server = SERVER (instance);
- const gchar *caller_name;
- PolkitSubject *caller;
-
- caller_name = egg_dbus_method_invocation_get_caller (method_invocation);
- caller = polkit_system_bus_name_new (caller_name);
+ else if (g_strcmp0 (property_name, "BackendFeatures") == 0)
+ {
+ result = g_variant_new_uint32 (polkit_backend_authority_get_features (server->authority));
+ }
+ else
+ g_assert_not_reached ();
- polkit_backend_authority_remove_lockdown_for_action (server->authority,
- caller,
- action_id,
- remove_lockdown_cb,
- method_invocation);
+ return result;
}
/* ---------------------------------------------------------------------------------------------------- */
static void
-authority_iface_init (_PolkitAuthorityIface *authority_iface)
+server_on_name_owner_changed_signal (GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
{
- authority_iface->handle_enumerate_actions = authority_handle_enumerate_actions;
- authority_iface->handle_check_authorization = authority_handle_check_authorization;
- authority_iface->handle_cancel_check_authorization = authority_handle_cancel_check_authorization;
- authority_iface->handle_register_authentication_agent = authority_handle_register_authentication_agent;
- authority_iface->handle_unregister_authentication_agent = authority_handle_unregister_authentication_agent;
- authority_iface->handle_authentication_agent_response = authority_handle_authentication_agent_response;
- authority_iface->handle_enumerate_temporary_authorizations = authority_handle_enumerate_temporary_authorizations;
- authority_iface->handle_revoke_temporary_authorizations = authority_handle_revoke_temporary_authorizations;
- authority_iface->handle_revoke_temporary_authorization_by_id = authority_handle_revoke_temporary_authorization_by_id;
- authority_iface->handle_add_lockdown_for_action = authority_handle_add_lockdown_for_action;
- authority_iface->handle_remove_lockdown_for_action = authority_handle_remove_lockdown_for_action;
+ Server *server = user_data;
+ const gchar *name;
+ const gchar *old_owner;
+ const gchar *new_owner;
+
+ g_variant_get (parameters,
+ "(&s&s&s)",
+ &name,
+ &old_owner,
+ &new_owner);
+
+ polkit_backend_authority_system_bus_name_owner_changed (server->authority,
+ name,
+ old_owner,
+ new_owner);
}
-static void
-authority_died (gpointer user_data,
- GObject *where_the_object_was)
-{
- Server *server = SERVER (user_data);
+/* ---------------------------------------------------------------------------------------------------- */
- g_object_unref (server);
-}
+static const GDBusInterfaceVTable server_vtable =
+{
+ server_handle_method_call,
+ server_handle_get_property,
+ NULL, /* server_handle_set_property */
+};
/**
* polkit_backend_register_authority:
@@ -1425,70 +1472,98 @@ polkit_backend_register_authority (PolkitBackendAuthority *authority,
GError **error)
{
Server *server;
- EggDBusRequestNameReply rn_ret;
- server = SERVER (g_object_new (TYPE_SERVER, NULL));
+ server = g_new0 (Server, 1);
+
+ server->cancellation_id_to_check_auth_data = g_hash_table_new (g_str_hash, g_str_equal);
- server->system_bus = egg_dbus_connection_get_for_bus (EGG_DBUS_BUS_TYPE_SYSTEM);
+ server->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
+ if (server->system_bus == NULL)
+ goto error;
server->well_known_name = g_strdup (well_known_name);
+ server->object_path = g_strdup (object_path);
+
+ server->introspection_info = g_dbus_node_info_new_for_xml (server_introspection_data, error);
+ if (server->introspection_info == NULL)
+ goto error;
+
+ server->authority_registration_id = g_dbus_connection_register_object (server->system_bus,
+ object_path,
+ g_dbus_node_info_lookup_interface (server->introspection_info, "org.freedesktop.PolicyKit1.Authority"),
+ &server_vtable,
+ server,
+ NULL,
+ error);
+ if (server->authority_registration_id == 0)
+ {
+ goto error;
+ }
if (well_known_name != NULL)
{
- if (!egg_dbus_bus_request_name_sync (egg_dbus_connection_get_bus (server->system_bus),
- EGG_DBUS_CALL_FLAGS_NONE,
- well_known_name,
- EGG_DBUS_REQUEST_NAME_FLAGS_NONE,
- &rn_ret,
- NULL,
- error))
+ GVariant *result;
+ guint32 request_name_result;
+
+ /* TODO: use g_bus_own_name() instead */
+ result = g_dbus_connection_call_sync (server->system_bus,
+ "org.freedesktop.DBus", /* name */
+ "/org/freedesktop/DBus", /* path */
+ "org.freedesktop.DBus", /* interface */
+ "RequestName",
+ g_variant_new ("(su)", well_known_name, 0),
+ G_VARIANT_TYPE ("(u)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL, /* GCancellable */
+ error);
+ if (result == NULL)
{
+ g_prefix_error (error,
+ "Could not become primary name owner for `%s'. RequestName() failed with: ",
+ well_known_name);
goto error;
}
-
- if (rn_ret != EGG_DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
+ g_variant_get (result, "(u)", &request_name_result);
+ g_variant_unref (result);
+ if (request_name_result != 1)
{
g_set_error (error,
POLKIT_ERROR,
POLKIT_ERROR_FAILED,
- "Could not become primary name owner for %s",
- well_known_name);
+ "Could not become primary name owner for `%s'. RequestName returned %d",
+ well_known_name,
+ request_name_result);
goto error;
}
}
- server->authority = authority;
-
- /* TODO: it's a bit wasteful listening to all name-owner-changed signals... needs to be optimized */
- server->bus_proxy = egg_dbus_connection_get_object_proxy (server->system_bus,
- "org.freedesktop.DBus",
- "/org/freedesktop/DBus");
-
- server->bus = EGG_DBUS_QUERY_INTERFACE_BUS (server->bus_proxy);
+ server->name_owner_changed_signal_id =
+ g_dbus_connection_signal_subscribe (server->system_bus,
+ "org.freedesktop.DBus", /* sender */
+ "org.freedesktop.DBus", /* interface */
+ "NameOwnerChanged", /* member */
+ "/org/freedesktop/DBus", /* path */
+ NULL, /* arg0 */
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ server_on_name_owner_changed_signal,
+ server,
+ NULL); /* GDestroyNotify */
- server->name_owner_changed_id = g_signal_connect (server->bus,
- "name-owner-changed",
- (GCallback) name_owner_changed,
- server);
+ server->authority = authority;
server->authority_changed_id = g_signal_connect (server->authority,
"changed",
- (GCallback) authority_changed,
+ G_CALLBACK (on_authority_changed),
server);
- egg_dbus_connection_register_interface (server->system_bus,
- object_path,
- _POLKIT_TYPE_AUTHORITY,
- G_OBJECT (server),
- G_TYPE_INVALID);
-
/* take a weak ref and kill server when listener dies */
g_object_weak_ref (G_OBJECT (server->authority), authority_died, server);
return TRUE;
error:
- g_object_unref (server);
+ server_free (server);
return FALSE;
}
diff --git a/src/polkitd/main.c b/src/polkitd/main.c
index 432d02b..ff39dd9 100644
--- a/src/polkitd/main.c
+++ b/src/polkitd/main.c
@@ -51,7 +51,7 @@ main (int argc, char **argv)
"/org/freedesktop/PolicyKit1/Authority",
&error))
{
- g_printerr ("Error registering authority: %s", error->message);
+ g_printerr ("Error registering authority: %s\n", error->message);
g_error_free (error);
goto out;
}
More information about the hal-commit
mailing list