gnome-initial-setup/0005-summary-Write-uid-file-with-other-state-files.patch

242 lines
7.9 KiB
Diff
Raw Normal View History

From 42d8bdfc0d37460cedf6fb3fe59bdfc0769c48ec Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Fri, 25 Aug 2023 21:30:42 -0400
Subject: [PATCH 05/10] summary: Write uid file with other state files
When creating a user account gnome-initial-setup writes a file
saying what the uid of the new user is, so that GDM can make
gnome-initial-setup's configuration available to the user.
It does this from the summary page, but it would be better to do
it more centrally along with other state files so it can be used
for modes that don't have the summary page.
This is important groundwork for a "live user" mode that will
get added in a future commit.
---
gnome-initial-setup/gnome-initial-setup.c | 37 +++++++++++++++++++
.../pages/summary/gis-summary-page.c | 24 ------------
2 files changed, 37 insertions(+), 24 deletions(-)
diff --git a/gnome-initial-setup/gnome-initial-setup.c b/gnome-initial-setup/gnome-initial-setup.c
index 49e8e6ca..3635f293 100644
--- a/gnome-initial-setup/gnome-initial-setup.c
+++ b/gnome-initial-setup/gnome-initial-setup.c
@@ -418,61 +418,98 @@ write_state (GisDriver *driver)
g_auto(GStrv) visited_pages = NULL;
GisAssistant *assistant;
GList *pages, *node;
state = g_key_file_new ();
builder = g_strv_builder_new ();
assistant = gis_driver_get_assistant (driver);
pages = gis_assistant_get_all_pages (assistant);
for (node = pages; node != NULL; node = node->next) {
GisPage *page = node->data;
g_strv_builder_add (builder, GIS_PAGE_GET_CLASS (page)->page_id);
}
visited_pages = g_strv_builder_end (builder);
g_key_file_set_string_list (state,
VENDOR_PAGES_GROUP,
VENDOR_SKIP_KEY,
(const char * const *)
visited_pages,
g_strv_length (visited_pages));
if (!g_key_file_save_to_file (state, STATE_FILE, &error)) {
g_warning ("Unable to save state to %s: %s", STATE_FILE, error->message);
return;
}
}
+static void
+add_uid_file (GisDriver *driver)
+{
+ gchar *gis_uid_path;
+ gchar *uid_str;
+ uid_t uid;
+ g_autoptr(GError) error = NULL;
+ ActUser *user_account = NULL;
+
+ gis_driver_get_user_permissions (driver, &user_account, NULL);
+
+ if (user_account == NULL)
+ return;
+
+ uid = act_user_get_uid (user_account);
+
+ gis_uid_path = g_build_filename (g_get_home_dir (),
+ "gnome-initial-setup-uid",
+ NULL);
+ uid_str = g_strdup_printf ("%u", uid);
+
+ if (!g_file_set_contents (gis_uid_path, uid_str, -1, &error))
+ g_warning ("Unable to create %s: %s", gis_uid_path, error->message);
+
+ g_free (uid_str);
+ g_free (gis_uid_path);
+}
+
void
gis_ensure_stamp_files (GisDriver *driver)
{
g_autofree gchar *done_file = NULL;
g_autoptr(GError) error = NULL;
+ GisDriverMode driver_mode;
done_file = g_build_filename (g_get_user_config_dir (), "gnome-initial-setup-done", NULL);
if (!g_file_set_contents (done_file, "yes", -1, &error)) {
g_warning ("Unable to create %s: %s", done_file, error->message);
g_clear_error (&error);
}
+ driver_mode = gis_driver_get_mode (driver);
+
+ /* If we're in a system mode write out which UID the created user is so GDM can make the
+ * gnome-initial-setup home directory readable to the created user.
+ */
+ if (driver_mode & GIS_DRIVER_MODE_SYSTEM)
+ add_uid_file (driver);
+
write_state (driver);
}
/**
* gis_get_mock_mode:
*
* Gets whether gnome-initial-setup has been built for development, and hence
* shouldnt permanently change any system configuration.
*
* By default, mock mode is enabled when running in a build environment. This
* heuristic may be changed in future.
*
* Returns: %TRUE if in mock mode, %FALSE otherwise
*/
gboolean
gis_get_mock_mode (void)
{
return (g_getenv ("UNDER_JHBUILD") != NULL);
}
diff --git a/gnome-initial-setup/pages/summary/gis-summary-page.c b/gnome-initial-setup/pages/summary/gis-summary-page.c
index 0aee2dad..b072f7fc 100644
--- a/gnome-initial-setup/pages/summary/gis-summary-page.c
+++ b/gnome-initial-setup/pages/summary/gis-summary-page.c
@@ -91,110 +91,86 @@ static void
on_secret_info_query (GdmUserVerifier *user_verifier,
const char *service_name,
const char *question,
GisSummaryPage *page)
{
GisSummaryPagePrivate *priv = gis_summary_page_get_instance_private (page);
gboolean should_send_password = priv->user_password != NULL;
g_debug ("PAM module secret info query: %s", question);
if (should_send_password) {
g_debug ("sending password\n");
gdm_user_verifier_call_answer_query (user_verifier,
service_name,
priv->user_password,
NULL, NULL, NULL);
priv->user_password = NULL;
} else {
request_info_query (page, user_verifier, question, TRUE);
}
}
static void
on_session_opened (GdmGreeter *greeter,
const char *service_name,
GisSummaryPage *page)
{
gdm_greeter_call_start_session_when_ready_sync (greeter, service_name,
TRUE, NULL, NULL);
}
-static void
-add_uid_file (uid_t uid)
-{
- gchar *gis_uid_path;
- gchar *uid_str;
- g_autoptr(GError) error = NULL;
-
- gis_uid_path = g_build_filename (g_get_home_dir (),
- "gnome-initial-setup-uid",
- NULL);
- uid_str = g_strdup_printf ("%u", uid);
-
- if (!g_file_set_contents (gis_uid_path, uid_str, -1, &error))
- g_warning ("Unable to create %s: %s", gis_uid_path, error->message);
-
- g_free (uid_str);
- g_free (gis_uid_path);
-}
-
static void
log_user_in (GisSummaryPage *page)
{
GisSummaryPagePrivate *priv = gis_summary_page_get_instance_private (page);
g_autoptr(GError) error = NULL;
GdmGreeter *greeter = NULL;
GdmUserVerifier *user_verifier = NULL;
if (!gis_driver_get_gdm_objects (GIS_PAGE (page)->driver,
&greeter, &user_verifier)) {
g_warning ("No GDM connection; not initiating login");
return;
}
g_signal_connect (user_verifier, "info",
G_CALLBACK (on_info), page);
g_signal_connect (user_verifier, "problem",
G_CALLBACK (on_problem), page);
g_signal_connect (user_verifier, "info-query",
G_CALLBACK (on_info_query), page);
g_signal_connect (user_verifier, "secret-info-query",
G_CALLBACK (on_secret_info_query), page);
g_signal_connect (greeter, "session-opened",
G_CALLBACK (on_session_opened), page);
- /* We are in NEW_USER mode and we want to make it possible for third
- * parties to find out which user ID we created.
- */
- add_uid_file (act_user_get_uid (priv->user_account));
-
gdm_user_verifier_call_begin_verification_for_user_sync (user_verifier,
SERVICE_NAME,
act_user_get_user_name (priv->user_account),
NULL, &error);
if (error != NULL)
g_warning ("Could not begin verification: %s", error->message);
}
static void
done_cb (GtkButton *button, GisSummaryPage *page)
{
gis_ensure_stamp_files (GIS_PAGE (page)->driver);
switch (gis_driver_get_mode (GIS_PAGE (page)->driver))
{
case GIS_DRIVER_MODE_NEW_USER:
gis_driver_hide_window (GIS_PAGE (page)->driver);
log_user_in (page);
break;
case GIS_DRIVER_MODE_EXISTING_USER:
g_application_quit (G_APPLICATION (GIS_PAGE (page)->driver));
default:
break;
}
}
static void
gis_summary_page_shown (GisPage *page)
{
--
2.41.0.rc2