*target_res = g_object_ref (res);
}
+static void
+generic_async_cb (GObject *source_obj,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
+
+ g_simple_async_result_set_op_res_gpointer (simple, g_object_ref (res), g_object_unref);
+ g_simple_async_result_complete (simple);
+}
+
/* ---------------------------------------------------------------------------------------------------- */
static guint
gpointer user_data)
{
guint call_id;
+ GSimpleAsyncResult *simple;
+
+ simple = g_simple_async_result_new (G_OBJECT (authority),
+ callback,
+ user_data,
+ polkit_authority_enumerate_actions_async);
call_id = _polkit_authority_enumerate_actions (authority->real,
EGG_DBUS_CALL_FLAGS_NONE,
locale,
cancellable,
- callback,
- user_data);
+ generic_async_cb,
+ simple);
return call_id;
}
EggDBusArraySeq *array_seq;
GList *result;
guint n;
+ GSimpleAsyncResult *simple;
+ GAsyncResult *real_res;
+
+ simple = G_SIMPLE_ASYNC_RESULT (res);
+ real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));
+
+ g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_enumerate_actions_async);
result = NULL;
if (!_polkit_authority_enumerate_actions_finish (authority->real,
&array_seq,
- res,
+ real_res,
error))
goto out;
g_object_unref (array_seq);
out:
+ g_object_unref (real_res);
return result;
}
gpointer user_data)
{
guint call_id;
+ GSimpleAsyncResult *simple;
+
+ simple = g_simple_async_result_new (G_OBJECT (authority),
+ callback,
+ user_data,
+ polkit_authority_enumerate_actions_async);
call_id = _polkit_authority_enumerate_users (authority->real,
EGG_DBUS_CALL_FLAGS_NONE,
cancellable,
- callback,
- user_data);
+ generic_async_cb,
+ simple);
return call_id;
}
EggDBusArraySeq *array_seq;
GList *result;
guint n;
+ GSimpleAsyncResult *simple;
+ GAsyncResult *real_res;
+
+ simple = G_SIMPLE_ASYNC_RESULT (res);
+ real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));
+
+ g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_enumerate_actions_async);
result = NULL;
if (!_polkit_authority_enumerate_users_finish (authority->real,
&array_seq,
- res,
+ real_res,
error))
goto out;
g_object_unref (array_seq);
out:
+ g_object_unref (real_res);
return result;
}
static guint
polkit_authority_enumerate_groups_async (PolkitAuthority *authority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
guint call_id;
+ GSimpleAsyncResult *simple;
+
+ simple = g_simple_async_result_new (G_OBJECT (authority),
+ callback,
+ user_data,
+ polkit_authority_enumerate_actions_async);
call_id = _polkit_authority_enumerate_groups (authority->real,
- EGG_DBUS_CALL_FLAGS_NONE,
- cancellable,
- callback,
- user_data);
+ EGG_DBUS_CALL_FLAGS_NONE,
+ cancellable,
+ generic_async_cb,
+ simple);
return call_id;
}
EggDBusArraySeq *array_seq;
GList *result;
guint n;
+ GSimpleAsyncResult *simple;
+ GAsyncResult *real_res;
+
+ simple = G_SIMPLE_ASYNC_RESULT (res);
+ real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));
+
+ g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_enumerate_actions_async);
result = NULL;
if (!_polkit_authority_enumerate_groups_finish (authority->real,
&array_seq,
- res,
+ real_res,
error))
goto out;
g_object_unref (array_seq);
out:
+ g_object_unref (real_res);
return result;
}
{
_PolkitAuthorizationClaim *real_claim;
guint call_id;
+ GSimpleAsyncResult *simple;
real_claim = polkit_authorization_claim_get_real (claim);
+ simple = g_simple_async_result_new (G_OBJECT (authority),
+ callback,
+ user_data,
+ polkit_authority_check_claim_async);
+
+ g_object_set_data_full (G_OBJECT (simple), "claim", g_object_ref (claim), (GDestroyNotify) g_object_unref);
+
call_id = _polkit_authority_check_claim (authority->real,
EGG_DBUS_CALL_FLAGS_NONE,
real_claim,
cancellable,
- callback,
- user_data);
+ generic_async_cb,
+ simple);
g_object_unref (real_claim);
{
_PolkitAuthorizationResult result;
EggDBusHashMap *result_attributes;
+ GSimpleAsyncResult *simple;
+ GAsyncResult *real_res;
+
+ simple = G_SIMPLE_ASYNC_RESULT (res);
+ real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple));
+
+ g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_check_claim_async);
result = _POLKIT_AUTHORIZATION_RESULT_NOT_AUTHORIZED;
if (!_polkit_authority_check_claim_finish (authority->real,
&result,
&result_attributes,
- res,
+ real_res,
error))
goto out;
- /* TODO: pass these back */
+ /* TODO: pass these back? */
if (result_attributes != NULL)
g_object_unref (result_attributes);
out:
-
+ g_object_unref (real_res);
return result;
}
/* ---------------------------------------------------------------------------------------------------- */
-GList *polkit_authority_enumerate_actions_sync (PolkitAuthority *authority,
- const gchar *locale,
- GCancellable *cancellable,
- GError **error);
-
-GList *polkit_authority_enumerate_users_sync (PolkitAuthority *authority,
- GCancellable *cancellable,
- GError **error);
+GList *polkit_authority_enumerate_actions_sync (PolkitAuthority *authority,
+ const gchar *locale,
+ GCancellable *cancellable,
+ GError **error);
-GList *polkit_authority_enumerate_groups_sync (PolkitAuthority *authority,
+GList *polkit_authority_enumerate_users_sync (PolkitAuthority *authority,
GCancellable *cancellable,
GError **error);
-PolkitAuthorizationResult polkit_authority_check_claim_sync (PolkitAuthority *authority,
- PolkitAuthorizationClaim *claim,
- GCancellable *cancellable,
- GError **error);
-
-/* ---------------------------------------------------------------------------------------------------- */
+GList *polkit_authority_enumerate_groups_sync (PolkitAuthority *authority,
+ GCancellable *cancellable,
+ GError **error);
-void polkit_authority_enumerate_actions (PolkitAuthority *authority,
- const gchar *locale,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
+PolkitAuthorizationResult polkit_authority_check_claim_sync (PolkitAuthority *authority,
+ PolkitAuthorizationClaim *claim,
+ GCancellable *cancellable,
+ GError **error);
-GList * polkit_authority_enumerate_actions_finish (PolkitAuthority *authority,
- GAsyncResult *res,
- GError **error);
+/* ---------------------------------------------------------------------------------------------------- */
-void polkit_authority_enumerate_users (PolkitAuthority *authority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
+void polkit_authority_enumerate_actions (PolkitAuthority *authority,
+ const gchar *locale,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
-GList * polkit_authority_enumerate_users_finish (PolkitAuthority *authority,
- GAsyncResult *res,
- GError **error);
+GList * polkit_authority_enumerate_actions_finish (PolkitAuthority *authority,
+ GAsyncResult *res,
+ GError **error);
-void polkit_authority_enumerate_groups (PolkitAuthority *authority,
+void polkit_authority_enumerate_users (PolkitAuthority *authority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
-GList * polkit_authority_enumerate_groups_finish (PolkitAuthority *authority,
+GList * polkit_authority_enumerate_users_finish (PolkitAuthority *authority,
GAsyncResult *res,
GError **error);
-void polkit_authority_check_claim (PolkitAuthority *authority,
- PolkitAuthorizationClaim *claim,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
+void polkit_authority_enumerate_groups (PolkitAuthority *authority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+GList * polkit_authority_enumerate_groups_finish (PolkitAuthority *authority,
+ GAsyncResult *res,
+ GError **error);
+
+void polkit_authority_check_claim (PolkitAuthority *authority,
+ PolkitAuthorizationClaim *claim,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
-PolkitAuthorizationResult polkit_authority_check_claim_finish (PolkitAuthority *authority,
- GAsyncResult *res,
- GError **error);
+PolkitAuthorizationResult polkit_authority_check_claim_finish (PolkitAuthority *authority,
+ GAsyncResult *res,
+ GError **error);
/* ---------------------------------------------------------------------------------------------------- */
--- /dev/null
+/*
+ * Copyright (C) 2008 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: David Zeuthen <davidz@redhat.com>
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "polkitauthorizationresult.h"
+#include "polkitprivate.h"
+
+
+/**
+ * SECTION:polkitauthorizationresult
+ * @title: PolkitAuthorizationResult
+ * @short_result: Authorization Results
+ *
+ * Results of a check for an claim.
+ */
+
+GType
+polkit_authorization_result_get_type (void)
+{
+ return _polkit_authorization_result_get_type ();
+}
+
--- /dev/null
+/*
+ * Copyright (C) 2008 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: David Zeuthen <davidz@redhat.com>
+ */
+
+#ifndef __POLKIT_AUTHORIZATION_RESULT_H
+#define __POLKIT_AUTHORIZATION_RESULT_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+GType polkit_authorization_result_get_type (void) G_GNUC_CONST;
+
+#define POLKIT_TYPE_AUTHORIZATION_RESULT (polkit_authorization_result_get_type ())
+
+/**
+ * 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;
+
+G_END_DECLS
+
+#endif /* __POLKIT_AUTHORIZATION_RESULT_H */
PolkitAuthorizationClaim *polkit_authorization_claim_new_for_real (_PolkitAuthorizationClaim *real);
_PolkitAuthorizationClaim *polkit_authorization_claim_get_real (PolkitAuthorizationClaim *claim);
-
#endif /* __POLKIT_PRIVATE_H */
struct _PolkitAuthorizationClaim;
typedef struct _PolkitAuthorizationClaim PolkitAuthorizationClaim;
-
#endif /* __POLKIT_TYPES_H */
subject_str,
action_id);
+ /* TODO: temp */
+ polkit_backend_authority_check_claim_finish (pending_call, POLKIT_AUTHORIZATION_RESULT_AUTHORIZED);
+
+#if 0
polkit_backend_pending_call_return_error (pending_call,
POLKIT_ERROR,
POLKIT_ERROR_NOT_SUPPORTED,
"Not implemented");
+#endif
g_free (inquirer_str);
g_free (subject_str);
static gchar *action_id = NULL;
+/* ---------------------------------------------------------------------------------------------------- */
+
static gboolean list_actions (void);
static gboolean list_users (void);
static gboolean list_groups (void);
+static gboolean list_authorizations (void);
static gboolean check (void);
static gboolean show_action (const gchar *action_id);
+/* ---------------------------------------------------------------------------------------------------- */
+
static void
usage (int argc, char *argv[])
{
}
}
+/* ---------------------------------------------------------------------------------------------------- */
+
int
main (int argc, char *argv[])
{
{
ret = list_groups ();
}
+ else if (opt_list_authorizations)
+ {
+ ret = list_authorizations ();
+ }
else if (opt_check)
{
if (subject == NULL || action_id == NULL)
return ret ? 0 : 1;
}
+/* ---------------------------------------------------------------------------------------------------- */
+
static void
print_action (PolkitActionDescription *action)
{
}
}
+/* ---------------------------------------------------------------------------------------------------- */
+
static gboolean
show_action (const gchar *action_id)
{
return ret;
}
+/* ---------------------------------------------------------------------------------------------------- */
+
static void
print_subjects (GList *subjects)
{
}
}
+/* ---------------------------------------------------------------------------------------------------- */
+
static gboolean
list_users (void)
{
return ret;
}
+/* ---------------------------------------------------------------------------------------------------- */
+
static gboolean
list_groups (void)
{
return ret;
}
+/* ---------------------------------------------------------------------------------------------------- */
+
static gboolean
check (void)
{
goto out;
}
- g_debug ("result = %d", result);
-
out:
if (claim != NULL)
g_object_unref (claim);
return result == POLKIT_AUTHORIZATION_RESULT_AUTHORIZED;
}
+/* ---------------------------------------------------------------------------------------------------- */
+
+
+typedef struct
+{
+ PolkitAuthorizationClaim *claim;
+ PolkitAuthorizationResult result;
+} AuthzData;
+
+static GPtrArray *authz_data_array;
+
+static gint authz_data_num_pending = 0;
+
+static GMainLoop *authz_data_loop = NULL;
+
+static void
+authz_data_free (AuthzData *data)
+{
+ g_object_unref (data->claim);
+ g_free (data);
+}
+
+static gint
+authz_data_sort_func (gconstpointer a,
+ gconstpointer b)
+{
+ AuthzData *da;
+ AuthzData *db;
+ const gchar *aa;
+ const gchar *ab;
+
+ da = (AuthzData *) *((gpointer **) a);
+ db = (AuthzData *) *((gpointer **) b);
+
+ aa = polkit_authorization_claim_get_action_id (da->claim);
+ ab = polkit_authorization_claim_get_action_id (db->claim);
+
+ return strcmp (aa, ab);
+}
+
+static void
+list_authz_cb (GObject *source_obj,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ PolkitAuthority *authority;
+ AuthzData *data;
+ GError *error;
+ PolkitAuthorizationResult result;
+
+ authority = POLKIT_AUTHORITY (source_obj);
+ data = user_data;
+ error = NULL;
+
+ result = polkit_authority_check_claim_finish (authority,
+ res,
+ &error);
+ if (error != NULL)
+ {
+ g_printerr ("Unable to check claim: %s\n", error->message);
+ g_error_free (error);
+ }
+ else
+ {
+ data->result = result;
+ }
+
+ authz_data_num_pending -= 1;
+
+ if (authz_data_num_pending == 0)
+ g_main_loop_quit (authz_data_loop);
+}
+
+static gboolean
+list_authorizations (void)
+{
+ GError *error;
+ GList *actions;
+ GList *l;
+ gboolean ret;
+ PolkitSubject *calling_process;
+ guint n;
+
+ ret = FALSE;
+
+ authz_data_array = g_ptr_array_new ();
+ authz_data_num_pending = 0;
+ authz_data_loop = g_main_loop_new (NULL, FALSE);
+
+ calling_process = polkit_unix_process_new (getppid ());
+
+ error = NULL;
+ actions = polkit_authority_enumerate_actions_sync (authority,
+ NULL,
+ 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);
+ PolkitAuthorizationClaim *claim;
+ AuthzData *data;
+
+ claim = polkit_authorization_claim_new (calling_process,
+ polkit_action_description_get_action_id (action));
+
+ data = g_new0 (AuthzData, 1);
+ data->claim = g_object_ref (claim);
+
+ g_ptr_array_add (authz_data_array, data);
+
+ authz_data_num_pending += 1;
+
+ polkit_authority_check_claim (authority,
+ claim,
+ NULL,
+ list_authz_cb,
+ data);
+
+ g_object_unref (claim);
+ }
+
+ g_main_loop_run (authz_data_loop);
+
+ ret = TRUE;
+
+ /* sort authorizations by name */
+ g_ptr_array_sort (authz_data_array, authz_data_sort_func);
+
+ for (n = 0; n < authz_data_array->len; n++)
+ {
+ AuthzData *data = authz_data_array->pdata[n];
+
+ if (data->result == POLKIT_AUTHORIZATION_RESULT_AUTHORIZED)
+ g_print ("%s\n", polkit_authorization_claim_get_action_id (data->claim));
+ }
+
+ out:
+
+ g_list_foreach (actions, (GFunc) g_object_unref, NULL);
+ g_list_free (actions);
+
+ g_ptr_array_foreach (authz_data_array, (GFunc) authz_data_free, NULL);
+ g_ptr_array_free (authz_data_array, TRUE);
+
+ g_object_unref (calling_process);
+
+ g_main_loop_unref (authz_data_loop);
+ return ret;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */