diff options
author | Michael Terry <michael.terry@canonical.com> | 2014-02-18 15:22:31 -0500 |
---|---|---|
committer | Michael Terry <michael.terry@canonical.com> | 2014-02-18 15:22:31 -0500 |
commit | 02c262c40c904a57e2981e90543321dba7094c3c (patch) | |
tree | 90bf7766338b3b82c1adfe3c2668f980e75963b7 /src | |
parent | d76a74ec30d44167976b7e3175260f3e6b596a0a (diff) | |
download | lightdm-02c262c40c904a57e2981e90543321dba7094c3c.tar.gz |
Use usernames for users for shared data dirs rather than uids
Diffstat (limited to 'src')
-rw-r--r-- | src/shared-data-manager.c | 50 |
1 files changed, 18 insertions, 32 deletions
diff --git a/src/shared-data-manager.c b/src/shared-data-manager.c index fe803dc0..d4b4c188 100644 --- a/src/shared-data-manager.c +++ b/src/shared-data-manager.c @@ -23,7 +23,7 @@ struct SharedDataManagerPrivate { - guint32 greeter_uid; + gchar *greeter_user; guint32 greeter_gid; GHashTable *starting_dirs; }; @@ -142,18 +142,20 @@ make_user_dir_cb (GObject *object, GAsyncResult *res, gpointer user_data) g_free (owner); } -static void -setup_user_dir (SharedDataManager *manager, guint32 uid) +void +shared_data_manager_ensure_user_dir (SharedDataManager *manager, const gchar *user) { + struct passwd *entry = getpwnam (user); + if (!entry) + return; + struct OwnerInfo *owner = g_malloc (sizeof (struct OwnerInfo)); owner->manager = g_object_ref (manager); - owner->uid = uid; + owner->uid = entry->pw_uid; - gchar *uidstr = g_strdup_printf ("%u", uid); - gchar *path = g_build_filename (USERS_DIR, uidstr, NULL); + gchar *path = g_build_filename (USERS_DIR, user, NULL); GFile *file = g_file_new_for_path (path); g_free (path); - g_free (uidstr); g_file_make_directory_async (file, G_PRIORITY_DEFAULT, NULL, make_user_dir_cb, owner); @@ -161,15 +163,6 @@ setup_user_dir (SharedDataManager *manager, guint32 uid) g_object_unref (file); } -void -shared_data_manager_ensure_user_dir (SharedDataManager *manager, const gchar *user) -{ - struct passwd *entry; - entry = getpwnam (user); - if (entry) - setup_user_dir (manager, entry->pw_uid); -} - static void next_user_dirs_cb (GObject *object, GAsyncResult *res, gpointer user_data) { @@ -212,19 +205,17 @@ next_user_dirs_cb (GObject *object, GAsyncResult *res, gpointer user_data) for (link = users; link; link = link->next) { CommonUser *user = link->data; - gchar *uidstr = g_strdup_printf ("%u", common_user_get_uid (user)); - g_hash_table_remove (manager->priv->starting_dirs, uidstr); - g_free (uidstr); + g_hash_table_remove (manager->priv->starting_dirs, common_user_get_name (user)); } - g_hash_table_foreach (manager->priv->starting_dirs, - delete_unused_user, manager); + g_hash_table_foreach (manager->priv->starting_dirs, delete_unused_user, manager); g_hash_table_destroy (manager->priv->starting_dirs); manager->priv->starting_dirs = NULL; // Also set up our own greeter dir, so it has a place to dump its own files // (imagine it holding some large files temporarily before shunting them // to the next user to log in's specific directory). - setup_user_dir (manager, manager->priv->greeter_uid); + shared_data_manager_ensure_user_dir (manager, manager->priv->greeter_user); + g_object_unref (manager); } } @@ -259,9 +250,7 @@ static void user_removed_cb (CommonUserList *list, CommonUser *user, SharedDataManager *manager) { - gchar *uid = g_strdup_printf ("%u", common_user_get_uid (user)); - delete_unused_user (uid, NULL, manager); - g_free (uid); + delete_unused_user (common_user_get_name (user), NULL, manager); } void @@ -287,16 +276,11 @@ shared_data_manager_init (SharedDataManager *manager) manager->priv = G_TYPE_INSTANCE_GET_PRIVATE (manager, SHARED_DATA_MANAGER_TYPE, SharedDataManagerPrivate); // Grab current greeter-user gid - gchar *greeter_user; struct passwd *greeter_entry; - greeter_user = config_get_string (config_get_instance (), "LightDM", "greeter-user"); - greeter_entry = getpwnam (greeter_user); + manager->priv->greeter_user = config_get_string (config_get_instance (), "LightDM", "greeter-user"); + greeter_entry = getpwnam (manager->priv->greeter_user); if (greeter_entry) - { - manager->priv->greeter_uid = greeter_entry->pw_uid; manager->priv->greeter_gid = greeter_entry->pw_gid; - } - g_free (greeter_user); } static void @@ -321,6 +305,8 @@ shared_data_manager_finalize (GObject *object) if (self->priv->starting_dirs) g_hash_table_destroy (self->priv->starting_dirs); + g_free (self->priv->greeter_user); + G_OBJECT_CLASS (shared_data_manager_parent_class)->finalize (object); } |