@GLIB_GENMARSHAL@ --prefix=ldm_marshal $(srcdir)/ldm-marshal.list --header > ldm-marshal.h
lightdm_SOURCES = \
+ accounts.c \
+ accounts.h \
configuration.c \
configuration.h \
display.c \
display-manager.h \
display-server.c \
display-server.h \
- dmrc.c \
- dmrc.h \
greeter.c \
greeter.h \
guest-account.c \
--- /dev/null
+/* -*- Mode: C; indent-tabs-mode: nil; tab-width: 4 -*-
+ *
+ * Copyright (C) 2011 Canonical Ltd
+ * Author: Michael Terry <michael.terry@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 "accounts.h"
+#include <gio/gio.h>
+
+struct AccountsPrivate
+{
+ GDBusProxy *proxy;
+};
+
+G_DEFINE_TYPE (Accounts, accounts, G_TYPE_OBJECT);
+
+static gboolean
+call_method (GDBusProxy *proxy, const gchar *method, GVariant *args,
+ const gchar *expected, GVariant **result)
+{
+ GVariant *answer;
+ GError *error = NULL;
+
+ answer = g_dbus_proxy_call_sync (proxy,
+ method,
+ args,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (!answer) {
+ g_warning ("Could not call %s: %s", method, error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ if (!g_variant_is_of_type (answer, G_VARIANT_TYPE (expected))) {
+ g_warning ("Unexpected response from %s: %s",
+ method, g_variant_get_type_string (answer));
+ g_variant_unref (answer);
+ return FALSE;
+ }
+
+ if (result)
+ *result = answer;
+ else
+ g_variant_unref (answer);
+ return TRUE;
+}
+
+static gboolean
+get_property (GDBusProxy *proxy, const gchar *property,
+ const gchar *expected, GVariant **result)
+{
+ GVariant *answer;
+
+ answer = g_dbus_proxy_get_cached_property (proxy, property);
+
+ if (!answer) {
+ g_warning ("Could not get accounts property %s", property);
+ return FALSE;
+ }
+
+ if (!g_variant_is_of_type (answer, G_VARIANT_TYPE (expected))) {
+ g_warning ("Unexpected accounts property type for %s: %s",
+ property, g_variant_get_type_string (answer));
+ g_variant_unref (answer);
+ return FALSE;
+ }
+
+ if (result)
+ *result = answer;
+ else
+ g_variant_unref (answer);
+ return TRUE;
+}
+
+Accounts *
+accounts_new (const gchar *user)
+{
+ g_return_val_if_fail (user != NULL, NULL);
+
+ Accounts *accounts;
+ GDBusProxy *proxy;
+ GError *error = NULL;
+ GVariant *result;
+ gboolean success;
+ gchar *user_path = NULL;
+
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.freedesktop.Accounts",
+ "/org/freedesktop/Accounts",
+ "org.freedesktop.Accounts",
+ NULL, &error);
+
+ if (!proxy) {
+ g_warning ("Could not get accounts proxy: %s", error->message);
+ g_error_free (error);
+ return NULL;
+ }
+
+ success = call_method (proxy, "FindUserByName", g_variant_new ("(s)", user),
+ "(o)", &result);
+ g_object_unref (proxy);
+
+ if (!success)
+ return NULL;
+
+ g_variant_get (result, "(o)", &user_path);
+ g_variant_unref (result);
+
+ if (!user_path)
+ return NULL;
+
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.freedesktop.Accounts",
+ user_path,
+ "org.freedesktop.Accounts.User",
+ NULL, &error);
+ g_free (user_path);
+
+ if (!proxy) {
+ g_warning ("Could not get accounts user proxy: %s", error->message);
+ g_error_free (error);
+ return NULL;
+ }
+
+ accounts = g_object_new (ACCOUNTS_TYPE, NULL);
+ accounts->priv->proxy = proxy;
+ return accounts;
+}
+
+void
+accounts_set_session (Accounts *accounts, const gchar *session)
+{
+ g_return_if_fail (accounts != NULL);
+
+ call_method (accounts->priv->proxy, "SetXSession",
+ g_variant_new ("(s)", session), "()", NULL);
+}
+
+gchar *
+accounts_get_session (Accounts *accounts)
+{
+ g_return_val_if_fail (accounts != NULL, NULL);
+
+ GVariant *result;
+ gchar *session;
+
+ if (!get_property (accounts->priv->proxy, "XSession",
+ "s", &result))
+ return NULL;
+
+ g_variant_get (result, "s", &session);
+ g_variant_unref (result);
+
+ if (g_strcmp0 (session, "") == 0) {
+ g_free (session);
+ return NULL;
+ }
+
+ return session;
+}
+
+static void
+accounts_init (Accounts *accounts)
+{
+ accounts->priv = G_TYPE_INSTANCE_GET_PRIVATE (accounts, ACCOUNTS_TYPE, AccountsPrivate);
+}
+
+static void
+accounts_dispose (GObject *object)
+{
+ Accounts *self;
+
+ self = ACCOUNTS (object);
+
+ if (self->priv->proxy) {
+ g_object_unref (self->priv->proxy);
+ self->priv->proxy = NULL;
+ }
+
+ G_OBJECT_CLASS (accounts_parent_class)->dispose (object);
+}
+
+static void
+accounts_class_init (AccountsClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = accounts_dispose;
+
+ g_type_class_add_private (klass, sizeof (AccountsPrivate));
+}
--- /dev/null
+/*
+ * Copyright (C) 2011 Canonical Ltd
+ * Author: Michael Terry <michael.terry@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.
+ */
+
+#ifndef _ACCOUNTS_H_
+#define _ACCOUNTS_H_
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define ACCOUNTS_TYPE (accounts_get_type())
+#define ACCOUNTS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ACCOUNTS_TYPE, Accounts));
+
+typedef struct AccountsPrivate AccountsPrivate;
+
+typedef struct
+{
+ GObject parent_instance;
+ AccountsPrivate *priv;
+} Accounts;
+
+typedef struct
+{
+ GObjectClass parent_class;
+} AccountsClass;
+
+GType accounts_get_type (void);
+
+Accounts *accounts_new (const gchar *user);
+
+void accounts_set_session (Accounts *accounts, const gchar *section);
+
+gchar *accounts_get_session (Accounts *accounts);
+
+G_END_DECLS
+
+#endif /* _ACCOUNTS_H_ */
#include "configuration.h"
#include "user.h"
#include "pam-session.h"
-#include "dmrc.h"
+#include "accounts.h"
#include "ldm-marshal.h"
#include "greeter.h"
#include "xserver-local.h" // FIXME: Shouldn't know if it's an xserver
start_user_session (Display *display, PAMSession *authentication)
{
User *user;
- GKeyFile *dmrc_file;
+ Accounts *accounts;
gchar *log_filename;
gboolean result = FALSE;
user = pam_session_get_user (authentication);
- /* Load the users login settings (~/.dmrc) */
- dmrc_file = dmrc_load (user_get_name (user));
-
- /* Update the .dmrc with changed settings */
- g_key_file_set_string (dmrc_file, "Desktop", "Session", display->priv->user_session);
- dmrc_save (dmrc_file, user_get_name (user));
- g_key_file_free (dmrc_file);
+ /* Update user's xsession setting */
+ accounts = accounts_new (user_get_name (user));
+ accounts_set_session (accounts, display->priv->user_session);
+ g_object_unref (accounts);
// FIXME: Copy old error file
log_filename = g_build_filename (user_get_home_directory (user), ".xsession-errors", NULL);
+++ /dev/null
-/*
- * Copyright (C) 2010-2011 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 <errno.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "dmrc.h"
-#include "configuration.h"
-#include "user.h"
-
-GKeyFile *
-dmrc_load (const gchar *username)
-{
- User *user;
- GKeyFile *dmrc_file;
- gchar *path;
- gboolean have_dmrc;
-
- dmrc_file = g_key_file_new ();
-
- user = user_get_by_name (username);
- if (!user)
- {
- g_warning ("Cannot load .dmrc file, unable to get information on user %s", username);
- return dmrc_file;
- }
-
- /* Load from the user directory, if this fails (e.g. the user directory
- * is not yet mounted) then load from the cache */
- path = g_build_filename (user_get_home_directory (user), ".dmrc", NULL);
- have_dmrc = g_key_file_load_from_file (dmrc_file, path, G_KEY_FILE_KEEP_COMMENTS, NULL);
- g_free (path);
-
- /* If no ~/.dmrc, then load from the cache */
- if (!have_dmrc)
- {
- gchar *filename, *cache_dir;
-
- filename = g_strdup_printf ("%s.dmrc", user_get_name (user));
- cache_dir = config_get_string (config_get_instance (), "LightDM", "cache-directory");
- path = g_build_filename (cache_dir, "dmrc", filename, NULL);
- g_free (filename);
- g_free (cache_dir);
-
- g_key_file_load_from_file (dmrc_file, path, G_KEY_FILE_KEEP_COMMENTS, NULL);
- g_free (path);
- }
-
- g_object_unref (user);
-
- return dmrc_file;
-}
-
-void
-dmrc_save (GKeyFile *dmrc_file, const gchar *username)
-{
- User *user;
- gchar *path, *filename, *cache_dir, *dmrc_cache_dir;
- gchar *data;
- gsize length;
-
- user = user_get_by_name (username);
- if (!user)
- {
- g_warning ("Not saving DMRC file - unable to get information on user %s", username);
- return;
- }
-
- data = g_key_file_to_data (dmrc_file, &length, NULL);
-
- /* Update the users .dmrc */
- if (user)
- {
- path = g_build_filename (user_get_home_directory (user), ".dmrc", NULL);
- g_file_set_contents (path, data, length, NULL);
- if (getuid () == 0 && chown (path, user_get_uid (user), user_get_gid (user)) < 0)
- g_warning ("Error setting ownership on %s: %s", path, strerror (errno));
- g_free (path);
- }
-
- /* Update the .dmrc cache */
- cache_dir = config_get_string (config_get_instance (), "LightDM", "cache-directory");
- dmrc_cache_dir = g_build_filename (cache_dir, "dmrc", NULL);
- g_mkdir_with_parents (dmrc_cache_dir, 0700);
-
- filename = g_strdup_printf ("%s.dmrc", username);
- path = g_build_filename (dmrc_cache_dir, filename, NULL);
- g_file_set_contents (path, data, length, NULL);
-
- g_free (dmrc_cache_dir);
- g_free (path);
- g_free (filename);
- g_object_unref (user);
-}
+++ /dev/null
-/*
- * Copyright (C) 2010-2011 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.
- */
-
-#ifndef _DMRC_H_
-#define _DMRC_H_
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-GKeyFile *dmrc_load (const gchar *username);
-
-void dmrc_save (GKeyFile *dmrc_file, const gchar *username);
-
-G_END_DECLS
-
-#endif /* _DMRC_H_ */