diff -urN lightdm-1.5.0.orig/src/Makefile.am lightdm-1.5.0/src/Makefile.am --- lightdm-1.5.0.orig/src/Makefile.am 2013-01-31 21:28:23.000000000 +0100 +++ lightdm-1.5.0/src/Makefile.am 2013-02-08 21:21:13.505010102 +0100 @@ -48,6 +48,8 @@ session.h \ session-child.c \ session-child.h \ + systemd-logind.c \ + systemd-logind.h \ vnc-server.c \ vnc-server.h \ vt.c \ diff -urN lightdm-1.5.0.orig/src/session-child.c lightdm-1.5.0/src/session-child.c --- lightdm-1.5.0.orig/src/session-child.c 2013-01-31 21:28:23.000000000 +0100 +++ lightdm-1.5.0/src/session-child.c 2013-02-08 21:11:35.682274318 +0100 @@ -189,7 +189,8 @@ XAuthority *xauthority = NULL; gchar *xauth_filename; GDBusConnection *bus; - gchar *console_kit_cookie; + gchar *systemd_logind_session; + gchar *console_kit_cookie = NULL; const gchar *path; GError *error = NULL; @@ -418,34 +419,41 @@ if (!bus) return EXIT_FAILURE; + /* Open a logind session */ + systemd_logind_session = sl_open_session (); + write_string (systemd_logind_session); + /* Open a Console Kit session */ - g_variant_builder_init (&ck_parameters, G_VARIANT_TYPE ("(a(sv))")); - g_variant_builder_open (&ck_parameters, G_VARIANT_TYPE ("a(sv)")); - g_variant_builder_add (&ck_parameters, "(sv)", "unix-user", g_variant_new_int32 (user_get_uid (user))); - if (g_strcmp0 (class, XDG_SESSION_CLASS_GREETER) == 0) - g_variant_builder_add (&ck_parameters, "(sv)", "session-type", g_variant_new_string ("LoginWindow")); - if (xdisplay) + if (systemd_logind_session == NULL) { - g_variant_builder_add (&ck_parameters, "(sv)", "x11-display", g_variant_new_string (xdisplay)); - if (tty) - g_variant_builder_add (&ck_parameters, "(sv)", "x11-display-device", g_variant_new_string (tty)); - } - if (remote_host_name) - { - g_variant_builder_add (&ck_parameters, "(sv)", "is-local", g_variant_new_boolean (FALSE)); - g_variant_builder_add (&ck_parameters, "(sv)", "remote-host-name", g_variant_new_string (remote_host_name)); + g_variant_builder_init (&ck_parameters, G_VARIANT_TYPE ("(a(sv))")); + g_variant_builder_open (&ck_parameters, G_VARIANT_TYPE ("a(sv)")); + g_variant_builder_add (&ck_parameters, "(sv)", "unix-user", g_variant_new_int32 (user_get_uid (user))); + if (g_strcmp0 (class, XDG_SESSION_CLASS_GREETER) == 0) + g_variant_builder_add (&ck_parameters, "(sv)", "session-type", g_variant_new_string ("LoginWindow")); + if (xdisplay) + { + g_variant_builder_add (&ck_parameters, "(sv)", "x11-display", g_variant_new_string (xdisplay)); + if (tty) + g_variant_builder_add (&ck_parameters, "(sv)", "x11-display-device", g_variant_new_string (tty)); + } + if (remote_host_name) + { + g_variant_builder_add (&ck_parameters, "(sv)", "is-local", g_variant_new_boolean (FALSE)); + g_variant_builder_add (&ck_parameters, "(sv)", "remote-host-name", g_variant_new_string (remote_host_name)); + } + else + g_variant_builder_add (&ck_parameters, "(sv)", "is-local", g_variant_new_boolean (TRUE)); + console_kit_cookie = ck_open_session (&ck_parameters); + if (console_kit_cookie) + { + gchar *value; + value = g_strdup_printf ("XDG_SESSION_COOKIE=%s", console_kit_cookie); + pam_putenv (pam_handle, value); + g_free (value); + } } - else - g_variant_builder_add (&ck_parameters, "(sv)", "is-local", g_variant_new_boolean (TRUE)); - console_kit_cookie = ck_open_session (&ck_parameters); write_string (console_kit_cookie); - if (console_kit_cookie) - { - gchar *value; - value = g_strdup_printf ("XDG_SESSION_COOKIE=%s", console_kit_cookie); - pam_putenv (pam_handle, value); - g_free (value); - } /* Write X authority */ if (xauthority) @@ -625,6 +633,10 @@ _exit (EXIT_FAILURE); } + /* Close the logind session */ + if (systemd_logind_session) + sl_close_session (systemd_logind_session); + /* Close the Console Kit session */ if (console_kit_cookie) ck_close_session (console_kit_cookie); diff -urN lightdm-1.5.0.orig/src/session.c lightdm-1.5.0/src/session.c --- lightdm-1.5.0.orig/src/session.c 2012-08-29 23:25:16.000000000 +0200 +++ lightdm-1.5.0/src/session.c 2013-02-08 21:15:28.539346907 +0100 @@ -21,6 +21,7 @@ #include "session.h" #include "configuration.h" +#include "systemd-logind.h" #include "console-kit.h" #include "guest-account.h" @@ -80,6 +81,9 @@ /* Remote host this session is being controlled from */ gchar *remote_host_name; + /* logind session */ + gchar *systmed_logind_session; + /* Console kit cookie */ gchar *console_kit_cookie; @@ -558,6 +562,7 @@ for (i = 0; i < argc; i++) write_string (session, argv[i]); + session->priv->systmed_logind_session = read_string_from_child (session); session->priv->console_kit_cookie = read_string_from_child (session); } @@ -566,7 +571,12 @@ { g_return_if_fail (session != NULL); if (getuid () == 0) - ck_lock_session (session->priv->console_kit_cookie); + { + if (session->priv->systmed_logind_session) + sl_lock_session (session->priv->systmed_logind_session); + if (session->priv->console_kit_cookie) + ck_lock_session (session->priv->console_kit_cookie); + } } void @@ -574,7 +584,12 @@ { g_return_if_fail (session != NULL); if (getuid () == 0) - ck_unlock_session (session->priv->console_kit_cookie); + { + if (session->priv->systmed_logind_session) + sl_unlock_session (session->priv->systmed_logind_session); + if (session->priv->console_kit_cookie) + ck_unlock_session (session->priv->console_kit_cookie); + } } void @@ -631,6 +646,7 @@ if (self->priv->xauthority) g_object_unref (self->priv->xauthority); g_free (self->priv->remote_host_name); + g_free (self->priv->systmed_logind_session); g_free (self->priv->console_kit_cookie); g_list_free_full (self->priv->env, g_free); diff -urN lightdm-1.5.0.orig/src/systemd-logind.c lightdm-1.5.0/src/systemd-logind.c --- lightdm-1.5.0.orig/src/systemd-logind.c 1970-01-01 01:00:00.000000000 +0100 +++ lightdm-1.5.0/src/systemd-logind.c 2013-02-08 21:30:07.918291618 +0100 @@ -0,0 +1,142 @@ +/* -*- Mode: C; indent-tabs-mode: nil; tab-width: 4 -*- + * + * Copyright (C) 2010-2011 Robert Ancell. + * Author: Robert Ancell + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. See http://www.gnu.org/copyleft/gpl.html the full text of the + * license. + */ + +#include + +#include "systemd-logind.h" + +gchar * +sl_open_session (void) +{ + GDBusConnection *bus; + GVariant *result; + gchar *session_path; + GError *error = NULL; + + bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); + if (error) + g_warning ("Failed to get system bus: %s", error->message); + g_clear_error (&error); + if (!bus) + return NULL; + result = g_dbus_connection_call_sync (bus, + "org.freedesktop.login1", + "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + "GetSessionByPID", + g_variant_new ("(u)", getpid()), + G_VARIANT_TYPE ("(o)"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + g_object_unref (bus); + + if (error) + g_warning ("Failed to open logind session: %s", error->message); + g_clear_error (&error); + if (!result) + return NULL; + + g_variant_get (result, "(o)", &session_path); + g_variant_unref (result); + g_debug ("Opened logind session %s", session_path); + + return session_path; +} + +void +sl_lock_session (const gchar *session_path) +{ + GDBusConnection *bus; + GError *error = NULL; + + g_return_if_fail (session_path != NULL); + + g_debug ("Locking logind session %s", session_path); + + bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); + if (error) + g_warning ("Failed to get system bus: %s", error->message); + g_clear_error (&error); + if (!bus) + return; + + if (session_path) + { + GVariant *result; + + result = g_dbus_connection_call_sync (bus, + "org.freedesktop.login1", + session_path, + "org.freedesktop.login1.Session", + "Lock", + g_variant_new ("()"), + G_VARIANT_TYPE ("()"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (error) + g_warning ("Error locking logind session: %s", error->message); + g_clear_error (&error); + if (result) + g_variant_unref (result); + } + g_object_unref (bus); +} + +void +sl_unlock_session (const gchar *session_path) +{ + GDBusConnection *bus; + GError *error = NULL; + + g_return_if_fail (session_path != NULL); + + g_debug ("Unlocking logind session %s", session_path); + + bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); + if (error) + g_warning ("Failed to get system bus: %s", error->message); + g_clear_error (&error); + if (!bus) + return; + + if (session_path) + { + GVariant *result; + + result = g_dbus_connection_call_sync (bus, + "org.freedesktop.login1", + session_path, + "org.freedesktop.login1.Session", + "Unlock", + g_variant_new ("()"), + G_VARIANT_TYPE ("()"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (error) + g_warning ("Error unlocking logind session: %s", error->message); + g_clear_error (&error); + if (result) + g_variant_unref (result); + } + g_object_unref (bus); +} + +void +sl_close_session (const gchar *session_path) +{ +} diff -urN lightdm-1.5.0.orig/src/systemd-logind.h lightdm-1.5.0/src/systemd-logind.h --- lightdm-1.5.0.orig/src/systemd-logind.h 1970-01-01 01:00:00.000000000 +0100 +++ lightdm-1.5.0/src/systemd-logind.h 2013-02-08 21:14:52.769796592 +0100 @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2010-2011 Robert Ancell. + * Author: Robert Ancell + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. See http://www.gnu.org/copyleft/gpl.html the full text of the + * license. + */ + +#ifndef _SYSTEMD_LOGIND_H_ +#define _SYSTEMD_LOGIND_H_ + +#include + +G_BEGIN_DECLS + +gchar *sl_open_session (void); + +void sl_lock_session (const gchar *session_path); + +void sl_unlock_session (const gchar *session_path); + +void sl_close_session (const gchar *session_path); + +G_END_DECLS + +#endif /* _SYSTEMD_LOGIND_H_ */