summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndrej Holy <oholy@redhat.com>2023-11-02 10:35:48 +0100
committerOndrej Holy <oholy@redhat.com>2023-11-14 15:21:00 +0100
commit8f417fb7fee088dba728e083bc5553a5f237f660 (patch)
treee71fd61a621bdc53fd1f6e30bf10be6ade665d28
parente80a3ca95672e91772b70d0d8b3fccc52cd0c868 (diff)
ipa: Propagate hostname error
When a computer hostname is wrong, the `ipa-client-install` cmd fails with the "invalid hostname" error. However, the join method fails with the generic `REALM_ERROR_INTERNAL` error. Let's fail with the dedicated `REALM_ERROR_BAD_HOSTNAME` instead. Related: https://gitlab.gnome.org/GNOME/gnome-initial-setup/-/issues/123 Related: https://gitlab.gnome.org/GNOME/gnome-initial-setup/-/issues/124
-rw-r--r--service/realm-sssd-ipa.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/service/realm-sssd-ipa.c b/service/realm-sssd-ipa.c
index 0cb1a5b..fca8e25 100644
--- a/service/realm-sssd-ipa.c
+++ b/service/realm-sssd-ipa.c
@@ -129,6 +129,23 @@ on_restart_done (GObject *source,
g_object_unref (task);
}
+static gchar *
+parse_hostname_error (const gchar *output)
+{
+ GRegex* regex;
+ GMatchInfo *match_info = NULL;
+ gchar *reason = NULL;
+
+ regex = g_regex_new ("invalid hostname: (.+)", 0, 0, NULL);
+ if (g_regex_match (regex, output, 0, &match_info))
+ reason = g_match_info_fetch (match_info, 1);
+
+ g_match_info_unref (match_info);
+ g_regex_unref (regex);
+
+ return reason;
+}
+
static void
on_ipa_client_do_restart (GObject *source,
GAsyncResult *result,
@@ -149,6 +166,7 @@ on_ipa_client_do_restart (GObject *source,
gchar *section;
gchar *home;
gint status;
+ gchar *reason;
status = realm_command_run_finish (result, &output, &error);
@@ -163,6 +181,11 @@ on_ipa_client_do_restart (GObject *source,
if (g_pattern_match_simple ("*kinit: Password incorrect*", output->str)) {
g_set_error (&error, REALM_ERROR, REALM_ERROR_AUTH_FAILED,
"Password is incorrect");
+ } else if ((reason = parse_hostname_error (output->str)) != NULL) {
+ g_set_error (&error, REALM_ERROR, REALM_ERROR_BAD_HOSTNAME,
+ "This computer's host name is not set correctly: %s",
+ reason);
+ g_free (reason);
} else {
g_set_error (&error, REALM_ERROR, REALM_ERROR_INTERNAL,
"Running ipa-client-install failed");