From 2645459721dabd3aed5ce7899abfce5772eb3b89 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Tue, 6 Jan 2009 13:35:24 -0500 Subject: [PATCH] update to latest EggDBus and rework how things are done --- data/org.freedesktop.PolicyKit1.Authority.xml | 60 ++-- src/polkit/Makefile.am | 55 ++-- src/polkit/polkit.h | 10 +- src/polkit/polkitactiondescription.c | 244 ++++---------- src/polkit/polkitactiondescription.h | 25 +- src/polkit/polkitauthority.c | 140 +++++++++ src/polkit/polkitauthority.h | 54 ++++ src/polkit/polkitauthoritystub.c | 62 ---- src/polkit/polkitauthorizationclaim.c | 238 -------------- src/polkit/polkitauthorizationclaim.h | 68 ---- .../{polkitauthoritystub.h => polkiterror.c} | 23 +- src/polkit/polkiterror.h | 58 ++++ src/polkit/polkitsubject.c | 349 --------------------- src/polkit/polkitsubject.h | 67 ---- src/polkitbackend/Makefile.am | 7 + src/polkitbackend/polkitbackend.h | 3 + src/polkitbackend/polkitbackendactionpool.c | 76 +++-- src/polkitbackend/polkitbackendauthority.c | 51 +++ src/polkitbackend/polkitbackendauthority.h | 77 +++++ src/polkitbackend/polkitbackendlocalauthority.c | 40 ++- src/polkitbackend/polkitbackendlocalauthority.h | 14 +- src/polkitbackend/polkitbackendserver.c | 119 +++++++ src/polkitbackend/polkitbackendserver.h | 50 +++ src/polkitbackend/polkitbackendtypes.h | 34 ++ src/polkitd/Makefile.am | 1 + src/polkitd/main.c | 48 ++- src/programs/polkit-verify-claim.c | 49 ++- 27 files changed, 892 insertions(+), 1130 deletions(-) create mode 100644 src/polkit/polkitauthority.c create mode 100644 src/polkit/polkitauthority.h delete mode 100644 src/polkit/polkitauthoritystub.c delete mode 100644 src/polkit/polkitauthorizationclaim.c delete mode 100644 src/polkit/polkitauthorizationclaim.h rename src/polkit/{polkitauthoritystub.h => polkiterror.c} (77%) create mode 100644 src/polkit/polkiterror.h delete mode 100644 src/polkit/polkitsubject.c delete mode 100644 src/polkit/polkitsubject.h create mode 100644 src/polkitbackend/polkitbackendauthority.c create mode 100644 src/polkitbackend/polkitbackendauthority.h create mode 100644 src/polkitbackend/polkitbackendserver.c create mode 100644 src/polkitbackend/polkitbackendserver.h create mode 100644 src/polkitbackend/polkitbackendtypes.h diff --git a/data/org.freedesktop.PolicyKit1.Authority.xml b/data/org.freedesktop.PolicyKit1.Authority.xml index 85826d9..90f405d 100644 --- a/data/org.freedesktop.PolicyKit1.Authority.xml +++ b/data/org.freedesktop.PolicyKit1.Authority.xml @@ -2,41 +2,63 @@ "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> - + - - + + + - + + + - + - + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - + - + + + - - - + + + + + + + diff --git a/src/polkit/Makefile.am b/src/polkit/Makefile.am index 39d4a6e..9c69b5f 100644 --- a/src/polkit/Makefile.am +++ b/src/polkit/Makefile.am @@ -12,21 +12,24 @@ INCLUDES = \ -DPACKAGE_LIB_DIR=\""$(libdir)"\" \ -D_POSIX_PTHREAD_SEMANTICS \ -D_REENTRANT \ + -DEGG_DBUS_I_KNOW_API_IS_SUBJECT_TO_CHANGE \ $(NULL) -BUILT_SOURCES = \ - polkitbindings.h polkitbindings.c \ - polkitbindingstypes.h \ - polkitauthority.h polkitauthority.c \ - polkiterror.h polkiterror.c \ - polkitbindingsmarshal.h polkitbindingsmarshal.c \ - polkitauthorizationresult.h polkitauthorizationresult.c \ - polkitbindingsmarshal.list \ - $(NULL) +BUILT_SOURCES = \ + _polkitactiondescription.c _polkitactiondescription.h \ + _polkitauthority.c _polkitauthority.h \ + _polkitauthorizationclaim.c _polkitauthorizationclaim.h \ + _polkitauthorizationresult.c _polkitauthorizationresult.h \ + _polkitbindings.c _polkitbindings.h \ + _polkitbindingsmarshal.c _polkitbindingsmarshal.h \ + _polkitbindingstypes.h \ + _polkiterror.c _polkiterror.h \ + _polkitsubject.c _polkitsubject.h \ + $(NULL) $(BUILT_SOURCES) : Makefile.am $(top_srcdir)/data/org.freedesktop.PolicyKit1.Authority.xml - dbus2gobject \ - --namespace "Polkit" \ + eggdbus-binding-tool \ + --namespace "_Polkit" \ --dbus-namespace "org.freedesktop.PolicyKit1" \ --introspection-xml $(top_srcdir)/data/org.freedesktop.PolicyKit1.Authority.xml \ $(NULL) @@ -35,27 +38,19 @@ lib_LTLIBRARIES=libpolkit-gobject-1.la libpolkit_gobject_1includedir=$(includedir)/polkit-1/polkit -libpolkit_gobject_1include_HEADERS = \ - polkit.h \ - polkitauthoritystub.h \ - polkitactiondescription.h \ - polkitauthority.h \ - polkitauthorizationclaim.h \ - polkitauthorizationresult.h \ - polkiterror.h \ - polkitsubject.h \ - polkitbindings.h \ - polkitbindingstypes.h \ - polkitauthority.h \ +libpolkit_gobject_1include_HEADERS = \ + polkit.h \ + polkitactiondescription.h \ + polkitauthority.h \ + polkiterror.h \ $(NULL) -libpolkit_gobject_1_la_SOURCES = \ - polkit.h \ - polkitauthoritystub.h polkitauthoritystub.c \ - polkitactiondescription.h polkitactiondescription.c \ - polkitauthorizationclaim.h polkitauthorizationclaim.c \ - polkitsubject.h polkitsubject.c \ - $(BUILT_SOURCES) \ +libpolkit_gobject_1_la_SOURCES = \ + polkit.h \ + $(BUILT_SOURCES) \ + polkitactiondescription.c polkitactiondescription.h \ + polkitauthority.c polkitauthority.h \ + polkiterror.c polkiterror.h \ $(NULL) libpolkit_gobject_1_la_CFLAGS = \ diff --git a/src/polkit/polkit.h b/src/polkit/polkit.h index b813cf3..6cab9b1 100644 --- a/src/polkit/polkit.h +++ b/src/polkit/polkit.h @@ -23,17 +23,11 @@ #define __POLKIT_H #define _POLKIT_INSIDE_POLKIT_H 1 -#include -#include -#include -#include -#include -#include #include +#include +#include #undef _POLKIT_INSIDE_POLKIT_H #endif /* __POLKIT_H */ - - diff --git a/src/polkit/polkitactiondescription.c b/src/polkit/polkitactiondescription.c index de6ea57..05d2e47 100644 --- a/src/polkit/polkitactiondescription.c +++ b/src/polkit/polkitactiondescription.c @@ -22,232 +22,120 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif -#include -#include "polkitbindings.h" + #include "polkitactiondescription.h" +#include "_polkitactiondescription.h" + +#include "polkitprivate.h" /** * SECTION:polkitactiondescription * @title: PolkitActionDescription - * @short_description: Descriptions of actions + * @short_description: Actions * - * The #PolkitActionDescription type is used to described registered PolicyKit actions. + * Encapsulates an action. */ -static void -base_init (gpointer g_iface) +struct _PolkitActionDescription { -} + GObject parent_instance; + + _PolkitActionDescription *real; +}; -GType -polkit_action_description_get_type (void) +struct _PolkitActionDescriptionClass { - static GType iface_type = 0; + GObjectClass parent_class; +}; - if (iface_type == 0) - { - static const GTypeInfo info = - { - sizeof (PolkitActionDescriptionIface), - base_init, /* base_init */ - NULL, /* base_finalize */ - NULL, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - 0, /* instance_size */ - 0, /* n_preallocs */ - NULL, /* instance_init */ - NULL /* value_table */ - }; - - iface_type = g_type_register_static (G_TYPE_INTERFACE, "PolkitActionDescription", &info, 0); - - g_type_interface_add_prerequisite (iface_type, EGG_DBUS_TYPE_STRUCTURE); - } +G_DEFINE_TYPE (PolkitActionDescription, polkit_action_description, G_TYPE_OBJECT); - return iface_type; +static void +polkit_action_description_init (PolkitActionDescription *action_description) +{ } -#define ACTION_DESCRIPTION_SIGNATURE "(ssssssa{ss})" - -/** - * polkit_action_description_get_action_id: - * @action_description: A #PolkitActionDescription. - * - * Gets the action identifer for @action_description. - * - * Returns: The action identifier for @action_description. - */ -const gchar * -polkit_action_description_get_action_id (PolkitActionDescription *action_description) +static void +polkit_action_description_finalize (GObject *object) { - const gchar *s; + PolkitActionDescription *action_description; - g_return_val_if_fail (POLKIT_IS_ACTION_DESCRIPTION (action_description), NULL); - g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (action_description)), ACTION_DESCRIPTION_SIGNATURE) == 0, NULL); + action_description = POLKIT_ACTION_DESCRIPTION (object); - egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (action_description), - 0, &s, - -1); - - return s; + g_object_unref (action_description->real); } -/** - * polkit_action_description_get_description: - * @action_description: A #PolkitActionDescription. - * - * Gets a human readable description of @action_description. - * - * Returns: The human readable description for @action_description or %NULL if not set. - */ -const gchar * -polkit_action_description_get_description (PolkitActionDescription *action_description) +static void +polkit_action_description_class_init (PolkitActionDescriptionClass *klass) { - const gchar *s; + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - g_return_val_if_fail (POLKIT_IS_ACTION_DESCRIPTION (action_description), NULL); - g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (action_description)), ACTION_DESCRIPTION_SIGNATURE) == 0, NULL); - - egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (action_description), - 1, &s, - -1); - - return strlen (s) > 0 ? s : NULL; + gobject_class->finalize = polkit_action_description_finalize; } -/** - * polkit_action_description_get_message: - * @action_description: A #PolkitActionDescription. - * - * Gets the message shown for @action_description. - * - * Returns: The message for @action_description or %NULL if not set. - */ -const gchar * -polkit_action_description_get_message (PolkitActionDescription *action_description) +PolkitActionDescription * +polkit_action_description_new_for_real (_PolkitActionDescription *real) { - const gchar *s; + PolkitActionDescription *action_description; - g_return_val_if_fail (POLKIT_IS_ACTION_DESCRIPTION (action_description), NULL); - g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (action_description)), ACTION_DESCRIPTION_SIGNATURE) == 0, NULL); + action_description = POLKIT_ACTION_DESCRIPTION (g_object_new (POLKIT_TYPE_ACTION_DESCRIPTION, NULL)); + action_description->real = g_object_ref (real); - egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (action_description), - 2, &s, - -1); + return action_description; +} - return strlen (s) > 0 ? s : NULL; +_PolkitActionDescription * +polkit_action_description_get_real (PolkitActionDescription *action_description) +{ + return action_description->real; } -/** - * polkit_action_description_get_vendor_name: - * @action_description: A #PolkitActionDescription. - * - * Gets the name of the vendor for @action_description. - * - * Returns: The vendor of @action_description or %NULL if not set. - */ -const gchar * -polkit_action_description_get_vendor_name (PolkitActionDescription *action_description) +const gchar * +polkit_action_description_get_action_id (PolkitActionDescription *action_description) { - const gchar *s; + return _polkit_action_description_get_action_id (action_description->real); +} - g_return_val_if_fail (POLKIT_IS_ACTION_DESCRIPTION (action_description), NULL); - g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (action_description)), ACTION_DESCRIPTION_SIGNATURE) == 0, NULL); +const gchar * +polkit_action_description_get_description (PolkitActionDescription *action_description) +{ + return _polkit_action_description_get_description (action_description->real); +} - egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (action_description), - 3, &s, - -1); +const gchar * +polkit_action_description_get_message (PolkitActionDescription *action_description) +{ + return _polkit_action_description_get_message (action_description->real); +} - return strlen (s) > 0 ? s : NULL; +const gchar * +polkit_action_description_get_vendor_name (PolkitActionDescription *action_description) +{ + return _polkit_action_description_get_vendor_name (action_description->real); } -/** - * polkit_action_description_get_vendor_url: - * @action_description: A #PolkitActionDescription. - * - * Gets the vendor URL for @action_description. - * - * Returns: The vendor URL for @action_description or %NULL if not set. - */ -const gchar * +const gchar * polkit_action_description_get_vendor_url (PolkitActionDescription *action_description) { - const gchar *s; - - g_return_val_if_fail (POLKIT_IS_ACTION_DESCRIPTION (action_description), NULL); - g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (action_description)), ACTION_DESCRIPTION_SIGNATURE) == 0, NULL); - - egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (action_description), - 4, &s, - -1); - - return strlen (s) > 0 ? s : NULL; + return _polkit_action_description_get_vendor_url (action_description->real); } -/** - * polkit_action_description_get_icon: - * @action_description: A #PolkitActionDescription. - * - * Gets the #GIcon for @action_description. - * - * Returns: A #GIcon (free with g_object_unref() when done with it) or %NULL if not set. - */ GIcon * polkit_action_description_get_icon (PolkitActionDescription *action_description) { - const gchar *s; + const gchar *icon_name; GIcon *icon; + GError *error; - g_return_val_if_fail (POLKIT_IS_ACTION_DESCRIPTION (action_description), NULL); - g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (action_description)), ACTION_DESCRIPTION_SIGNATURE) == 0, NULL); - - egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (action_description), - 5, &s, - -1); + icon_name = _polkit_action_description_get_icon_name (action_description->real); - if (strlen (s) > 0) + error = NULL; + icon = g_icon_new_for_string (icon_name, &error); + if (icon_name == NULL) { - icon = NULL; - } - else - { - GError *error; - - error = NULL; - icon = g_icon_new_for_string (s, &error); - if (icon == NULL) - { - g_warning ("Error getting icon for action description: %s", error->message); - g_error_free (error); - } + g_warning ("polkit_action_description_get_icon: %s", error->message); + g_error_free (error); } return icon; } - -/** - * polkit_action_description_get_annotations: - * @action_description: A #PolkitActionDescription. - * - * Gets the annotations for @action_description. - * - * Returns: A #GHashTable from strings to strings with the annotations - * for @action_description. Do not destroy or unref this hash table; - * it is owned by @action_description. - */ -GHashTable * -polkit_action_description_get_annotations (PolkitActionDescription *action_description) -{ - GHashTable *hash; - - g_return_val_if_fail (POLKIT_IS_ACTION_DESCRIPTION (action_description), NULL); - g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (action_description)), ACTION_DESCRIPTION_SIGNATURE) == 0, NULL); - - egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (action_description), - 6, &hash, - -1); - - return hash; -} - diff --git a/src/polkit/polkitactiondescription.h b/src/polkit/polkitactiondescription.h index 22a3799..cc4d2b4 100644 --- a/src/polkit/polkitactiondescription.h +++ b/src/polkit/polkitactiondescription.h @@ -22,27 +22,23 @@ #ifndef __POLKIT_ACTION_DESCRIPTION_H #define __POLKIT_ACTION_DESCRIPTION_H -#include -#include #include -#include +#include +#include G_BEGIN_DECLS -#define POLKIT_TYPE_ACTION_DESCRIPTION (polkit_action_description_get_type()) -#define POLKIT_ACTION_DESCRIPTION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_ACTION_DESCRIPTION, PolkitActionDescription)) -#define POLKIT_IS_ACTION_DESCRIPTION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_ACTION_DESCRIPTION)) -#define POLKIT_ACTION_DESCRIPTION_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE((o), POLKIT_TYPE_ACTION_DESCRIPTION, PolkitActionDescriptionIface)) +#define POLKIT_TYPE_ACTION_DESCRIPTION (polkit_action_description_get_type()) +#define POLKIT_ACTION_DESCRIPTION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_ACTION_DESCRIPTION, PolkitActionDescription)) +#define POLKIT_ACTION_DESCRIPTION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), POLKIT_TYPE_ACTION_DESCRIPTION, PolkitActionDescriptionClass)) +#define POLKIT_ACTION_DESCRIPTION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_TYPE_ACTION_DESCRIPTION, PolkitActionDescriptionClass)) +#define POLKIT_IS_ACTION_DESCRIPTION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_ACTION_DESCRIPTION)) +#define POLKIT_IS_ACTION_DESCRIPTION_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_TYPE_ACTION_DESCRIPTION)) #if 0 -typedef struct _PolkitActionDescription PolkitActionDescription; /* Dummy typedef */ +typedef struct _PolkitActionDescription PolkitActionDescription; #endif -typedef struct _PolkitActionDescriptionIface PolkitActionDescriptionIface; - -struct _PolkitActionDescriptionIface -{ - GTypeInterface g_iface; -}; +typedef struct _PolkitActionDescriptionClass PolkitActionDescriptionClass; GType polkit_action_description_get_type (void) G_GNUC_CONST; const gchar *polkit_action_description_get_action_id (PolkitActionDescription *action_description); @@ -51,7 +47,6 @@ const gchar *polkit_action_description_get_message (PolkitActionDescriptio const gchar *polkit_action_description_get_vendor_name (PolkitActionDescription *action_description); const gchar *polkit_action_description_get_vendor_url (PolkitActionDescription *action_description); GIcon *polkit_action_description_get_icon (PolkitActionDescription *action_description); -GHashTable *polkit_action_description_get_annotations (PolkitActionDescription *action_description); G_END_DECLS diff --git a/src/polkit/polkitauthority.c b/src/polkit/polkitauthority.c new file mode 100644 index 0000000..18e6181 --- /dev/null +++ b/src/polkit/polkitauthority.c @@ -0,0 +1,140 @@ +/* + * 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 + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "polkitauthority.h" + +#include "polkitprivate.h" + +/** + * SECTION:polkitauthority + * @title: PolkitAuthority + * @short_description: Authority + * + * Checking claims. + */ + +struct _PolkitAuthority +{ + GObject parent_instance; + + EggDBusObjectProxy *authority_object_proxy; + + _PolkitAuthority *real; +}; + +struct _PolkitAuthorityClass +{ + GObjectClass parent_class; + +}; + +/* TODO: locking */ + +static PolkitAuthority *the_authority = NULL; + +G_DEFINE_TYPE (PolkitAuthority, polkit_authority, G_TYPE_OBJECT); + +static void +polkit_authority_init (PolkitAuthority *authority) +{ + EggDBusConnection *system_bus; + + system_bus = egg_dbus_connection_get_for_bus (EGG_DBUS_BUS_TYPE_SYSTEM); + + authority->authority_object_proxy = egg_dbus_connection_get_object_proxy (system_bus, + "org.freedesktop.PolicyKit1", + "/org/freedesktop/PolicyKit1/Authority"); + + authority->real = _POLKIT_QUERY_INTERFACE_AUTHORITY (authority->authority_object_proxy); + + g_object_unref (system_bus); +} + +static void +polkit_authority_finalize (GObject *object) +{ + PolkitAuthority *authority; + + authority = POLKIT_AUTHORITY (object); + + g_object_unref (authority->authority_object_proxy); + + the_authority = NULL; +} + +static void +polkit_authority_class_init (PolkitAuthorityClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->finalize = polkit_authority_finalize; +} + +PolkitAuthority * +polkit_authority_get (void) +{ + if (the_authority != NULL) + goto out; + + the_authority = POLKIT_AUTHORITY (g_object_new (POLKIT_TYPE_AUTHORITY, NULL)); + + out: + return the_authority; +} + +GList * +polkit_authority_enumerate_actions_sync (PolkitAuthority *authority, + const gchar *locale, + GCancellable *cancellable, + GError **error) +{ + EggDBusArraySeq *array_seq; + GList *result; + guint n; + + result = NULL; + + if (!_polkit_authority_enumerate_actions_sync (authority->real, + EGG_DBUS_CALL_FLAGS_NONE, + locale, + &array_seq, + cancellable, + error)) + goto out; + + for (n = 0; n < array_seq->size; n++) + { + _PolkitActionDescription *real_ad; + + real_ad = array_seq->data.v_ptr[n]; + + result = g_list_prepend (result, polkit_action_description_new_for_real (real_ad)); + } + + result = g_list_reverse (result); + + out: + return result; +} diff --git a/src/polkit/polkitauthority.h b/src/polkit/polkitauthority.h new file mode 100644 index 0000000..1b6cb9d --- /dev/null +++ b/src/polkit/polkitauthority.h @@ -0,0 +1,54 @@ +/* + * 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 + */ + +#ifndef __POLKIT_AUTHORITY_H +#define __POLKIT_AUTHORITY_H + +#include +#include +#include + +G_BEGIN_DECLS + +#define POLKIT_TYPE_AUTHORITY (polkit_authority_get_type()) +#define POLKIT_AUTHORITY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_AUTHORITY, PolkitAuthority)) +#define POLKIT_AUTHORITY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), POLKIT_TYPE_AUTHORITY, PolkitAuthorityClass)) +#define POLKIT_AUTHORITY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_TYPE_AUTHORITY, PolkitAuthorityClass)) +#define POLKIT_IS_AUTHORITY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_AUTHORITY)) +#define POLKIT_IS_AUTHORITY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_TYPE_AUTHORITY)) + +#if 0 +typedef struct _PolkitAuthority PolkitAuthority; +#endif +typedef struct _PolkitAuthorityClass PolkitAuthorityClass; + +GType polkit_authority_get_type (void) G_GNUC_CONST; + +PolkitAuthority *polkit_authority_get (void); + +GList *polkit_authority_enumerate_actions_sync (PolkitAuthority *authority, + const gchar *locale, + GCancellable *cancellable, + GError **error); + +G_END_DECLS + +#endif /* __POLKIT_AUTHORITY_H */ diff --git a/src/polkit/polkitauthoritystub.c b/src/polkit/polkitauthoritystub.c deleted file mode 100644 index 9928f08..0000000 --- a/src/polkit/polkitauthoritystub.c +++ /dev/null @@ -1,62 +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 "polkitauthoritystub.h" - -/* TODO: locking */ - -static PolkitAuthority *the_authority = NULL; - -/** - * polkit_authority_get: - * - * Gets the default authority for checking claims. - * - * Returns: A reference to a #PolkitAuthority instance. Call g_object_unref() when done with it - **/ -PolkitAuthority * -polkit_authority_get (void) -{ - PolkitAuthority *authority; - - polkit_bindings_register_types (); /* TODO: use __attribute ((constructor)) */ - - if (the_authority != NULL) - { - authority = g_object_ref (the_authority); - } - else - { - EggDBusConnection *connection; - - connection = egg_dbus_connection_get_for_bus (EGG_DBUS_BUS_TYPE_SYSTEM); - authority = POLKIT_AUTHORITY (egg_dbus_connection_get_proxy (connection, - "org.freedesktop.PolicyKit1", - "/org/freedesktop/PolicyKit1/Authority")); - - /* TODO: take a weak reference and set the_authority to NULL on destruction */ - - /* TODO: unref connection since authority holds a reference? */ - } - - return authority; -} diff --git a/src/polkit/polkitauthorizationclaim.c b/src/polkit/polkitauthorizationclaim.c deleted file mode 100644 index 81b692f..0000000 --- a/src/polkit/polkitauthorizationclaim.c +++ /dev/null @@ -1,238 +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 "polkitauthorizationclaim.h" -#include "polkitsubject.h" - -/** - * SECTION:polkitauthorizationclaim - * @title: PolkitAuthorizationClaim - * @short_description: Authorization Claim - * - * Represents an authorization claim. - */ - -static void -base_init (gpointer g_iface) -{ -} - -GType -polkit_authorization_claim_get_type (void) -{ - static GType iface_type = 0; - - if (iface_type == 0) - { - static const GTypeInfo info = - { - sizeof (PolkitAuthorizationClaimIface), - base_init, /* base_init */ - NULL, /* base_finalize */ - NULL, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - 0, /* instance_size */ - 0, /* n_preallocs */ - NULL, /* instance_init */ - NULL /* value_table */ - }; - - iface_type = g_type_register_static (G_TYPE_INTERFACE, "PolkitAuthorizationClaim", &info, 0); - - g_type_interface_add_prerequisite (iface_type, EGG_DBUS_TYPE_STRUCTURE); - } - - return iface_type; -} - -#define AUTHORIZATION_CLAIM_SIGNATURE "((sa{sv})sa{ss})" - -/** - * polkit_authorization_claim_new: - * @subject: The subject the claim is for. - * @action_id: The action identifier for the PolicyKit action the claim is about. - * - * Constructs a new #PolkitAuthorizationClaim representing a claim that @subject is authorized for @action_id. - * - * Returns: A #PolkitAuthorizationClaim. - */ -PolkitAuthorizationClaim * -polkit_authorization_claim_new (PolkitSubject *subject, - const gchar *action_id) -{ - GValue *values; - EggDBusHashTable *attributes; - - attributes = g_hash_table_new_full (g_str_hash, - g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) g_object_unref); - egg_dbus_hash_table_set_signature (attributes, "s", "s"); - - values = g_new0 (GValue, 3); - g_value_init (&(values[0]), POLKIT_TYPE_SUBJECT); - g_value_set_object (&(values[0]), subject); - g_value_init (&(values[1]), G_TYPE_STRING); - g_value_set_string (&(values[1]), action_id); - g_value_init (&(values[2]), EGG_DBUS_TYPE_HASH_TABLE); - g_value_take_boxed (&(values[2]), attributes); - - return POLKIT_AUTHORIZATION_CLAIM (egg_dbus_structure_new (AUTHORIZATION_CLAIM_SIGNATURE, 3, values)); -} - -/** - * polkit_authorization_claim_get_subject: - * @authorization_claim: A #PolkitAuthorizationClaim. - * - * Gets the subject for @authorization_claim. - * - * Returns: A #PolkitSubject instance owned by @authorization_claim. Do not free. - **/ -PolkitSubject * -polkit_authorization_claim_get_subject (PolkitAuthorizationClaim *authorization_claim) -{ - PolkitSubject *subject; - - g_return_val_if_fail (POLKIT_IS_AUTHORIZATION_CLAIM (authorization_claim), NULL); - g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (authorization_claim)), AUTHORIZATION_CLAIM_SIGNATURE) == 0, NULL); - - egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (authorization_claim), - 0, &subject, - -1); - - return subject; -} - -/** - * polkit_authorization_claim_get_action_id: - * @authorization_claim: A #PolkitAuthorizationClaim. - * - * Gets the action identifier for @authorization_claim. - * - * Returns: A string owned by @authorization_claim. Do not free. - **/ -const gchar * -polkit_authorization_claim_get_action_id (PolkitAuthorizationClaim *authorization_claim) -{ - const gchar *action_id; - - g_return_val_if_fail (POLKIT_IS_AUTHORIZATION_CLAIM (authorization_claim), NULL); - g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (authorization_claim)), AUTHORIZATION_CLAIM_SIGNATURE) == 0, NULL); - - egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (authorization_claim), - 1, &action_id, - -1); - - return action_id; -} - -/** - * polkit_authorization_claim_get_attributes: - * @authorization_claim: A #PolkitAuthorizationClaim. - * - * Gets the attributes for @authorization_claim. - * - * Returns: A #GHashTable owned by @authorization_claim. Do not free or modify. - **/ -GHashTable * -polkit_authorization_claim_get_attributes (PolkitAuthorizationClaim *authorization_claim) -{ - GHashTable *attributes; - - g_return_val_if_fail (POLKIT_IS_AUTHORIZATION_CLAIM (authorization_claim), NULL); - g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (authorization_claim)), AUTHORIZATION_CLAIM_SIGNATURE) == 0, NULL); - - egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (authorization_claim), - 2, &attributes, - -1); - - return attributes; -} - -/** - * polkit_authorization_claim_set_subject: - * @authorization_claim: A #PolkitAuthorizationClaim. - * @subject: A #PolkitSubject. - * - * Sets the subject of @authorization_claim to @subject. - **/ -void -polkit_authorization_claim_set_subject (PolkitAuthorizationClaim *authorization_claim, - PolkitSubject *subject) -{ - g_return_if_fail (POLKIT_IS_AUTHORIZATION_CLAIM (authorization_claim)); - g_return_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (authorization_claim)), AUTHORIZATION_CLAIM_SIGNATURE) == 0); - - egg_dbus_structure_set_element (EGG_DBUS_STRUCTURE (authorization_claim), - 0, subject, - -1); -} - -/** - * polkit_authorization_claim_set_action_id: - * @authorization_claim: A #PolkitAuthorizationClaim. - * @action_id: The action identifier for the PolicyKit action the claim is about. - * - * Sets the PolicyKit action for @authorization_claim to @action_id. - **/ -void -polkit_authorization_claim_set_action_id (PolkitAuthorizationClaim *authorization_claim, - const gchar *action_id) -{ - g_return_if_fail (POLKIT_IS_AUTHORIZATION_CLAIM (authorization_claim)); - g_return_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (authorization_claim)), AUTHORIZATION_CLAIM_SIGNATURE) == 0); - g_return_if_fail (action_id != NULL); - - egg_dbus_structure_set_element (EGG_DBUS_STRUCTURE (authorization_claim), - 1, action_id, - -1); -} - -/** - * polkit_authorization_claim_set_attribute: - * @authorization_claim: A #PolkitAuthorizationClaim. - * @key: Key of the attribute. - * @value: Value of the attribute or %NULL to clear the attribute for @key. - * - * Sets or clear an attribute of @authorization_claim. - **/ -void -polkit_authorization_claim_set_attribute (PolkitAuthorizationClaim *authorization_claim, - const gchar *key, - const gchar *value) -{ - EggDBusHashTable *attributes; - - g_return_if_fail (POLKIT_IS_AUTHORIZATION_CLAIM (authorization_claim)); - g_return_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (authorization_claim)), AUTHORIZATION_CLAIM_SIGNATURE) == 0); - g_return_if_fail (key != NULL); - - attributes = polkit_authorization_claim_get_attributes (authorization_claim); - - if (value == NULL) - g_hash_table_remove (attributes, key); - else - g_hash_table_insert (attributes, g_strdup (key), g_strdup (value)); -} - diff --git a/src/polkit/polkitauthorizationclaim.h b/src/polkit/polkitauthorizationclaim.h deleted file mode 100644 index df948f5..0000000 --- a/src/polkit/polkitauthorizationclaim.h +++ /dev/null @@ -1,68 +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_COMPILATION) && !defined(_POLKIT_INSIDE_POLKIT_H) -#error "Only can be included directly, this file may disappear or change contents." -#endif - -#include -#include - -#ifndef __POLKIT_AUTHORIZATION_CLAIM_H__ -#define __POLKIT_AUTHORIZATION_CLAIM_H__ - -G_BEGIN_DECLS - -#define POLKIT_TYPE_AUTHORIZATION_CLAIM (polkit_authorization_claim_get_type()) -#define POLKIT_AUTHORIZATION_CLAIM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_AUTHORIZATION_CLAIM, PolkitAuthorizationClaim)) -#define POLKIT_IS_AUTHORIZATION_CLAIM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_AUTHORIZATION_CLAIM)) -#define POLKIT_AUTHORIZATION_CLAIM_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE((o), POLKIT_TYPE_AUTHORIZATION_CLAIM, PolkitAuthorizationClaimIface)) - -#if 0 -typedef struct _PolkitAuthorizationClaim PolkitAuthorizationClaim; /* Dummy typedef */ -#endif -typedef struct _PolkitAuthorizationClaimIface PolkitAuthorizationClaimIface; - -struct _PolkitAuthorizationClaimIface -{ - GTypeInterface g_iface; -}; - -GType polkit_authorization_claim_get_type (void) G_GNUC_CONST; -PolkitAuthorizationClaim *polkit_authorization_claim_new (PolkitSubject *subject, - const gchar *action_id); - -void polkit_authorization_claim_set_subject (PolkitAuthorizationClaim *authorization_claim, - PolkitSubject *subject); -void polkit_authorization_claim_set_action_id (PolkitAuthorizationClaim *authorization_claim, - const gchar *action_id); -void polkit_authorization_claim_set_attribute (PolkitAuthorizationClaim *authorization_claim, - const gchar *key, - const gchar *value); - -PolkitSubject *polkit_authorization_claim_get_subject (PolkitAuthorizationClaim *authorization_claim); -const gchar *polkit_authorization_claim_get_action_id (PolkitAuthorizationClaim *authorization_claim); -GHashTable *polkit_authorization_claim_get_attributes (PolkitAuthorizationClaim *authorization_claim); - - -G_END_DECLS - -#endif /* __POLKIT_AUTHORIZATION_CLAIM_H__ */ diff --git a/src/polkit/polkitauthoritystub.h b/src/polkit/polkiterror.c similarity index 77% rename from src/polkit/polkitauthoritystub.h rename to src/polkit/polkiterror.c index d7fe57b..604b9c7 100644 --- a/src/polkit/polkitauthoritystub.h +++ b/src/polkit/polkiterror.c @@ -19,15 +19,22 @@ * Author: David Zeuthen */ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif -#ifndef __POLKIT_AUTHORITY_STUB_H -#define __POLKIT_AUTHORITY_STUB_H +#include "polkiterror.h" +#include "polkitprivate.h" -G_BEGIN_DECLS +GQuark +polkit_error_quark (void) +{ + return _polkit_error_quark (); +} -PolkitAuthority *polkit_authority_get (void); +GType +polkit_error_get_type (void) +{ + return _polkit_error_get_type (); +} -G_END_DECLS - -#endif /* __POLKIT_AUTHORITY_STUB_H */ diff --git a/src/polkit/polkiterror.h b/src/polkit/polkiterror.h new file mode 100644 index 0000000..5dd21dc --- /dev/null +++ b/src/polkit/polkiterror.h @@ -0,0 +1,58 @@ +/* + * 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 + */ + +#ifndef __POLKIT_ERROR_H +#define __POLKIT_ERROR_H + +#include + +G_BEGIN_DECLS + +/** + * POLKIT_ERROR: + * + * Error domain for errors when using PolicyKit. Errors in this domain will be from the #PolkitError + * enumeration. See #GError for information on error domains + */ +#define POLKIT_ERROR polkit_error_quark() + +GQuark polkit_error_quark (void); + +GType polkit_error_get_type (void) G_GNUC_CONST; + +#define POLKIT_TYPE_ERROR (polkit_error_get_type ()) + +/** + * PolkitError: + * @POLKIT_ERROR_FAILED: The operation failed + * @POLKIT_ERROR_NOT_SUPPORTED: Operation is not supported + * + * Errors when using PolicyKit. + */ +typedef enum +{ + POLKIT_ERROR_FAILED = 0, + POLKIT_ERROR_NOT_SUPPORTED = 1, +} PolkitError; + +G_END_DECLS + +#endif /* __POLKIT_ERROR_H */ diff --git a/src/polkit/polkitsubject.c b/src/polkit/polkitsubject.c deleted file mode 100644 index ffa46e7..0000000 --- a/src/polkit/polkitsubject.c +++ /dev/null @@ -1,349 +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 - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include -#include "polkitbindings.h" -#include "polkitsubject.h" - -/** - * SECTION:polkitsubject - * @title: PolkitSubject - * @short_description: Subjects - * - * The #PolkitSubject type is used for representing subject such as - * users, groups and processes. - */ - -static void -base_init (gpointer g_iface) -{ -} - -GType -polkit_subject_get_type (void) -{ - static GType iface_type = 0; - - if (iface_type == 0) - { - static const GTypeInfo info = - { - sizeof (PolkitSubjectIface), - base_init, /* base_init */ - NULL, /* base_finalize */ - NULL, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - 0, /* instance_size */ - 0, /* n_preallocs */ - NULL, /* instance_init */ - NULL /* value_table */ - }; - - iface_type = g_type_register_static (G_TYPE_INTERFACE, "PolkitSubject", &info, 0); - - g_type_interface_add_prerequisite (iface_type, EGG_DBUS_TYPE_STRUCTURE); - } - - return iface_type; -} - -/** - * polkit_subject_new_for_unix_process: - * @unix_process_id: The Process ID. - * - * Constructs a new #PolkitSubject for a the UNIX process with PID @process_id. - * - * Returns: A #PolkitSubject. - */ -PolkitSubject * -polkit_subject_new_for_unix_process (pid_t unix_process_id) -{ - GValue *values; - EggDBusHashTable *properties; - - properties = g_hash_table_new_full (g_str_hash, - g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) g_object_unref); - egg_dbus_hash_table_set_signature (properties, "s", "v"); - - g_hash_table_insert (properties, - g_strdup ("unix-process-id"), - egg_dbus_variant_new_for_uint32 (unix_process_id)); - - values = g_new0 (GValue, 2); - g_value_init (&(values[0]), G_TYPE_STRING); - g_value_set_string (&(values[0]), "unix-process"); - g_value_init (&(values[1]), EGG_DBUS_TYPE_HASH_TABLE); - g_value_set_boxed (&(values[1]), properties); - - return POLKIT_SUBJECT (egg_dbus_structure_new ("(sa{sv})", 2, values)); -} - -/** - * polkit_subject_new_for_unix_user: - * @unix_user_id: The User ID. - * - * Constructs a new #PolkitSubject for a the UNIX user with UID @user_id. - * - * Returns: A #PolkitSubject. - */ -PolkitSubject * -polkit_subject_new_for_unix_user (uid_t unix_user_id) -{ - GValue *values; - EggDBusHashTable *properties; - - properties = g_hash_table_new_full (g_str_hash, - g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) g_object_unref); - egg_dbus_hash_table_set_signature (properties, "s", "v"); - - g_hash_table_insert (properties, - g_strdup ("unix-user-id"), - egg_dbus_variant_new_for_uint32 (unix_user_id)); - - values = g_new0 (GValue, 2); - g_value_init (&(values[0]), G_TYPE_STRING); - g_value_set_string (&(values[0]), "unix-user"); - g_value_init (&(values[1]), EGG_DBUS_TYPE_HASH_TABLE); - g_value_set_boxed (&(values[1]), properties); - - return POLKIT_SUBJECT (egg_dbus_structure_new ("(sa{sv})", 2, values)); -} - -/** - * polkit_subject_new_for_unix_group: - * @unix_group_id: The Group ID. - * - * Constructs a new #PolkitSubject for a the UNIX group with GID @group_id. - * - * Returns: A #PolkitSubject. - */ -PolkitSubject * -polkit_subject_new_for_unix_group (gid_t unix_group_id) -{ - GValue *values; - EggDBusHashTable *properties; - - properties = g_hash_table_new_full (g_str_hash, - g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) g_object_unref); - egg_dbus_hash_table_set_signature (properties, "s", "v"); - - g_hash_table_insert (properties, - g_strdup ("unix-group-id"), - egg_dbus_variant_new_for_uint32 (unix_group_id)); - - values = g_new0 (GValue, 2); - g_value_init (&(values[0]), G_TYPE_STRING); - g_value_set_string (&(values[0]), "unix-group"); - g_value_init (&(values[1]), EGG_DBUS_TYPE_HASH_TABLE); - g_value_set_boxed (&(values[1]), properties); - - return POLKIT_SUBJECT (egg_dbus_structure_new ("(sa{sv})", 2, values)); -} - -/** - * polkit_subject_get_kind: - * @subject: A #PolkitSubject. - * - * Gets the kind of @subject. - * - * Returns: A #PolkitSubjectKind. - */ -PolkitSubjectKind -polkit_subject_get_kind (PolkitSubject *subject) -{ - const gchar *kind_str; - PolkitSubjectKind kind; - - g_return_val_if_fail (POLKIT_IS_SUBJECT (subject), -1); - g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (subject)), "(sa{sv})") == 0, -1); - - egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (subject), - 0, &kind_str, - -1); - - if (strcmp (kind_str, "unix-process") == 0) - kind = POLKIT_SUBJECT_KIND_UNIX_PROCESS; - else if (strcmp (kind_str, "unix-user") == 0) - kind = POLKIT_SUBJECT_KIND_UNIX_USER; - else if (strcmp (kind_str, "unix-group") == 0) - kind = POLKIT_SUBJECT_KIND_UNIX_GROUP; - else - { - g_warning ("unknown kind str '%s'", kind_str); - kind = -1; - } - - return kind; -} - -/** - * polkit_subject_equal: - * @a: A #PolkitSubject. - * @b: A #PolkitSubject. - * - * Checks if the two subjects @a and @b are equal. - * - * Returns: %TRUE if @a and @b are equal, %FALSE otherwise. - **/ -gboolean -polkit_subject_equal (PolkitSubject *a, - PolkitSubject *b) -{ - gboolean ret; - PolkitSubjectKind kind_a; - PolkitSubjectKind kind_b; - - g_return_val_if_fail (POLKIT_IS_SUBJECT (a), FALSE); - g_return_val_if_fail (POLKIT_IS_SUBJECT (b), FALSE); - g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (a)), "(sa{sv})") == 0, FALSE); - g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (b)), "(sa{sv})") == 0, FALSE); - - ret = FALSE; - - kind_a = polkit_subject_get_kind (a); - kind_b = polkit_subject_get_kind (b); - - if (kind_a != kind_b) - goto out; - - switch (kind_a) - { - case POLKIT_SUBJECT_KIND_UNIX_PROCESS: - if (polkit_subject_unix_process_get_id (a) == polkit_subject_unix_process_get_id (b)) - ret = TRUE; - break; - - case POLKIT_SUBJECT_KIND_UNIX_USER: - if (polkit_subject_unix_user_get_id (a) == polkit_subject_unix_user_get_id (b)) - ret = TRUE; - break; - - case POLKIT_SUBJECT_KIND_UNIX_GROUP: - if (polkit_subject_unix_group_get_id (a) == polkit_subject_unix_group_get_id (b)) - ret = TRUE; - break; - - default: - /* get_kind() will already have warned */ - goto out; - } - - out: - return ret; -} - -/** - * polkit_subject_unix_process_get_id: - * @subject: A #PolkitSubject of the @POLKIT_SUBJECT_KIND_UNIX_PROCESS kind. - * - * Gets the UNIX process id for @subject. - * - * Returns: UNIX process id. - **/ -pid_t -polkit_subject_unix_process_get_id (PolkitSubject *subject) -{ - EggDBusHashTable *value; - EggDBusVariant *variant; - pid_t pid; - - g_return_val_if_fail (POLKIT_IS_SUBJECT (subject), 0); - g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (subject)), "(sa{sv})") == 0, 0); - g_return_val_if_fail (polkit_subject_get_kind (subject) != POLKIT_SUBJECT_KIND_UNIX_PROCESS, 0); - - egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (subject), - 1, &value, - -1); - - variant = g_hash_table_lookup (value, "unix-process-id"); - pid = (pid_t) egg_dbus_variant_get_uint32 (variant); - - return pid; -} - -/** - * polkit_subject_unix_user_get_id: - * @subject: A #PolkitSubject of the @POLKIT_SUBJECT_KIND_UNIX_USER kind. - * - * Gets the UNIX user id for @subject. - * - * Returns: UNIX user id. - **/ -uid_t -polkit_subject_unix_user_get_id (PolkitSubject *subject) -{ - EggDBusHashTable *value; - EggDBusVariant *variant; - uid_t uid; - - g_return_val_if_fail (POLKIT_IS_SUBJECT (subject), 0); - g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (subject)), "(sa{sv})") == 0, 0); - g_return_val_if_fail (polkit_subject_get_kind (subject) != POLKIT_SUBJECT_KIND_UNIX_USER, 0); - - egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (subject), - 1, &value, - -1); - - variant = g_hash_table_lookup (value, "unix-user-id"); - uid = (uid_t) egg_dbus_variant_get_uint32 (variant); - - return uid; -} - -/** - * polkit_subject_unix_group_get_id: - * @subject: A #PolkitSubject of the @POLKIT_SUBJECT_KIND_UNIX_GROUP kind. - * - * Gets the UNIX group id for @subject. - * - * Returns: UNIX group id. - **/ -gid_t -polkit_subject_unix_group_get_id (PolkitSubject *subject) -{ - EggDBusHashTable *value; - EggDBusVariant *variant; - gid_t gid; - - g_return_val_if_fail (POLKIT_IS_SUBJECT (subject), 0); - g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (subject)), "(sa{sv})") == 0, 0); - g_return_val_if_fail (polkit_subject_get_kind (subject) != POLKIT_SUBJECT_KIND_UNIX_GROUP, 0); - - egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (subject), - 1, &value, - -1); - - variant = g_hash_table_lookup (value, "unix-group-id"); - gid = (gid_t) egg_dbus_variant_get_uint32 (variant); - - return gid; -} - diff --git a/src/polkit/polkitsubject.h b/src/polkit/polkitsubject.h deleted file mode 100644 index 8b47786..0000000 --- a/src/polkit/polkitsubject.h +++ /dev/null @@ -1,67 +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 - */ - -#ifndef __POLKIT_SUBJECT_H -#define __POLKIT_SUBJECT_H - -#include -#include -#include -#include - -G_BEGIN_DECLS - -#define POLKIT_TYPE_SUBJECT (polkit_subject_get_type()) -#define POLKIT_SUBJECT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_SUBJECT, PolkitSubject)) -#define POLKIT_IS_SUBJECT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_SUBJECT)) -#define POLKIT_SUBJECT_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE((o), POLKIT_TYPE_SUBJECT, PolkitSubjectIface)) - -#if 0 -typedef struct _PolkitSubject PolkitSubject; /* Dummy typedef */ -#endif -typedef struct _PolkitSubjectIface PolkitSubjectIface; - -typedef enum -{ - POLKIT_SUBJECT_KIND_UNIX_PROCESS, - POLKIT_SUBJECT_KIND_UNIX_USER, - POLKIT_SUBJECT_KIND_UNIX_GROUP, -} PolkitSubjectKind; - -struct _PolkitSubjectIface -{ - GTypeInterface g_iface; -}; - -GType polkit_subject_get_type (void) G_GNUC_CONST; -PolkitSubject *polkit_subject_new_for_unix_process (pid_t unix_process_id); -PolkitSubject *polkit_subject_new_for_unix_user (uid_t unix_user_id); -PolkitSubject *polkit_subject_new_for_unix_group (gid_t unix_group_id); -PolkitSubjectKind polkit_subject_get_kind (PolkitSubject *subject); -pid_t polkit_subject_unix_process_get_id (PolkitSubject *subject); -uid_t polkit_subject_unix_user_get_id (PolkitSubject *subject); -gid_t polkit_subject_unix_group_get_id (PolkitSubject *subject); -gboolean polkit_subject_equal (PolkitSubject *a, - PolkitSubject *b); - -G_END_DECLS - -#endif /* __POLKIT_SUBJECT_H */ diff --git a/src/polkitbackend/Makefile.am b/src/polkitbackend/Makefile.am index 2d31cb5..41ea29a 100644 --- a/src/polkitbackend/Makefile.am +++ b/src/polkitbackend/Makefile.am @@ -12,6 +12,7 @@ INCLUDES = \ -DPACKAGE_LIB_DIR=\""$(libdir)"\" \ -D_POSIX_PTHREAD_SEMANTICS \ -D_REENTRANT \ + -DEGG_DBUS_I_KNOW_API_IS_SUBJECT_TO_CHANGE \ $(NULL) lib_LTLIBRARIES=libpolkit-backend-1.la @@ -20,14 +21,20 @@ libpolkit_backend_1includedir=$(includedir)/polkit-1/polkitbackend libpolkit_backend_1include_HEADERS = \ polkitbackend.h \ + polkitbackendtypes.h \ + polkitbackendauthority.h \ polkitbackendlocalauthority.h \ polkitbackendactionpool.h \ + polkitbackendserver.h \ $(NULL) libpolkit_backend_1_la_SOURCES = \ polkitbackend.h \ + polkitbackendtypes.h \ + polkitbackendauthority.h polkitbackendauthority.c \ polkitbackendlocalauthority.h polkitbackendlocalauthority.c \ polkitbackendactionpool.h polkitbackendactionpool.c \ + polkitbackendserver.h polkitbackendserver.c \ $(NULL) libpolkit_backend_1_la_CFLAGS = \ diff --git a/src/polkitbackend/polkitbackend.h b/src/polkitbackend/polkitbackend.h index 1dc847c..63090aa 100644 --- a/src/polkitbackend/polkitbackend.h +++ b/src/polkitbackend/polkitbackend.h @@ -23,8 +23,11 @@ #define __POLKIT_BACKEND_H #define _POLKIT_BACKEND_INSIDE_POLKIT_BACKEND_H 1 +#include +#include #include #include +#include #undef _POLKIT_BACKEND_INSIDE_POLKIT_BACKEND_H #endif /* __POLKIT_BACKEND_H */ diff --git a/src/polkitbackend/polkitbackendactionpool.c b/src/polkitbackend/polkitbackendactionpool.c index d81b0f9..b5a7398 100644 --- a/src/polkitbackend/polkitbackendactionpool.c +++ b/src/polkitbackend/polkitbackendactionpool.c @@ -26,7 +26,10 @@ #include #include #include + #include +#include + #include "polkitbackendactionpool.h" typedef struct @@ -43,7 +46,7 @@ typedef struct GHashTable *localized_message; /* this maps from annotation key (string) to annotation value (also a string) */ - GHashTable *annotations; + EggDBusHashMap *annotations; } ParsedAction; static void @@ -59,7 +62,7 @@ parsed_action_free (ParsedAction *action) g_hash_table_unref (action->localized_description); g_hash_table_unref (action->localized_message); - g_hash_table_unref (action->annotations); + g_object_unref (action->annotations); g_free (action); } @@ -256,10 +259,10 @@ polkit_backend_action_pool_get_action (PolkitBackendActionPool *pool, { PolkitBackendActionPoolPrivate *priv; PolkitActionDescription *ret; + _PolkitActionDescription *real; ParsedAction *parsed_action; gchar *description; gchar *message; - GValue *values; g_return_val_if_fail (POLKIT_BACKEND_IS_ACTION_POOL (pool), NULL); @@ -284,23 +287,16 @@ polkit_backend_action_pool_get_action (PolkitBackendActionPool *pool, parsed_action->message, locale)); - values = g_new0 (GValue, 7); - g_value_init (&(values[0]), G_TYPE_STRING); - g_value_set_string (&(values[0]), parsed_action->action_id); - g_value_init (&(values[1]), G_TYPE_STRING); - g_value_set_string (&(values[1]), description != NULL ? description : g_strdup ("")); - g_value_init (&(values[2]), G_TYPE_STRING); - g_value_set_string (&(values[2]), message != NULL ? message : g_strdup ("")); - g_value_init (&(values[3]), G_TYPE_STRING); - g_value_set_string (&(values[3]), parsed_action->vendor_name != NULL ? parsed_action->vendor_name : g_strdup ("")); - g_value_init (&(values[4]), G_TYPE_STRING); - g_value_set_string (&(values[4]), parsed_action->vendor_url != NULL ? parsed_action->vendor_url : g_strdup ("")); - g_value_init (&(values[5]), G_TYPE_STRING); - g_value_set_string (&(values[5]), parsed_action->icon_name != NULL ? parsed_action->icon_name : g_strdup ("")); - g_value_init (&(values[6]), G_TYPE_HASH_TABLE); - g_value_set_boxed (&(values[6]), parsed_action->annotations); - - ret = POLKIT_ACTION_DESCRIPTION (egg_dbus_structure_new ("(ssssssa{ss})", 7, values)); + real = _polkit_action_description_new (action_id, + description, + message, + parsed_action->vendor_name, + parsed_action->vendor_url, + parsed_action->icon_name, + parsed_action->annotations); + + ret = polkit_action_description_new_for_real (real); + g_object_unref (real); out: return ret; @@ -510,7 +506,7 @@ typedef struct { char *elem_lang; char *annotate_key; - GHashTable *annotations; + EggDBusHashMap *annotations; PolkitBackendActionPool *pool; } ParserData; @@ -532,20 +528,23 @@ pd_unref_action_data (ParserData *pd) pd->policy_description_nolang = NULL; g_free (pd->policy_message_nolang); pd->policy_message_nolang = NULL; - if (pd->policy_descriptions != NULL) { - g_hash_table_unref (pd->policy_descriptions); - pd->policy_descriptions = NULL; - } - if (pd->policy_messages != NULL) { - g_hash_table_unref (pd->policy_messages); - pd->policy_messages = NULL; - } + if (pd->policy_descriptions != NULL) + { + g_hash_table_unref (pd->policy_descriptions); + pd->policy_descriptions = NULL; + } + if (pd->policy_messages != NULL) + { + g_hash_table_unref (pd->policy_messages); + pd->policy_messages = NULL; + } g_free (pd->annotate_key); pd->annotate_key = NULL; - if (pd->annotations != NULL) { - g_hash_table_unref (pd->annotations); - pd->annotations = NULL; - } + if (pd->annotations != NULL) + { + g_object_unref (pd->annotations); + pd->annotations = NULL; + } g_free (pd->elem_lang); pd->elem_lang = NULL; } @@ -604,10 +603,7 @@ _start (void *data, const char *el, const char **attr) g_str_equal, g_free, g_free); - pd->annotations = g_hash_table_new_full (g_str_hash, - g_str_equal, - g_free, - g_free); + pd->annotations = egg_dbus_hash_map_new (G_TYPE_STRING, g_free, G_TYPE_STRING, g_free); /* initialize defaults */ //pd->defaults_allow_any = POLKIT_RESULT_NO; //pd->defaults_allow_inactive = POLKIT_RESULT_NO; @@ -838,9 +834,9 @@ _cdata (void *data, const char *s, int len) break; case STATE_IN_ANNOTATE: - g_hash_table_insert (pd->annotations, - g_strdup (pd->annotate_key), - str); + egg_dbus_hash_map_insert (pd->annotations, + g_strdup (pd->annotate_key), + str); str = NULL; break; diff --git a/src/polkitbackend/polkitbackendauthority.c b/src/polkitbackend/polkitbackendauthority.c new file mode 100644 index 0000000..3de036a --- /dev/null +++ b/src/polkitbackend/polkitbackendauthority.c @@ -0,0 +1,51 @@ +/* + * 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 "polkitbackendauthority.h" + +G_DEFINE_ABSTRACT_TYPE (PolkitBackendAuthority, polkit_backend_authority, G_TYPE_OBJECT); + +static void +polkit_backend_authority_init (PolkitBackendAuthority *local_authority) +{ +} + +static void +polkit_backend_authority_class_init (PolkitBackendAuthorityClass *klass) +{ +} + +GList * +polkit_backend_authority_enumerate_actions (PolkitBackendAuthority *authority, + const gchar *locale) +{ + PolkitBackendAuthorityClass *klass; + + klass = POLKIT_BACKEND_AUTHORITY_GET_CLASS (authority); + + return klass->enumerate_actions (authority, locale); +} + diff --git a/src/polkitbackend/polkitbackendauthority.h b/src/polkitbackend/polkitbackendauthority.h new file mode 100644 index 0000000..1657251 --- /dev/null +++ b/src/polkitbackend/polkitbackendauthority.h @@ -0,0 +1,77 @@ +/* + * 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_AUTHORITY_H +#define __POLKIT_BACKEND_AUTHORITY_H + +#include +#include "polkitbackendtypes.h" + +G_BEGIN_DECLS + +#define POLKIT_BACKEND_TYPE_AUTHORITY (polkit_backend_authority_get_type ()) +#define POLKIT_BACKEND_AUTHORITY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_BACKEND_TYPE_AUTHORITY, PolkitBackendAuthority)) +#define POLKIT_BACKEND_AUTHORITY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), POLKIT_BACKEND_TYPE_AUTHORITY, PolkitBackendAuthorityClass)) +#define POLKIT_BACKEND_AUTHORITY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_BACKEND_TYPE_AUTHORITY,PolkitBackendAuthorityClass)) +#define POLKIT_BACKEND_IS_AUTHORITY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_BACKEND_TYPE_AUTHORITY)) +#define POLKIT_BACKEND_IS_AUTHORITY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_BACKEND_TYPE_AUTHORITY)) + +typedef struct _PolkitBackendAuthorityClass PolkitBackendAuthorityClass; + +struct _PolkitBackendAuthority +{ + GObject parent_instance; +}; + +struct _PolkitBackendAuthorityClass +{ + GObjectClass parent_class; + + /*< public >*/ + + GList * (*enumerate_actions) (PolkitBackendAuthority *authority, + const gchar *locale); + + /*< private >*/ + /* Padding for future expansion */ + void (*_polkit_reserved1) (void); + void (*_polkit_reserved2) (void); + void (*_polkit_reserved3) (void); + void (*_polkit_reserved4) (void); + void (*_polkit_reserved5) (void); + void (*_polkit_reserved6) (void); + void (*_polkit_reserved7) (void); + void (*_polkit_reserved8) (void); +}; + +GType polkit_backend_authority_get_type (void) G_GNUC_CONST; + +GList *polkit_backend_authority_enumerate_actions (PolkitBackendAuthority *authority, + const gchar *locale); + +G_END_DECLS + +#endif /* __POLKIT_BACKEND_AUTHORITY_H */ + diff --git a/src/polkitbackend/polkitbackendlocalauthority.c b/src/polkitbackend/polkitbackendlocalauthority.c index fcac673..9e2ffc8 100644 --- a/src/polkitbackend/polkitbackendlocalauthority.c +++ b/src/polkitbackend/polkitbackendlocalauthority.c @@ -33,16 +33,13 @@ typedef struct } PolkitBackendLocalAuthorityPrivate; -static void authority_iface_init (PolkitAuthorityIface *authority_iface, - gpointer iface_data); +static GList *polkit_backend_local_authority_enumerate_actions (PolkitBackendAuthority *authority, + const gchar *locale); -G_DEFINE_TYPE_WITH_CODE (PolkitBackendLocalAuthority, polkit_backend_local_authority, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (POLKIT_TYPE_AUTHORITY, - authority_iface_init) - ); -#define POLKIT_BACKEND_LOCAL_AUTHORITY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), POLKIT_BACKEND_TYPE_LOCAL_AUTHORITY, PolkitBackendLocalAuthorityPrivate)) +G_DEFINE_TYPE (PolkitBackendLocalAuthority, polkit_backend_local_authority, POLKIT_BACKEND_TYPE_AUTHORITY); +#define POLKIT_BACKEND_LOCAL_AUTHORITY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), POLKIT_BACKEND_TYPE_LOCAL_AUTHORITY, PolkitBackendLocalAuthorityPrivate)) static void polkit_backend_local_authority_init (PolkitBackendLocalAuthority *local_authority) @@ -75,24 +72,42 @@ polkit_backend_local_authority_finalize (GObject *object) static void polkit_backend_local_authority_class_init (PolkitBackendLocalAuthorityClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GObjectClass *gobject_class; + PolkitBackendAuthorityClass *authority_class; + + gobject_class = G_OBJECT_CLASS (klass); + authority_class = POLKIT_BACKEND_AUTHORITY_CLASS (klass); gobject_class->finalize = polkit_backend_local_authority_finalize; + authority_class->enumerate_actions = polkit_backend_local_authority_enumerate_actions; + g_type_class_add_private (klass, sizeof (PolkitBackendLocalAuthorityPrivate)); } -PolkitBackendLocalAuthority * +PolkitBackendAuthority * polkit_backend_local_authority_new (void) { + return POLKIT_BACKEND_AUTHORITY (g_object_new (POLKIT_BACKEND_TYPE_LOCAL_AUTHORITY, + NULL)); +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static GList * +polkit_backend_local_authority_enumerate_actions (PolkitBackendAuthority *authority, + const gchar *locale) +{ PolkitBackendLocalAuthority *local_authority; + PolkitBackendLocalAuthorityPrivate *priv; - local_authority = POLKIT_BACKEND_LOCAL_AUTHORITY (g_object_new (POLKIT_BACKEND_TYPE_LOCAL_AUTHORITY, - NULL)); + local_authority = POLKIT_BACKEND_LOCAL_AUTHORITY (authority); + priv = POLKIT_BACKEND_LOCAL_AUTHORITY_GET_PRIVATE (local_authority); - return local_authority; + return polkit_backend_action_pool_get_all_actions (priv->action_pool, locale); } +#if 0 /* ---------------------------------------------------------------------------------------------------- */ static void @@ -189,3 +204,4 @@ authority_iface_init (PolkitAuthorityIface *authority_iface, } /* ---------------------------------------------------------------------------------------------------- */ +#endif diff --git a/src/polkitbackend/polkitbackendlocalauthority.h b/src/polkitbackend/polkitbackendlocalauthority.h index 8aa2619..1bdc50f 100644 --- a/src/polkitbackend/polkitbackendlocalauthority.h +++ b/src/polkitbackend/polkitbackendlocalauthority.h @@ -23,11 +23,12 @@ #error "Only can be included directly, this file may disappear or change contents." #endif -#include - #ifndef __POLKIT_BACKEND_LOCAL_AUTHORITY_H #define __POLKIT_BACKEND_LOCAL_AUTHORITY_H +#include +#include + G_BEGIN_DECLS #define POLKIT_BACKEND_TYPE_LOCAL_AUTHORITY (polkit_backend_local_authority_get_type ()) @@ -42,12 +43,12 @@ typedef struct _PolkitBackendLocalAuthorityClass PolkitBackendLocalAuthorityC struct _PolkitBackendLocalAuthority { - GObject parent_instance; + PolkitBackendAuthority parent_instance; }; struct _PolkitBackendLocalAuthorityClass { - GObjectClass parent_class; + PolkitBackendAuthorityClass parent_class; /*< public >*/ @@ -63,9 +64,8 @@ struct _PolkitBackendLocalAuthorityClass void (*_polkit_reserved8) (void); }; -GType polkit_backend_local_authority_get_type (void) G_GNUC_CONST; - -PolkitBackendLocalAuthority *polkit_backend_local_authority_new (void); +GType polkit_backend_local_authority_get_type (void) G_GNUC_CONST; +PolkitBackendAuthority *polkit_backend_local_authority_new (void); G_END_DECLS diff --git a/src/polkitbackend/polkitbackendserver.c b/src/polkitbackend/polkitbackendserver.c new file mode 100644 index 0000000..090e37f --- /dev/null +++ b/src/polkitbackend/polkitbackendserver.c @@ -0,0 +1,119 @@ +/* + * 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" + +struct _PolkitBackendServer +{ + GObject parent_instance; + + PolkitBackendAuthority *authority; +}; + +struct _PolkitBackendServerClass +{ + GObjectClass parent_class; +}; + +static void authority_iface_init (_PolkitAuthorityIface *authority_iface); + +G_DEFINE_TYPE_WITH_CODE (PolkitBackendServer, polkit_backend_server, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (_POLKIT_TYPE_AUTHORITY, authority_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_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; +} + +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); + + return server; +} + +static void +authority_handle_enumerate_actions (_PolkitAuthority *instance, + const gchar *locale, + EggDBusMethodInvocation *method_invocation) +{ + PolkitBackendServer *server = POLKIT_BACKEND_SERVER (instance); + EggDBusArraySeq *array; + GList *actions; + GList *l; + + actions = polkit_backend_authority_enumerate_actions (server->authority, locale); + + array = egg_dbus_array_seq_new (_POLKIT_TYPE_ACTION_DESCRIPTION, NULL, NULL, NULL); + + for (l = actions; l != NULL; l = l->next) + { + PolkitActionDescription *ad = POLKIT_ACTION_DESCRIPTION (l->data); + egg_dbus_array_seq_add (array, polkit_action_description_get_real (ad)); + } + + _polkit_authority_handle_enumerate_actions_finish (method_invocation, array); + + g_object_unref (array); + + g_list_foreach (actions, (GFunc) g_object_unref, NULL); + g_list_free (actions); +} + +static void +authority_iface_init (_PolkitAuthorityIface *authority_iface) +{ + authority_iface->handle_enumerate_actions = authority_handle_enumerate_actions; +} diff --git a/src/polkitbackend/polkitbackendserver.h b/src/polkitbackend/polkitbackendserver.h new file mode 100644 index 0000000..95567bf --- /dev/null +++ b/src/polkitbackend/polkitbackendserver.h @@ -0,0 +1,50 @@ +/* + * 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)) + +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 new file mode 100644 index 0000000..715adda --- /dev/null +++ b/src/polkitbackend/polkitbackendtypes.h @@ -0,0 +1,34 @@ +/* + * 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 + */ + +#ifndef __POLKIT_BACKEND_TYPES_H +#define __POLKIT_BACKEND_TYPES_H + +#include + +struct _PolkitBackendAuthority; +typedef struct _PolkitBackendAuthority PolkitBackendAuthority; + +struct _PolkitBackendServer; +typedef struct _PolkitBackendServer PolkitBackendServer; + +#endif /* __POLKIT_BACKEND_TYPES_H */ + diff --git a/src/polkitd/Makefile.am b/src/polkitd/Makefile.am index f1b54dd..24e9551 100644 --- a/src/polkitd/Makefile.am +++ b/src/polkitd/Makefile.am @@ -12,6 +12,7 @@ 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 diff --git a/src/polkitd/main.c b/src/polkitd/main.c index 9fc6bb6..ab43694 100644 --- a/src/polkitd/main.c +++ b/src/polkitd/main.c @@ -24,13 +24,24 @@ #endif #include +#include + #include -static PolkitAuthority * +static _PolkitAuthority * get_authority_backend (void) { + PolkitBackendAuthority *authority; + PolkitBackendServer *server; + /* TODO: use extension points etc. */ - return POLKIT_AUTHORITY (polkit_backend_local_authority_new ()); + authority = polkit_backend_local_authority_new (); + + server = polkit_backend_server_new (authority); + + g_object_unref (authority); + + return _POLKIT_AUTHORITY (server); } int @@ -41,24 +52,25 @@ main (int argc, char **argv) GError *error; GMainLoop *loop; EggDBusConnection *connection; - PolkitAuthority *authority; + _PolkitAuthority *authority; ret = 1; + authority = NULL; + connection = NULL; g_type_init (); - polkit_bindings_register_types (); /* TODO: use __attribute ((constructor)) */ 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_invoke_request_name_sync (egg_dbus_connection_get_bus_proxy (connection), - 0, /* call flags */ - "org.freedesktop.PolicyKit1", - 0, /* flags */ - &rn_ret, - NULL, - &error)) + 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); @@ -73,16 +85,20 @@ main (int argc, char **argv) authority = get_authority_backend (); - egg_dbus_connection_export_object (connection, - G_OBJECT (authority), - "/org/freedesktop/PolicyKit1/Authority"); + egg_dbus_connection_register_interface (connection, + "/org/freedesktop/PolicyKit1/Authority", + _POLKIT_TYPE_AUTHORITY, + G_OBJECT (authority), + G_TYPE_INVALID); g_main_loop_run (loop); - g_object_unref (authority); - g_object_unref (connection); ret = 0; out: + if (authority != NULL) + g_object_unref (authority); + if (connection != NULL) + g_object_unref (connection); return ret; } diff --git a/src/programs/polkit-verify-claim.c b/src/programs/polkit-verify-claim.c index 7199339..fb22b6a 100644 --- a/src/programs/polkit-verify-claim.c +++ b/src/programs/polkit-verify-claim.c @@ -21,26 +21,49 @@ #include -int -main (int argc, char *argv[]) +static PolkitAuthority *authority; + +static void +list_actions (void) { GError *error; - PolkitAuthority *authority; - gchar *result; + GList *actions; + GList *l; + + error = NULL; + actions = polkit_authority_enumerate_actions_sync (authority, + "", + NULL, + &error); + if (error != NULL) + { + g_printerr ("Error enumerating actions: %s\n", error->message); + g_error_free (error); + goto out; + } + + for (l = actions; l != NULL; l = l->next) + { + PolkitActionDescription *action = POLKIT_ACTION_DESCRIPTION (l->data); + + g_print ("%s\n", polkit_action_description_get_action_id (action)); + } + g_list_foreach (actions, (GFunc) g_object_unref, NULL); + g_list_free (actions); + + out: + ; +} + +int +main (int argc, char *argv[]) +{ g_type_init (); authority = polkit_authority_get (); - error = NULL; - polkit_authority_invoke_say_hello_sync (authority, - 0, /* call_flags */ - "Hi there!", - &result, - NULL, - &error); - g_print ("Authority replied: %s\n", result); - g_free (result); + list_actions (); g_object_unref (authority); -- 2.7.4