summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/org.freedesktop.PolicyKit1.Authority.xml19
-rw-r--r--src/polkit/polkitauthorizationclaim.c361
-rw-r--r--src/polkit/polkitauthorizationclaim.h52
3 files changed, 191 insertions, 241 deletions
diff --git a/data/org.freedesktop.PolicyKit1.Authority.xml b/data/org.freedesktop.PolicyKit1.Authority.xml
index d3e2fd5..85826d9 100644
--- a/data/org.freedesktop.PolicyKit1.Authority.xml
+++ b/data/org.freedesktop.PolicyKit1.Authority.xml
@@ -30,6 +30,16 @@
</annotation>
+ <!-- User defined struct for AuthorizationClaim -->
+ <annotation name="org.gtk.EggDBus.DeclareStruct" value="AuthorizationClaim">
+ <annotation name="org.gtk.EggDBus.Struct.Signature" value="((sa{sv})sa{ss})"/>
+
+ <!-- element 0: (sa{sv}): subject -->
+ <!-- element 1: string: action-id -->
+ <!-- element 2: map<string,string>: attributes -->
+
+ </annotation>
+
<!-- The error domain used for reporting errors -->
<annotation name="org.gtk.EggDBus.DeclareErrorDomain" value="Error">
<annotation name="org.gtk.EggDBus.ErrorDomain.Member" value="org.freedesktop.PolicyKit1.Error.Failed">
@@ -70,5 +80,14 @@
<arg name="action_descriptions" direction="out" type="a(ssssssa{ss})"/>
</method>
+ <method name="CheckClaim">
+ <arg name="claim" direction="in" type="((sa{sv})sa{ss})">
+ <annotation name="org.gtk.EggDBus.StructType" value="AuthorizationClaim"/>
+ </arg>
+ <arg name="result" direction="out" type="i">
+ <annotation name="org.gtk.EggDBus.EnumType" value="AuthorizationResult"/>
+ </arg>
+ </method>
+
</interface>
</node>
diff --git a/src/polkit/polkitauthorizationclaim.c b/src/polkit/polkitauthorizationclaim.c
index 33b852c..81b692f 100644
--- a/src/polkit/polkitauthorizationclaim.c
+++ b/src/polkit/polkitauthorizationclaim.c
@@ -22,280 +22,217 @@
#include "config.h"
#include <string.h>
#include "polkitauthorizationclaim.h"
+#include "polkitsubject.h"
/**
* SECTION:polkitauthorizationclaim
+ * @title: PolkitAuthorizationClaim
* @short_description: Authorization Claim
- * @include: polkit/polkit.h
*
* Represents an authorization claim.
*/
-/*--------------------------------------------------------------------------------------------------------------*/
-
-struct _PolkitAuthorizationClaimPrivate
+static void
+base_init (gpointer g_iface)
{
- PolkitSubject *subject;
- char *action_id;
- GHashTable *attributes;
-};
-
-enum {
- PROP_0,
- PROP_SUBJECT,
- PROP_ACTION_ID,
- PROP_ATTRIBUTES,
-};
-
-G_DEFINE_TYPE (PolkitAuthorizationClaim, polkit_authorization_claim, G_TYPE_OBJECT)
-
-#define POLKIT_AUTHORIZATION_CLAIM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), POLKIT_TYPE_AUTHORIZATION_CLAIM, PolkitAuthorizationClaimPrivate))
+}
-static void
-polkit_authorization_claim_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+GType
+polkit_authorization_claim_get_type (void)
{
- PolkitAuthorizationClaim *authorization_claim = POLKIT_AUTHORIZATION_CLAIM (object);
+ static GType iface_type = 0;
- switch (prop_id)
+ if (iface_type == 0)
{
- case PROP_SUBJECT:
- g_value_set_object (value, authorization_claim->priv->subject);
- break;
+ 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);
+ }
- case PROP_ACTION_ID:
- g_value_set_string (value, authorization_claim->priv->action_id);
- break;
+ return iface_type;
+}
- case PROP_ATTRIBUTES:
- g_value_set_boxed (value, authorization_claim->priv->attributes);
- break;
+#define AUTHORIZATION_CLAIM_SIGNATURE "((sa{sv})sa{ss})"
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+/**
+ * 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));
}
-static void
-polkit_authorization_claim_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+/**
+ * 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)
{
- PolkitAuthorizationClaim *authorization_claim = POLKIT_AUTHORIZATION_CLAIM (object);
-
- switch (prop_id)
- {
- case PROP_SUBJECT:
- polkit_authorization_claim_set_subject (authorization_claim, POLKIT_SUBJECT (g_value_get_object (value)));
- break;
-
- case PROP_ACTION_ID:
- polkit_authorization_claim_set_action_id (authorization_claim, g_value_get_string (value));
- break;
+ PolkitSubject *subject;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
+ 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);
-static void
-polkit_authorization_claim_init (PolkitAuthorizationClaim *authorization_claim)
-{
- authorization_claim->priv = POLKIT_AUTHORIZATION_CLAIM_GET_PRIVATE (authorization_claim);
+ egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (authorization_claim),
+ 0, &subject,
+ -1);
- authorization_claim->priv->attributes = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- g_free);
+ return subject;
}
-static void
-polkit_authorization_claim_finalize (GObject *object)
+/**
+ * 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)
{
- PolkitAuthorizationClaim *authorization_claim;
+ const gchar *action_id;
- g_return_if_fail (object != NULL);
- g_return_if_fail (POLKIT_IS_AUTHORIZATION_CLAIM (object));
-
- authorization_claim = POLKIT_AUTHORIZATION_CLAIM (object);
+ 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);
- if (authorization_claim->priv->subject != NULL)
- g_object_unref (authorization_claim->priv->subject);
- g_free (authorization_claim->priv->action_id);
- g_hash_table_unref (authorization_claim->priv->attributes);
+ egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (authorization_claim),
+ 1, &action_id,
+ -1);
- G_OBJECT_CLASS (polkit_authorization_claim_parent_class)->finalize (object);
+ return action_id;
}
-static void
-polkit_authorization_claim_class_init (PolkitAuthorizationClaimClass *klass)
+/**
+ * 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)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->get_property = polkit_authorization_claim_get_property;
- object_class->set_property = polkit_authorization_claim_set_property;
- object_class->finalize = polkit_authorization_claim_finalize;
-
- /**
- * PolkitAuthorizationClaim:subject:
- *
- * The subject making the authorization claim.
- */
- g_object_class_install_property (object_class,
- PROP_SUBJECT,
- g_param_spec_object ("subject",
- "subject",
- "The subject making the authorization claim",
- POLKIT_TYPE_SUBJECT,
- G_PARAM_CONSTRUCT |
- G_PARAM_READWRITE |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_NICK |
- G_PARAM_STATIC_BLURB));
-
- /**
- * PolkitAuthorizationClaim:action-id:
- *
- * The action id for the authorization claim.
- */
- g_object_class_install_property (object_class,
- PROP_ACTION_ID,
- g_param_spec_string ("action-id",
- "action-id",
- "The action for the authorization claim",
- NULL,
- G_PARAM_CONSTRUCT |
- G_PARAM_READWRITE |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_NICK |
- G_PARAM_STATIC_BLURB));
-
- /**
- * PolkitAuthorizationClaim:attributes:
- *
- * A #GHashTable from strings into the strings containing
- * attributes for the claim.
- */
- g_object_class_install_property (object_class,
- PROP_ATTRIBUTES,
- g_param_spec_boxed ("attributes",
- "attributes",
- "The attributes for the authorization claim",
- G_TYPE_HASH_TABLE,
- G_PARAM_READABLE |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_NICK |
- G_PARAM_STATIC_BLURB));
-
- g_type_class_add_private (klass, sizeof (PolkitAuthorizationClaimPrivate));
-}
+ GHashTable *attributes;
-PolkitSubject *
-polkit_authorization_claim_get_subject (PolkitAuthorizationClaim *authorization_claim)
-{
g_return_val_if_fail (POLKIT_IS_AUTHORIZATION_CLAIM (authorization_claim), NULL);
- return g_object_ref (authorization_claim->priv->subject);
+ 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 (POLKIT_IS_SUBJECT (subject));
+ g_return_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (authorization_claim)), AUTHORIZATION_CLAIM_SIGNATURE) == 0);
- if (!polkit_subject_equal (authorization_claim->priv->subject, subject)) {
- if (authorization_claim->priv->subject != NULL)
- g_object_unref (authorization_claim->priv->subject);
- authorization_claim->priv->subject = g_object_ref (subject);
- }
-}
-
-gchar *
-polkit_authorization_claim_get_action_id (PolkitAuthorizationClaim *authorization_claim)
-{
- g_return_val_if_fail (POLKIT_IS_AUTHORIZATION_CLAIM (authorization_claim), NULL);
- return g_strdup (authorization_claim->priv->action_id);
+ 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);
- if (authorization_claim->priv->action_id == NULL ||
- strcmp (authorization_claim->priv->action_id, action_id) != 0) {
- g_free (authorization_claim->priv->action_id);
- authorization_claim->priv->action_id = g_strdup (action_id);
- g_object_notify (G_OBJECT (authorization_claim), "action-id");
- }
+ egg_dbus_structure_set_element (EGG_DBUS_STRUCTURE (authorization_claim),
+ 1, action_id,
+ -1);
}
/**
- * polkit_authorization_claim_get_attributes:
+ * 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.
*
- * Gets the attributes (a #GHashTable mapping strings to strings) for
- * @authorization_claim.
- *
- * Returns: A #GHashTable. Caller should not free it, it is owned by
- * @authorization_claim.
+ * Sets or clear an attribute of @authorization_claim.
**/
-GHashTable *
-polkit_authorization_claim_get_attributes (PolkitAuthorizationClaim *authorization_claim)
-{
- g_return_val_if_fail (POLKIT_IS_AUTHORIZATION_CLAIM (authorization_claim), NULL);
- return authorization_claim->priv->attributes;
-}
-
-char *
-polkit_authorization_claim_get_attribute (PolkitAuthorizationClaim *authorization_claim,
- const gchar *key)
-{
- g_return_val_if_fail (POLKIT_IS_AUTHORIZATION_CLAIM (authorization_claim), NULL);
- g_return_val_if_fail (key != NULL, NULL);
-
- return g_strdup (g_hash_table_lookup (authorization_claim->priv->attributes, key));
-}
-
void
-polkit_authorization_claim_set_attribute (PolkitAuthorizationClaim *authorization_claim,
- const gchar *key,
- const gchar *value)
+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 (authorization_claim->priv->attributes, key);
- }
+ g_hash_table_remove (attributes, key);
else
- {
- g_hash_table_replace (authorization_claim->priv->attributes,
- g_strdup (key),
- g_strdup (value));
- }
+ g_hash_table_insert (attributes, g_strdup (key), g_strdup (value));
}
-
-PolkitAuthorizationClaim *
-polkit_authorization_claim_new (PolkitSubject *subject,
- const gchar *action_id)
-{
- PolkitAuthorizationClaim *authorization_claim;
-
- authorization_claim = POLKIT_AUTHORIZATION_CLAIM (g_object_new (POLKIT_TYPE_AUTHORIZATION_CLAIM,
- "subject", subject,
- "action-id", action_id,
- NULL));
-
- return authorization_claim;
-}
diff --git a/src/polkit/polkitauthorizationclaim.h b/src/polkit/polkitauthorizationclaim.h
index ab481ca..df948f5 100644
--- a/src/polkit/polkitauthorizationclaim.h
+++ b/src/polkit/polkitauthorizationclaim.h
@@ -31,43 +31,37 @@
G_BEGIN_DECLS
-#define POLKIT_TYPE_AUTHORIZATION_CLAIM (polkit_authorization_claim_get_type ())
+#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_AUTHORIZATION_CLAIM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), POLKIT_TYPE_AUTHORIZATION_CLAIM, PolkitAuthorizationClaimClass))
#define POLKIT_IS_AUTHORIZATION_CLAIM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_AUTHORIZATION_CLAIM))
-#define POLKIT_IS_AUTHORIZATION_CLAIM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_TYPE_AUTHORIZATION_CLAIM))
-#define POLKIT_AUTHORIZATION_CLAIM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_TYPE_AUTHORIZATION_CLAIM, PolkitAuthorizationClaimClass))
+#define POLKIT_AUTHORIZATION_CLAIM_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE((o), POLKIT_TYPE_AUTHORIZATION_CLAIM, PolkitAuthorizationClaimIface))
-typedef struct _PolkitAuthorizationClaim PolkitAuthorizationClaim;
-typedef struct _PolkitAuthorizationClaimClass PolkitAuthorizationClaimClass;
-typedef struct _PolkitAuthorizationClaimPrivate PolkitAuthorizationClaimPrivate;
+#if 0
+typedef struct _PolkitAuthorizationClaim PolkitAuthorizationClaim; /* Dummy typedef */
+#endif
+typedef struct _PolkitAuthorizationClaimIface PolkitAuthorizationClaimIface;
-struct _PolkitAuthorizationClaim
+struct _PolkitAuthorizationClaimIface
{
- GObject parent_instance;
- PolkitAuthorizationClaimPrivate *priv;
+ GTypeInterface g_iface;
};
-struct _PolkitAuthorizationClaimClass
-{
- GObjectClass parent_class;
-};
+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);
-GType polkit_authorization_claim_get_type (void) G_GNUC_CONST;
-PolkitAuthorizationClaim * polkit_authorization_claim_new (PolkitSubject *subject,
- const gchar *action_id);
-PolkitSubject * polkit_authorization_claim_get_subject (PolkitAuthorizationClaim *authorization_claim);
-void polkit_authorization_claim_set_subject (PolkitAuthorizationClaim *authorization_claim,
- PolkitSubject *subject);
-gchar * polkit_authorization_claim_get_action_id (PolkitAuthorizationClaim *authorization_claim);
-void polkit_authorization_claim_set_action_id (PolkitAuthorizationClaim *authorization_claim,
- const gchar *action_id);
-GHashTable * polkit_authorization_claim_get_attributes (PolkitAuthorizationClaim *authorization_claim);
-char * polkit_authorization_claim_get_attribute (PolkitAuthorizationClaim *authorization_claim,
- const gchar *key);
-void polkit_authorization_claim_set_attribute (PolkitAuthorizationClaim *authorization_claim,
- const gchar *key,
- const gchar *value);
G_END_DECLS