Blame SOURCES/0003-service-add-ldaps-support-when-using-adcli.patch

3eb28c
From ae247ae2ad87858741d64341633cd4e74f72e873 Mon Sep 17 00:00:00 2001
3eb28c
From: Sumit Bose <sbose@redhat.com>
3eb28c
Date: Fri, 30 Oct 2020 13:28:52 +0100
3eb28c
Subject: [PATCH 3/6] service: add ldaps support when using adcli
3eb28c
3eb28c
Call adcli with the --use-ldaps option if the realmd service is
3eb28c
requested to do so.
3eb28c
3eb28c
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1826964
3eb28c
---
3eb28c
 service/realm-adcli-enroll.c | 10 ++++++++++
3eb28c
 service/realm-adcli-enroll.h |  2 ++
3eb28c
 service/realm-samba.c        | 11 +++++++++--
3eb28c
 service/realm-sssd-ad.c      | 27 ++++++++++++++++++++++++++-
3eb28c
 4 files changed, 47 insertions(+), 3 deletions(-)
3eb28c
3eb28c
diff --git a/service/realm-adcli-enroll.c b/service/realm-adcli-enroll.c
3eb28c
index 05947fa..2731283 100644
3eb28c
--- a/service/realm-adcli-enroll.c
3eb28c
+++ b/service/realm-adcli-enroll.c
3eb28c
@@ -68,6 +68,7 @@ void
3eb28c
 realm_adcli_enroll_join_async (RealmDisco *disco,
3eb28c
                                RealmCredential *cred,
3eb28c
                                GVariant *options,
3eb28c
+                               gboolean use_ldaps,
3eb28c
                                GDBusMethodInvocation *invocation,
3eb28c
                                GAsyncReadyCallback callback,
3eb28c
                                gpointer user_data)
3eb28c
@@ -102,6 +103,10 @@ realm_adcli_enroll_join_async (RealmDisco *disco,
3eb28c
 	g_ptr_array_add (args, "--domain-realm");
3eb28c
 	g_ptr_array_add (args, (gpointer)disco->kerberos_realm);
3eb28c
 
3eb28c
+	if (use_ldaps) {
3eb28c
+		g_ptr_array_add (args, "--use-ldaps");
3eb28c
+	}
3eb28c
+
3eb28c
 	if (G_IS_INET_SOCKET_ADDRESS (disco->server_address)) {
3eb28c
 		address = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (disco->server_address));
3eb28c
 		server_arg = g_inet_address_to_string (address);
3eb28c
@@ -218,6 +223,7 @@ void
3eb28c
 realm_adcli_enroll_delete_async (RealmDisco *disco,
3eb28c
                                  RealmCredential *cred,
3eb28c
                                  GVariant *options,
3eb28c
+                                 gboolean use_ldaps,
3eb28c
                                  GDBusMethodInvocation *invocation,
3eb28c
                                  GAsyncReadyCallback callback,
3eb28c
                                  gpointer user_data)
3eb28c
@@ -246,6 +252,10 @@ realm_adcli_enroll_delete_async (RealmDisco *disco,
3eb28c
 	g_ptr_array_add (args, "--domain-realm");
3eb28c
 	g_ptr_array_add (args, (gpointer)disco->kerberos_realm);
3eb28c
 
3eb28c
+	if (use_ldaps) {
3eb28c
+		g_ptr_array_add (args, "--use-ldaps");
3eb28c
+	}
3eb28c
+
3eb28c
 	if (G_IS_INET_SOCKET_ADDRESS (disco->server_address)) {
3eb28c
 		address = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (disco->server_address));
3eb28c
 		server_arg = g_inet_address_to_string (address);
3eb28c
diff --git a/service/realm-adcli-enroll.h b/service/realm-adcli-enroll.h
3eb28c
index 855b2f7..3f535d0 100644
3eb28c
--- a/service/realm-adcli-enroll.h
3eb28c
+++ b/service/realm-adcli-enroll.h
3eb28c
@@ -29,6 +29,7 @@ G_BEGIN_DECLS
3eb28c
 void         realm_adcli_enroll_join_async    (RealmDisco *disco,
3eb28c
                                                RealmCredential *cred,
3eb28c
                                                GVariant *options,
3eb28c
+                                               gboolean use_ldaps,
3eb28c
                                                GDBusMethodInvocation *invocation,
3eb28c
                                                GAsyncReadyCallback callback,
3eb28c
                                                gpointer user_data);
3eb28c
@@ -39,6 +40,7 @@ gboolean     realm_adcli_enroll_join_finish   (GAsyncResult *result,
3eb28c
 void         realm_adcli_enroll_delete_async  (RealmDisco *disco,
3eb28c
                                                RealmCredential *cred,
3eb28c
                                                GVariant *options,
3eb28c
+                                               gboolean use_ldaps,
3eb28c
                                                GDBusMethodInvocation *invocation,
3eb28c
                                                GAsyncReadyCallback callback,
3eb28c
                                                gpointer user_data);
3eb28c
diff --git a/service/realm-samba.c b/service/realm-samba.c
3eb28c
index e7b80a0..7aa5416 100644
3eb28c
--- a/service/realm-samba.c
3eb28c
+++ b/service/realm-samba.c
3eb28c
@@ -257,7 +257,8 @@ on_install_do_join (GObject *source,
3eb28c
 }
3eb28c
 
3eb28c
 static gboolean
3eb28c
-validate_membership_options (GVariant *options,
3eb28c
+validate_membership_options (EnrollClosure *enroll,
3eb28c
+                             GVariant *options,
3eb28c
                              GError **error)
3eb28c
 {
3eb28c
 	const gchar *software;
3eb28c
@@ -271,6 +272,12 @@ validate_membership_options (GVariant *options,
3eb28c
 		}
3eb28c
 	}
3eb28c
 
3eb28c
+	if (realm_option_use_ldaps (options)) {
3eb28c
+		realm_diagnostics_info (enroll->invocation,
3eb28c
+		                        "Membership software %s does "
3eb28c
+		                        "not support ldaps, trying without.",
3eb28c
+		                        software);
3eb28c
+	}
3eb28c
 	return TRUE;
3eb28c
 }
3eb28c
 
3eb28c
@@ -303,7 +310,7 @@ realm_samba_join_async (RealmKerberosMembership *membership,
3eb28c
 		g_task_return_new_error (task, REALM_ERROR, REALM_ERROR_ALREADY_CONFIGURED,
3eb28c
 		                         _("Already joined to a domain"));
3eb28c
 
3eb28c
-	} else if (!validate_membership_options (options, &error)) {
3eb28c
+	} else if (!validate_membership_options (enroll, options, &error)) {
3eb28c
 		g_task_return_error (task, error);
3eb28c
 
3eb28c
 	} else {
3eb28c
diff --git a/service/realm-sssd-ad.c b/service/realm-sssd-ad.c
3eb28c
index 6b2f9f8..00a9093 100644
3eb28c
--- a/service/realm-sssd-ad.c
3eb28c
+++ b/service/realm-sssd-ad.c
3eb28c
@@ -98,6 +98,7 @@ typedef struct {
3eb28c
 	GVariant *options;
3eb28c
 	RealmDisco *disco;
3eb28c
 	gboolean use_adcli;
3eb28c
+	gboolean use_ldaps;
3eb28c
 	const gchar **packages;
3eb28c
 } JoinClosure;
3eb28c
 
3eb28c
@@ -294,6 +295,7 @@ on_install_do_join (GObject *source,
3eb28c
 			realm_adcli_enroll_join_async (join->disco,
3eb28c
 			                               join->cred,
3eb28c
 			                               join->options,
3eb28c
+			                               join->use_ldaps,
3eb28c
 			                               join->invocation,
3eb28c
 			                               on_join_do_sssd,
3eb28c
 			                               g_object_ref (task));
3eb28c
@@ -347,6 +349,19 @@ parse_join_options (JoinClosure *join,
3eb28c
 			return FALSE;
3eb28c
 		}
3eb28c
 
3eb28c
+	/*
3eb28c
+	 * Check if ldaps should be used and if membership software supports
3eb28c
+	 * it.
3eb28c
+	 */
3eb28c
+	join->use_ldaps = realm_option_use_ldaps (options);
3eb28c
+	if (join->use_ldaps &&
3eb28c
+	           g_str_equal (software, REALM_DBUS_IDENTIFIER_SAMBA)) {
3eb28c
+		realm_diagnostics_info (join->invocation,
3eb28c
+		                        "Membership software %s does "
3eb28c
+		                        "not support ldaps, trying "
3eb28c
+		                        "without.", software);
3eb28c
+	}
3eb28c
+
3eb28c
 	/*
3eb28c
 	 * If we are enrolling with a user password, then we have to use samba,
3eb28c
 	 * adcli only supports admin passwords.
3eb28c
@@ -523,6 +538,7 @@ realm_sssd_ad_leave_async (RealmKerberosMembership *membership,
3eb28c
 	GTask *task;
3eb28c
 	LeaveClosure *leave;
3eb28c
 	gchar *tags;
3eb28c
+	gboolean use_ldaps = FALSE;
3eb28c
 
3eb28c
 	task = g_task_new (self, NULL, callback, user_data);
3eb28c
 
3eb28c
@@ -551,10 +567,19 @@ realm_sssd_ad_leave_async (RealmKerberosMembership *membership,
3eb28c
 		leave->invocation = g_object_ref (invocation);
3eb28c
 		leave->use_adcli = strstr (tags ? tags : "", "joined-with-adcli") ? TRUE : FALSE;
3eb28c
 		g_task_set_task_data (task, leave, leave_closure_free);
3eb28c
+
3eb28c
+		use_ldaps = realm_option_use_ldaps (options);
3eb28c
 		if (leave->use_adcli) {
3eb28c
-			realm_adcli_enroll_delete_async (disco, cred, options, invocation,
3eb28c
+			realm_adcli_enroll_delete_async (disco, cred, options,
3eb28c
+			                                 use_ldaps,  invocation,
3eb28c
 			                                 on_leave_do_deconfigure, g_object_ref (task));
3eb28c
 		} else {
3eb28c
+			if (use_ldaps) {
3eb28c
+				realm_diagnostics_info (leave->invocation,
3eb28c
+				                        "Membership software does "
3eb28c
+				                        "not support ldaps, trying "
3eb28c
+				                        "without.");
3eb28c
+			}
3eb28c
 			realm_samba_enroll_leave_async (disco, cred, options, invocation,
3eb28c
 			                                on_leave_do_deconfigure, g_object_ref (task));
3eb28c
 		}
3eb28c
-- 
3eb28c
2.26.2
3eb28c