summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2009-05-13 12:20:16 -0400
committerDavid Zeuthen <davidz@redhat.com>2009-05-13 12:20:16 -0400
commit7a9f7c1389befed09abc9d2187c213868f638c43 (patch)
treeef769feb4b6d81cdfd9ed440a6d3e6a20fd8fe29
parent86008e618476834c040bf7db40bbc887cca2fbb5 (diff)
Change the PolkitAuthorizationResult enumeration into an object
-rw-r--r--data/org.freedesktop.PolicyKit1.Authority.xml24
-rw-r--r--docs/polkit/polkit-docs.xml1
-rw-r--r--docs/polkit/polkit-sections.txt27
-rw-r--r--src/polkit/polkitauthority.c25
-rw-r--r--src/polkit/polkitauthority.h4
-rw-r--r--src/polkit/polkitauthorizationresult.c155
-rw-r--r--src/polkit/polkitauthorizationresult.h36
-rw-r--r--src/polkit/polkitprivate.h4
-rw-r--r--src/polkit/polkittypes.h3
-rw-r--r--src/polkitbackend/polkitbackendauthority.c13
-rw-r--r--src/polkitbackend/polkitbackendauthority.h12
-rw-r--r--src/polkitbackend/polkitbackendlocalauthority.c66
12 files changed, 276 insertions, 94 deletions
diff --git a/data/org.freedesktop.PolicyKit1.Authority.xml b/data/org.freedesktop.PolicyKit1.Authority.xml
index da2fe59..abe0d3f 100644
--- a/data/org.freedesktop.PolicyKit1.Authority.xml
+++ b/data/org.freedesktop.PolicyKit1.Authority.xml
@@ -109,18 +109,20 @@
<!-- ---------------------------------------------------------------------------------------------------- -->
<!-- An enumeration for results when checking for an authorization -->
- <annotation name="org.gtk.EggDBus.DeclareEnum" value="AuthorizationResult">
- <annotation name="org.gtk.EggDBus.DocString.Summary" value="Possible results for checking authorizations"/>
- <annotation name="org.gtk.EggDBus.DocString" value="Possible results that the org.freedesktop.PolicyKit1.Authority.CheckAuthorization() method can return."/>
+ <annotation name="org.gtk.EggDBus.DeclareStruct" value="AuthorizationResult">
+ <annotation name="org.gtk.EggDBus.DocString.Summary" value="Authorization Results"/>
+ <annotation name="org.gtk.EggDBus.DocString" value="Describes the result of calling org.freedesktop.PolicyKit1.Authority.CheckAuthorization()."/>
- <annotation name="org.gtk.EggDBus.Enum.Member" value="NotAuthorized">
- <annotation name="org.gtk.EggDBus.DocString" value="The given #Subject is not authorized for the specified action."/>
+ <annotation name="org.gtk.EggDBus.Struct.Member" value="Boolean:is_authorized">
+ <annotation name="org.gtk.EggDBus.DocString" value="#TRUE if the given #Subject is authorized for the given action."/>
</annotation>
- <annotation name="org.gtk.EggDBus.Enum.Member" value="Authorized">
- <annotation name="org.gtk.EggDBus.DocString" value="The given #Subject is authorized for the specified action."/>
+
+ <annotation name="org.gtk.EggDBus.Struct.Member" value="Boolean:is_challenge">
+ <annotation name="org.gtk.EggDBus.DocString" value="#TRUE if the given #Subject could be authorized if more information was provided, and %CheckAuthorizationFlags.AllowUserInteraction wasn't passed."/>
</annotation>
- <annotation name="org.gtk.EggDBus.Enum.Member" value="Challenge">
- <annotation name="org.gtk.EggDBus.DocString" value="The given #Subject is authorized if more information is provided."/>
+
+ <annotation name="org.gtk.EggDBus.Struct.Member" value="Dict<String,String>:details">
+ <annotation name="org.gtk.EggDBus.DocString" value="Details for the result or empty if not authorized."/>
</annotation>
</annotation>
@@ -226,9 +228,9 @@
<annotation name="org.gtk.EggDBus.DocString" value="A unique id used to cancel the the authentication check via org.freedesktop.PolicyKit1.Authority.CancelCheckAuthorization() or the empty string if cancellation is not needed."/>
</arg>
- <arg name="result" direction="out" type="u">
+ <arg name="result" direction="out" type="(bba{ss})">
<annotation name="org.gtk.EggDBus.Type" value="AuthorizationResult"/>
- <annotation name="org.gtk.EggDBus.DocString" value="A value from the #AuthorizationResult enumeration."/>
+ <annotation name="org.gtk.EggDBus.DocString" value="An #AuthorizationResult structure."/>
</arg>
</method>
diff --git a/docs/polkit/polkit-docs.xml b/docs/polkit/polkit-docs.xml
index e9c4af4..c2da1ea 100644
--- a/docs/polkit/polkit-docs.xml
+++ b/docs/polkit/polkit-docs.xml
@@ -65,6 +65,7 @@
<reference id="ref-api">
<title>Core API Reference</title>
<xi:include href="xml/polkitauthority.xml"/>
+ <xi:include href="xml/polkitauthorizationresult.xml"/>
<xi:include href="xml/polkiterror.xml"/>
<xi:include href="xml/polkitactiondescription.xml"/>
<xi:include href="xml/polkitauthoritymanager.xml"/>
diff --git a/docs/polkit/polkit-sections.txt b/docs/polkit/polkit-sections.txt
index 2094a3f..2e56a30 100644
--- a/docs/polkit/polkit-sections.txt
+++ b/docs/polkit/polkit-sections.txt
@@ -50,7 +50,6 @@ POLKIT_AUTHORITY_MANAGER_GET_CLASS
<FILE>polkitauthority</FILE>
PolkitAuthority
PolkitCheckAuthorizationFlags
-PolkitAuthorizationResult
polkit_authority_get
polkit_authority_enumerate_actions_sync
polkit_authority_check_authorization_sync
@@ -79,6 +78,24 @@ POLKIT_AUTHORITY_GET_CLASS
</SECTION>
<SECTION>
+<FILE>polkitauthorizationresult</FILE>
+PolkitAuthorizationResult
+polkit_authorization_result_new
+polkit_authorization_result_get_is_authorized
+polkit_authorization_result_get_is_challenge
+polkit_authorization_result_get_details
+<SUBSECTION Standard>
+PolkitAuthorizationResultClass
+POLKIT_AUTHORIZATION_RESULT
+POLKIT_IS_AUTHORIZATION_RESULT
+POLKIT_TYPE_AUTHORIZATION_RESULT
+polkit_authorization_result_get_type
+POLKIT_AUTHORIZATION_RESULT_CLASS
+POLKIT_IS_AUTHORIZATION_RESULT_CLASS
+POLKIT_AUTHORIZATION_RESULT_GET_CLASS
+</SECTION>
+
+<SECTION>
<FILE>polkitsystembusname</FILE>
PolkitSystemBusName
polkit_system_bus_name_new
@@ -252,11 +269,3 @@ polkit_error_quark
polkit_error_get_type
</SECTION>
-<SECTION>
-<FILE>polkitauthorizationresult</FILE>
-POLKIT_TYPE_AUTHORIZATION_RESULT
-PolkitAuthorizationResult
-<SUBSECTION Standard>
-polkit_authorization_result_get_type
-</SECTION>
-
diff --git a/src/polkit/polkitauthority.c b/src/polkit/polkitauthority.c
index 041ba7e..5505346 100644
--- a/src/polkit/polkitauthority.c
+++ b/src/polkit/polkitauthority.c
@@ -448,14 +448,15 @@ authorization_check_cancelled_cb (GObject *source_object,
*
* Finishes checking if a subject is authorized for an action.
*
- * Returns: A #PolkitAuthorizationResult.
+ * Returns: A #PolkitAuthorizationResult or %NULL if @error is set. Free with g_object_unref().
**/
-PolkitAuthorizationResult
+PolkitAuthorizationResult *
polkit_authority_check_authorization_finish (PolkitAuthority *authority,
GAsyncResult *res,
GError **error)
{
- _PolkitAuthorizationResult result;
+ PolkitAuthorizationResult *result;
+ _PolkitAuthorizationResult *real_result;
GSimpleAsyncResult *simple;
GAsyncResult *real_res;
GError *local_error;
@@ -465,11 +466,11 @@ polkit_authority_check_authorization_finish (PolkitAuthority *authority
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_check_authorization_async);
- result = _POLKIT_AUTHORIZATION_RESULT_NOT_AUTHORIZED;
+ result = NULL;
local_error = NULL;
_polkit_authority_check_authorization_finish (authority->real,
- &result,
+ &real_result,
real_res,
&local_error);
@@ -504,8 +505,14 @@ polkit_authority_check_authorization_finish (PolkitAuthority *authority
g_propagate_error (error, local_error);
}
}
-
g_object_unref (real_res);
+
+ if (real_result != NULL)
+ {
+ result = polkit_authorization_result_new_for_real (real_result);
+ g_object_unref (real_result);
+ }
+
return result;
}
@@ -521,9 +528,9 @@ polkit_authority_check_authorization_finish (PolkitAuthority *authority
*
* Checks if @subject is authorized to perform the action represented by @action_id.
*
- * Returns: A #PolkitAuthorizationResult.
+ * Returns: A #PolkitAuthorizationResult or %NULL if @error is set. Free with g_object_unref().
*/
-PolkitAuthorizationResult
+PolkitAuthorizationResult *
polkit_authority_check_authorization_sync (PolkitAuthority *authority,
PolkitSubject *subject,
const gchar *action_id,
@@ -534,7 +541,7 @@ polkit_authority_check_authorization_sync (PolkitAuthority *author
{
guint call_id;
GAsyncResult *res;
- PolkitAuthorizationResult result;
+ PolkitAuthorizationResult *result;
call_id = polkit_authority_check_authorization_async (authority,
subject,
diff --git a/src/polkit/polkitauthority.h b/src/polkit/polkitauthority.h
index 2aa74ae..642c400 100644
--- a/src/polkit/polkitauthority.h
+++ b/src/polkit/polkitauthority.h
@@ -62,7 +62,7 @@ GList *polkit_authority_enumerate_groups_sync (PolkitAuthori
GCancellable *cancellable,
GError **error);
-PolkitAuthorizationResult polkit_authority_check_authorization_sync (PolkitAuthority *authority,
+PolkitAuthorizationResult *polkit_authority_check_authorization_sync (PolkitAuthority *authority,
PolkitSubject *subject,
const gchar *action_id,
GHashTable *details,
@@ -109,7 +109,7 @@ void polkit_authority_check_authorization (PolkitAuthority
GAsyncReadyCallback callback,
gpointer user_data);
-PolkitAuthorizationResult polkit_authority_check_authorization_finish (PolkitAuthority *authority,
+PolkitAuthorizationResult *polkit_authority_check_authorization_finish (PolkitAuthority *authority,
GAsyncResult *res,
GError **error);
diff --git a/src/polkit/polkitauthorizationresult.c b/src/polkit/polkitauthorizationresult.c
index ad224f3..314c39f 100644
--- a/src/polkit/polkitauthorizationresult.c
+++ b/src/polkit/polkitauthorizationresult.c
@@ -26,18 +26,161 @@
#include "polkitauthorizationresult.h"
#include "polkitprivate.h"
-
/**
* SECTION:polkitauthorizationresult
* @title: PolkitAuthorizationResult
- * @short_result: Authorization Results
+ * @short_description: Result for checking an authorization
+ * @stability: Stable
*
- * Results of a check for an claim.
+ * This class represents the result you get when checking for an authorization.
*/
-GType
-polkit_authorization_result_get_type (void)
+struct _PolkitAuthorizationResult
+{
+ GObject parent_instance;
+
+ _PolkitAuthorizationResult *real;
+};
+
+struct _PolkitAuthorizationResultClass
+{
+ GObjectClass parent_class;
+};
+
+G_DEFINE_TYPE (PolkitAuthorizationResult, polkit_authorization_result, G_TYPE_OBJECT);
+
+static void
+polkit_authorization_result_init (PolkitAuthorizationResult *authorization_result)
+{
+}
+
+static void
+polkit_authorization_result_finalize (GObject *object)
{
- return _polkit_authorization_result_get_type ();
+ PolkitAuthorizationResult *authorization_result;
+
+ authorization_result = POLKIT_AUTHORIZATION_RESULT (object);
+
+ g_object_unref (authorization_result->real);
+
+ if (G_OBJECT_CLASS (polkit_authorization_result_parent_class)->finalize != NULL)
+ G_OBJECT_CLASS (polkit_authorization_result_parent_class)->finalize (object);
}
+static void
+polkit_authorization_result_class_init (PolkitAuthorizationResultClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->finalize = polkit_authorization_result_finalize;
+}
+
+PolkitAuthorizationResult *
+polkit_authorization_result_new_for_real (_PolkitAuthorizationResult *real)
+{
+ PolkitAuthorizationResult *authorization_result;
+
+ authorization_result = POLKIT_AUTHORIZATION_RESULT (g_object_new (POLKIT_TYPE_AUTHORIZATION_RESULT, NULL));
+
+ authorization_result->real = g_object_ref (real);
+
+ return authorization_result;
+}
+
+_PolkitAuthorizationResult *
+polkit_authorization_result_get_real (PolkitAuthorizationResult *authorization_result)
+{
+ return g_object_ref (authorization_result->real);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+/**
+ * polkit_authorization_result_new:
+ * @is_authorized:
+ * @is_challenge:
+ * @details:
+ *
+ *
+ *
+ * Returns:
+ **/
+PolkitAuthorizationResult *
+polkit_authorization_result_new (gboolean is_authorized,
+ gboolean is_challenge,
+ GHashTable *details)
+{
+ PolkitAuthorizationResult *authorization_result;
+ _PolkitAuthorizationResult *real;
+ EggDBusHashMap *real_details;
+
+ real_details = egg_dbus_hash_map_new (G_TYPE_STRING, g_free, G_TYPE_STRING, g_free);
+ if (details != NULL)
+ {
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init (&iter, details);
+ while (g_hash_table_iter_next (&iter, &key, &value))
+ {
+ egg_dbus_hash_map_insert (real_details, g_strdup (key), g_strdup (value));
+ }
+ }
+
+ real = _polkit_authorization_result_new (is_authorized, is_challenge, real_details);
+ g_object_unref (real_details);
+
+ authorization_result = polkit_authorization_result_new_for_real (real);
+
+ g_object_unref (real);
+
+ return authorization_result;
+}
+
+/**
+ * polkit_authorization_result_get_is_authorized:
+ * @result:
+ *
+ *
+ *
+ * Returns:
+ **/
+gboolean
+polkit_authorization_result_get_is_authorized (PolkitAuthorizationResult *result)
+{
+ return _polkit_authorization_result_get_is_authorized (result->real);
+}
+
+/**
+ * polkit_authorization_result_get_is_challenge:
+ * @result:
+ *
+ *
+ *
+ * Returns:
+ **/
+gboolean
+polkit_authorization_result_get_is_challenge (PolkitAuthorizationResult *result)
+{
+ return _polkit_authorization_result_get_is_challenge (result->real);
+}
+
+/**
+ * polkit_authorization_result_get_details:
+ * @result:
+ *
+ *
+ *
+ * Returns:
+ **/
+GHashTable *
+polkit_authorization_result_get_details (PolkitAuthorizationResult *result)
+{
+ EggDBusHashMap *real_details;
+
+ real_details = _polkit_authorization_result_get_details (result->real);
+ if (real_details != NULL)
+ return real_details->data;
+ else
+ return NULL;
+}
diff --git a/src/polkit/polkitauthorizationresult.h b/src/polkit/polkitauthorizationresult.h
index 8458e40..69bec13 100644
--- a/src/polkit/polkitauthorizationresult.h
+++ b/src/polkit/polkitauthorizationresult.h
@@ -27,27 +27,31 @@
#define __POLKIT_AUTHORIZATION_RESULT_H
#include <glib-object.h>
+#include <polkit/polkittypes.h>
G_BEGIN_DECLS
-GType polkit_authorization_result_get_type (void) G_GNUC_CONST;
+#define POLKIT_TYPE_AUTHORIZATION_RESULT (polkit_authorization_result_get_type())
+#define POLKIT_AUTHORIZATION_RESULT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_AUTHORIZATION_RESULT, PolkitAuthorizationResult))
+#define POLKIT_AUTHORIZATION_RESULT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), POLKIT_TYPE_AUTHORIZATION_RESULT, PolkitAuthorizationResultClass))
+#define POLKIT_AUTHORIZATION_RESULT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_TYPE_AUTHORIZATION_RESULT, PolkitAuthorizationResultClass))
+#define POLKIT_IS_AUTHORIZATION_RESULT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_AUTHORIZATION_RESULT))
+#define POLKIT_IS_AUTHORIZATION_RESULT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_TYPE_AUTHORIZATION_RESULT))
-#define POLKIT_TYPE_AUTHORIZATION_RESULT (polkit_authorization_result_get_type ())
+#if 0
+typedef struct _PolkitAuthorizationResult PolkitAuthorizationResult;
+#endif
+typedef struct _PolkitAuthorizationResultClass PolkitAuthorizationResultClass;
-/**
- * PolkitAuthorizationResult:
- * @POLKIT_AUTHORIZATION_RESULT_NOT_AUTHORIZED: The subject is not authorized for the specified action
- * @POLKIT_AUTHORIZATION_RESULT_AUTHORIZED: The subject is authorized for the specified action
- * @POLKIT_AUTHORIZATION_RESULT_CHALLENGE: The subject is authorized if more information is provided
- *
- * Result codes for checking whether a subject is authorized for an action.
- */
-typedef enum
-{
- POLKIT_AUTHORIZATION_RESULT_NOT_AUTHORIZED = 0,
- POLKIT_AUTHORIZATION_RESULT_AUTHORIZED = 1,
- POLKIT_AUTHORIZATION_RESULT_CHALLENGE = 2,
-} PolkitAuthorizationResult;
+GType polkit_authorization_result_get_type (void) G_GNUC_CONST;
+PolkitAuthorizationResult *polkit_authorization_result_new (gboolean is_authorized,
+ gboolean is_challenge,
+ GHashTable *details);
+gboolean polkit_authorization_result_get_is_authorized (PolkitAuthorizationResult *result);
+gboolean polkit_authorization_result_get_is_challenge (PolkitAuthorizationResult *result);
+GHashTable *polkit_authorization_result_get_details (PolkitAuthorizationResult *result);
+
+/* ---------------------------------------------------------------------------------------------------- */
G_END_DECLS
diff --git a/src/polkit/polkitprivate.h b/src/polkit/polkitprivate.h
index 88b4b41..64954f0 100644
--- a/src/polkit/polkitprivate.h
+++ b/src/polkit/polkitprivate.h
@@ -25,6 +25,7 @@
#include "polkitimplicitauthorization.h"
#include "polkitactiondescription.h"
#include "polkitsubject.h"
+#include "polkitauthorizationresult.h"
#include "_polkitbindings.h"
/* notes:
@@ -46,4 +47,7 @@ _PolkitIdentity *polkit_identity_get_real (PolkitIdentity *identity);
PolkitAuthorization *polkit_authorization_new_for_real (_PolkitAuthorization *real);
_PolkitAuthorization *polkit_authorization_get_real (PolkitAuthorization *authorization);
+PolkitAuthorizationResult *polkit_authorization_result_new_for_real (_PolkitAuthorizationResult *real);
+_PolkitAuthorizationResult *polkit_authorization_result_get_real (PolkitAuthorizationResult *authorization_result);
+
#endif /* __POLKIT_PRIVATE_H */
diff --git a/src/polkit/polkittypes.h b/src/polkit/polkittypes.h
index 5da914b..47e1f21 100644
--- a/src/polkit/polkittypes.h
+++ b/src/polkit/polkittypes.h
@@ -55,4 +55,7 @@ typedef struct _PolkitUnixGroup PolkitUnixGroup;
struct _PolkitAuthorization;
typedef struct _PolkitAuthorization PolkitAuthorization;
+struct _PolkitAuthorizationResult;
+typedef struct _PolkitAuthorizationResult PolkitAuthorizationResult;
+
#endif /* __POLKIT_TYPES_H */
diff --git a/src/polkitbackend/polkitbackendauthority.c b/src/polkitbackend/polkitbackendauthority.c
index b53513f..e0f3a8e 100644
--- a/src/polkitbackend/polkitbackendauthority.c
+++ b/src/polkitbackend/polkitbackendauthority.c
@@ -261,9 +261,9 @@ polkit_backend_authority_check_authorization (PolkitBackendAuthority *aut
*
* Finishes checking if a subject is authorized for an action.
*
- * Returns: A #PolkitAuthorizationResult.
+ * Returns: A #PolkitAuthorizationResult or %NULL if @error is set. Free with g_object_unref().
**/
-PolkitAuthorizationResult
+PolkitAuthorizationResult *
polkit_backend_authority_check_authorization_finish (PolkitBackendAuthority *authority,
GAsyncResult *res,
GError **error)
@@ -276,7 +276,7 @@ polkit_backend_authority_check_authorization_finish (PolkitBackendAuthority *au
{
g_warning ("check_authorization_finish is not implemented (it is not optional)");
g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
- return POLKIT_AUTHORIZATION_RESULT_NOT_AUTHORIZED;
+ return NULL;
}
else
{
@@ -786,7 +786,7 @@ check_auth_cb (GObject *source_object,
{
EggDBusMethodInvocation *method_invocation = EGG_DBUS_METHOD_INVOCATION (user_data);
const gchar *full_cancellation_id;
- PolkitAuthorizationResult result;
+ PolkitAuthorizationResult *result;
GError *error;
error = NULL;
@@ -809,7 +809,10 @@ check_auth_cb (GObject *source_object,
}
else
{
- _polkit_authority_handle_check_authorization_finish (method_invocation, result);
+ _PolkitAuthorizationResult *real_result;
+ real_result = polkit_authorization_result_get_real (result);
+ _polkit_authority_handle_check_authorization_finish (method_invocation, real_result);
+ g_object_unref (result);
}
}
diff --git a/src/polkitbackend/polkitbackendauthority.h b/src/polkitbackend/polkitbackendauthority.h
index bb9d5e9..9b4acfe 100644
--- a/src/polkitbackend/polkitbackendauthority.h
+++ b/src/polkitbackend/polkitbackendauthority.h
@@ -129,9 +129,9 @@ struct _PolkitBackendAuthorityClass
GAsyncReadyCallback callback,
gpointer user_data);
- PolkitAuthorizationResult (*check_authorization_finish) (PolkitBackendAuthority *authority,
- GAsyncResult *res,
- GError **error);
+ PolkitAuthorizationResult * (*check_authorization_finish) (PolkitBackendAuthority *authority,
+ GAsyncResult *res,
+ GError **error);
gboolean (*register_authentication_agent) (PolkitBackendAuthority *authority,
PolkitSubject *caller,
@@ -227,9 +227,9 @@ void polkit_backend_authority_check_authorization (PolkitBackendAuthor
GAsyncReadyCallback callback,
gpointer user_data);
-PolkitAuthorizationResult polkit_backend_authority_check_authorization_finish (PolkitBackendAuthority *authority,
- GAsyncResult *res,
- GError **error);
+PolkitAuthorizationResult *polkit_backend_authority_check_authorization_finish (PolkitBackendAuthority *authority,
+ GAsyncResult *res,
+ GError **error);
GList *polkit_backend_authority_enumerate_authorizations (PolkitBackendAuthority *authority,
PolkitSubject *caller,
diff --git a/src/polkitbackend/polkitbackendlocalauthority.c b/src/polkitbackend/polkitbackendlocalauthority.c
index 74e6b3e..f677fc3 100644
--- a/src/polkitbackend/polkitbackendlocalauthority.c
+++ b/src/polkitbackend/polkitbackendlocalauthority.c
@@ -173,17 +173,17 @@ static void polkit_backend_local_authority_check_authorization (PolkitBackendAut
GAsyncReadyCallback callback,
gpointer user_data);
-static PolkitAuthorizationResult polkit_backend_local_authority_check_authorization_finish (
+static PolkitAuthorizationResult *polkit_backend_local_authority_check_authorization_finish (
PolkitBackendAuthority *authority,
GAsyncResult *res,
GError **error);
-static PolkitAuthorizationResult check_authorization_sync (PolkitBackendAuthority *authority,
- PolkitSubject *subject,
- const gchar *action_id,
- PolkitCheckAuthorizationFlags flags,
- PolkitImplicitAuthorization *out_implicit_authorization,
- GError **error);
+static PolkitAuthorizationResult *check_authorization_sync (PolkitBackendAuthority *authority,
+ PolkitSubject *subject,
+ const gchar *action_id,
+ PolkitCheckAuthorizationFlags flags,
+ PolkitImplicitAuthorization *out_implicit_authorization,
+ GError **error);
static GList *polkit_backend_local_authority_enumerate_authorizations (PolkitBackendAuthority *authority,
PolkitSubject *caller,
@@ -454,9 +454,10 @@ check_authorization_challenge_cb (AuthenticationAgent *agent,
gpointer user_data)
{
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
- PolkitAuthorizationResult result;
+ PolkitAuthorizationResult *result;
gchar *subject_str;
+ result = NULL;
subject_str = polkit_subject_to_string (subject);
g_debug ("In check_authorization_challenge_cb\n"
@@ -469,7 +470,7 @@ check_authorization_challenge_cb (AuthenticationAgent *agent,
if (authentication_success)
{
- result = POLKIT_AUTHORIZATION_RESULT_AUTHORIZED;
+ result = polkit_authorization_result_new (TRUE, FALSE, NULL);
/* store temporary authorization depending on value of implicit_authorization */
if (implicit_authorization == POLKIT_IMPLICIT_AUTHORIZATION_AUTHENTICATION_REQUIRED_RETAINED ||
@@ -498,37 +499,37 @@ check_authorization_challenge_cb (AuthenticationAgent *agent,
}
else
{
- /* TODO: maybe return FAILED_CHALLENGE instead? */
- result = POLKIT_AUTHORIZATION_RESULT_NOT_AUTHORIZED;
+ /* TODO: maybe return set is_challenge? */
+ result = polkit_authorization_result_new (FALSE, FALSE, NULL);
}
g_simple_async_result_set_op_res_gpointer (simple,
- GINT_TO_POINTER ((gint) result),
- NULL);
+ result,
+ g_object_unref);
g_simple_async_result_complete (simple);
g_object_unref (simple);
g_free (subject_str);
}
-static PolkitAuthorizationResult
+static PolkitAuthorizationResult *
polkit_backend_local_authority_check_authorization_finish (PolkitBackendAuthority *authority,
GAsyncResult *res,
GError **error)
{
GSimpleAsyncResult *simple;
- PolkitAuthorizationResult result;
+ PolkitAuthorizationResult *result;
simple = G_SIMPLE_ASYNC_RESULT (res);
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_backend_local_authority_check_authorization);
- result = POLKIT_AUTHORIZATION_RESULT_NOT_AUTHORIZED;
+ result = NULL;
if (g_simple_async_result_propagate_error (simple, error))
goto out;
- result = (PolkitAuthorizationResult) (GPOINTER_TO_INT (g_simple_async_result_get_op_res_gpointer (simple)));
+ result = g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
out:
return result;
@@ -553,7 +554,7 @@ polkit_backend_local_authority_check_authorization (PolkitBackendAuthority
PolkitIdentity *user_of_subject;
gchar *user_of_caller_str;
gchar *user_of_subject_str;
- PolkitAuthorizationResult result;
+ PolkitAuthorizationResult *result;
PolkitImplicitAuthorization implicit_authorization;
GError *error;
GSimpleAsyncResult *simple;
@@ -568,6 +569,7 @@ polkit_backend_local_authority_check_authorization (PolkitBackendAuthority
user_of_subject = NULL;
user_of_caller_str = NULL;
user_of_subject_str = NULL;
+ result = NULL;
simple = g_simple_async_result_new (G_OBJECT (authority),
callback,
@@ -643,7 +645,7 @@ polkit_backend_local_authority_check_authorization (PolkitBackendAuthority
}
/* Caller is up for a challenge! With light sabers! Use an authentication agent if one exists... */
- if ((result == POLKIT_AUTHORIZATION_RESULT_CHALLENGE) &&
+ if (polkit_authorization_result_get_is_challenge (result) &&
(flags & POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION))
{
AuthenticationAgent *agent;
@@ -661,6 +663,9 @@ polkit_backend_local_authority_check_authorization (PolkitBackendAuthority
}
else
{
+ g_object_unref (result);
+ result = NULL;
+
g_debug (" using authentication agent for challenge");
authentication_agent_initiate_challenge (agent,
@@ -682,8 +687,8 @@ polkit_backend_local_authority_check_authorization (PolkitBackendAuthority
/* Otherwise just return the result */
g_simple_async_result_set_op_res_gpointer (simple,
- GINT_TO_POINTER ((gint) result),
- NULL);
+ result,
+ g_object_unref);
g_simple_async_result_complete (simple);
g_object_unref (simple);
@@ -703,7 +708,7 @@ polkit_backend_local_authority_check_authorization (PolkitBackendAuthority
/* ---------------------------------------------------------------------------------------------------- */
-static PolkitAuthorizationResult
+static PolkitAuthorizationResult *
check_authorization_sync (PolkitBackendAuthority *authority,
PolkitSubject *subject,
const gchar *action_id,
@@ -713,7 +718,7 @@ check_authorization_sync (PolkitBackendAuthority *authority,
{
PolkitBackendLocalAuthority *local_authority;
PolkitBackendLocalAuthorityPrivate *priv;
- PolkitAuthorizationResult result;
+ PolkitAuthorizationResult *result;
PolkitIdentity *user_of_subject;
PolkitSubject *session_for_subject;
gchar *subject_str;
@@ -727,7 +732,7 @@ check_authorization_sync (PolkitBackendAuthority *authority,
local_authority = POLKIT_BACKEND_LOCAL_AUTHORITY (authority);
priv = POLKIT_BACKEND_LOCAL_AUTHORITY_GET_PRIVATE (local_authority);
- result = POLKIT_AUTHORIZATION_RESULT_NOT_AUTHORIZED;
+ result = NULL;
user_of_subject = NULL;
groups_of_user = NULL;
@@ -768,7 +773,7 @@ check_authorization_sync (PolkitBackendAuthority *authority,
/* special case: uid 0, root, is _always_ authorized for anything */
if (POLKIT_IS_UNIX_USER (user_of_subject) && polkit_unix_user_get_uid (POLKIT_UNIX_USER (user_of_subject)) == 0)
{
- result = POLKIT_AUTHORIZATION_RESULT_AUTHORIZED;
+ result = polkit_authorization_result_new (TRUE, FALSE, NULL);
goto out;
}
@@ -807,7 +812,7 @@ check_authorization_sync (PolkitBackendAuthority *authority,
g_debug (" is authorized (has implicit authorization local=%d active=%d)",
session_is_local,
session_is_active);
- result = POLKIT_AUTHORIZATION_RESULT_AUTHORIZED;
+ result = polkit_authorization_result_new (TRUE, FALSE, NULL);
goto out;
}
@@ -815,7 +820,7 @@ check_authorization_sync (PolkitBackendAuthority *authority,
if (check_temporary_authorization_for_identity (local_authority, user_of_subject, subject, action_id))
{
g_debug (" is authorized (has temporary authorization)");
- result = POLKIT_AUTHORIZATION_RESULT_AUTHORIZED;
+ result = polkit_authorization_result_new (TRUE, FALSE, NULL);
goto out;
}
@@ -823,7 +828,7 @@ check_authorization_sync (PolkitBackendAuthority *authority,
if (check_authorization_for_identity (local_authority, user_of_subject, action_id))
{
g_debug (" is authorized (user identity has authorization)");
- result = POLKIT_AUTHORIZATION_RESULT_AUTHORIZED;
+ result = polkit_authorization_result_new (TRUE, FALSE, NULL);
goto out;
}
@@ -836,14 +841,14 @@ check_authorization_sync (PolkitBackendAuthority *authority,
if (check_authorization_for_identity (local_authority, group, action_id))
{
g_debug (" is authorized (group identity has authorization)");
- result = POLKIT_AUTHORIZATION_RESULT_AUTHORIZED;
+ result = polkit_authorization_result_new (TRUE, FALSE, NULL);
goto out;
}
}
if (implicit_authorization != POLKIT_IMPLICIT_AUTHORIZATION_NOT_AUTHORIZED)
{
- result = POLKIT_AUTHORIZATION_RESULT_CHALLENGE;
+ result = polkit_authorization_result_new (FALSE, TRUE, NULL);
/* return implicit_authorization so the caller can use an authentication agent if applicable */
if (out_implicit_authorization != NULL)
@@ -854,6 +859,7 @@ check_authorization_sync (PolkitBackendAuthority *authority,
}
else
{
+ result = polkit_authorization_result_new (FALSE, FALSE, NULL);
g_debug (" not authorized");
}
out: