#include "configuration.h"
#include "guest-account.h"
#include "greeter.h"
+#include "session-config.h"
enum {
SESSION_ADDED,
}
static gchar **
-get_session_argv_from_filename (const gchar *filename, const gchar *session_wrapper)
+get_session_argv (SessionConfig *session_config, const gchar *session_wrapper)
{
- GKeyFile *session_desktop_file;
gboolean result;
int argc;
- gchar *command = NULL, **argv, *path;
+ gchar **argv, *path;
GError *error = NULL;
- /* Read the command from the .desktop file */
- session_desktop_file = g_key_file_new ();
- result = g_key_file_load_from_file (session_desktop_file, filename, G_KEY_FILE_NONE, &error);
- if (error)
- g_debug ("Failed to load session file %s: %s", filename, error->message);
- g_clear_error (&error);
- if (result)
- {
- command = g_key_file_get_string (session_desktop_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL);
- if (!command)
- g_debug ("No command in session file %s", filename);
- }
- g_key_file_free (session_desktop_file);
-
- if (!command)
- return NULL;
-
/* If configured, run sessions through a wrapper */
if (session_wrapper)
{
argv = g_malloc (sizeof (gchar *) * 3);
path = g_find_program_in_path (session_wrapper);
argv[0] = path ? path : g_strdup (session_wrapper);
- argv[1] = command;
+ argv[1] = g_strdup (session_config_get_command (session_config));
argv[2] = NULL;
return argv;
}
/* Split command into an array listing and make command absolute */
- result = g_shell_parse_argv (command, &argc, &argv, &error);
+ result = g_shell_parse_argv (session_config_get_command (session_config), &argc, &argv, &error);
if (error)
- g_debug ("Invalid session command '%s': %s", command, error->message);
+ g_debug ("Invalid session command '%s': %s", session_config_get_command (session_config), error->message);
g_clear_error (&error);
- g_free (command);
if (!result)
return NULL;
path = g_find_program_in_path (argv[0]);
return argv;
}
-static gchar **
-get_session_argv (const gchar *sessions_dir, const gchar *session_name, const gchar *session_wrapper)
+static SessionConfig *
+find_session_config (const gchar *sessions_dir, const gchar *session_name)
{
- gchar **dirs, **argv = NULL;
+ gchar **dirs;
+ SessionConfig *session_config = NULL;
int i;
+ GError *error = NULL;
g_return_val_if_fail (sessions_dir != NULL, NULL);
g_return_val_if_fail (session_name != NULL, NULL);
filename = g_strdup_printf ("%s.desktop", session_name);
path = g_build_filename (dirs[i], filename, NULL);
g_free (filename);
- argv = get_session_argv_from_filename (path, session_wrapper);
+ session_config = session_config_new_from_file (path, &error);
g_free (path);
- if (argv)
+ if (session_config)
break;
+
+ if (dirs[i+1] == NULL)
+ g_debug ("Failed to find session configuration %s", session_name);
+ g_clear_error (&error);
}
g_strfreev (dirs);
- return argv;
+ return session_config;
}
static Session *
create_user_session (Seat *seat, const gchar *username)
{
User *user;
- gchar *sessions_dir, **argv;
+ gchar *sessions_dir;
const gchar *session_name, *language;
+ SessionConfig *session_config;
Session *session = NULL;
/* Load user preferences */
if (!session_name)
session_name = seat_get_string_property (seat, "user-session");
sessions_dir = config_get_string (config_get_instance (), "LightDM", "sessions-directory");
- argv = get_session_argv (sessions_dir, session_name, seat_get_string_property (seat, "session-wrapper"));
+ session_config = find_session_config (sessions_dir, session_name);
g_free (sessions_dir);
- if (argv)
+ if (session_config)
{
+ gchar **argv;
+
session = create_session (seat, TRUE);
session_set_env (session, "DESKTOP_SESSION", session_name);
session_set_env (session, "GDMSESSION", session_name);
session_set_pam_service (session, AUTOLOGIN_SERVICE);
session_set_username (session, username);
session_set_do_authenticate (session, TRUE);
- session_set_argv (session, argv);
+ argv = get_session_argv (session_config, seat_get_string_property (seat, "session-wrapper"));
+ session_set_argv (session, argv);
+ g_strfreev (argv);
+
+ g_object_unref (session_config);
}
else
g_debug ("Can't find session '%s'", seat_get_string_property (seat, "user-session"));
+
g_object_unref (user);
return session;
create_guest_session (Seat *seat)
{
gchar *sessions_dir, **argv;
+ SessionConfig *session_config;
Session *session;
sessions_dir = config_get_string (config_get_instance (), "LightDM", "sessions-directory");
- argv = get_session_argv (sessions_dir,
- seat_get_string_property (seat, "user-session"),
- seat_get_string_property (seat, "session-wrapper"));
+ session_config = find_session_config (sessions_dir, seat_get_string_property (seat, "user-session"));
g_free (sessions_dir);
- if (!argv)
+ if (!session_config)
{
g_debug ("Can't find session '%s'", seat_get_string_property (seat, "user-session"));
return NULL;
session = create_session (seat, TRUE);
session_set_do_authenticate (session, TRUE);
session_set_is_guest (session, TRUE);
+ argv = get_session_argv (session_config, seat_get_string_property (seat, "session-wrapper"));
+ g_object_unref (session_config);
session_set_argv (session, argv);
+ g_strfreev (argv);
return session;
}
{
Session *session, *existing_session;
const gchar *username, *language = NULL;
+ SessionConfig *session_config;
User *user;
gchar *sessions_dir = NULL;
gchar **argv;
if (user)
user_set_xsession (session_get_user (session), session_name);
- argv = get_session_argv (sessions_dir, session_name, seat_get_string_property (seat, "session-wrapper"));
+ session_config = find_session_config (sessions_dir, session_name);
g_free (sessions_dir);
-
- if (!argv)
+ if (!session_config)
{
g_debug ("Can't find session '%s'", seat_get_string_property (seat, "user-session"));
return FALSE;
}
+ argv = get_session_argv (session_config, seat_get_string_property (seat, "session-wrapper"));
+ g_object_unref (session_config);
session_set_argv (session, argv);
g_strfreev (argv);
session_set_env (session, "DESKTOP_SESSION", session_name);
create_greeter_session (Seat *seat)
{
gchar *sessions_dir, **argv;
+ SessionConfig *session_config;
Greeter *greeter_session;
gchar *greeter_user;
const gchar *greeter_wrapper;
sessions_dir = config_get_string (config_get_instance (), "LightDM", "greeters-directory");
- argv = get_session_argv (sessions_dir,
- seat_get_string_property (seat, "greeter-session"),
- NULL);
+ session_config = find_session_config (sessions_dir, seat_get_string_property (seat, "greeter-session"));
g_free (sessions_dir);
- if (!argv)
+ if (!session_config)
return NULL;
+ argv = get_session_argv (session_config, NULL);
greeter_wrapper = seat_get_string_property (seat, "greeter-wrapper");
if (greeter_wrapper)
{
session_set_username (SESSION (greeter_session), greeter_user);
g_free (greeter_user);
session_set_argv (SESSION (greeter_session), argv);
+ g_strfreev (argv);
greeter_set_pam_services (greeter_session, USER_SERVICE, AUTOLOGIN_SERVICE);
g_signal_connect (greeter_session, "create-session", G_CALLBACK (greeter_create_session_cb), seat);
greeter_set_hint (greeter_session, "show-remote-login", seat_get_boolean_property (seat, "greeter-show-remote-login") ? "true" : "false");
greeter_set_hint (greeter_session, "has-guest-account", seat_get_allow_guest (seat) && seat_get_boolean_property (seat, "greeter-allow-guest") ? "true" : "false");
+ g_object_unref (session_config);
+
return greeter_session;
}
--- /dev/null
+/*
+ * Copyright (C) 2013 Robert Ancell.
+ * Author: Robert Ancell <robert.ancell@canonical.com>
+ *
+ * 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 "session-config.h"
+
+struct SessionConfigPrivate
+{
+ /* Command to run */
+ gchar *command;
+};
+
+G_DEFINE_TYPE (SessionConfig, session_config, G_TYPE_OBJECT);
+
+SessionConfig *
+session_config_new_from_file (const gchar *filename, GError **error)
+{
+ GKeyFile *desktop_file;
+ SessionConfig *config;
+ gchar *command;
+
+ desktop_file = g_key_file_new ();
+ if (!g_key_file_load_from_file (desktop_file, filename, G_KEY_FILE_NONE, error))
+ return NULL;
+ command = g_key_file_get_string (desktop_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL);
+ if (!command)
+ {
+ g_set_error (error,
+ G_KEY_FILE_ERROR,
+ G_KEY_FILE_ERROR_KEY_NOT_FOUND,
+ "No Exec option in session file: %s", filename);
+ return NULL;
+ }
+
+ config = g_object_new (SESSION_CONFIG_TYPE, NULL);
+ config->priv->command = command;
+
+ g_key_file_free (desktop_file);
+
+ return config;
+}
+
+const gchar *
+session_config_get_command (SessionConfig *config)
+{
+ g_return_val_if_fail (config != NULL, NULL);
+ return config->priv->command;
+}
+
+
+static void
+session_config_init (SessionConfig *config)
+{
+ config->priv = G_TYPE_INSTANCE_GET_PRIVATE (config, SESSION_CONFIG_TYPE, SessionConfigPrivate);
+}
+
+static void
+session_config_finalize (GObject *object)
+{
+ SessionConfig *self = SESSION_CONFIG (object);
+
+ g_free (self->priv->command);
+
+ G_OBJECT_CLASS (session_config_parent_class)->finalize (object);
+}
+
+static void
+session_config_class_init (SessionConfigClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = session_config_finalize;
+
+ g_type_class_add_private (klass, sizeof (SessionConfigPrivate));
+}