From d691c679c1531b3eb457c494141bafdc4e0bc692 Mon Sep 17 00:00:00 2001 From: Sumit Bose Date: Fri, 1 Dec 2023 12:14:06 +0100 Subject: [PATCH 2/3] service: fix error message when removing host from AD If there is an error while trying to remove the host from AD with the help of adcli the error message talks about "joining" which might be irritating when figuring out the reason for the failure. This patch adds a better message when leaving the domain. --- service/realm-adcli-enroll.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/service/realm-adcli-enroll.c b/service/realm-adcli-enroll.c index e0d752b..c913987 100644 --- a/service/realm-adcli-enroll.c +++ b/service/realm-adcli-enroll.c @@ -25,9 +25,10 @@ #include "realm-settings.h" static void -on_join_process (GObject *source, - GAsyncResult *result, - gpointer user_data) +on_join_leave_process (GObject *source, + GAsyncResult *result, + gpointer user_data, + gboolean is_join) { GTask *task = G_TASK (user_data); GError *error = NULL; @@ -39,15 +40,18 @@ on_join_process (GObject *source, switch (status) { case 2: /* ADCLI_ERR_UNEXPECTED */ g_set_error (&error, REALM_ERROR, REALM_ERROR_INTERNAL, - "Internal unexpected error joining the domain"); + is_join ? "Internal unexpected error joining the domain" + : "Internal unexpected error removing host from the domain"); break; case 6: /* ADCLI_ERR_CREDENTIALS */ g_set_error (&error, REALM_ERROR, REALM_ERROR_AUTH_FAILED, - "Insufficient permissions to join the domain"); + is_join ? "Insufficient permissions to join the domain" + : "Insufficient permissions to remove the host from the domain"); break; default: g_set_error (&error, REALM_ERROR, REALM_ERROR_FAILED, - "Failed to join the domain"); + is_join ? "Failed to join the domain" + : "Failed to remove the host from the domain"); break; } } @@ -64,6 +68,22 @@ on_join_process (GObject *source, g_object_unref (task); } +static void +on_join_process (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + on_join_leave_process (source, result, user_data, TRUE); +} + +static void +on_leave_process (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + on_join_leave_process (source, result, user_data, FALSE); +} + void realm_adcli_enroll_join_async (RealmDisco *disco, RealmCredential *cred, @@ -290,7 +310,7 @@ realm_adcli_enroll_delete_async (RealmDisco *disco, g_ptr_array_add (args, NULL); realm_command_runv_async ((gchar **)args->pdata, environ, input, - invocation, on_join_process, + invocation, on_leave_process, g_object_ref (task)); g_ptr_array_free (args, TRUE); -- 2.43.0