diff options
author | David Zeuthen <davidz@redhat.com> | 2009-02-01 13:26:53 -0500 |
---|---|---|
committer | David Zeuthen <davidz@redhat.com> | 2009-02-01 13:26:53 -0500 |
commit | 5326cc0a02a631ab6bc0bd6dc16c2a861ab90423 (patch) | |
tree | a1201c84d97d4bcd8ad1ee1f49e49cfb97085ab9 | |
parent | a114ed8f1fee8dabffe004cf8092d986601e9510 (diff) | |
download | polkit-5326cc0a02a631ab6bc0bd6dc16c2a861ab90423.tar.gz |
move management functions to a separate D-Bus interface and GObject class
This will allow us, in the near future, to declare org.fd.PK1.Authority and
PolkitAuthority as stable while allowing changes to how we manage the (local)
authority even after 1.0.
-rw-r--r-- | data/Makefile.am | 1 | ||||
-rw-r--r-- | data/org.freedesktop.PolicyKit1.Authority.xml | 61 | ||||
-rw-r--r-- | data/org.freedesktop.PolicyKit1.AuthorityManager.xml | 69 | ||||
-rw-r--r-- | src/polkit/Makefile.am | 14 | ||||
-rw-r--r-- | src/polkit/polkit.h | 1 | ||||
-rw-r--r-- | src/polkit/polkitauthority.c | 520 | ||||
-rw-r--r-- | src/polkit/polkitauthoritymanager.c | 651 | ||||
-rw-r--r-- | src/polkit/polkitauthoritymanager.h | 131 | ||||
-rw-r--r-- | src/polkit/polkittypes.h | 3 | ||||
-rw-r--r-- | src/polkitbackend/polkitbackendauthority.h | 1 | ||||
-rw-r--r-- | src/polkitbackend/polkitbackendserver.c | 65 | ||||
-rw-r--r-- | src/polkitd/main.c | 2 | ||||
-rw-r--r-- | src/programs/polkit.c | 45 |
13 files changed, 928 insertions, 636 deletions
diff --git a/data/Makefile.am b/data/Makefile.am index 0a6b4d8..f4b1005 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -28,6 +28,7 @@ CLEANFILES = $(BUILT_SOURCES) EXTRA_DIST = \ org.freedesktop.PolicyKit1.Authority.xml \ + org.freedesktop.PolicyKit1.AuthorityManager.xml \ org.freedesktop.PolicyKit1.AuthenticationAgent.xml \ $(service_in_files) \ $(dbusconf_in_files) \ diff --git a/data/org.freedesktop.PolicyKit1.Authority.xml b/data/org.freedesktop.PolicyKit1.Authority.xml index e362d7a..e33df65 100644 --- a/data/org.freedesktop.PolicyKit1.Authority.xml +++ b/data/org.freedesktop.PolicyKit1.Authority.xml @@ -142,36 +142,8 @@ </annotation> </annotation> - <!-- Authorization struct --> - <annotation name="org.gtk.EggDBus.DeclareStruct" value="Authorization"> - <annotation name="org.gtk.EggDBus.Struct.Member" value="s:action_id"> - <annotation name="org.gtk.EggDBus.DocString" value="Identifier for the action the authorization is for"/> - </annotation> - - <annotation name="org.gtk.EggDBus.Struct.Member" value="(sa{sv}):subject"> - <annotation name="org.gtk.EggDBus.StructType" value="Subject"/> - <annotation name="org.gtk.EggDBus.DocString" value="Subject that the authorization applies to"/> - </annotation> - - <annotation name="org.gtk.EggDBus.Struct.Member" value="b:is_negative"> - <annotation name="org.gtk.EggDBus.DocString" value="Whether the authorization is negative"/> - </annotation> - </annotation> - <interface name="org.freedesktop.PolicyKit1.Authority"> - <method name="EnumerateUsers"> - <arg name="users" direction="out" type="a(sa{sv})"> - <annotation name="org.gtk.EggDBus.StructType" value="Identity"/> - </arg> - </method> - - <method name="EnumerateGroups"> - <arg name="groups" direction="out" type="a(sa{sv})"> - <annotation name="org.gtk.EggDBus.StructType" value="Identity"/> - </arg> - </method> - <method name="EnumerateActions"> <arg name="locale" direction="in" type="s"/> <arg name="action_descriptions" direction="out" type="a(ssssssiiia{ss})"> @@ -193,39 +165,6 @@ </arg> </method> - <method name="AddAuthorization"> - <arg name="identity" direction="in" type="(sa{sv})"> - <annotation name="org.gtk.EggDBus.StructType" value="Identity"/> - <annotation name="org.gtk.EggDBus.DocString" value="The identity to add @authorization to"/> - </arg> - <arg name="authorization" direction="in" type="(s(sa{sv})b)"> - <annotation name="org.gtk.EggDBus.StructType" value="Authorization"/> - <annotation name="org.gtk.EggDBus.DocString" value="The authorization to add for @identity"/> - </arg> - </method> - - <method name="RemoveAuthorization"> - <arg name="identity" direction="in" type="(sa{sv})"> - <annotation name="org.gtk.EggDBus.StructType" value="Identity"/> - <annotation name="org.gtk.EggDBus.DocString" value="The identity to remove @authorization from"/> - </arg> - <arg name="authorization" direction="in" type="(s(sa{sv})b)"> - <annotation name="org.gtk.EggDBus.StructType" value="Authorization"/> - <annotation name="org.gtk.EggDBus.DocString" value="The authorization to remove from @identity"/> - </arg> - </method> - - <method name="EnumerateAuthorizations"> - <arg name="identity" direction="in" type="(sa{sv})"> - <annotation name="org.gtk.EggDBus.StructType" value="Identity"/> - <annotation name="org.gtk.EggDBus.DocString" value="The identity to enumerate authorizations for"/> - </arg> - <arg name="authorizations" direction="out" type="a(s(sa{sv})b)"> - <annotation name="org.gtk.EggDBus.StructType" value="Authorization"/> - <annotation name="org.gtk.EggDBus.DocString" value="An array of authorizations for @identity"/> - </arg> - </method> - <method name="RegisterAuthenticationAgent"> <arg name="object_path" direction="in" type="s"> <annotation name="org.gtk.EggDBus.DocString" value="Path of authentication agent object on the unique name of the caller"/> diff --git a/data/org.freedesktop.PolicyKit1.AuthorityManager.xml b/data/org.freedesktop.PolicyKit1.AuthorityManager.xml new file mode 100644 index 0000000..5c05fcc --- /dev/null +++ b/data/org.freedesktop.PolicyKit1.AuthorityManager.xml @@ -0,0 +1,69 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" +"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> +<node> + + <!-- Authorization struct --> + <annotation name="org.gtk.EggDBus.DeclareStruct" value="Authorization"> + <annotation name="org.gtk.EggDBus.Struct.Member" value="s:action_id"> + <annotation name="org.gtk.EggDBus.DocString" value="Identifier for the action the authorization is for"/> + </annotation> + + <annotation name="org.gtk.EggDBus.Struct.Member" value="(sa{sv}):subject"> + <annotation name="org.gtk.EggDBus.StructType" value="Subject"/> + <annotation name="org.gtk.EggDBus.DocString" value="Subject that the authorization applies to"/> + </annotation> + + <annotation name="org.gtk.EggDBus.Struct.Member" value="b:is_negative"> + <annotation name="org.gtk.EggDBus.DocString" value="Whether the authorization is negative"/> + </annotation> + </annotation> + + <interface name="org.freedesktop.PolicyKit1.AuthorityManager"> + + <method name="EnumerateUsers"> + <arg name="users" direction="out" type="a(sa{sv})"> + <annotation name="org.gtk.EggDBus.StructType" value="Identity"/> + </arg> + </method> + + <method name="EnumerateGroups"> + <arg name="groups" direction="out" type="a(sa{sv})"> + <annotation name="org.gtk.EggDBus.StructType" value="Identity"/> + </arg> + </method> + + <method name="AddAuthorization"> + <arg name="identity" direction="in" type="(sa{sv})"> + <annotation name="org.gtk.EggDBus.StructType" value="Identity"/> + <annotation name="org.gtk.EggDBus.DocString" value="The identity to add @authorization to"/> + </arg> + <arg name="authorization" direction="in" type="(s(sa{sv})b)"> + <annotation name="org.gtk.EggDBus.StructType" value="Authorization"/> + <annotation name="org.gtk.EggDBus.DocString" value="The authorization to add for @identity"/> + </arg> + </method> + + <method name="RemoveAuthorization"> + <arg name="identity" direction="in" type="(sa{sv})"> + <annotation name="org.gtk.EggDBus.StructType" value="Identity"/> + <annotation name="org.gtk.EggDBus.DocString" value="The identity to remove @authorization from"/> + </arg> + <arg name="authorization" direction="in" type="(s(sa{sv})b)"> + <annotation name="org.gtk.EggDBus.StructType" value="Authorization"/> + <annotation name="org.gtk.EggDBus.DocString" value="The authorization to remove from @identity"/> + </arg> + </method> + + <method name="EnumerateAuthorizations"> + <arg name="identity" direction="in" type="(sa{sv})"> + <annotation name="org.gtk.EggDBus.StructType" value="Identity"/> + <annotation name="org.gtk.EggDBus.DocString" value="The identity to enumerate authorizations for"/> + </arg> + <arg name="authorizations" direction="out" type="a(s(sa{sv})b)"> + <annotation name="org.gtk.EggDBus.StructType" value="Authorization"/> + <annotation name="org.gtk.EggDBus.DocString" value="An array of authorizations for @identity"/> + </arg> + </method> + + </interface> +</node> diff --git a/src/polkit/Makefile.am b/src/polkit/Makefile.am index 3f6b268..61233ee 100644 --- a/src/polkit/Makefile.am +++ b/src/polkit/Makefile.am @@ -18,6 +18,7 @@ INCLUDES = \ BUILT_SOURCES = \ _polkitactiondescription.c _polkitactiondescription.h \ _polkitauthority.c _polkitauthority.h \ + _polkitauthoritymanager.c _polkitauthoritymanager.h \ _polkitauthorization.c _polkitauthorization.h \ _polkitauthorizationresult.c _polkitauthorizationresult.h \ _polkitimplicitauthorization.c _polkitimplicitauthorization.h \ @@ -30,11 +31,12 @@ BUILT_SOURCES = \ _polkitidentity.c _polkitidentity.h \ $(NULL) -$(BUILT_SOURCES) : Makefile.am $(top_srcdir)/data/org.freedesktop.PolicyKit1.Authority.xml - eggdbus-binding-tool \ - --namespace "_Polkit" \ - --dbus-namespace "org.freedesktop.PolicyKit1" \ - --introspection-xml $(top_srcdir)/data/org.freedesktop.PolicyKit1.Authority.xml \ +$(BUILT_SOURCES) : Makefile.am $(top_srcdir)/data/org.freedesktop.PolicyKit1.Authority.xml $(top_srcdir)/data/org.freedesktop.PolicyKit1.AuthorityManager.xml + eggdbus-binding-tool \ + --namespace "_Polkit" \ + --dbus-namespace "org.freedesktop.PolicyKit1" \ + --introspection-xml $(top_srcdir)/data/org.freedesktop.PolicyKit1.Authority.xml \ + --introspection-xml $(top_srcdir)/data/org.freedesktop.PolicyKit1.AuthorityManager.xml \ $(NULL) lib_LTLIBRARIES=libpolkit-gobject-1.la @@ -47,6 +49,7 @@ libpolkit_gobject_1include_HEADERS = \ polkittypes.h \ polkitactiondescription.h \ polkitauthority.h \ + polkitauthoritymanager.h \ polkiterror.h \ polkitsubject.h \ polkitunixprocess.h \ @@ -66,6 +69,7 @@ libpolkit_gobject_1_la_SOURCES = \ $(BUILT_SOURCES) \ polkitactiondescription.c polkitactiondescription.h \ polkitauthority.c polkitauthority.h \ + polkitauthoritymanager.c polkitauthoritymanager.h \ polkiterror.c polkiterror.h \ polkitsubject.c polkitsubject.h \ polkitunixprocess.c polkitunixprocess.h \ diff --git a/src/polkit/polkit.h b/src/polkit/polkit.h index 6de31f2..6baccb5 100644 --- a/src/polkit/polkit.h +++ b/src/polkit/polkit.h @@ -37,6 +37,7 @@ #include <polkit/polkitauthorizationresult.h> #include <polkit/polkitcheckauthorizationflags.h> #include <polkit/polkitauthority.h> +#include <polkit/polkitauthoritymanager.h> #include <polkit/polkitauthorization.h> #undef _POLKIT_INSIDE_POLKIT_H diff --git a/src/polkit/polkitauthority.c b/src/polkit/polkitauthority.c index c8e6c8e..2d591a3 100644 --- a/src/polkit/polkitauthority.c +++ b/src/polkit/polkitauthority.c @@ -270,198 +270,6 @@ polkit_authority_enumerate_actions_sync (PolkitAuthority *authority, /* ---------------------------------------------------------------------------------------------------- */ static guint -polkit_authority_enumerate_users_async (PolkitAuthority *authority, - 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_enumerate_users_async); - - call_id = _polkit_authority_enumerate_users (authority->real, - EGG_DBUS_CALL_FLAGS_NONE, - cancellable, - generic_async_cb, - simple); - - return call_id; -} - -void -polkit_authority_enumerate_users (PolkitAuthority *authority, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - polkit_authority_enumerate_users_async (authority, cancellable, callback, user_data); -} - -GList * -polkit_authority_enumerate_users_finish (PolkitAuthority *authority, - GAsyncResult *res, - GError **error) -{ - EggDBusArraySeq *array_seq; - GList *result; - guint n; - GSimpleAsyncResult *simple; - GAsyncResult *real_res; - - 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_enumerate_users_async); - - result = NULL; - - if (!_polkit_authority_enumerate_users_finish (authority->real, - &array_seq, - real_res, - error)) - goto out; - - for (n = 0; n < array_seq->size; n++) - { - _PolkitIdentity *real_identity; - - real_identity = array_seq->data.v_ptr[n]; - - result = g_list_prepend (result, polkit_identity_new_for_real (real_identity)); - } - - result = g_list_reverse (result); - - g_object_unref (array_seq); - - out: - g_object_unref (real_res); - return result; -} - -GList * -polkit_authority_enumerate_users_sync (PolkitAuthority *authority, - GCancellable *cancellable, - GError **error) -{ - guint call_id; - GAsyncResult *res; - GList *result; - - call_id = polkit_authority_enumerate_users_async (authority, cancellable, generic_cb, &res); - - egg_dbus_connection_pending_call_block (authority->system_bus, call_id); - - result = polkit_authority_enumerate_users_finish (authority, res, error); - - g_object_unref (res); - - return result; -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static guint -polkit_authority_enumerate_groups_async (PolkitAuthority *authority, - 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_enumerate_groups_async); - - call_id = _polkit_authority_enumerate_groups (authority->real, - EGG_DBUS_CALL_FLAGS_NONE, - cancellable, - generic_async_cb, - simple); - - return call_id; -} - -void -polkit_authority_enumerate_groups (PolkitAuthority *authority, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - polkit_authority_enumerate_groups_async (authority, cancellable, callback, user_data); -} - -GList * -polkit_authority_enumerate_groups_finish (PolkitAuthority *authority, - GAsyncResult *res, - GError **error) -{ - EggDBusArraySeq *array_seq; - GList *result; - guint n; - GSimpleAsyncResult *simple; - GAsyncResult *real_res; - - 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_enumerate_groups_async); - - result = NULL; - - if (!_polkit_authority_enumerate_groups_finish (authority->real, - &array_seq, - real_res, - error)) - goto out; - - for (n = 0; n < array_seq->size; n++) - { - _PolkitIdentity *real_identity; - - real_identity = array_seq->data.v_ptr[n]; - - result = g_list_prepend (result, polkit_identity_new_for_real (real_identity)); - } - - result = g_list_reverse (result); - - g_object_unref (array_seq); - - out: - g_object_unref (real_res); - return result; -} - -GList * -polkit_authority_enumerate_groups_sync (PolkitAuthority *authority, - GCancellable *cancellable, - GError **error) -{ - guint call_id; - GAsyncResult *res; - GList *result; - - call_id = polkit_authority_enumerate_groups_async (authority, cancellable, generic_cb, &res); - - egg_dbus_connection_pending_call_block (authority->system_bus, call_id); - - result = polkit_authority_enumerate_groups_finish (authority, res, error); - - g_object_unref (res); - - return result; -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static guint polkit_authority_check_authorization_async (PolkitAuthority *authority, PolkitSubject *subject, const gchar *action_id, @@ -572,334 +380,6 @@ polkit_authority_check_authorization_sync (PolkitAuthority *author /* ---------------------------------------------------------------------------------------------------- */ static guint -polkit_authority_enumerate_authorizations_async (PolkitAuthority *authority, - 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_enumerate_authorizations_async); - - real_identity = polkit_identity_get_real (identity); - - call_id = _polkit_authority_enumerate_authorizations (authority->real, - EGG_DBUS_CALL_FLAGS_NONE, - real_identity, - cancellable, - generic_async_cb, - simple); - - g_object_unref (real_identity); - - return call_id; -} - -void -polkit_authority_enumerate_authorizations (PolkitAuthority *authority, - PolkitIdentity *identity, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - polkit_authority_enumerate_authorizations_async (authority, - identity, - cancellable, - callback, - user_data); -} - -GList * -polkit_authority_enumerate_authorizations_finish (PolkitAuthority *authority, - GAsyncResult *res, - GError **error) -{ - EggDBusArraySeq *array_seq; - GList *result; - guint n; - GSimpleAsyncResult *simple; - GAsyncResult *real_res; - - 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_enumerate_authorizations_async); - - result = NULL; - - if (!_polkit_authority_enumerate_authorizations_finish (authority->real, - &array_seq, - real_res, - error)) - goto out; - - for (n = 0; n < array_seq->size; n++) - { - _PolkitAuthorization *real_authorization; - - real_authorization = array_seq->data.v_ptr[n]; - - result = g_list_prepend (result, polkit_authorization_new_for_real (real_authorization)); - } - - result = g_list_reverse (result); - - g_object_unref (array_seq); - - out: - g_object_unref (real_res); - return result; -} - - -GList * -polkit_authority_enumerate_authorizations_sync (PolkitAuthority *authority, - PolkitIdentity *identity, - GCancellable *cancellable, - GError **error) -{ - guint call_id; - GAsyncResult *res; - GList *result; - - call_id = polkit_authority_enumerate_authorizations_async (authority, - identity, - cancellable, - generic_cb, - &res); - - egg_dbus_connection_pending_call_block (authority->system_bus, call_id); - - result = polkit_authority_enumerate_authorizations_finish (authority, res, error); - - g_object_unref (res); - - return result; -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static guint -polkit_authority_add_authorization_async (PolkitAuthority *authority, - PolkitIdentity *identity, - PolkitAuthorization *authorization, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - guint call_id; - GSimpleAsyncResult *simple; - _PolkitAuthorization *real_authorization; - _PolkitIdentity *real_identity; - - simple = g_simple_async_result_new (G_OBJECT (authority), - callback, - user_data, - polkit_authority_add_authorization_async); - - real_identity = polkit_identity_get_real (identity); - real_authorization = polkit_authorization_get_real (authorization); - - call_id = _polkit_authority_add_authorization (authority->real, - EGG_DBUS_CALL_FLAGS_NONE, - real_identity, - real_authorization, - cancellable, - generic_async_cb, - simple); - - g_object_unref (real_authorization); - g_object_unref (real_identity); - - return call_id; -} - -void -polkit_authority_add_authorization (PolkitAuthority *authority, - PolkitIdentity *identity, - PolkitAuthorization *authorization, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - polkit_authority_add_authorization_async (authority, - identity, - authorization, - cancellable, - callback, - user_data); -} - -gboolean -polkit_authority_add_authorization_finish (PolkitAuthority *authority, - GAsyncResult *res, - GError **error) -{ - GSimpleAsyncResult *simple; - GAsyncResult *real_res; - gboolean ret; - - 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_authorization_async); - - ret = _polkit_authority_add_authorization_finish (authority->real, - real_res, - error); - - if (!ret) - goto out; - - out: - g_object_unref (real_res); - return ret; -} - - -gboolean -polkit_authority_add_authorization_sync (PolkitAuthority *authority, - PolkitIdentity *identity, - PolkitAuthorization *authorization, - GCancellable *cancellable, - GError **error) -{ - guint call_id; - GAsyncResult *res; - gboolean ret; - - call_id = polkit_authority_add_authorization_async (authority, - identity, - authorization, - cancellable, - generic_cb, - &res); - - egg_dbus_connection_pending_call_block (authority->system_bus, call_id); - - ret = polkit_authority_add_authorization_finish (authority, res, error); - - g_object_unref (res); - - return ret; -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static guint -polkit_authority_remove_authorization_async (PolkitAuthority *authority, - PolkitIdentity *identity, - PolkitAuthorization *authorization, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - guint call_id; - GSimpleAsyncResult *simple; - _PolkitAuthorization *real_authorization; - _PolkitIdentity *real_identity; - - simple = g_simple_async_result_new (G_OBJECT (authority), - callback, - user_data, - polkit_authority_remove_authorization_async); - - real_identity = polkit_identity_get_real (identity); - real_authorization = polkit_authorization_get_real (authorization); - - call_id = _polkit_authority_remove_authorization (authority->real, - EGG_DBUS_CALL_FLAGS_NONE, - real_identity, - real_authorization, - cancellable, - generic_async_cb, - simple); - - g_object_unref (real_authorization); - g_object_unref (real_identity); - - return call_id; -} - -void -polkit_authority_remove_authorization (PolkitAuthority *authority, - PolkitIdentity *identity, - PolkitAuthorization *authorization, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - polkit_authority_remove_authorization_async (authority, - identity, - authorization, - cancellable, - callback, - user_data); -} - -gboolean -polkit_authority_remove_authorization_finish (PolkitAuthority *authority, - GAsyncResult *res, - GError **error) -{ - GSimpleAsyncResult *simple; - GAsyncResult *real_res; - gboolean ret; - - 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_authorization_async); - - ret = _polkit_authority_remove_authorization_finish (authority->real, - real_res, - error); - - if (!ret) - goto out; - - out: - g_object_unref (real_res); - return ret; -} - - -gboolean -polkit_authority_remove_authorization_sync (PolkitAuthority *authority, - PolkitIdentity *identity, - PolkitAuthorization *authorization, - GCancellable *cancellable, - GError **error) -{ - guint call_id; - GAsyncResult *res; - gboolean ret; - - call_id = polkit_authority_remove_authorization_async (authority, - identity, - authorization, - cancellable, - generic_cb, - &res); - - egg_dbus_connection_pending_call_block (authority->system_bus, call_id); - - ret = polkit_authority_remove_authorization_finish (authority, res, error); - - g_object_unref (res); - - return ret; -} - -/* ---------------------------------------------------------------------------------------------------- */ - -static guint polkit_authority_register_authentication_agent_async (PolkitAuthority *authority, const gchar *object_path, GCancellable *cancellable, diff --git a/src/polkit/polkitauthoritymanager.c b/src/polkit/polkitauthoritymanager.c new file mode 100644 index 0000000..55a4530 --- /dev/null +++ b/src/polkit/polkitauthoritymanager.c @@ -0,0 +1,651 @@ +/* + * 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 <davidz@redhat.com> + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "polkitauthoritymanager.h" + +#include "polkitprivate.h" + +/** + * SECTION:polkitauthoritymanager + * @title: PolkitAuthorityManager + * @short_description: Authority Manager + * + * Checking claims. + */ + +struct _PolkitAuthorityManager +{ + GObject parent_instance; + + EggDBusConnection *system_bus; + EggDBusObjectProxy *authority_manager_object_proxy; + + _PolkitAuthorityManager *real; +}; + +struct _PolkitAuthorityManagerClass +{ + GObjectClass parent_class; + +}; + +/* TODO: locking */ + +static PolkitAuthorityManager *the_authority_manager = NULL; + +G_DEFINE_TYPE (PolkitAuthorityManager, polkit_authority_manager, G_TYPE_OBJECT); + + +static void +polkit_authority_manager_init (PolkitAuthorityManager *authority_manager) +{ + authority_manager->system_bus = egg_dbus_connection_get_for_bus (EGG_DBUS_BUS_TYPE_SYSTEM); + + authority_manager->authority_manager_object_proxy = egg_dbus_connection_get_object_proxy (authority_manager->system_bus, + "org.freedesktop.PolicyKit1", + "/org/freedesktop/PolicyKit1/Authority"); + + authority_manager->real = _POLKIT_QUERY_INTERFACE_AUTHORITY_MANAGER (authority_manager->authority_manager_object_proxy); +} + +static void +polkit_authority_manager_finalize (GObject *object) +{ + PolkitAuthorityManager *authority_manager; + + authority_manager = POLKIT_AUTHORITY_MANAGER (object); + + g_object_unref (authority_manager->authority_manager_object_proxy); + g_object_unref (authority_manager->system_bus); + + the_authority_manager = NULL; + + if (G_OBJECT_CLASS (polkit_authority_manager_parent_class)->finalize != NULL) + G_OBJECT_CLASS (polkit_authority_manager_parent_class)->finalize (object); +} + +static void +polkit_authority_manager_class_init (PolkitAuthorityManagerClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->finalize = polkit_authority_manager_finalize; + +} + +PolkitAuthorityManager * +polkit_authority_manager_get (void) +{ + if (the_authority_manager != NULL) + goto out; + + the_authority_manager = POLKIT_AUTHORITY_MANAGER (g_object_new (POLKIT_TYPE_AUTHORITY_MANAGER, NULL)); + + out: + return the_authority_manager; +} + +static void +generic_cb (GObject *source_obj, + GAsyncResult *res, + gpointer user_data) +{ + GAsyncResult **target_res = user_data; + + *target_res = g_object_ref (res); +} + +static void +generic_async_cb (GObject *source_obj, + 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); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static guint +polkit_authority_manager_enumerate_users_async (PolkitAuthorityManager *authority_manager, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + guint call_id; + GSimpleAsyncResult *simple; + + simple = g_simple_async_result_new (G_OBJECT (authority_manager), + callback, + user_data, + polkit_authority_manager_enumerate_users_async); + + call_id = _polkit_authority_manager_enumerate_users (authority_manager->real, + EGG_DBUS_CALL_FLAGS_NONE, + cancellable, + generic_async_cb, + simple); + + return call_id; +} + +void +polkit_authority_manager_enumerate_users (PolkitAuthorityManager *authority_manager, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + polkit_authority_manager_enumerate_users_async (authority_manager, cancellable, callback, user_data); +} + +GList * +polkit_authority_manager_enumerate_users_finish (PolkitAuthorityManager *authority_manager, + GAsyncResult *res, + GError **error) +{ + EggDBusArraySeq *array_seq; + GList *result; + guint n; + GSimpleAsyncResult *simple; + GAsyncResult *real_res; + + 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_manager_enumerate_users_async); + + result = NULL; + + if (!_polkit_authority_manager_enumerate_users_finish (authority_manager->real, + &array_seq, + real_res, + error)) + goto out; + + for (n = 0; n < array_seq->size; n++) + { + _PolkitIdentity *real_identity; + + real_identity = array_seq->data.v_ptr[n]; + + result = g_list_prepend (result, polkit_identity_new_for_real (real_identity)); + } + + result = g_list_reverse (result); + + g_object_unref (array_seq); + + out: + g_object_unref (real_res); + return result; +} + +GList * +polkit_authority_manager_enumerate_users_sync (PolkitAuthorityManager *authority_manager, + GCancellable *cancellable, + GError **error) +{ + guint call_id; + GAsyncResult *res; + GList *result; + + call_id = polkit_authority_manager_enumerate_users_async (authority_manager, cancellable, generic_cb, &res); + + egg_dbus_connection_pending_call_block (authority_manager->system_bus, call_id); + + result = polkit_authority_manager_enumerate_users_finish (authority_manager, res, error); + + g_object_unref (res); + + return result; +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static guint +polkit_authority_manager_enumerate_groups_async (PolkitAuthorityManager *authority_manager, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + guint call_id; + GSimpleAsyncResult *simple; + + simple = g_simple_async_result_new (G_OBJECT (authority_manager), + callback, + user_data, + polkit_authority_manager_enumerate_groups_async); + + call_id = _polkit_authority_manager_enumerate_groups (authority_manager->real, + EGG_DBUS_CALL_FLAGS_NONE, + cancellable, + generic_async_cb, + simple); + + return call_id; +} + +void +polkit_authority_manager_enumerate_groups (PolkitAuthorityManager *authority_manager, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + polkit_authority_manager_enumerate_groups_async (authority_manager, cancellable, callback, user_data); +} + +GList * +polkit_authority_manager_enumerate_groups_finish (PolkitAuthorityManager *authority_manager, + GAsyncResult *res, + GError **error) +{ + EggDBusArraySeq *array_seq; + GList *result; + guint n; + GSimpleAsyncResult *simple; + GAsyncResult *real_res; + + 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_manager_enumerate_groups_async); + + result = NULL; + + if (!_polkit_authority_manager_enumerate_groups_finish (authority_manager->real, + &array_seq, + real_res, + error)) + goto out; + + for (n = 0; n < array_seq->size; n++) + { + _PolkitIdentity *real_identity; + + real_identity = array_seq->data.v_ptr[n]; + + result = g_list_prepend (result, polkit_identity_new_for_real (real_identity)); + } + + result = g_list_reverse (result); + + g_object_unref (array_seq); + + out: + g_object_unref (real_res); + return result; +} + +GList * +polkit_authority_manager_enumerate_groups_sync (PolkitAuthorityManager *authority_manager, + GCancellable *cancellable, + GError **error) +{ + guint call_id; + GAsyncResult *res; + GList *result; + + call_id = polkit_authority_manager_enumerate_groups_async (authority_manager, cancellable, generic_cb, &res); + + egg_dbus_connection_pending_call_block (authority_manager->system_bus, call_id); + + result = polkit_authority_manager_enumerate_groups_finish (authority_manager, res, error); + + g_object_unref (res); + + return result; +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static guint +polkit_authority_manager_enumerate_authorizations_async (PolkitAuthorityManager *authority_manager, + 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_manager), + callback, + user_data, + polkit_authority_manager_enumerate_authorizations_async); + + real_identity = polkit_identity_get_real (identity); + + call_id = _polkit_authority_manager_enumerate_authorizations (authority_manager->real, + EGG_DBUS_CALL_FLAGS_NONE, + real_identity, + cancellable, + generic_async_cb, + simple); + + g_object_unref (real_identity); + + return call_id; +} + +void +polkit_authority_manager_enumerate_authorizations (PolkitAuthorityManager *authority_manager, + PolkitIdentity *identity, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + polkit_authority_manager_enumerate_authorizations_async (authority_manager, + identity, + cancellable, + callback, + user_data); +} + +GList * +polkit_authority_manager_enumerate_authorizations_finish (PolkitAuthorityManager *authority_manager, + GAsyncResult *res, + GError **error) +{ + EggDBusArraySeq *array_seq; + GList *result; + guint n; + GSimpleAsyncResult *simple; + GAsyncResult *real_res; + + 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_manager_enumerate_authorizations_async); + + result = NULL; + + if (!_polkit_authority_manager_enumerate_authorizations_finish (authority_manager->real, + &array_seq, + real_res, + error)) + goto out; + + for (n = 0; n < array_seq->size; n++) + { + _PolkitAuthorization *real_authorization; + + real_authorization = array_seq->data.v_ptr[n]; + + result = g_list_prepend (result, polkit_authorization_new_for_real (real_authorization)); + } + + result = g_list_reverse (result); + + g_object_unref (array_seq); + + out: + g_object_unref (real_res); + return result; +} + + +GList * +polkit_authority_manager_enumerate_authorizations_sync (PolkitAuthorityManager *authority_manager, + PolkitIdentity *identity, + GCancellable *cancellable, + GError **error) +{ + guint call_id; + GAsyncResult *res; + GList *result; + + call_id = polkit_authority_manager_enumerate_authorizations_async (authority_manager, + identity, + cancellable, + generic_cb, + &res); + + egg_dbus_connection_pending_call_block (authority_manager->system_bus, call_id); + + result = polkit_authority_manager_enumerate_authorizations_finish (authority_manager, res, error); + + g_object_unref (res); + + return result; +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static guint +polkit_authority_manager_add_authorization_async (PolkitAuthorityManager *authority_manager, + PolkitIdentity *identity, + PolkitAuthorization *authorization, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + guint call_id; + GSimpleAsyncResult *simple; + _PolkitAuthorization *real_authorization; + _PolkitIdentity *real_identity; + + simple = g_simple_async_result_new (G_OBJECT (authority_manager), + callback, + user_data, + polkit_authority_manager_add_authorization_async); + + real_identity = polkit_identity_get_real (identity); + real_authorization = polkit_authorization_get_real (authorization); + + call_id = _polkit_authority_manager_add_authorization (authority_manager->real, + EGG_DBUS_CALL_FLAGS_NONE, + real_identity, + real_authorization, + cancellable, + generic_async_cb, + simple); + + g_object_unref (real_authorization); + g_object_unref (real_identity); + + return call_id; +} + +void +polkit_authority_manager_add_authorization (PolkitAuthorityManager *authority_manager, + PolkitIdentity *identity, + PolkitAuthorization *authorization, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + polkit_authority_manager_add_authorization_async (authority_manager, + identity, + authorization, + cancellable, + callback, + user_data); +} + +gboolean +polkit_authority_manager_add_authorization_finish (PolkitAuthorityManager *authority_manager, + GAsyncResult *res, + GError **error) +{ + GSimpleAsyncResult *simple; + GAsyncResult *real_res; + gboolean ret; + + 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_manager_add_authorization_async); + + ret = _polkit_authority_manager_add_authorization_finish (authority_manager->real, + real_res, + error); + + if (!ret) + goto out; + + out: + g_object_unref (real_res); + return ret; +} + + +gboolean +polkit_authority_manager_add_authorization_sync (PolkitAuthorityManager *authority_manager, + PolkitIdentity *identity, + PolkitAuthorization *authorization, + GCancellable *cancellable, + GError **error) +{ + guint call_id; + GAsyncResult *res; + gboolean ret; + + call_id = polkit_authority_manager_add_authorization_async (authority_manager, + identity, + authorization, + cancellable, + generic_cb, + &res); + + egg_dbus_connection_pending_call_block (authority_manager->system_bus, call_id); + + ret = polkit_authority_manager_add_authorization_finish (authority_manager, res, error); + + g_object_unref (res); + + return ret; +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static guint +polkit_authority_manager_remove_authorization_async (PolkitAuthorityManager *authority_manager, + PolkitIdentity *identity, + PolkitAuthorization *authorization, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + guint call_id; + GSimpleAsyncResult *simple; + _PolkitAuthorization *real_authorization; + _PolkitIdentity *real_identity; + + simple = g_simple_async_result_new (G_OBJECT (authority_manager), + callback, + user_data, + polkit_authority_manager_remove_authorization_async); + + real_identity = polkit_identity_get_real (identity); + real_authorization = polkit_authorization_get_real (authorization); + + call_id = _polkit_authority_manager_remove_authorization (authority_manager->real, + EGG_DBUS_CALL_FLAGS_NONE, + real_identity, + real_authorization, + cancellable, + generic_async_cb, + simple); + + g_object_unref (real_authorization); + g_object_unref (real_identity); + + return call_id; +} + +void +polkit_authority_manager_remove_authorization (PolkitAuthorityManager *authority_manager, + PolkitIdentity *identity, + PolkitAuthorization *authorization, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + polkit_authority_manager_remove_authorization_async (authority_manager, + identity, + authorization, + cancellable, + callback, + user_data); +} + +gboolean +polkit_authority_manager_remove_authorization_finish (PolkitAuthorityManager *authority_manager, + GAsyncResult *res, + GError **error) +{ + GSimpleAsyncResult *simple; + GAsyncResult *real_res; + gboolean ret; + + 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_manager_remove_authorization_async); + + ret = _polkit_authority_manager_remove_authorization_finish (authority_manager->real, + real_res, + error); + + if (!ret) + goto out; + + out: + g_object_unref (real_res); + return ret; +} + + +gboolean +polkit_authority_manager_remove_authorization_sync (PolkitAuthorityManager *authority_manager, + PolkitIdentity *identity, + PolkitAuthorization *authorization, + GCancellable *cancellable, + GError **error) +{ + guint call_id; + GAsyncResult *res; + gboolean ret; + + call_id = polkit_authority_manager_remove_authorization_async (authority_manager, + identity, + authorization, + cancellable, + generic_cb, + &res); + + egg_dbus_connection_pending_call_block (authority_manager->system_bus, call_id); + + ret = polkit_authority_manager_remove_authorization_finish (authority_manager, res, error); + + g_object_unref (res); + + return ret; +} + +/* ---------------------------------------------------------------------------------------------------- */ diff --git a/src/polkit/polkitauthoritymanager.h b/src/polkit/polkitauthoritymanager.h new file mode 100644 index 0000000..36ff1cf --- /dev/null +++ b/src/polkit/polkitauthoritymanager.h @@ -0,0 +1,131 @@ +/* + * 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 <davidz@redhat.com> + */ + +#ifndef __POLKIT_AUTHORITY_MANAGER_H +#define __POLKIT_AUTHORITY_MANAGER_H + +#include <glib-object.h> +#include <gio/gio.h> +#include <polkit/polkittypes.h> + +G_BEGIN_DECLS + +#define POLKIT_TYPE_AUTHORITY_MANAGER (polkit_authority_manager_get_type()) +#define POLKIT_AUTHORITY_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_AUTHORITY_MANAGER, PolkitAuthorityManager)) +#define POLKIT_AUTHORITY_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), POLKIT_TYPE_AUTHORITY_MANAGER, PolkitAuthorityManagerClass)) +#define POLKIT_AUTHORITY_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_TYPE_AUTHORITY_MANAGER, PolkitAuthorityManagerClass)) +#define POLKIT_IS_AUTHORITY_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_AUTHORITY_MANAGER)) +#define POLKIT_IS_AUTHORITY_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_TYPE_AUTHORITY_MANAGER)) + +#if 0 +typedef struct _PolkitAuthorityManager PolkitAuthorityManager; +#endif +typedef struct _PolkitAuthorityManagerClass PolkitAuthorityManagerClass; + +GType polkit_authority_manager_get_type (void) G_GNUC_CONST; + +PolkitAuthorityManager *polkit_authority_manager_get (void); + +/* ---------------------------------------------------------------------------------------------------- */ + +GList *polkit_authority_manager_enumerate_users_sync (PolkitAuthorityManager *authority_manager, + GCancellable *cancellable, + GError **error); + +GList *polkit_authority_manager_enumerate_groups_sync (PolkitAuthorityManager *authority_manager, + GCancellable *cancellable, + GError **error); + +GList *polkit_authority_manager_enumerate_authorizations_sync (PolkitAuthorityManager *authority_manager, + PolkitIdentity *identity, + GCancellable *cancellable, + GError **error); + +gboolean polkit_authority_manager_add_authorization_sync (PolkitAuthorityManager *authority_manager, + PolkitIdentity *identity, + PolkitAuthorization *authorization, + GCancellable *cancellable, + GError **error); + +gboolean polkit_authority_manager_remove_authorization_sync (PolkitAuthorityManager *authority_manager, + PolkitIdentity *identity, + PolkitAuthorization *authorization, + GCancellable *cancellable, + GError **error); + +/* ---------------------------------------------------------------------------------------------------- */ + + +void polkit_authority_manager_enumerate_users (PolkitAuthorityManager *authority_manager, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); + +GList * polkit_authority_manager_enumerate_users_finish (PolkitAuthorityManager *authority_manager, + GAsyncResult *res, + GError **error); + +void polkit_authority_manager_enumerate_groups (PolkitAuthorityManager *authority_manager, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); + +GList * polkit_authority_manager_enumerate_groups_finish (PolkitAuthorityManager *authority_manager, + GAsyncResult *res, + GError **error); + +void polkit_authority_manager_enumerate_authorizations (PolkitAuthorityManager *authority_manager, + PolkitIdentity *identity, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); + +GList * polkit_authority_manager_enumerate_authorizations_finish (PolkitAuthorityManager *authority_manager, + GAsyncResult *res, + GError **error); + +void polkit_authority_manager_add_authorization (PolkitAuthorityManager *authority_manager, + PolkitIdentity *identity, + PolkitAuthorization *authorization, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); + +gboolean polkit_authority_manager_add_authorization_finish (PolkitAuthorityManager *authority_manager, + GAsyncResult *res, + GError **error); + +void polkit_authority_manager_remove_authorization (PolkitAuthorityManager *authority_manager, + PolkitIdentity *identity, + PolkitAuthorization *authorization, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); + +gboolean polkit_authority_manager_remove_authorization_finish (PolkitAuthorityManager *authority_manager, + GAsyncResult *res, + GError **error); + +/* ---------------------------------------------------------------------------------------------------- */ + +G_END_DECLS + +#endif /* __POLKIT_AUTHORITY_MANAGER_H */ diff --git a/src/polkit/polkittypes.h b/src/polkit/polkittypes.h index 4d6aa28..5da914b 100644 --- a/src/polkit/polkittypes.h +++ b/src/polkit/polkittypes.h @@ -27,6 +27,9 @@ struct _PolkitAuthority; typedef struct _PolkitAuthority PolkitAuthority; +struct _PolkitAuthorityManager; +typedef struct _PolkitAuthorityManager PolkitAuthorityManager; + struct _PolkitActionDescription; typedef struct _PolkitActionDescription PolkitActionDescription; diff --git a/src/polkitbackend/polkitbackendauthority.h b/src/polkitbackend/polkitbackendauthority.h index 70841e5..8a2d959 100644 --- a/src/polkitbackend/polkitbackendauthority.h +++ b/src/polkitbackend/polkitbackendauthority.h @@ -196,7 +196,6 @@ void polkit_backend_authority_unregister_authentication_agent_finish (Polkit void polkit_backend_authority_authentication_agent_response_finish (PolkitBackendPendingCall *pending_call); - G_END_DECLS #endif /* __POLKIT_BACKEND_AUTHORITY_H */ diff --git a/src/polkitbackend/polkitbackendserver.c b/src/polkitbackend/polkitbackendserver.c index 25fb96c..00963a8 100644 --- a/src/polkitbackend/polkitbackendserver.c +++ b/src/polkitbackend/polkitbackendserver.c @@ -60,10 +60,12 @@ struct _PolkitBackendServerClass GObjectClass parent_class; }; -static void authority_iface_init (_PolkitAuthorityIface *authority_iface); +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 @@ -197,8 +199,8 @@ polkit_backend_authority_enumerate_actions_finish (PolkitBackendPendingCall *pen /* ---------------------------------------------------------------------------------------------------- */ static void -authority_handle_enumerate_users (_PolkitAuthority *instance, - EggDBusMethodInvocation *method_invocation) +authority_manager_handle_enumerate_users (_PolkitAuthorityManager *instance, + EggDBusMethodInvocation *method_invocation) { PolkitBackendServer *server = POLKIT_BACKEND_SERVER (instance); PolkitBackendPendingCall *pending_call; @@ -229,8 +231,8 @@ polkit_backend_authority_enumerate_users_finish (PolkitBackendPendingCall *pendi egg_dbus_array_seq_add (array, real); } - _polkit_authority_handle_enumerate_users_finish (_polkit_backend_pending_call_get_method_invocation (pending_call), - array); + _polkit_authority_manager_handle_enumerate_users_finish (_polkit_backend_pending_call_get_method_invocation (pending_call), + array); g_object_unref (array); @@ -243,8 +245,8 @@ polkit_backend_authority_enumerate_users_finish (PolkitBackendPendingCall *pendi /* ---------------------------------------------------------------------------------------------------- */ static void -authority_handle_enumerate_groups (_PolkitAuthority *instance, - EggDBusMethodInvocation *method_invocation) +authority_manager_handle_enumerate_groups (_PolkitAuthorityManager *instance, + EggDBusMethodInvocation *method_invocation) { PolkitBackendServer *server = POLKIT_BACKEND_SERVER (instance); PolkitBackendPendingCall *pending_call; @@ -275,8 +277,8 @@ polkit_backend_authority_enumerate_groups_finish (PolkitBackendPendingCall *pend egg_dbus_array_seq_add (array, real); } - _polkit_authority_handle_enumerate_groups_finish (_polkit_backend_pending_call_get_method_invocation (pending_call), - array); + _polkit_authority_manager_handle_enumerate_groups_finish (_polkit_backend_pending_call_get_method_invocation (pending_call), + array); g_object_unref (array); @@ -325,9 +327,9 @@ polkit_backend_authority_check_authorization_finish (PolkitBackendPendingCall * /* ---------------------------------------------------------------------------------------------------- */ static void -authority_handle_enumerate_authorizations (_PolkitAuthority *instance, - _PolkitIdentity *real_identity, - EggDBusMethodInvocation *method_invocation) +authority_manager_handle_enumerate_authorizations (_PolkitAuthorityManager *instance, + _PolkitIdentity *real_identity, + EggDBusMethodInvocation *method_invocation) { PolkitBackendServer *server = POLKIT_BACKEND_SERVER (instance); PolkitBackendPendingCall *pending_call; @@ -365,8 +367,8 @@ polkit_backend_authority_enumerate_authorizations_finish (PolkitBackendPendingCa egg_dbus_array_seq_add (array, real); } - _polkit_authority_handle_enumerate_authorizations_finish (_polkit_backend_pending_call_get_method_invocation (pending_call), - array); + _polkit_authority_manager_handle_enumerate_authorizations_finish (_polkit_backend_pending_call_get_method_invocation (pending_call), + array); g_object_unref (array); @@ -379,10 +381,10 @@ polkit_backend_authority_enumerate_authorizations_finish (PolkitBackendPendingCa /* ---------------------------------------------------------------------------------------------------- */ static void -authority_handle_add_authorization (_PolkitAuthority *instance, - _PolkitIdentity *real_identity, - _PolkitAuthorization *real_authorization, - EggDBusMethodInvocation *method_invocation) +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; @@ -407,17 +409,17 @@ authority_handle_add_authorization (_PolkitAuthority *instance, void polkit_backend_authority_add_authorization_finish (PolkitBackendPendingCall *pending_call) { - _polkit_authority_handle_add_authorization_finish (_polkit_backend_pending_call_get_method_invocation (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_handle_remove_authorization (_PolkitAuthority *instance, - _PolkitIdentity *real_identity, - _PolkitAuthorization *real_authorization, - EggDBusMethodInvocation *method_invocation) +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; @@ -442,7 +444,7 @@ authority_handle_remove_authorization (_PolkitAuthority *instance, void polkit_backend_authority_remove_authorization_finish (PolkitBackendPendingCall *pending_call) { - _polkit_authority_handle_remove_authorization_finish (_polkit_backend_pending_call_get_method_invocation (pending_call)); + _polkit_authority_manager_handle_remove_authorization_finish (_polkit_backend_pending_call_get_method_invocation (pending_call)); g_object_unref (pending_call); } @@ -531,13 +533,18 @@ static void authority_iface_init (_PolkitAuthorityIface *authority_iface) { authority_iface->handle_enumerate_actions = authority_handle_enumerate_actions; - authority_iface->handle_enumerate_users = authority_handle_enumerate_users; - authority_iface->handle_enumerate_groups = authority_handle_enumerate_groups; authority_iface->handle_check_authorization = authority_handle_check_authorization; - authority_iface->handle_enumerate_authorizations = authority_handle_enumerate_authorizations; - authority_iface->handle_add_authorization = authority_handle_add_authorization; - authority_iface->handle_remove_authorization = authority_handle_remove_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/polkitd/main.c b/src/polkitd/main.c index ab43694..9832cda 100644 --- a/src/polkitd/main.c +++ b/src/polkitd/main.c @@ -89,6 +89,8 @@ main (int argc, char **argv) "/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); diff --git a/src/programs/polkit.c b/src/programs/polkit.c index de46b15..c183909 100644 --- a/src/programs/polkit.c +++ b/src/programs/polkit.c @@ -27,6 +27,7 @@ #include <polkit/polkit.h> static PolkitAuthority *authority; +static PolkitAuthorityManager *authority_manager; static gboolean opt_list_actions = FALSE; static gboolean opt_list_users = FALSE; @@ -295,6 +296,7 @@ main (int argc, char *argv[]) } authority = polkit_authority_get (); + authority_manager = polkit_authority_manager_get (); if (opt_show_help) { @@ -379,6 +381,9 @@ main (int argc, char *argv[]) if (authority != NULL) g_object_unref (authority); + if (authority_manager != NULL) + g_object_unref (authority_manager); + if (subject != NULL) g_object_unref (subject); @@ -570,9 +575,9 @@ list_users (void) ret = FALSE; error = NULL; - identities = polkit_authority_enumerate_users_sync (authority, - NULL, - &error); + identities = polkit_authority_manager_enumerate_users_sync (authority_manager, + NULL, + &error); if (error != NULL) { g_printerr ("Error enumerating users: %s\n", error->message); @@ -603,9 +608,9 @@ list_groups (void) ret = FALSE; error = NULL; - identities = polkit_authority_enumerate_groups_sync (authority, - NULL, - &error); + identities = polkit_authority_manager_enumerate_groups_sync (authority_manager, + NULL, + &error); if (error != NULL) { g_printerr ("Error enumerating users: %s\n", error->message); @@ -862,10 +867,10 @@ list_explicit_authorizations (void) ret = FALSE; error = NULL; - authorizations = polkit_authority_enumerate_authorizations_sync (authority, - identity, - NULL, - &error); + authorizations = polkit_authority_manager_enumerate_authorizations_sync (authority_manager, + identity, + NULL, + &error); if (error != NULL) { g_printerr ("Error enumerating authorizations: %s\n", error->message); @@ -928,11 +933,11 @@ do_grant (void) subject, FALSE); /* TODO: handle negative */ - if (!polkit_authority_add_authorization_sync (authority, - identity, - authorization, - NULL, - &error)) + if (!polkit_authority_manager_add_authorization_sync (authority_manager, + identity, + authorization, + NULL, + &error)) { g_printerr ("Error adding authorization: %s\n", error->message); g_error_free (error); @@ -964,11 +969,11 @@ do_revoke (void) subject, FALSE); /* TODO: handle negative */ - if (!polkit_authority_remove_authorization_sync (authority, - identity, - authorization, - NULL, - &error)) + if (!polkit_authority_manager_remove_authorization_sync (authority_manager, + identity, + authorization, + NULL, + &error)) { g_printerr ("Error removing authorization: %s\n", error->message); g_error_free (error); |