From: David Zeuthen Date: Sun, 1 Feb 2009 19:01:59 +0000 (-0500) Subject: replace PolkitBackendServer with polkit_backend_register_authority() X-Git-Tag: 0.91~24 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5977ce758ceb745bdc4cef42b56b9cf2b0c8d14e;p=platform%2Fupstream%2Fpolkit.git replace PolkitBackendServer with polkit_backend_register_authority() This is consistent with how the PolkitAgentListener API works. --- diff --git a/docs/polkit/polkit-docs.xml b/docs/polkit/polkit-docs.xml index ed8361e..d486dbb 100644 --- a/docs/polkit/polkit-docs.xml +++ b/docs/polkit/polkit-docs.xml @@ -83,7 +83,6 @@ - diff --git a/src/polkitbackend/Makefile.am b/src/polkitbackend/Makefile.am index f34370e..6b128bc 100644 --- a/src/polkitbackend/Makefile.am +++ b/src/polkitbackend/Makefile.am @@ -55,7 +55,6 @@ libpolkit_backend_1include_HEADERS = \ polkitbackendlocalauthority.h \ polkitbackendactionpool.h \ polkitbackendpendingcall.h \ - polkitbackendserver.h \ polkitbackendsessionmonitor.h \ $(NULL) @@ -67,7 +66,6 @@ libpolkit_backend_1_la_SOURCES = \ polkitbackendlocalauthority.h polkitbackendlocalauthority.c \ polkitbackendactionpool.h polkitbackendactionpool.c \ polkitbackendpendingcall.h polkitbackendpendingcall.c \ - polkitbackendserver.h polkitbackendserver.c \ polkitbackendsessionmonitor.h polkitbackendsessionmonitor.c \ $(BUILT_SOURCES) \ $(NULL) diff --git a/src/polkitbackend/polkitbackend.h b/src/polkitbackend/polkitbackend.h index b9bb362..79caee0 100644 --- a/src/polkitbackend/polkitbackend.h +++ b/src/polkitbackend/polkitbackend.h @@ -28,7 +28,6 @@ #include #include #include -#include #include #undef _POLKIT_BACKEND_INSIDE_POLKIT_BACKEND_H diff --git a/src/polkitbackend/polkitbackendauthority.c b/src/polkitbackend/polkitbackendauthority.c index 0599381..c553ba6 100644 --- a/src/polkitbackend/polkitbackendauthority.c +++ b/src/polkitbackend/polkitbackendauthority.c @@ -24,8 +24,12 @@ #include #include #include +#include #include "polkitbackendauthority.h" +#include "polkitbackendpendingcall.h" +#include "polkitbackendprivate.h" + enum { CHANGED_SIGNAL, @@ -197,3 +201,597 @@ polkit_backend_authority_authentication_agent_response (PolkitBackendAuthority klass->authentication_agent_response (authority, cookie, identity, pending_call); } +/* ---------------------------------------------------------------------------------------------------- */ + +#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 +{ + GObject parent_instance; + + PolkitBackendAuthority *authority; + + EggDBusConnection *system_bus; + + EggDBusObjectProxy *bus_proxy; + + EggDBusBus *bus; + + gulong name_owner_changed_id; + + gulong authority_changed_id; + + gchar *well_known_name; +}; + +struct _ServerClass +{ + GObjectClass parent_class; +}; + +static void authority_iface_init (_PolkitAuthorityIface *authority_iface); +static void authority_manager_iface_init (_PolkitAuthorityManagerIface *authority_manager_iface); + +G_DEFINE_TYPE_WITH_CODE (Server, server, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (_POLKIT_TYPE_AUTHORITY, authority_iface_init) + G_IMPLEMENT_INTERFACE (_POLKIT_TYPE_AUTHORITY_MANAGER, authority_manager_iface_init) + ); + +static void +server_init (Server *local_server) +{ +} + +static void +server_finalize (GObject *object) +{ + Server *server; + + server = SERVER (object); + + g_free (server->well_known_name); + + /* 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->authority, server->authority_changed_id); + +} + +static void +server_class_init (ServerClass *klass) +{ + GObjectClass *gobject_class; + + gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->finalize = server_finalize; +} + +static void +name_owner_changed (EggDBusBus *instance, + gchar *name, + gchar *old_owner, + gchar *new_owner, + Server *server) +{ + polkit_backend_authority_system_bus_name_owner_changed (server->authority, name, old_owner, new_owner); +} + +static void +authority_changed (PolkitBackendAuthority *authority, + Server *server) +{ + _polkit_authority_emit_signal_changed (_POLKIT_AUTHORITY (server), NULL); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static void +authority_handle_enumerate_actions (_PolkitAuthority *instance, + const gchar *locale, + EggDBusMethodInvocation *method_invocation) +{ + Server *server = SERVER (instance); + PolkitBackendPendingCall *pending_call; + + pending_call = _polkit_backend_pending_call_new (method_invocation); + + polkit_backend_authority_enumerate_actions (server->authority, locale, pending_call); +} + +void +polkit_backend_authority_enumerate_actions_finish (PolkitBackendPendingCall *pending_call, + GList *actions) +{ + EggDBusArraySeq *array; + GList *l; + + array = egg_dbus_array_seq_new (G_TYPE_OBJECT, //_POLKIT_TYPE_ACTION_DESCRIPTION, + (GDestroyNotify) g_object_unref, + NULL, + NULL); + + 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); + } + + _polkit_authority_handle_enumerate_actions_finish (_polkit_backend_pending_call_get_method_invocation (pending_call), + array); + + g_object_unref (array); + + g_list_foreach (actions, (GFunc) g_object_unref, NULL); + g_list_free (actions); + + g_object_unref (pending_call); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static void +authority_manager_handle_enumerate_users (_PolkitAuthorityManager *instance, + EggDBusMethodInvocation *method_invocation) +{ + Server *server = SERVER (instance); + PolkitBackendPendingCall *pending_call; + + pending_call = _polkit_backend_pending_call_new (method_invocation); + + polkit_backend_authority_enumerate_users (server->authority, pending_call); +} + +void +polkit_backend_authority_enumerate_users_finish (PolkitBackendPendingCall *pending_call, + GList *users) +{ + EggDBusArraySeq *array; + GList *l; + + array = egg_dbus_array_seq_new (G_TYPE_OBJECT, //_POLKIT_TYPE_IDENTITY, + (GDestroyNotify) g_object_unref, + NULL, + NULL); + + for (l = users; l != NULL; l = l->next) + { + PolkitIdentity *identity = POLKIT_IDENTITY (l->data); + _PolkitIdentity *real; + + real = polkit_identity_get_real (identity); + egg_dbus_array_seq_add (array, real); + } + + _polkit_authority_manager_handle_enumerate_users_finish (_polkit_backend_pending_call_get_method_invocation (pending_call), + array); + + g_object_unref (array); + + g_list_foreach (users, (GFunc) g_object_unref, NULL); + g_list_free (users); + + g_object_unref (pending_call); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static void +authority_manager_handle_enumerate_groups (_PolkitAuthorityManager *instance, + EggDBusMethodInvocation *method_invocation) +{ + Server *server = SERVER (instance); + PolkitBackendPendingCall *pending_call; + + pending_call = _polkit_backend_pending_call_new (method_invocation); + + polkit_backend_authority_enumerate_groups (server->authority, pending_call); +} + +void +polkit_backend_authority_enumerate_groups_finish (PolkitBackendPendingCall *pending_call, + GList *groups) +{ + EggDBusArraySeq *array; + GList *l; + + array = egg_dbus_array_seq_new (G_TYPE_OBJECT, //_POLKIT_TYPE_IDENTITY, + (GDestroyNotify) g_object_unref, + NULL, + NULL); + + for (l = groups; l != NULL; l = l->next) + { + PolkitIdentity *identity = POLKIT_IDENTITY (l->data); + _PolkitIdentity *real; + + real = polkit_identity_get_real (identity); + egg_dbus_array_seq_add (array, real); + } + + _polkit_authority_manager_handle_enumerate_groups_finish (_polkit_backend_pending_call_get_method_invocation (pending_call), + array); + + g_object_unref (array); + + g_list_foreach (groups, (GFunc) g_object_unref, NULL); + g_list_free (groups); + + g_object_unref (pending_call); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static void +authority_handle_check_authorization (_PolkitAuthority *instance, + _PolkitSubject *real_subject, + const gchar *action_id, + _PolkitCheckAuthorizationFlags flags, + EggDBusMethodInvocation *method_invocation) +{ + Server *server = SERVER (instance); + PolkitBackendPendingCall *pending_call; + PolkitSubject *subject; + + pending_call = _polkit_backend_pending_call_new (method_invocation); + + subject = polkit_subject_new_for_real (real_subject); + + g_object_set_data_full (G_OBJECT (pending_call), "subject", subject, (GDestroyNotify) g_object_unref); + + polkit_backend_authority_check_authorization (server->authority, + subject, + action_id, + flags, + pending_call); +} + +void +polkit_backend_authority_check_authorization_finish (PolkitBackendPendingCall *pending_call, + PolkitAuthorizationResult result) +{ + _polkit_authority_handle_check_authorization_finish (_polkit_backend_pending_call_get_method_invocation (pending_call), + result); + + g_object_unref (pending_call); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static void +authority_manager_handle_enumerate_authorizations (_PolkitAuthorityManager *instance, + _PolkitIdentity *real_identity, + EggDBusMethodInvocation *method_invocation) +{ + Server *server = SERVER (instance); + PolkitBackendPendingCall *pending_call; + PolkitIdentity *identity; + + pending_call = _polkit_backend_pending_call_new (method_invocation); + + identity = polkit_identity_new_for_real (real_identity); + + g_object_set_data_full (G_OBJECT (pending_call), "identity", identity, (GDestroyNotify) g_object_unref); + + polkit_backend_authority_enumerate_authorizations (server->authority, + identity, + pending_call); +} + +void +polkit_backend_authority_enumerate_authorizations_finish (PolkitBackendPendingCall *pending_call, + GList *authorizations) +{ + EggDBusArraySeq *array; + GList *l; + + array = egg_dbus_array_seq_new (G_TYPE_OBJECT, //_POLKIT_TYPE_AUTHORIZATION, + (GDestroyNotify) g_object_unref, + NULL, + NULL); + + for (l = authorizations; l != NULL; l = l->next) + { + PolkitAuthorization *a = POLKIT_AUTHORIZATION (l->data); + _PolkitAuthorization *real; + + real = polkit_authorization_get_real (a); + egg_dbus_array_seq_add (array, real); + } + + _polkit_authority_manager_handle_enumerate_authorizations_finish (_polkit_backend_pending_call_get_method_invocation (pending_call), + array); + + g_object_unref (array); + + g_list_foreach (authorizations, (GFunc) g_object_unref, NULL); + g_list_free (authorizations); + + g_object_unref (pending_call); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static void +authority_manager_handle_add_authorization (_PolkitAuthorityManager *instance, + _PolkitIdentity *real_identity, + _PolkitAuthorization *real_authorization, + EggDBusMethodInvocation *method_invocation) +{ + Server *server = SERVER (instance); + PolkitBackendPendingCall *pending_call; + PolkitIdentity *identity; + PolkitAuthorization *authorization; + + pending_call = _polkit_backend_pending_call_new (method_invocation); + + identity = polkit_identity_new_for_real (real_identity); + + authorization = polkit_authorization_new_for_real (real_authorization); + + g_object_set_data_full (G_OBJECT (pending_call), "identity", identity, (GDestroyNotify) g_object_unref); + g_object_set_data_full (G_OBJECT (pending_call), "authorization", authorization, (GDestroyNotify) g_object_unref); + + polkit_backend_authority_add_authorization (server->authority, + identity, + authorization, + pending_call); +} + +void +polkit_backend_authority_add_authorization_finish (PolkitBackendPendingCall *pending_call) +{ + _polkit_authority_manager_handle_add_authorization_finish (_polkit_backend_pending_call_get_method_invocation (pending_call)); + g_object_unref (pending_call); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static void +authority_manager_handle_remove_authorization (_PolkitAuthorityManager *instance, + _PolkitIdentity *real_identity, + _PolkitAuthorization *real_authorization, + EggDBusMethodInvocation *method_invocation) +{ + Server *server = SERVER (instance); + PolkitBackendPendingCall *pending_call; + PolkitIdentity *identity; + PolkitAuthorization *authorization; + + pending_call = _polkit_backend_pending_call_new (method_invocation); + + identity = polkit_identity_new_for_real (real_identity); + + authorization = polkit_authorization_new_for_real (real_authorization); + + g_object_set_data_full (G_OBJECT (pending_call), "identity", identity, (GDestroyNotify) g_object_unref); + g_object_set_data_full (G_OBJECT (pending_call), "authorization", authorization, (GDestroyNotify) g_object_unref); + + polkit_backend_authority_remove_authorization (server->authority, + identity, + authorization, + pending_call); +} + +void +polkit_backend_authority_remove_authorization_finish (PolkitBackendPendingCall *pending_call) +{ + _polkit_authority_manager_handle_remove_authorization_finish (_polkit_backend_pending_call_get_method_invocation (pending_call)); + g_object_unref (pending_call); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static void +authority_handle_register_authentication_agent (_PolkitAuthority *instance, + const gchar *object_path, + EggDBusMethodInvocation *method_invocation) +{ + Server *server = SERVER (instance); + PolkitBackendPendingCall *pending_call; + + pending_call = _polkit_backend_pending_call_new (method_invocation); + + polkit_backend_authority_register_authentication_agent (server->authority, + object_path, + pending_call); +} + +void +polkit_backend_authority_register_authentication_agent_finish (PolkitBackendPendingCall *pending_call) +{ + _polkit_authority_handle_register_authentication_agent_finish (_polkit_backend_pending_call_get_method_invocation (pending_call)); + g_object_unref (pending_call); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static void +authority_handle_unregister_authentication_agent (_PolkitAuthority *instance, + const gchar *object_path, + EggDBusMethodInvocation *method_invocation) +{ + Server *server = SERVER (instance); + PolkitBackendPendingCall *pending_call; + + pending_call = _polkit_backend_pending_call_new (method_invocation); + + polkit_backend_authority_unregister_authentication_agent (server->authority, + object_path, + pending_call); +} + +void +polkit_backend_authority_unregister_authentication_agent_finish (PolkitBackendPendingCall *pending_call) +{ + _polkit_authority_handle_unregister_authentication_agent_finish (_polkit_backend_pending_call_get_method_invocation (pending_call)); + g_object_unref (pending_call); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static void +authority_handle_authentication_agent_response (_PolkitAuthority *instance, + const gchar *cookie, + _PolkitIdentity *real_identity, + EggDBusMethodInvocation *method_invocation) +{ + Server *server = SERVER (instance); + PolkitBackendPendingCall *pending_call; + PolkitIdentity *identity; + + pending_call = _polkit_backend_pending_call_new (method_invocation); + + identity = polkit_identity_new_for_real (real_identity); + + g_object_set_data_full (G_OBJECT (pending_call), "identity", identity, (GDestroyNotify) g_object_unref); + + polkit_backend_authority_authentication_agent_response (server->authority, + cookie, + identity, + pending_call); +} + +void +polkit_backend_authority_authentication_agent_response_finish (PolkitBackendPendingCall *pending_call) +{ + _polkit_authority_handle_authentication_agent_response_finish (_polkit_backend_pending_call_get_method_invocation (pending_call)); + g_object_unref (pending_call); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static void +authority_iface_init (_PolkitAuthorityIface *authority_iface) +{ + authority_iface->handle_enumerate_actions = authority_handle_enumerate_actions; + authority_iface->handle_check_authorization = authority_handle_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; +} + +static void +authority_manager_iface_init (_PolkitAuthorityManagerIface *authority_manager_iface) +{ + authority_manager_iface->handle_enumerate_users = authority_manager_handle_enumerate_users; + authority_manager_iface->handle_enumerate_groups = authority_manager_handle_enumerate_groups; + authority_manager_iface->handle_enumerate_authorizations = authority_manager_handle_enumerate_authorizations; + authority_manager_iface->handle_add_authorization = authority_manager_handle_add_authorization; + authority_manager_iface->handle_remove_authorization = authority_manager_handle_remove_authorization; +} + +static void +authority_died (gpointer user_data, + GObject *where_the_object_was) +{ + Server *server = SERVER (user_data); + + g_object_unref (server); +} + +/** + * polkit_backend_register_authority: + * @authority: A #PolkitBackendAuthority. + * @well_known_name: Well-known name to claim on the system bus or %NULL to not claim a well-known name. + * @object_path: Object path of the authority. + * @error: Return location for error. + * + * Registers @authority on the system message bus. + * + * Returns: %TRUE if @authority was registered, %FALSE if @error is set. + **/ +gboolean +polkit_backend_register_authority (PolkitBackendAuthority *authority, + const gchar *well_known_name, + const gchar *object_path, + GError **error) +{ + Server *server; + EggDBusRequestNameReply rn_ret; + + server = SERVER (g_object_new (TYPE_SERVER, NULL)); + + server->system_bus = egg_dbus_connection_get_for_bus (EGG_DBUS_BUS_TYPE_SYSTEM); + + server->well_known_name = g_strdup (well_known_name); + + 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)) + { + goto error; + } + + if (rn_ret != EGG_DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) + { + g_set_error (error, + POLKIT_ERROR, + POLKIT_ERROR_FAILED, + "Could not become primary name owner for %s", + well_known_name); + 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_id = g_signal_connect (server->bus, + "name-owner-changed", + (GCallback) name_owner_changed, + server); + + server->authority_changed_id = g_signal_connect (server->authority, + "changed", + (GCallback) authority_changed, + server); + + egg_dbus_connection_register_interface (server->system_bus, + object_path, + _POLKIT_TYPE_AUTHORITY, + G_OBJECT (server), + _POLKIT_TYPE_AUTHORITY_MANAGER, + 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); + return FALSE; +} diff --git a/src/polkitbackend/polkitbackendauthority.h b/src/polkitbackend/polkitbackendauthority.h index 8a2d959..413f18f 100644 --- a/src/polkitbackend/polkitbackendauthority.h +++ b/src/polkitbackend/polkitbackendauthority.h @@ -196,6 +196,11 @@ void polkit_backend_authority_unregister_authentication_agent_finish (Polkit void polkit_backend_authority_authentication_agent_response_finish (PolkitBackendPendingCall *pending_call); +gboolean polkit_backend_register_authority (PolkitBackendAuthority *authority, + const gchar *well_known_name, + const gchar *object_path, + GError **error); + G_END_DECLS #endif /* __POLKIT_BACKEND_AUTHORITY_H */ diff --git a/src/polkitbackend/polkitbackendpendingcall.c b/src/polkitbackend/polkitbackendpendingcall.c index 9cce8b6..5489ef2 100644 --- a/src/polkitbackend/polkitbackendpendingcall.c +++ b/src/polkitbackend/polkitbackendpendingcall.c @@ -28,7 +28,6 @@ typedef struct { EggDBusMethodInvocation *method_invocation; - PolkitBackendServer *server; PolkitSubject *inquirer; } PolkitBackendPendingCallPrivate; @@ -55,7 +54,6 @@ polkit_backend_pending_call_finalize (GObject *object) priv = POLKIT_BACKEND_PENDING_CALL_GET_PRIVATE (pending_call); g_object_unref (priv->method_invocation); - g_object_unref (priv->server); if (priv->inquirer != NULL) g_object_unref (priv->inquirer); @@ -76,8 +74,7 @@ polkit_backend_pending_call_class_init (PolkitBackendPendingCallClass *klass) } PolkitBackendPendingCall * -_polkit_backend_pending_call_new (EggDBusMethodInvocation *method_invocation, - PolkitBackendServer *server) +_polkit_backend_pending_call_new (EggDBusMethodInvocation *method_invocation) { PolkitBackendPendingCall *pending_call; PolkitBackendPendingCallPrivate *priv; @@ -88,19 +85,10 @@ _polkit_backend_pending_call_new (EggDBusMethodInvocation *method_invocation, priv = POLKIT_BACKEND_PENDING_CALL_GET_PRIVATE (pending_call); priv->method_invocation = g_object_ref (method_invocation); - priv->server = g_object_ref (server); return pending_call; } -PolkitBackendServer * -polkit_backend_pending_call_get_server (PolkitBackendPendingCall *pending_call) -{ - PolkitBackendPendingCallPrivate *priv; - priv = POLKIT_BACKEND_PENDING_CALL_GET_PRIVATE (pending_call); - return priv->server; -} - EggDBusMethodInvocation * _polkit_backend_pending_call_get_method_invocation (PolkitBackendPendingCall *pending_call) { diff --git a/src/polkitbackend/polkitbackendpendingcall.h b/src/polkitbackend/polkitbackendpendingcall.h index de26e52..18142ea 100644 --- a/src/polkitbackend/polkitbackendpendingcall.h +++ b/src/polkitbackend/polkitbackendpendingcall.h @@ -68,7 +68,6 @@ struct _PolkitBackendPendingCallClass GType polkit_backend_pending_call_get_type (void) G_GNUC_CONST; PolkitSubject *polkit_backend_pending_call_get_caller (PolkitBackendPendingCall *pending_call); -PolkitBackendServer *polkit_backend_pending_call_get_server (PolkitBackendPendingCall *pending_call); void polkit_backend_pending_call_return_error (PolkitBackendPendingCall *pending_call, GQuark domain, gint code, diff --git a/src/polkitbackend/polkitbackendprivate.h b/src/polkitbackend/polkitbackendprivate.h index e43635c..67950de 100644 --- a/src/polkitbackend/polkitbackendprivate.h +++ b/src/polkitbackend/polkitbackendprivate.h @@ -24,10 +24,8 @@ #include #include "polkitbackendpendingcall.h" -#include "polkitbackendserver.h" -PolkitBackendPendingCall *_polkit_backend_pending_call_new (EggDBusMethodInvocation *method_invocation, - PolkitBackendServer *server); +PolkitBackendPendingCall *_polkit_backend_pending_call_new (EggDBusMethodInvocation *method_invocation); EggDBusMethodInvocation *_polkit_backend_pending_call_get_method_invocation (PolkitBackendPendingCall *pending_call); diff --git a/src/polkitbackend/polkitbackendserver.c b/src/polkitbackend/polkitbackendserver.c deleted file mode 100644 index 00963a8..0000000 --- a/src/polkitbackend/polkitbackendserver.c +++ /dev/null @@ -1,550 +0,0 @@ -/* - * Copyright (C) 2008 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#include "config.h" -#include -#include -#include -#include -#include - -#include "polkitbackendauthority.h" -#include "polkitbackendserver.h" -#include "polkitbackendprivate.h" - -/** - * SECTION:polkitbackendserver - * @title: PolkitBackendServer - * @short_description: Proxies authorization backends - * - * The #PolkitBackendServer class is used for proxying #PolkitBackendAuthority instances on the system message bus. - */ - -struct _PolkitBackendServer -{ - GObject parent_instance; - - PolkitBackendAuthority *authority; - - EggDBusConnection *system_bus; - - EggDBusObjectProxy *bus_proxy; - - EggDBusBus *bus; - - gulong name_owner_changed_id; - - gulong authority_changed_id; -}; - -struct _PolkitBackendServerClass -{ - GObjectClass parent_class; -}; - -static void authority_iface_init (_PolkitAuthorityIface *authority_iface); -static void authority_manager_iface_init (_PolkitAuthorityManagerIface *authority_manager_iface); - -G_DEFINE_TYPE_WITH_CODE (PolkitBackendServer, polkit_backend_server, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (_POLKIT_TYPE_AUTHORITY, authority_iface_init) - G_IMPLEMENT_INTERFACE (_POLKIT_TYPE_AUTHORITY_MANAGER, authority_manager_iface_init) - ); - -static void -polkit_backend_server_init (PolkitBackendServer *local_server) -{ -} - -static void -polkit_backend_server_finalize (GObject *object) -{ - PolkitBackendServer *server; - - server = POLKIT_BACKEND_SERVER (object); - - 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->authority, server->authority_changed_id); - - g_object_unref (server->authority); -} - -static void -polkit_backend_server_class_init (PolkitBackendServerClass *klass) -{ - GObjectClass *gobject_class; - - gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->finalize = polkit_backend_server_finalize; -} - -static void -name_owner_changed (EggDBusBus *instance, - gchar *name, - gchar *old_owner, - gchar *new_owner, - PolkitBackendServer *server) -{ - polkit_backend_authority_system_bus_name_owner_changed (server->authority, name, old_owner, new_owner); -} - -static void -authority_changed (PolkitBackendAuthority *authority, - PolkitBackendServer *server) -{ - _polkit_authority_emit_signal_changed (_POLKIT_AUTHORITY (server), NULL); -} - -PolkitBackendServer * -polkit_backend_server_new (PolkitBackendAuthority *authority) -{ - PolkitBackendServer *server; - - server = POLKIT_BACKEND_SERVER (g_object_new (POLKIT_BACKEND_TYPE_SERVER, NULL)); - - server->authority = g_object_ref (authority); - - /* TODO: it's a bit wasteful listening to all name-owner-changed signals... needs to be optimized */ - - server->system_bus = egg_dbus_connection_get_for_bus (EGG_DBUS_BUS_TYPE_SYSTEM); - 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_id = g_signal_connect (server->bus, - "name-owner-changed", - (GCallback) name_owner_changed, - server); - - server->authority_changed_id = g_signal_connect (authority, - "changed", - (GCallback) authority_changed, - server); - - return server; -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static void -authority_handle_enumerate_actions (_PolkitAuthority *instance, - const gchar *locale, - EggDBusMethodInvocation *method_invocation) -{ - PolkitBackendServer *server = POLKIT_BACKEND_SERVER (instance); - PolkitBackendPendingCall *pending_call; - - pending_call = _polkit_backend_pending_call_new (method_invocation, server); - - polkit_backend_authority_enumerate_actions (server->authority, locale, pending_call); -} - -void -polkit_backend_authority_enumerate_actions_finish (PolkitBackendPendingCall *pending_call, - GList *actions) -{ - EggDBusArraySeq *array; - GList *l; - - array = egg_dbus_array_seq_new (G_TYPE_OBJECT, //_POLKIT_TYPE_ACTION_DESCRIPTION, - (GDestroyNotify) g_object_unref, - NULL, - NULL); - - 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); - } - - _polkit_authority_handle_enumerate_actions_finish (_polkit_backend_pending_call_get_method_invocation (pending_call), - array); - - g_object_unref (array); - - g_list_foreach (actions, (GFunc) g_object_unref, NULL); - g_list_free (actions); - - g_object_unref (pending_call); -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static void -authority_manager_handle_enumerate_users (_PolkitAuthorityManager *instance, - EggDBusMethodInvocation *method_invocation) -{ - PolkitBackendServer *server = POLKIT_BACKEND_SERVER (instance); - PolkitBackendPendingCall *pending_call; - - pending_call = _polkit_backend_pending_call_new (method_invocation, server); - - polkit_backend_authority_enumerate_users (server->authority, pending_call); -} - -void -polkit_backend_authority_enumerate_users_finish (PolkitBackendPendingCall *pending_call, - GList *users) -{ - EggDBusArraySeq *array; - GList *l; - - array = egg_dbus_array_seq_new (G_TYPE_OBJECT, //_POLKIT_TYPE_IDENTITY, - (GDestroyNotify) g_object_unref, - NULL, - NULL); - - for (l = users; l != NULL; l = l->next) - { - PolkitIdentity *identity = POLKIT_IDENTITY (l->data); - _PolkitIdentity *real; - - real = polkit_identity_get_real (identity); - egg_dbus_array_seq_add (array, real); - } - - _polkit_authority_manager_handle_enumerate_users_finish (_polkit_backend_pending_call_get_method_invocation (pending_call), - array); - - g_object_unref (array); - - g_list_foreach (users, (GFunc) g_object_unref, NULL); - g_list_free (users); - - g_object_unref (pending_call); -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static void -authority_manager_handle_enumerate_groups (_PolkitAuthorityManager *instance, - EggDBusMethodInvocation *method_invocation) -{ - PolkitBackendServer *server = POLKIT_BACKEND_SERVER (instance); - PolkitBackendPendingCall *pending_call; - - pending_call = _polkit_backend_pending_call_new (method_invocation, server); - - polkit_backend_authority_enumerate_groups (server->authority, pending_call); -} - -void -polkit_backend_authority_enumerate_groups_finish (PolkitBackendPendingCall *pending_call, - GList *groups) -{ - EggDBusArraySeq *array; - GList *l; - - array = egg_dbus_array_seq_new (G_TYPE_OBJECT, //_POLKIT_TYPE_IDENTITY, - (GDestroyNotify) g_object_unref, - NULL, - NULL); - - for (l = groups; l != NULL; l = l->next) - { - PolkitIdentity *identity = POLKIT_IDENTITY (l->data); - _PolkitIdentity *real; - - real = polkit_identity_get_real (identity); - egg_dbus_array_seq_add (array, real); - } - - _polkit_authority_manager_handle_enumerate_groups_finish (_polkit_backend_pending_call_get_method_invocation (pending_call), - array); - - g_object_unref (array); - - g_list_foreach (groups, (GFunc) g_object_unref, NULL); - g_list_free (groups); - - g_object_unref (pending_call); -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static void -authority_handle_check_authorization (_PolkitAuthority *instance, - _PolkitSubject *real_subject, - const gchar *action_id, - _PolkitCheckAuthorizationFlags flags, - EggDBusMethodInvocation *method_invocation) -{ - PolkitBackendServer *server = POLKIT_BACKEND_SERVER (instance); - PolkitBackendPendingCall *pending_call; - PolkitSubject *subject; - - pending_call = _polkit_backend_pending_call_new (method_invocation, server); - - subject = polkit_subject_new_for_real (real_subject); - - g_object_set_data_full (G_OBJECT (pending_call), "subject", subject, (GDestroyNotify) g_object_unref); - - polkit_backend_authority_check_authorization (server->authority, - subject, - action_id, - flags, - pending_call); -} - -void -polkit_backend_authority_check_authorization_finish (PolkitBackendPendingCall *pending_call, - PolkitAuthorizationResult result) -{ - _polkit_authority_handle_check_authorization_finish (_polkit_backend_pending_call_get_method_invocation (pending_call), - result); - - g_object_unref (pending_call); -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static void -authority_manager_handle_enumerate_authorizations (_PolkitAuthorityManager *instance, - _PolkitIdentity *real_identity, - EggDBusMethodInvocation *method_invocation) -{ - PolkitBackendServer *server = POLKIT_BACKEND_SERVER (instance); - PolkitBackendPendingCall *pending_call; - PolkitIdentity *identity; - - pending_call = _polkit_backend_pending_call_new (method_invocation, server); - - identity = polkit_identity_new_for_real (real_identity); - - g_object_set_data_full (G_OBJECT (pending_call), "identity", identity, (GDestroyNotify) g_object_unref); - - polkit_backend_authority_enumerate_authorizations (server->authority, - identity, - pending_call); -} - -void -polkit_backend_authority_enumerate_authorizations_finish (PolkitBackendPendingCall *pending_call, - GList *authorizations) -{ - EggDBusArraySeq *array; - GList *l; - - array = egg_dbus_array_seq_new (G_TYPE_OBJECT, //_POLKIT_TYPE_AUTHORIZATION, - (GDestroyNotify) g_object_unref, - NULL, - NULL); - - for (l = authorizations; l != NULL; l = l->next) - { - PolkitAuthorization *a = POLKIT_AUTHORIZATION (l->data); - _PolkitAuthorization *real; - - real = polkit_authorization_get_real (a); - egg_dbus_array_seq_add (array, real); - } - - _polkit_authority_manager_handle_enumerate_authorizations_finish (_polkit_backend_pending_call_get_method_invocation (pending_call), - array); - - g_object_unref (array); - - g_list_foreach (authorizations, (GFunc) g_object_unref, NULL); - g_list_free (authorizations); - - g_object_unref (pending_call); -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static void -authority_manager_handle_add_authorization (_PolkitAuthorityManager *instance, - _PolkitIdentity *real_identity, - _PolkitAuthorization *real_authorization, - EggDBusMethodInvocation *method_invocation) -{ - PolkitBackendServer *server = POLKIT_BACKEND_SERVER (instance); - PolkitBackendPendingCall *pending_call; - PolkitIdentity *identity; - PolkitAuthorization *authorization; - - pending_call = _polkit_backend_pending_call_new (method_invocation, server); - - identity = polkit_identity_new_for_real (real_identity); - - authorization = polkit_authorization_new_for_real (real_authorization); - - g_object_set_data_full (G_OBJECT (pending_call), "identity", identity, (GDestroyNotify) g_object_unref); - g_object_set_data_full (G_OBJECT (pending_call), "authorization", authorization, (GDestroyNotify) g_object_unref); - - polkit_backend_authority_add_authorization (server->authority, - identity, - authorization, - pending_call); -} - -void -polkit_backend_authority_add_authorization_finish (PolkitBackendPendingCall *pending_call) -{ - _polkit_authority_manager_handle_add_authorization_finish (_polkit_backend_pending_call_get_method_invocation (pending_call)); - g_object_unref (pending_call); -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static void -authority_manager_handle_remove_authorization (_PolkitAuthorityManager *instance, - _PolkitIdentity *real_identity, - _PolkitAuthorization *real_authorization, - EggDBusMethodInvocation *method_invocation) -{ - PolkitBackendServer *server = POLKIT_BACKEND_SERVER (instance); - PolkitBackendPendingCall *pending_call; - PolkitIdentity *identity; - PolkitAuthorization *authorization; - - pending_call = _polkit_backend_pending_call_new (method_invocation, server); - - identity = polkit_identity_new_for_real (real_identity); - - authorization = polkit_authorization_new_for_real (real_authorization); - - g_object_set_data_full (G_OBJECT (pending_call), "identity", identity, (GDestroyNotify) g_object_unref); - g_object_set_data_full (G_OBJECT (pending_call), "authorization", authorization, (GDestroyNotify) g_object_unref); - - polkit_backend_authority_remove_authorization (server->authority, - identity, - authorization, - pending_call); -} - -void -polkit_backend_authority_remove_authorization_finish (PolkitBackendPendingCall *pending_call) -{ - _polkit_authority_manager_handle_remove_authorization_finish (_polkit_backend_pending_call_get_method_invocation (pending_call)); - g_object_unref (pending_call); -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static void -authority_handle_register_authentication_agent (_PolkitAuthority *instance, - const gchar *object_path, - EggDBusMethodInvocation *method_invocation) -{ - PolkitBackendServer *server = POLKIT_BACKEND_SERVER (instance); - PolkitBackendPendingCall *pending_call; - - pending_call = _polkit_backend_pending_call_new (method_invocation, server); - - polkit_backend_authority_register_authentication_agent (server->authority, - object_path, - pending_call); -} - -void -polkit_backend_authority_register_authentication_agent_finish (PolkitBackendPendingCall *pending_call) -{ - _polkit_authority_handle_register_authentication_agent_finish (_polkit_backend_pending_call_get_method_invocation (pending_call)); - g_object_unref (pending_call); -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static void -authority_handle_unregister_authentication_agent (_PolkitAuthority *instance, - const gchar *object_path, - EggDBusMethodInvocation *method_invocation) -{ - PolkitBackendServer *server = POLKIT_BACKEND_SERVER (instance); - PolkitBackendPendingCall *pending_call; - - pending_call = _polkit_backend_pending_call_new (method_invocation, server); - - polkit_backend_authority_unregister_authentication_agent (server->authority, - object_path, - pending_call); -} - -void -polkit_backend_authority_unregister_authentication_agent_finish (PolkitBackendPendingCall *pending_call) -{ - _polkit_authority_handle_unregister_authentication_agent_finish (_polkit_backend_pending_call_get_method_invocation (pending_call)); - g_object_unref (pending_call); -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static void -authority_handle_authentication_agent_response (_PolkitAuthority *instance, - const gchar *cookie, - _PolkitIdentity *real_identity, - EggDBusMethodInvocation *method_invocation) -{ - PolkitBackendServer *server = POLKIT_BACKEND_SERVER (instance); - PolkitBackendPendingCall *pending_call; - PolkitIdentity *identity; - - pending_call = _polkit_backend_pending_call_new (method_invocation, server); - - identity = polkit_identity_new_for_real (real_identity); - - g_object_set_data_full (G_OBJECT (pending_call), "identity", identity, (GDestroyNotify) g_object_unref); - - polkit_backend_authority_authentication_agent_response (server->authority, - cookie, - identity, - pending_call); -} - -void -polkit_backend_authority_authentication_agent_response_finish (PolkitBackendPendingCall *pending_call) -{ - _polkit_authority_handle_authentication_agent_response_finish (_polkit_backend_pending_call_get_method_invocation (pending_call)); - g_object_unref (pending_call); -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static void -authority_iface_init (_PolkitAuthorityIface *authority_iface) -{ - authority_iface->handle_enumerate_actions = authority_handle_enumerate_actions; - authority_iface->handle_check_authorization = authority_handle_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; -} - -static void -authority_manager_iface_init (_PolkitAuthorityManagerIface *authority_manager_iface) -{ - authority_manager_iface->handle_enumerate_users = authority_manager_handle_enumerate_users; - authority_manager_iface->handle_enumerate_groups = authority_manager_handle_enumerate_groups; - authority_manager_iface->handle_enumerate_authorizations = authority_manager_handle_enumerate_authorizations; - authority_manager_iface->handle_add_authorization = authority_manager_handle_add_authorization; - authority_manager_iface->handle_remove_authorization = authority_manager_handle_remove_authorization; -} diff --git a/src/polkitbackend/polkitbackendserver.h b/src/polkitbackend/polkitbackendserver.h deleted file mode 100644 index 62f4085..0000000 --- a/src/polkitbackend/polkitbackendserver.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2008 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: David Zeuthen - */ - -#if !defined (_POLKIT_BACKEND_COMPILATION) && !defined(_POLKIT_BACKEND_INSIDE_POLKIT_BACKEND_H) -#error "Only can be included directly, this file may disappear or change contents." -#endif - -#ifndef __POLKIT_BACKEND_SERVER_H -#define __POLKIT_BACKEND_SERVER_H - -#include -#include "polkitbackendtypes.h" - -G_BEGIN_DECLS - -#define POLKIT_BACKEND_TYPE_SERVER (polkit_backend_server_get_type ()) -#define POLKIT_BACKEND_SERVER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_BACKEND_TYPE_SERVER, PolkitBackendServer)) -#define POLKIT_BACKEND_SERVER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), POLKIT_BACKEND_TYPE_SERVER, PolkitBackendServerClass)) -#define POLKIT_BACKEND_SERVER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_BACKEND_TYPE_SERVER,PolkitBackendServerClass)) -#define POLKIT_BACKEND_IS_SERVER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_BACKEND_TYPE_SERVER)) -#define POLKIT_BACKEND_IS_SERVER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_BACKEND_TYPE_SERVER)) - -#if 0 -typedef struct _PolkitBackendServer PolkitBackendServer; -#endif -typedef struct _PolkitBackendServerClass PolkitBackendServerClass; - -GType polkit_backend_server_get_type (void) G_GNUC_CONST; - -PolkitBackendServer *polkit_backend_server_new (PolkitBackendAuthority *authority); - -G_END_DECLS - -#endif /* __POLKIT_BACKEND_SERVER_H */ - diff --git a/src/polkitbackend/polkitbackendtypes.h b/src/polkitbackend/polkitbackendtypes.h index 9f3b79a..2aeeb7c 100644 --- a/src/polkitbackend/polkitbackendtypes.h +++ b/src/polkitbackend/polkitbackendtypes.h @@ -33,9 +33,6 @@ typedef struct _PolkitBackendLocalAuthority PolkitBackendLocalAuthority; struct _PolkitBackendPendingCall; typedef struct _PolkitBackendPendingCall PolkitBackendPendingCall; -struct _PolkitBackendServer; -typedef struct _PolkitBackendServer PolkitBackendServer; - struct _PolkitBackendSessionMonitor; typedef struct _PolkitBackendSessionMonitor PolkitBackendSessionMonitor; diff --git a/src/polkitd/Makefile.am b/src/polkitd/Makefile.am index 24e9551..c93096d 100644 --- a/src/polkitd/Makefile.am +++ b/src/polkitd/Makefile.am @@ -12,7 +12,6 @@ INCLUDES = \ -DPACKAGE_LIB_DIR=\""$(libdir)"\" \ -D_POSIX_PTHREAD_SEMANTICS \ -D_REENTRANT \ - -DEGG_DBUS_I_KNOW_API_IS_SUBJECT_TO_CHANGE \ $(NULL) libexec_PROGRAMS = polkitd-1 @@ -25,13 +24,11 @@ polkitd_1_CFLAGS = \ -I$(top_srcdir)/src \ -DG_LOG_DOMAIN=\"polkitd-1\" \ $(GLIB_CFLAGS) \ - $(EGG_DBUS_CFLAGS) \ $(NULL) polkitd_1_LDADD = \ $(DBUS_GLIB_LIBS) \ $(GLIB_LIBS) \ - $(EGG_DBUS_LIBS) \ $(top_builddir)/src/polkit/libpolkit-gobject-1.la \ $(top_builddir)/src/polkitbackend/libpolkit-backend-1.la \ $(NULL) diff --git a/src/polkitd/main.c b/src/polkitd/main.c index 9832cda..00f82fe 100644 --- a/src/polkitd/main.c +++ b/src/polkitd/main.c @@ -24,75 +24,47 @@ #endif #include -#include - #include -static _PolkitAuthority * +static PolkitBackendAuthority * get_authority_backend (void) { PolkitBackendAuthority *authority; - PolkitBackendServer *server; /* TODO: use extension points etc. */ authority = polkit_backend_local_authority_new (); - server = polkit_backend_server_new (authority); - - g_object_unref (authority); - - return _POLKIT_AUTHORITY (server); + return authority; } int main (int argc, char **argv) { int ret; - guint rn_ret; GError *error; GMainLoop *loop; - EggDBusConnection *connection; - _PolkitAuthority *authority; + PolkitBackendAuthority *authority; ret = 1; + error = NULL; authority = NULL; - connection = NULL; g_type_init (); loop = g_main_loop_new (NULL, FALSE); - connection = egg_dbus_connection_get_for_bus (EGG_DBUS_BUS_TYPE_SYSTEM); - error = NULL; - if (!egg_dbus_bus_request_name_sync (egg_dbus_connection_get_bus (connection), - EGG_DBUS_CALL_FLAGS_NONE, - "org.freedesktop.PolicyKit1", - EGG_DBUS_REQUEST_NAME_FLAGS_NONE, - &rn_ret, - NULL, - &error)) - { - g_warning ("error: %s", error->message); - g_error_free (error); - goto out; - } + authority = get_authority_backend (); - if (rn_ret != 1) + if (!polkit_backend_register_authority (authority, + "org.freedesktop.PolicyKit1", + "/org/freedesktop/PolicyKit1/Authority", + &error)) { - g_warning ("could not become primary name owner"); + g_printerr ("Error registering authority: %s", error->message); + g_error_free (error); goto out; } - authority = get_authority_backend (); - - egg_dbus_connection_register_interface (connection, - "/org/freedesktop/PolicyKit1/Authority", - _POLKIT_TYPE_AUTHORITY, - G_OBJECT (authority), - _POLKIT_TYPE_AUTHORITY_MANAGER, - G_OBJECT (authority), - G_TYPE_INVALID); - g_main_loop_run (loop); ret = 0; @@ -100,7 +72,5 @@ main (int argc, char **argv) out: if (authority != NULL) g_object_unref (authority); - if (connection != NULL) - g_object_unref (connection); return ret; }