Blame SOURCES/0001-samba-use-new-Samba-4.15-command-line-options.patch

d9eb2f
From 68f73b78a34299ee37dd06e2ab3ede8985fa277b Mon Sep 17 00:00:00 2001
d9eb2f
From: Sumit Bose <sbose@redhat.com>
d9eb2f
Date: Tue, 14 Dec 2021 15:32:32 +0100
d9eb2f
Subject: [PATCH] samba: use new Samba-4.15 command line options
d9eb2f
d9eb2f
Samba-4.15 changed a couple of command line options of the net utility.
d9eb2f
This patch adds a configure option to select the new or the old style.
d9eb2f
If the option is not used configure tries to call the net utility to
d9eb2f
check for the options. If this fails the old style is used.
d9eb2f
d9eb2f
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2028530
d9eb2f
---
d9eb2f
 configure.ac                 | 34 ++++++++++++++++++++++++++++++++++
d9eb2f
 service/realm-samba-enroll.c | 18 +++++++++++++-----
d9eb2f
 2 files changed, 47 insertions(+), 5 deletions(-)
d9eb2f
d9eb2f
diff --git a/configure.ac b/configure.ac
d9eb2f
index ea51f92..ddc25d0 100644
d9eb2f
--- a/configure.ac
d9eb2f
+++ b/configure.ac
d9eb2f
@@ -227,6 +227,40 @@ LDAP_CFLAGS=""
d9eb2f
 AC_SUBST(LDAP_LIBS)
d9eb2f
 AC_SUBST(LDAP_CFLAGS)
d9eb2f
 
d9eb2f
+# -------------------------------------------------------------------
d9eb2f
+# Samba
d9eb2f
+
d9eb2f
+AC_ARG_WITH(new-samba-cli-options,
d9eb2f
+	AS_HELP_STRING([--with-new-samba-cli-options=yes/no],
d9eb2f
+	               [Use new command line options introduced with Samba-4.15,
d9eb2f
+	                if not provided the output of 'net help' is checked or old
d9eb2f
+	                style options are used]))
d9eb2f
+
d9eb2f
+if test "$with_new_samba_cli_options" = "no"; then
d9eb2f
+	AC_MSG_RESULT([Using old Samba command line options])
d9eb2f
+elif test "$with_new_samba_cli_options" = "yes"; then
d9eb2f
+	AC_DEFINE_UNQUOTED(WITH_NEW_SAMBA_CLI_OPTS, 1,
d9eb2f
+	                   [Use new command line options introduced with Samba-4.15])
d9eb2f
+	AC_MSG_RESULT([Using new Samba command line options])
d9eb2f
+else
d9eb2f
+	AC_PATH_PROG([SAMBA_NET], [net])
d9eb2f
+	if test ! -x "$SAMBA_NET"; then
d9eb2f
+		AC_MSG_NOTICE([Could not find Samba's net utility, ]
d9eb2f
+		              [assuming old style command line options, ]
d9eb2f
+		              [please install the net utility for proper detection.])
d9eb2f
+	else
d9eb2f
+		AC_MSG_CHECKING([for --debug-stdout option of net])
d9eb2f
+		if AC_RUN_LOG([$SAMBA_NET help 2>&1 |grep -- '--debug-stdout' > /dev/null]); then
d9eb2f
+			AC_DEFINE_UNQUOTED(WITH_NEW_SAMBA_CLI_OPTS, 1,
d9eb2f
+			                   [Use new command line options introduced with Samba-4.15])
d9eb2f
+			AC_MSG_RESULT([yes])
d9eb2f
+		else
d9eb2f
+			AC_MSG_RESULT([no])
d9eb2f
+		fi
d9eb2f
+	fi
d9eb2f
+fi
d9eb2f
+
d9eb2f
+
d9eb2f
 # -------------------------------------------------------------------
d9eb2f
 # Directories
d9eb2f
 
d9eb2f
diff --git a/service/realm-samba-enroll.c b/service/realm-samba-enroll.c
d9eb2f
index 5624a08..8b2ee38 100644
d9eb2f
--- a/service/realm-samba-enroll.c
d9eb2f
+++ b/service/realm-samba-enroll.c
d9eb2f
@@ -37,6 +37,14 @@
d9eb2f
 #include <sys/socket.h>
d9eb2f
 #include <netdb.h>
d9eb2f
 
d9eb2f
+#ifdef WITH_NEW_SAMBA_CLI_OPTS
d9eb2f
+#define SMBCLI_KERBEROS "--use-kerberos=required"
d9eb2f
+#define SMBCLI_CONF "--configfile"
d9eb2f
+#else
d9eb2f
+#define SMBCLI_KERBEROS "-k"
d9eb2f
+#define SMBCLI_CONF "-s"
d9eb2f
+#endif
d9eb2f
+
d9eb2f
 typedef struct {
d9eb2f
 	GDBusMethodInvocation *invocation;
d9eb2f
 	gchar *join_args[8];
d9eb2f
@@ -260,7 +268,7 @@ begin_net_process (JoinClosure *join,
d9eb2f
 	/* Use our custom smb.conf */
d9eb2f
 	g_ptr_array_add (args, (gpointer)realm_settings_path ("net"));
d9eb2f
 	if (join->custom_smb_conf) {
d9eb2f
-		g_ptr_array_add (args, "-s");
d9eb2f
+		g_ptr_array_add (args, SMBCLI_CONF);
d9eb2f
 		g_ptr_array_add (args, join->custom_smb_conf);
d9eb2f
 	}
d9eb2f
 
d9eb2f
@@ -370,7 +378,7 @@ on_join_do_keytab (GObject *source,
d9eb2f
 	} else {
d9eb2f
 		begin_net_process (join, NULL,
d9eb2f
 		                   on_keytab_do_finish, g_object_ref (task),
d9eb2f
-		                   "-k", "ads", "keytab", "create", NULL);
d9eb2f
+		                   SMBCLI_KERBEROS, "ads", "keytab", "create", NULL);
d9eb2f
 	}
d9eb2f
 
d9eb2f
 	g_object_unref (task);
d9eb2f
@@ -428,7 +436,7 @@ begin_join (GTask *task,
d9eb2f
 		begin_net_process (join, join->password_input,
d9eb2f
 		                   on_join_do_keytab, g_object_ref (task),
d9eb2f
 		                   "-U", join->user_name,
d9eb2f
-		                   "-k", "ads", "join", join->disco->domain_name,
d9eb2f
+		                   SMBCLI_KERBEROS, "ads", "join", join->disco->domain_name,
d9eb2f
 		                   join->join_args[0], join->join_args[1],
d9eb2f
 		                   join->join_args[2], join->join_args[3],
d9eb2f
 		                   join->join_args[4], NULL);
d9eb2f
@@ -437,7 +445,7 @@ begin_join (GTask *task,
d9eb2f
 	} else {
d9eb2f
 		begin_net_process (join, NULL,
d9eb2f
 		                   on_join_do_keytab, g_object_ref (task),
d9eb2f
-		                   "-k", "ads", "join", join->disco->domain_name,
d9eb2f
+		                   SMBCLI_KERBEROS, "ads", "join", join->disco->domain_name,
d9eb2f
 		                   join->join_args[0], join->join_args[1],
d9eb2f
 		                   join->join_args[2], join->join_args[3],
d9eb2f
 		                   join->join_args[4], NULL);
d9eb2f
@@ -543,7 +551,7 @@ realm_samba_enroll_leave_async (RealmDisco *disco,
d9eb2f
 		join->envvar = g_strdup_printf ("KRB5CCNAME=%s", cred->x.ccache.file);
d9eb2f
 		begin_net_process (join, NULL,
d9eb2f
 		                   on_leave_complete, g_object_ref (task),
d9eb2f
-		                   "-k", "ads", "leave", NULL);
d9eb2f
+		                   SMBCLI_KERBEROS, "ads", "leave", NULL);
d9eb2f
 		break;
d9eb2f
 	default:
d9eb2f
 		g_return_if_reached ();
d9eb2f
-- 
d9eb2f
2.33.1
d9eb2f