From 796bfa1deb02ea2718baad6dc82430b7b8a9f4af Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Fri, 16 Jan 2009 14:41:48 -0500 Subject: [PATCH] add PolkitUnixSession and associcated functions --- data/org.freedesktop.PolicyKit1.Authority.xml | 18 ++- docs/man/polkit.xml | 17 +++ src/polkit/Makefile.am | 2 + src/polkit/polkit.h | 1 + src/polkit/polkitauthority.c | 104 +++++++++++++- src/polkit/polkitauthority.h | 13 ++ src/polkit/polkitsubject.c | 13 ++ src/polkit/polkittypes.h | 3 + src/polkit/polkitunixsession.c | 183 ++++++++++++++++++++++++ src/polkit/polkitunixsession.h | 51 +++++++ src/polkitbackend/polkitbackendauthority.c | 11 ++ src/polkitbackend/polkitbackendauthority.h | 65 +++++---- src/polkitbackend/polkitbackendlocalauthority.c | 56 ++++++-- src/polkitbackend/polkitbackendserver.c | 62 +++++++- src/polkitbackend/polkitbackendsessionmonitor.c | 36 +++++ src/polkitbackend/polkitbackendsessionmonitor.h | 5 +- src/programs/polkit.c | 49 ++++++- 17 files changed, 631 insertions(+), 58 deletions(-) create mode 100644 src/polkit/polkitunixsession.c create mode 100644 src/polkit/polkitunixsession.h diff --git a/data/org.freedesktop.PolicyKit1.Authority.xml b/data/org.freedesktop.PolicyKit1.Authority.xml index 6ebba5b..75d9586 100644 --- a/data/org.freedesktop.PolicyKit1.Authority.xml +++ b/data/org.freedesktop.PolicyKit1.Authority.xml @@ -84,16 +84,28 @@ - + + + - + + + + + + + + + - + + + diff --git a/docs/man/polkit.xml b/docs/man/polkit.xml index 26ca53c..b8161b1 100644 --- a/docs/man/polkit.xml +++ b/docs/man/polkit.xml @@ -42,6 +42,11 @@ + sessions + + + + authorizations @@ -173,6 +178,18 @@ + polkit-1 list sessions + + + + Lists all sessions. + The returned identifiers can be used as subject parameters. + Prints detailed information about each session if is given. + + + + + polkit-1 list authorizations diff --git a/src/polkit/Makefile.am b/src/polkit/Makefile.am index 8caf9d8..3a62076 100644 --- a/src/polkit/Makefile.am +++ b/src/polkit/Makefile.am @@ -47,6 +47,7 @@ libpolkit_gobject_1include_HEADERS = \ polkitunixuser.h \ polkitunixgroup.h \ polkitunixprocess.h \ + polkitunixsession.h \ polkitsystembusname.h \ polkitauthorizationclaim.h \ polkitauthorizationresult.h \ @@ -62,6 +63,7 @@ libpolkit_gobject_1_la_SOURCES = \ polkitunixuser.c polkitunixuser.h \ polkitunixgroup.c polkitunixgroup.h \ polkitunixprocess.c polkitunixprocess.h \ + polkitunixsession.c polkitunixsession.h \ polkitsystembusname.c polkitsystembusname.h \ polkitauthorizationclaim.c polkitauthorizationclaim.h \ polkitauthorizationresult.c polkitauthorizationresult.h \ diff --git a/src/polkit/polkit.h b/src/polkit/polkit.h index c81d14e..40df617 100644 --- a/src/polkit/polkit.h +++ b/src/polkit/polkit.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/src/polkit/polkitauthority.c b/src/polkit/polkitauthority.c index dbf02b9..1646467 100644 --- a/src/polkit/polkitauthority.c +++ b/src/polkit/polkitauthority.c @@ -242,7 +242,7 @@ polkit_authority_enumerate_users_async (PolkitAuthority *authority, simple = g_simple_async_result_new (G_OBJECT (authority), callback, user_data, - polkit_authority_enumerate_actions_async); + polkit_authority_enumerate_users_async); call_id = _polkit_authority_enumerate_users (authority->real, EGG_DBUS_CALL_FLAGS_NONE, @@ -276,7 +276,7 @@ polkit_authority_enumerate_users_finish (PolkitAuthority *authority, 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); + g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_enumerate_users_async); result = NULL; @@ -338,7 +338,7 @@ polkit_authority_enumerate_groups_async (PolkitAuthority *authority, simple = g_simple_async_result_new (G_OBJECT (authority), callback, user_data, - polkit_authority_enumerate_actions_async); + polkit_authority_enumerate_groups_async); call_id = _polkit_authority_enumerate_groups (authority->real, EGG_DBUS_CALL_FLAGS_NONE, @@ -372,7 +372,7 @@ polkit_authority_enumerate_groups_finish (PolkitAuthority *authority, 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); + g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_enumerate_groups_async); result = NULL; @@ -423,6 +423,102 @@ polkit_authority_enumerate_groups_sync (PolkitAuthority *authority, /* ---------------------------------------------------------------------------------------------------- */ static guint +polkit_authority_enumerate_sessions_async (PolkitAuthority *authority, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + guint call_id; + GSimpleAsyncResult *simple; + + simple = g_simple_async_result_new (G_OBJECT (authority), + callback, + user_data, + polkit_authority_enumerate_sessions_async); + + call_id = _polkit_authority_enumerate_sessions (authority->real, + EGG_DBUS_CALL_FLAGS_NONE, + cancellable, + generic_async_cb, + simple); + + return call_id; +} + +void +polkit_authority_enumerate_sessions (PolkitAuthority *authority, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + polkit_authority_enumerate_sessions_async (authority, cancellable, callback, user_data); +} + +GList * +polkit_authority_enumerate_sessions_finish (PolkitAuthority *authority, + GAsyncResult *res, + GError **error) +{ + EggDBusArraySeq *array_seq; + GList *result; + guint n; + GSimpleAsyncResult *simple; + GAsyncResult *real_res; + + simple = G_SIMPLE_ASYNC_RESULT (res); + real_res = G_ASYNC_RESULT (g_simple_async_result_get_op_res_gpointer (simple)); + + g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_enumerate_sessions_async); + + result = NULL; + + if (!_polkit_authority_enumerate_sessions_finish (authority->real, + &array_seq, + real_res, + error)) + goto out; + + for (n = 0; n < array_seq->size; n++) + { + _PolkitSubject *real_subject; + + real_subject = array_seq->data.v_ptr[n]; + + result = g_list_prepend (result, polkit_subject_new_for_real (real_subject)); + } + + result = g_list_reverse (result); + + g_object_unref (array_seq); + + out: + g_object_unref (real_res); + return result; +} + +GList * +polkit_authority_enumerate_sessions_sync (PolkitAuthority *authority, + GCancellable *cancellable, + GError **error) +{ + guint call_id; + GAsyncResult *res; + GList *result; + + call_id = polkit_authority_enumerate_sessions_async (authority, cancellable, generic_cb, &res); + + egg_dbus_connection_pending_call_block (authority->system_bus, call_id); + + result = polkit_authority_enumerate_sessions_finish (authority, res, error); + + g_object_unref (res); + + return result; +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static guint polkit_authority_check_claim_async (PolkitAuthority *authority, PolkitAuthorizationClaim *claim, GCancellable *cancellable, diff --git a/src/polkit/polkitauthority.h b/src/polkit/polkitauthority.h index ba7bad3..85b1a51 100644 --- a/src/polkit/polkitauthority.h +++ b/src/polkit/polkitauthority.h @@ -59,6 +59,10 @@ GList *polkit_authority_enumerate_groups_sync (PolkitAuthori GCancellable *cancellable, GError **error); +GList *polkit_authority_enumerate_sessions_sync (PolkitAuthority *authority, + GCancellable *cancellable, + GError **error); + PolkitAuthorizationResult polkit_authority_check_claim_sync (PolkitAuthority *authority, PolkitAuthorizationClaim *claim, GCancellable *cancellable, @@ -94,6 +98,15 @@ GList * polkit_authority_enumerate_groups_finish (PolkitAutho GAsyncResult *res, GError **error); +void polkit_authority_enumerate_sessions (PolkitAuthority *authority, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); + +GList * polkit_authority_enumerate_sessions_finish (PolkitAuthority *authority, + GAsyncResult *res, + GError **error); + void polkit_authority_check_claim (PolkitAuthority *authority, PolkitAuthorizationClaim *claim, GCancellable *cancellable, diff --git a/src/polkit/polkitsubject.c b/src/polkit/polkitsubject.c index 4732262..d7c5434 100644 --- a/src/polkit/polkitsubject.c +++ b/src/polkit/polkitsubject.c @@ -29,6 +29,7 @@ #include "polkitunixuser.h" #include "polkitunixgroup.h" #include "polkitunixprocess.h" +#include "polkitunixsession.h" #include "polkitsystembusname.h" #include "polkiterror.h" #include "polkitprivate.h" @@ -188,6 +189,11 @@ polkit_subject_new_for_real (_PolkitSubject *real) s = polkit_unix_process_new_full (egg_dbus_variant_get_uint (variant), egg_dbus_variant_get_uint64 (variant2)); } + else if (strcmp (kind, "unix-session") == 0) + { + variant = egg_dbus_hash_map_lookup (details, "session-id"); + s = polkit_unix_session_new (egg_dbus_variant_get_string (variant)); + } else if (strcmp (kind, "system-bus-name") == 0) { variant = egg_dbus_hash_map_lookup (details, "name"); @@ -236,6 +242,13 @@ polkit_subject_get_real (PolkitSubject *subject) "start-time", egg_dbus_variant_new_for_uint64 (polkit_unix_process_get_start_time (POLKIT_UNIX_PROCESS (subject)))); } + else if (POLKIT_IS_UNIX_SESSION (subject)) + { + kind = "unix-session"; + egg_dbus_hash_map_insert (details, + "session-id", + egg_dbus_variant_new_for_string (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)))); + } else if (POLKIT_IS_SYSTEM_BUS_NAME (subject)) { kind = "system-bus-name"; diff --git a/src/polkit/polkittypes.h b/src/polkit/polkittypes.h index e1ab45d..e74a7ff 100644 --- a/src/polkit/polkittypes.h +++ b/src/polkit/polkittypes.h @@ -41,6 +41,9 @@ typedef struct _PolkitUnixGroup PolkitUnixGroup; struct _PolkitUnixProcess; typedef struct _PolkitUnixProcess PolkitUnixProcess; +struct _PolkitUnixSession; +typedef struct _PolkitUnixSession PolkitUnixSession; + struct _PolkitSystemBusName; typedef struct _PolkitSystemBusName PolkitSystemBusName; diff --git a/src/polkit/polkitunixsession.c b/src/polkit/polkitunixsession.c new file mode 100644 index 0000000..b81bbd0 --- /dev/null +++ b/src/polkit/polkitunixsession.c @@ -0,0 +1,183 @@ +/* + * 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 "polkitunixsession.h" +#include "polkitsubject.h" +#include "polkitprivate.h" + +/** + * SECTION:polkitunixsession + * @title: PolkitUnixSession + * @short_description: Unix sessions + * + * Encapsulates a login session on UNIX. + */ + +struct _PolkitUnixSession +{ + GObject parent_instance; + + gchar *session_id; +}; + +struct _PolkitUnixSessionClass +{ + GObjectClass parent_class; +}; + +enum +{ + PROP_0, + PROP_SESSION_ID, +}; + +static void subject_iface_init (PolkitSubjectIface *subject_iface); + +G_DEFINE_TYPE_WITH_CODE (PolkitUnixSession, polkit_unix_session, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (POLKIT_TYPE_SUBJECT, subject_iface_init) + ); + +static void +polkit_unix_session_init (PolkitUnixSession *unix_session) +{ +} + +static void +polkit_unix_session_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + PolkitUnixSession *session = POLKIT_UNIX_SESSION (object); + + switch (prop_id) + { + case PROP_SESSION_ID: + g_value_set_string (value, session->session_id); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +polkit_unix_session_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + PolkitUnixSession *session = POLKIT_UNIX_SESSION (object); + + switch (prop_id) + { + case PROP_SESSION_ID: + polkit_unix_session_set_session_id (session, g_value_get_string (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +polkit_unix_session_class_init (PolkitUnixSessionClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->get_property = polkit_unix_session_get_property; + gobject_class->set_property = polkit_unix_session_set_property; + + /** + * PolkitUnixSession:session-id: + * + * The UNIX session id. + */ + g_object_class_install_property (gobject_class, + PROP_SESSION_ID, + g_param_spec_string ("session-id", + "Session ID", + "The UNIX session ID", + NULL, + G_PARAM_CONSTRUCT | + G_PARAM_READWRITE | + G_PARAM_STATIC_NAME | + G_PARAM_STATIC_BLURB | + G_PARAM_STATIC_NICK)); + +} + +const gchar * +polkit_unix_session_get_session_id (PolkitUnixSession *session) +{ + return session->session_id; +} + +void +polkit_unix_session_set_session_id (PolkitUnixSession *session, + const gchar *session_id) +{ + g_free (session->session_id); + session->session_id = g_strdup (session_id); +} + +PolkitSubject * +polkit_unix_session_new (const gchar *session_id) +{ + return POLKIT_SUBJECT (g_object_new (POLKIT_TYPE_UNIX_SESSION, + "session-id", session_id, + NULL)); +} + +static gboolean +polkit_unix_session_equal (PolkitSubject *a, + PolkitSubject *b) +{ + PolkitUnixSession *session_a; + PolkitUnixSession *session_b; + + session_a = POLKIT_UNIX_SESSION (a); + session_b = POLKIT_UNIX_SESSION (b); + + return g_strcmp0 (session_a->session_id, session_b->session_id) == 0; +} + +static gchar * +polkit_unix_session_to_string (PolkitSubject *subject) +{ + PolkitUnixSession *session = POLKIT_UNIX_SESSION (subject); + + return g_strdup_printf ("unix-session:%s", session->session_id); +} + +static void +subject_iface_init (PolkitSubjectIface *subject_iface) +{ + subject_iface->equal = polkit_unix_session_equal; + subject_iface->to_string = polkit_unix_session_to_string; +} diff --git a/src/polkit/polkitunixsession.h b/src/polkit/polkitunixsession.h new file mode 100644 index 0000000..bbf431e --- /dev/null +++ b/src/polkit/polkitunixsession.h @@ -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 + */ + +#ifndef __POLKIT_UNIX_SESSION_H +#define __POLKIT_UNIX_SESSION_H + +#include +#include +#include + +G_BEGIN_DECLS + +#define POLKIT_TYPE_UNIX_SESSION (polkit_unix_session_get_type()) +#define POLKIT_UNIX_SESSION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_UNIX_SESSION, PolkitUnixSession)) +#define POLKIT_UNIX_SESSION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), POLKIT_TYPE_UNIX_SESSION, PolkitUnixSessionClass)) +#define POLKIT_UNIX_SESSION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_TYPE_UNIX_SESSION, PolkitUnixSessionClass)) +#define POLKIT_IS_UNIX_SESSION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_UNIX_SESSION)) +#define POLKIT_IS_UNIX_SESSION_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_TYPE_UNIX_SESSION)) + +#if 0 +typedef struct _PolkitUnixSession PolkitUnixSession; +#endif +typedef struct _PolkitUnixSessionClass PolkitUnixSessionClass; + +GType polkit_unix_session_get_type (void) G_GNUC_CONST; +PolkitSubject *polkit_unix_session_new (const gchar *session_id); +const gchar *polkit_unix_session_get_session_id (PolkitUnixSession *session); +void polkit_unix_session_set_session_id (PolkitUnixSession *session, + const gchar *session_id); + +G_END_DECLS + +#endif /* __POLKIT_UNIX_SESSION_H */ diff --git a/src/polkitbackend/polkitbackendauthority.c b/src/polkitbackend/polkitbackendauthority.c index 97ef38a..f00cfbe 100644 --- a/src/polkitbackend/polkitbackendauthority.c +++ b/src/polkitbackend/polkitbackendauthority.c @@ -73,6 +73,17 @@ polkit_backend_authority_enumerate_groups (PolkitBackendAuthority *authority, } void +polkit_backend_authority_enumerate_sessions (PolkitBackendAuthority *authority, + PolkitBackendPendingCall *pending_call) +{ + PolkitBackendAuthorityClass *klass; + + klass = POLKIT_BACKEND_AUTHORITY_GET_CLASS (authority); + + klass->enumerate_sessions (authority, pending_call); +} + +void polkit_backend_authority_check_claim (PolkitBackendAuthority *authority, PolkitAuthorizationClaim *claim, PolkitBackendPendingCall *pending_call) diff --git a/src/polkitbackend/polkitbackendauthority.h b/src/polkitbackend/polkitbackendauthority.h index 3a54a4c..fd641b3 100644 --- a/src/polkitbackend/polkitbackendauthority.h +++ b/src/polkitbackend/polkitbackendauthority.h @@ -51,19 +51,22 @@ struct _PolkitBackendAuthorityClass /*< public >*/ - void (*enumerate_actions) (PolkitBackendAuthority *authority, - const gchar *locale, - PolkitBackendPendingCall *pending_call); + void (*enumerate_actions) (PolkitBackendAuthority *authority, + const gchar *locale, + PolkitBackendPendingCall *pending_call); - void (*enumerate_users) (PolkitBackendAuthority *authority, - PolkitBackendPendingCall *pending_call); + void (*enumerate_users) (PolkitBackendAuthority *authority, + PolkitBackendPendingCall *pending_call); - void (*enumerate_groups) (PolkitBackendAuthority *authority, - PolkitBackendPendingCall *pending_call); + void (*enumerate_groups) (PolkitBackendAuthority *authority, + PolkitBackendPendingCall *pending_call); - void (*check_claim) (PolkitBackendAuthority *authority, - PolkitAuthorizationClaim *claim, - PolkitBackendPendingCall *pending_call); + void (*enumerate_sessions) (PolkitBackendAuthority *authority, + PolkitBackendPendingCall *pending_call); + + void (*check_claim) (PolkitBackendAuthority *authority, + PolkitAuthorizationClaim *claim, + PolkitBackendPendingCall *pending_call); /*< private >*/ /* Padding for future expansion */ @@ -81,33 +84,39 @@ GType polkit_backend_authority_get_type (void) G_GNUC_CONST; /* --- */ -void polkit_backend_authority_enumerate_actions (PolkitBackendAuthority *authority, - const gchar *locale, - PolkitBackendPendingCall *pending_call); +void polkit_backend_authority_enumerate_actions (PolkitBackendAuthority *authority, + const gchar *locale, + PolkitBackendPendingCall *pending_call); + +void polkit_backend_authority_enumerate_users (PolkitBackendAuthority *authority, + PolkitBackendPendingCall *pending_call); -void polkit_backend_authority_enumerate_users (PolkitBackendAuthority *authority, - PolkitBackendPendingCall *pending_call); +void polkit_backend_authority_enumerate_groups (PolkitBackendAuthority *authority, + PolkitBackendPendingCall *pending_call); -void polkit_backend_authority_enumerate_groups (PolkitBackendAuthority *authority, - PolkitBackendPendingCall *pending_call); +void polkit_backend_authority_enumerate_sessions (PolkitBackendAuthority *authority, + PolkitBackendPendingCall *pending_call); -void polkit_backend_authority_check_claim (PolkitBackendAuthority *authority, - PolkitAuthorizationClaim *claim, - PolkitBackendPendingCall *pending_call); +void polkit_backend_authority_check_claim (PolkitBackendAuthority *authority, + PolkitAuthorizationClaim *claim, + PolkitBackendPendingCall *pending_call); /* --- */ -void polkit_backend_authority_enumerate_actions_finish (PolkitBackendPendingCall *pending_call, - GList *actions); +void polkit_backend_authority_enumerate_actions_finish (PolkitBackendPendingCall *pending_call, + GList *actions); + +void polkit_backend_authority_enumerate_users_finish (PolkitBackendPendingCall *pending_call, + GList *users); -void polkit_backend_authority_enumerate_users_finish (PolkitBackendPendingCall *pending_call, - GList *users); +void polkit_backend_authority_enumerate_groups_finish (PolkitBackendPendingCall *pending_call, + GList *groups); -void polkit_backend_authority_enumerate_groups_finish (PolkitBackendPendingCall *pending_call, - GList *groups); +void polkit_backend_authority_enumerate_sessions_finish (PolkitBackendPendingCall *pending_call, + GList *sessions); -void polkit_backend_authority_check_claim_finish (PolkitBackendPendingCall *pending_call, - PolkitAuthorizationResult result); +void polkit_backend_authority_check_claim_finish (PolkitBackendPendingCall *pending_call, + PolkitAuthorizationResult result); G_END_DECLS diff --git a/src/polkitbackend/polkitbackendlocalauthority.c b/src/polkitbackend/polkitbackendlocalauthority.c index c4dbba8..db49f99 100644 --- a/src/polkitbackend/polkitbackendlocalauthority.c +++ b/src/polkitbackend/polkitbackendlocalauthority.c @@ -38,19 +38,22 @@ typedef struct } PolkitBackendLocalAuthorityPrivate; -static void polkit_backend_local_authority_enumerate_actions (PolkitBackendAuthority *authority, - const gchar *locale, - PolkitBackendPendingCall *pending_call); +static void polkit_backend_local_authority_enumerate_actions (PolkitBackendAuthority *authority, + const gchar *locale, + PolkitBackendPendingCall *pending_call); -static void polkit_backend_local_authority_enumerate_users (PolkitBackendAuthority *authority, - PolkitBackendPendingCall *pending_call); +static void polkit_backend_local_authority_enumerate_users (PolkitBackendAuthority *authority, + PolkitBackendPendingCall *pending_call); -static void polkit_backend_local_authority_enumerate_groups (PolkitBackendAuthority *authority, - PolkitBackendPendingCall *pending_call); +static void polkit_backend_local_authority_enumerate_groups (PolkitBackendAuthority *authority, + PolkitBackendPendingCall *pending_call); -static void polkit_backend_local_authority_check_claim (PolkitBackendAuthority *authority, - PolkitAuthorizationClaim *claim, - PolkitBackendPendingCall *pending_call); +static void polkit_backend_local_authority_enumerate_sessions (PolkitBackendAuthority *authority, + PolkitBackendPendingCall *pending_call); + +static void polkit_backend_local_authority_check_claim (PolkitBackendAuthority *authority, + PolkitAuthorizationClaim *claim, + PolkitBackendPendingCall *pending_call); G_DEFINE_TYPE (PolkitBackendLocalAuthority, polkit_backend_local_authority, POLKIT_BACKEND_TYPE_AUTHORITY); @@ -100,10 +103,11 @@ polkit_backend_local_authority_class_init (PolkitBackendLocalAuthorityClass *kla gobject_class->finalize = polkit_backend_local_authority_finalize; - authority_class->enumerate_actions = polkit_backend_local_authority_enumerate_actions; - authority_class->enumerate_users = polkit_backend_local_authority_enumerate_users; - authority_class->enumerate_groups = polkit_backend_local_authority_enumerate_groups; - authority_class->check_claim = polkit_backend_local_authority_check_claim; + authority_class->enumerate_actions = polkit_backend_local_authority_enumerate_actions; + authority_class->enumerate_users = polkit_backend_local_authority_enumerate_users; + authority_class->enumerate_groups = polkit_backend_local_authority_enumerate_groups; + authority_class->enumerate_sessions = polkit_backend_local_authority_enumerate_sessions; + authority_class->check_claim = polkit_backend_local_authority_check_claim; g_type_class_add_private (klass, sizeof (PolkitBackendLocalAuthorityPrivate)); } @@ -135,6 +139,8 @@ polkit_backend_local_authority_enumerate_actions (PolkitBackendAuthority *auth actions); } +/* ---------------------------------------------------------------------------------------------------- */ + static void polkit_backend_local_authority_enumerate_users (PolkitBackendAuthority *authority, PolkitBackendPendingCall *pending_call) @@ -179,6 +185,8 @@ polkit_backend_local_authority_enumerate_users (PolkitBackendAuthority *author ; } +/* ---------------------------------------------------------------------------------------------------- */ + static void polkit_backend_local_authority_enumerate_groups (PolkitBackendAuthority *authority, PolkitBackendPendingCall *pending_call) @@ -223,6 +231,26 @@ polkit_backend_local_authority_enumerate_groups (PolkitBackendAuthority *autho ; } +/* ---------------------------------------------------------------------------------------------------- */ + +static void +polkit_backend_local_authority_enumerate_sessions (PolkitBackendAuthority *authority, + PolkitBackendPendingCall *pending_call) +{ + PolkitBackendLocalAuthority *local_authority; + PolkitBackendLocalAuthorityPrivate *priv; + GList *list; + + local_authority = POLKIT_BACKEND_LOCAL_AUTHORITY (authority); + priv = POLKIT_BACKEND_LOCAL_AUTHORITY_GET_PRIVATE (local_authority); + + list = polkit_backend_session_monitor_get_sessions (priv->session_monitor); + + polkit_backend_authority_enumerate_sessions_finish (pending_call, list); +} + +/* ---------------------------------------------------------------------------------------------------- */ + static void polkit_backend_local_authority_check_claim (PolkitBackendAuthority *authority, PolkitAuthorizationClaim *claim, diff --git a/src/polkitbackend/polkitbackendserver.c b/src/polkitbackend/polkitbackendserver.c index 3da541e..915873c 100644 --- a/src/polkitbackend/polkitbackendserver.c +++ b/src/polkitbackend/polkitbackendserver.c @@ -85,6 +85,8 @@ polkit_backend_server_new (PolkitBackendAuthority *authority) return server; } +/* ---------------------------------------------------------------------------------------------------- */ + static void authority_handle_enumerate_actions (_PolkitAuthority *instance, const gchar *locale, @@ -127,6 +129,8 @@ polkit_backend_authority_enumerate_actions_finish (PolkitBackendPendingCall *pen g_object_unref (pending_call); } +/* ---------------------------------------------------------------------------------------------------- */ + static void authority_handle_enumerate_users (_PolkitAuthority *instance, EggDBusMethodInvocation *method_invocation) @@ -168,6 +172,8 @@ polkit_backend_authority_enumerate_users_finish (PolkitBackendPendingCall *pendi g_object_unref (pending_call); } +/* ---------------------------------------------------------------------------------------------------- */ + static void authority_handle_enumerate_groups (_PolkitAuthority *instance, EggDBusMethodInvocation *method_invocation) @@ -209,6 +215,51 @@ polkit_backend_authority_enumerate_groups_finish (PolkitBackendPendingCall *pend g_object_unref (pending_call); } +/* ---------------------------------------------------------------------------------------------------- */ + +static void +authority_handle_enumerate_sessions (_PolkitAuthority *instance, + EggDBusMethodInvocation *method_invocation) +{ + PolkitBackendServer *server = POLKIT_BACKEND_SERVER (instance); + PolkitBackendPendingCall *pending_call; + + pending_call = _polkit_backend_pending_call_new (method_invocation, server); + + polkit_backend_authority_enumerate_sessions (server->authority, pending_call); +} + +void +polkit_backend_authority_enumerate_sessions_finish (PolkitBackendPendingCall *pending_call, + GList *sessions) +{ + EggDBusArraySeq *array; + GList *l; + + array = egg_dbus_array_seq_new (_POLKIT_TYPE_SUBJECT, (GDestroyNotify) g_object_unref, NULL, NULL); + + for (l = sessions; l != NULL; l = l->next) + { + PolkitSubject *subject = POLKIT_SUBJECT (l->data); + _PolkitSubject *real; + + real = polkit_subject_get_real (subject); + egg_dbus_array_seq_add (array, real); + } + + _polkit_authority_handle_enumerate_sessions_finish (_polkit_backend_pending_call_get_method_invocation (pending_call), + array); + + g_object_unref (array); + + g_list_foreach (sessions, (GFunc) g_object_unref, NULL); + g_list_free (sessions); + + g_object_unref (pending_call); +} + +/* ---------------------------------------------------------------------------------------------------- */ + static void authority_handle_check_claim (_PolkitAuthority *instance, _PolkitAuthorizationClaim *real_claim, @@ -237,11 +288,14 @@ polkit_backend_authority_check_claim_finish (PolkitBackendPendingCall *pending_ g_object_unref (pending_call); } +/* ---------------------------------------------------------------------------------------------------- */ + static void authority_iface_init (_PolkitAuthorityIface *authority_iface) { - authority_iface->handle_enumerate_actions = authority_handle_enumerate_actions; - authority_iface->handle_enumerate_users = authority_handle_enumerate_users; - authority_iface->handle_enumerate_groups = authority_handle_enumerate_groups; - authority_iface->handle_check_claim = authority_handle_check_claim; + authority_iface->handle_enumerate_actions = authority_handle_enumerate_actions; + authority_iface->handle_enumerate_users = authority_handle_enumerate_users; + authority_iface->handle_enumerate_groups = authority_handle_enumerate_groups; + authority_iface->handle_enumerate_sessions = authority_handle_enumerate_sessions; + authority_iface->handle_check_claim = authority_handle_check_claim; } diff --git a/src/polkitbackend/polkitbackendsessionmonitor.c b/src/polkitbackend/polkitbackendsessionmonitor.c index ae97423..5284c20 100644 --- a/src/polkitbackend/polkitbackendsessionmonitor.c +++ b/src/polkitbackend/polkitbackendsessionmonitor.c @@ -313,3 +313,39 @@ polkit_backend_session_monitor_new (void) return monitor; } +static gboolean +get_sessions_foreach_cb (EggDBusHashMap *map, + gpointer key, + gpointer value, + gpointer user_data) +{ + GList **l; + const gchar *session_object_path; + PolkitSubject *session; + + l = user_data; + session_object_path = key; + + session = polkit_unix_session_new (session_object_path); + + *l = g_list_prepend (*l, session); + + return FALSE; +} + +GList * +polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monitor) +{ + GList *l; + + l = NULL; + + egg_dbus_hash_map_foreach (monitor->session_object_path_to_object_proxy, + get_sessions_foreach_cb, + &l); + + l = g_list_reverse (l); + + return l; +} + diff --git a/src/polkitbackend/polkitbackendsessionmonitor.h b/src/polkitbackend/polkitbackendsessionmonitor.h index a5a39f9..e5457bb 100644 --- a/src/polkitbackend/polkitbackendsessionmonitor.h +++ b/src/polkitbackend/polkitbackendsessionmonitor.h @@ -43,8 +43,9 @@ typedef struct _PolkitBackendSessionMonitor PolkitBackendSessionMonitor; #endif typedef struct _PolkitBackendSessionMonitorClass PolkitBackendSessionMonitorClass; -GType polkit_backend_session_monitor_get_type (void) G_GNUC_CONST; -PolkitBackendSessionMonitor *polkit_backend_session_monitor_new (void); +GType polkit_backend_session_monitor_get_type (void) G_GNUC_CONST; +PolkitBackendSessionMonitor *polkit_backend_session_monitor_new (void); +GList *polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monitor); G_END_DECLS diff --git a/src/programs/polkit.c b/src/programs/polkit.c index 6c79538..2ad71f6 100644 --- a/src/programs/polkit.c +++ b/src/programs/polkit.c @@ -28,9 +28,10 @@ static PolkitAuthority *authority; -static gboolean opt_list_actions = FALSE; -static gboolean opt_list_users = FALSE; -static gboolean opt_list_groups = FALSE; +static gboolean opt_list_actions = FALSE; +static gboolean opt_list_users = FALSE; +static gboolean opt_list_groups = FALSE; +static gboolean opt_list_sessions = FALSE; static gboolean opt_list_authorizations = FALSE; static gboolean opt_list_explicit_authorizations = FALSE; static gboolean opt_check = FALSE; @@ -49,6 +50,7 @@ static gchar *action_id = NULL; static gboolean list_actions (void); static gboolean list_users (void); static gboolean list_groups (void); +static gboolean list_sessions (void); static gboolean list_authorizations (void); static gboolean check (void); @@ -106,6 +108,10 @@ main (int argc, char *argv[]) { opt_list_groups = TRUE; } + else if (strcmp (argv[n], "sessions") == 0) + { + opt_list_sessions = TRUE; + } else if (strcmp (argv[n], "authorizations") == 0) { opt_list_authorizations = TRUE; @@ -217,6 +223,10 @@ main (int argc, char *argv[]) { ret = list_groups (); } + else if (opt_list_sessions) + { + ret = list_sessions (); + } else if (opt_list_authorizations) { ret = list_authorizations (); @@ -482,6 +492,39 @@ list_groups (void) /* ---------------------------------------------------------------------------------------------------- */ static gboolean +list_sessions (void) +{ + gboolean ret; + GError *error; + GList *subjects; + + ret = FALSE; + + error = NULL; + subjects = polkit_authority_enumerate_sessions_sync (authority, + NULL, + &error); + if (error != NULL) + { + g_printerr ("Error enumerating sessions: %s\n", error->message); + g_error_free (error); + goto out; + } + + print_subjects (subjects); + + g_list_foreach (subjects, (GFunc) g_object_unref, NULL); + g_list_free (subjects); + + ret = TRUE; + + out: + return ret; +} + +/* ---------------------------------------------------------------------------------------------------- */ + +static gboolean check (void) { PolkitAuthorizationResult result; -- 2.7.4