[gdm] simple-slave: Change g-i-s' home directory ownership to created user
- From: Rui Matos <rtcm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdm] simple-slave: Change g-i-s' home directory ownership to created user
- Date: Thu, 6 Jun 2013 08:20:03 +0000 (UTC)
commit 3f7ac6f865cccd77a2b632fa55667f9168947c2b
Author: Rui Matos <tiagomatos gmail com>
Date: Sun Jun 2 19:45:48 2013 +0200
simple-slave: Change g-i-s' home directory ownership to created user
We do this at the end of the gnome-initial-setup special session,
before logging in to the newly created user account.
This allows the user session's gnome-initial-setup instance to
manipulate files here.
https://bugzilla.gnome.org/show_bug.cgi?id=701473
daemon/gdm-simple-slave.c | 123 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 123 insertions(+), 0 deletions(-)
---
diff --git a/daemon/gdm-simple-slave.c b/daemon/gdm-simple-slave.c
index d61c62e..df586ce 100644
--- a/daemon/gdm-simple-slave.c
+++ b/daemon/gdm-simple-slave.c
@@ -104,6 +104,7 @@ struct GdmSimpleSlavePrivate
#ifdef WITH_PLYMOUTH
guint plymouth_is_running : 1;
#endif
+ guint doing_initial_setup : 1;
};
enum {
@@ -129,6 +130,123 @@ static void start_session (GdmSimpleSlave *slave);
static void queue_start_session (GdmSimpleSlave *slave,
const char *service_name);
+static gboolean
+chown_file (GFile *file,
+ uid_t uid,
+ gid_t gid,
+ GError **error)
+{
+ if (!g_file_set_attribute_uint32 (file, G_FILE_ATTRIBUTE_UNIX_UID, uid,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL, error)) {
+ return FALSE;
+ }
+ if (!g_file_set_attribute_uint32 (file, G_FILE_ATTRIBUTE_UNIX_GID, gid,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL, error)) {
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static gboolean
+chown_recursively (GFile *dir,
+ uid_t uid,
+ gid_t gid,
+ GError **error)
+{
+ GFile *file = NULL;
+ GFileInfo *info = NULL;
+ GFileEnumerator *enumerator = NULL;
+ gboolean retval = FALSE;
+
+ if (chown_file (dir, uid, gid, error) == FALSE) {
+ goto out;
+ }
+
+ enumerator = g_file_enumerate_children (dir,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE","
+ G_FILE_ATTRIBUTE_STANDARD_NAME,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL, error);
+ if (!enumerator) {
+ goto out;
+ }
+
+ while ((info = g_file_enumerator_next_file (enumerator, NULL, error)) != NULL) {
+ file = g_file_get_child (dir, g_file_info_get_name (info));
+
+ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
+ if (chown_recursively (file, uid, gid, error) == FALSE) {
+ goto out;
+ }
+ } else if (chown_file (file, uid, gid, error) == FALSE) {
+ goto out;
+ }
+
+ g_clear_object (&file);
+ g_clear_object (&info);
+ }
+
+ if (*error) {
+ goto out;
+ }
+
+ retval = TRUE;
+out:
+ g_clear_object (&file);
+ g_clear_object (&info);
+ g_clear_object (&enumerator);
+
+ return retval;
+}
+
+static void
+chown_initial_setup_home_dir (void)
+{
+ GFile *dir;
+ GError *error;
+ char *gis_dir_path;
+ char *gis_uid_path;
+ char *gis_uid_contents;
+ struct passwd *pwe;
+ uid_t uid;
+
+ if (!gdm_get_pwent_for_name (INITIAL_SETUP_USERNAME, &pwe)) {
+ g_warning ("Unknown user %s", INITIAL_SETUP_USERNAME);
+ return;
+ }
+
+ gis_dir_path = g_strdup (pwe->pw_dir);
+
+ gis_uid_path = g_build_filename (gis_dir_path,
+ "gnome-initial-setup-uid",
+ NULL);
+ if (!g_file_get_contents (gis_uid_path, &gis_uid_contents, NULL, NULL)) {
+ g_warning ("Unable to read %s", gis_uid_path);
+ goto out;
+ }
+
+ uid = (uid_t) atoi (gis_uid_contents);
+ pwe = getpwuid (uid);
+ if (uid == 0 || pwe == NULL) {
+ g_warning ("UID '%s' in %s is not valid", gis_uid_contents, gis_uid_path);
+ goto out;
+ }
+
+ error = NULL;
+ dir = g_file_new_for_path (gis_dir_path);
+ if (!chown_recursively (dir, pwe->pw_uid, pwe->pw_gid, &error)) {
+ g_warning ("Failed to change ownership for %s: %s", gis_dir_path, error->message);
+ g_error_free (error);
+ }
+ g_object_unref (dir);
+out:
+ g_free (gis_uid_contents);
+ g_free (gis_uid_path);
+ g_free (gis_dir_path);
+}
+
static void
on_session_started (GdmSession *session,
const char *service_name,
@@ -385,6 +503,10 @@ start_session (GdmSimpleSlave *slave)
g_free (auth_file);
+ if (slave->priv->doing_initial_setup) {
+ chown_initial_setup_home_dir ();
+ }
+
gdm_session_start_session (slave->priv->session,
slave->priv->start_session_service_name);
@@ -1166,6 +1288,7 @@ start_greeter (GdmSimpleSlave *slave)
static void
start_initial_setup (GdmSimpleSlave *slave)
{
+ slave->priv->doing_initial_setup = TRUE;
start_launch_environment (slave, INITIAL_SETUP_USERNAME, "gnome-initial-setup");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]