summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Nagy <robert@openbsd.org>2021-07-04 09:37:53 +0200
committerRobert Nagy <robert@openbsd.org>2021-07-04 09:37:53 +0200
commitf9d64a5128fc30a6cd65e0ffcc530d5255c1fa6c (patch)
tree5f22d35ebbc9d4f11e34d6dd60dc6e17714cc1b7
parent2618521ef21071643283a2e28f7e8510f12fe9e9 (diff)
downloadConsoleKit2-f9d64a5128fc30a6cd65e0ffcc530d5255c1fa6c.tar.gz
add a session-service parameter mainly to be used by gdm
this commit also adds GetSessionService so that the session service can be queried over dbus
-rw-r--r--data/ConsoleKit.conf3
-rw-r--r--libconsolekit/libconsolekit.c85
-rw-r--r--src/ck-session-leader.c1
-rw-r--r--src/ck-session.c46
-rw-r--r--src/org.freedesktop.ConsoleKit.Session.xml21
5 files changed, 156 insertions, 0 deletions
diff --git a/data/ConsoleKit.conf b/data/ConsoleKit.conf
index 216a0e9..81e52eb 100644
--- a/data/ConsoleKit.conf
+++ b/data/ConsoleKit.conf
@@ -154,6 +154,9 @@
send_member="GetLoginSessionId"/>
<allow send_destination="org.freedesktop.ConsoleKit"
send_interface="org.freedesktop.ConsoleKit.Session"
+ send_member="GetSessionService"/>
+ <allow send_destination="org.freedesktop.ConsoleKit"
+ send_interface="org.freedesktop.ConsoleKit.Session"
send_member="GetSessionType"/>
<allow send_destination="org.freedesktop.ConsoleKit"
send_interface="org.freedesktop.ConsoleKit.Session"
diff --git a/libconsolekit/libconsolekit.c b/libconsolekit/libconsolekit.c
index 52c9f84..6d6693f 100644
--- a/libconsolekit/libconsolekit.c
+++ b/libconsolekit/libconsolekit.c
@@ -743,6 +743,91 @@ lib_consolekit_session_get_seat (LibConsoleKit *ck,
}
/**
+ * lib_consolekit_session_get_service:
+ * @ck : A #LibConsoleKit
+ * @session : The session to query
+ * @service : (out) (transfer full): The session's service
+ * @error : (out) (allow-none) (transfer full): The error message if something failed
+ *
+ * Returns the service of the provided session. Defaults to:
+ * "unspecified" - Unknown session service.
+ *
+ * Return value: TRUE on Success.
+ *
+ * Since: 1.2.4
+ **/
+gboolean
+lib_consolekit_session_get_service (LibConsoleKit *ck,
+ const gchar *session,
+ gchar **service,
+ GError **error)
+{
+ GDBusProxy *session_proxy = NULL;
+ GVariant *variant = NULL;
+
+ if (ck == NULL) {
+ g_set_error (error,
+ CONSOLEKIT_ERROR,
+ CONSOLEKIT_ERROR_INVALID_INPUT,
+ "Invalid LibConsoleKit");
+ return FALSE;
+ }
+
+ if (session == NULL) {
+ g_set_error (error,
+ CONSOLEKIT_ERROR,
+ CONSOLEKIT_ERROR_INVALID_INPUT,
+ "Session must not be NULL");
+ return FALSE;
+ }
+
+ if (service == NULL) {
+ g_set_error (error,
+ CONSOLEKIT_ERROR,
+ CONSOLEKIT_ERROR_INVALID_INPUT,
+ "service must not be NULL");
+ return FALSE;
+ }
+
+ /* connect to the ConsoleKit session */
+ session_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ NULL,
+ CK_NAME,
+ session,
+ CK_SESSION_NAME,
+ NULL,
+ error);
+
+ /* failed to connect */
+ if (session_proxy == NULL) {
+ return FALSE;
+ }
+
+ variant = g_dbus_proxy_call_sync (session_proxy,
+ "GetSessionService",
+ g_variant_new ("()"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ error);
+
+ /* We're done with the session proxy */
+ g_clear_object(&session_proxy);
+
+ if (variant == NULL) {
+ return FALSE;
+ }
+
+ g_variant_get_child (variant, 0, "s", service);
+
+ g_variant_unref (variant);
+ variant = NULL;
+
+ return TRUE;
+}
+
+/**
* lib_consolekit_session_get_type:
* @ck : A #LibConsoleKit
* @session : The session to query
diff --git a/src/ck-session-leader.c b/src/ck-session-leader.c
index bc46147..96c93b5 100644
--- a/src/ck-session-leader.c
+++ b/src/ck-session-leader.c
@@ -51,6 +51,7 @@ static struct {
{ "remote-host-name", "s", G_TYPE_STRING },
{ "session-type", "s", G_TYPE_STRING },
{ "session-class", "s", G_TYPE_STRING },
+ { "session-service", "s", G_TYPE_STRING },
{ "is-local", "b", G_TYPE_BOOLEAN },
{ "unix-user", "i", G_TYPE_INT },
{ "user", "i", G_TYPE_INT },
diff --git a/src/ck-session.c b/src/ck-session.c
index 8a35044..14a09a1 100644
--- a/src/ck-session.c
+++ b/src/ck-session.c
@@ -261,6 +261,11 @@ register_session (CkSession *session, GDBusConnection *connection)
console_kit_session_set_session_type (CONSOLE_KIT_SESSION (session), "unspecified");
}
+ /* default to unspecified for the session service on startup */
+ if (console_kit_session_get_session_service (CONSOLE_KIT_SESSION (session)) == NULL) {
+ console_kit_session_set_session_service (CONSOLE_KIT_SESSION (session), "unspecified");
+ }
+
/* default to user for the session class on startup */
if (console_kit_session_get_session_class (CONSOLE_KIT_SESSION (session)) == NULL) {
console_kit_session_set_session_class (CONSOLE_KIT_SESSION (session), "user");
@@ -539,6 +544,23 @@ dbus_set_locked_hint (ConsoleKitSession *cksession,
}
static gboolean
+dbus_get_session_service (ConsoleKitSession *cksession,
+ GDBusMethodInvocation *context)
+{
+ const gchar *session_service = console_kit_session_get_session_service (cksession);
+
+ TRACE ();
+
+ if (session_service == NULL) {
+ /* default to unspecified */
+ session_service = "unspecified";
+ }
+
+ console_kit_session_complete_get_session_service (cksession, context, session_service);
+ return TRUE;
+}
+
+static gboolean
dbus_get_session_type (ConsoleKitSession *cksession,
GDBusMethodInvocation *context)
{
@@ -1369,6 +1391,20 @@ ck_session_set_login_session_id (CkSession *session,
}
gboolean
+ck_session_set_session_service (CkSession *session,
+ const char *service,
+ GError **error)
+{
+ ConsoleKitSession *cksession = CONSOLE_KIT_SESSION (session);
+
+ g_return_val_if_fail (CK_IS_SESSION (session), FALSE);
+
+ console_kit_session_set_session_service (cksession, service);
+
+ return TRUE;
+}
+
+gboolean
ck_session_set_session_type (CkSession *session,
const char *type,
GError **error)
@@ -2080,6 +2116,7 @@ ck_session_iface_init (ConsoleKitSessionIface *iface)
iface->handle_get_seat_id = dbus_get_seat_id;
iface->handle_get_login_session_id = dbus_get_login_session_id;
iface->handle_get_vtnr = dbus_get_vtnr;
+ iface->handle_get_session_service = dbus_get_session_service;
iface->handle_get_session_type = dbus_get_session_type;
iface->handle_get_session_class = dbus_get_session_class;
iface->handle_get_session_state = dbus_get_session_state;
@@ -2294,6 +2331,9 @@ ck_session_run_programs (CkSession *session,
cksession = CONSOLE_KIT_SESSION (session);
extra_env[n++] = g_strdup_printf ("CK_SESSION_ID=%s", session->priv->id);
+ if (console_kit_session_get_session_service (cksession) != NULL) {
+ extra_env[n++] = g_strdup_printf ("CK_SESSION_SERVICE=%s", console_kit_session_get_session_service (cksession));
+ }
if (console_kit_session_get_session_type (cksession) != NULL) {
extra_env[n++] = g_strdup_printf ("CK_SESSION_TYPE=%s", console_kit_session_get_session_type (cksession));
}
@@ -2342,6 +2382,12 @@ ck_session_dump (CkSession *session,
group_name,
"seat",
NONULL_STRING (session->priv->seat_id));
+ if (console_kit_session_get_session_service (cksession) != NULL) {
+ g_key_file_set_string (key_file,
+ group_name,
+ "service",
+ NONULL_STRING (console_kit_session_get_session_service (cksession)));
+ }
if (console_kit_session_get_session_type (cksession) != NULL) {
g_key_file_set_string (key_file,
group_name,
diff --git a/src/org.freedesktop.ConsoleKit.Session.xml b/src/org.freedesktop.ConsoleKit.Session.xml
index 97ceb64..20fd204 100644
--- a/src/org.freedesktop.ConsoleKit.Session.xml
+++ b/src/org.freedesktop.ConsoleKit.Session.xml
@@ -37,6 +37,20 @@
<doc:seealso><doc:ref type="interface" to="Seat">org.freedesktop.ConsoleKit.Seat</doc:ref></doc:seealso>
</doc:doc>
</method>
+ <method name="GetSessionService">
+ <arg name="type" direction="out" type="s">
+ <doc:doc>
+ <doc:summary>Session service</doc:summary>
+ </doc:doc>
+ </arg>
+ <doc:doc>
+ <doc:description>
+ <doc:para>Returns the service of the provided session. Defaults to:</doc:para>
+ <doc:para>"unspecified" - Unknown session type, the default.</doc:para>
+ </doc:description>
+ <doc:seealso><doc:ref type="property" to="Session:session-service">session-service</doc:ref></doc:seealso>
+ </doc:doc>
+ </method>
<method name="GetSessionType">
<arg name="type" direction="out" type="s">
<doc:doc>
@@ -643,6 +657,13 @@
</doc:description>
</doc:doc>
</property>
+ <property name="session-service" type="s" access="read">
+ <doc:doc>
+ <doc:description>
+ <doc:para>The service of the session.</doc:para>
+ </doc:description>
+ </doc:doc>
+ </property>
<property name="session-type" type="s" access="read">
<doc:doc>
<doc:description>