Blame SOURCES/0009-make-Samba-data-tool-configurable.patch

776d17
From c0784106a839c2686e01c75472bae2e7d9071c8b Mon Sep 17 00:00:00 2001
776d17
From: Sumit Bose <sbose@redhat.com>
776d17
Date: Thu, 1 Feb 2018 14:26:22 +0100
776d17
Subject: [PATCH 9/9] make Samba data tool configurable
776d17
776d17
Allow to specify an alternative path to Samba's net utility at configure
776d17
time and at run time.
776d17
776d17
https://bugs.freedesktop.org/show_bug.cgi?id=100118
776d17
776d17
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
776d17
---
776d17
 configure.ac                    | 13 ++++++++++++
776d17
 doc/adcli.xml                   | 21 ++++++++++++++++++-
776d17
 doc/samba_data_tool_path.xml.in |  1 +
776d17
 library/adenroll.c              | 46 ++++++++++++++++++++++++++++++++++-------
776d17
 library/adenroll.h              |  5 +++++
776d17
 tools/computer.c                | 16 ++++++++++++++
776d17
 7 files changed, 95 insertions(+), 8 deletions(-)
776d17
 create mode 100644 doc/samba_data_tool_path.xml.in
776d17
776d17
diff --git a/configure.ac b/configure.ac
776d17
index fe86638..68877c7 100644
776d17
--- a/configure.ac
776d17
+++ b/configure.ac
776d17
@@ -291,6 +291,18 @@ else
776d17
 	AC_DEFINE_UNQUOTED(BIN_ECHO, "$BIN_ECHO", [path to echo, used in unit test])
776d17
 fi
776d17
 
776d17
+AC_MSG_CHECKING([where is Samba's net utility])
776d17
+AC_ARG_WITH([samba_data_tool],
776d17
+              AC_HELP_STRING([--with-samba-data-tool=/path],
776d17
+              [Path to Samba's net utility]),
776d17
+              [],
776d17
+              [with_samba_data_tool=/usr/bin/net])
776d17
+AC_MSG_RESULT([$with_samba_data_tool])
776d17
+
776d17
+AC_DEFINE_UNQUOTED(SAMBA_DATA_TOOL, "$with_samba_data_tool",
776d17
+                   [Path to Samba's net utility])
776d17
+
776d17
+AC_SUBST(SAMBA_DATA_TOOL, [$with_samba_data_tool])
776d17
 # ---------------------------------------------------------------------
776d17
 
776d17
 ADCLI_LT_RELEASE=$ADCLI_CURRENT:$ADCLI_REVISION:$ADCLI_AGE
776d17
@@ -300,6 +312,7 @@ AC_CONFIG_FILES([Makefile
776d17
 	build/Makefile
776d17
 	doc/Makefile
776d17
 	doc/version.xml
776d17
+	doc/samba_data_tool_path.xml
776d17
 	library/Makefile
776d17
 	tools/Makefile
776d17
 ])
776d17
diff --git a/doc/adcli.xml b/doc/adcli.xml
776d17
index fbc6c63..c2b7760 100644
776d17
--- a/doc/adcli.xml
776d17
+++ b/doc/adcli.xml
776d17
@@ -1,6 +1,9 @@
776d17
 
776d17
 
776d17
-	"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
776d17
+	"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
776d17
+[
776d17
+	
776d17
+]>
776d17
 
776d17
 <refentry id="adcli">
776d17
 
776d17
@@ -307,6 +310,14 @@ Password for Administrator:
776d17
 			<citerefentry><refentrytitle>smb.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
776d17
 			for details.</para></listitem>
776d17
 		</varlistentry>
776d17
+		<varlistentry>
776d17
+			<term><option>--samba-data-tool=<parameter>/path/to/net</parameter></option></term>
776d17
+			<listitem><para>If Samba's <command>net</command>
776d17
+			cannot be found at
776d17
+			<filename>&samba_data_tool;</filename> this option can
776d17
+			be used to specific an alternative location with the
776d17
+			help of an absolute path.</para></listitem>
776d17
+		</varlistentry>
776d17
 	</variablelist>
776d17
 
776d17
 </refsect1>
776d17
@@ -412,6 +423,14 @@ $ adcli update --login-ccache=/tmp/krbcc_123
776d17
 			<citerefentry><refentrytitle>smb.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
776d17
 			for details.</para></listitem>
776d17
 		</varlistentry>
776d17
+		<varlistentry>
776d17
+			<term><option>--samba-data-tool=<parameter>/path/to/net</parameter></option></term>
776d17
+			<listitem><para>If Samba's <command>net</command>
776d17
+			cannot be found at
776d17
+			<filename>&samba_data_tool;</filename> this option can
776d17
+			be used to specific an alternative location with the
776d17
+			help of an absolute path.</para></listitem>
776d17
+		</varlistentry>
776d17
 	</variablelist>
776d17
 
776d17
 </refsect1>
776d17
diff --git a/doc/samba_data_tool_path.xml.in b/doc/samba_data_tool_path.xml.in
776d17
new file mode 100644
776d17
index 0000000..a667c57
776d17
--- /dev/null
776d17
+++ b/doc/samba_data_tool_path.xml.in
776d17
@@ -0,0 +1 @@
776d17
+@SAMBA_DATA_TOOL@
776d17
diff --git a/library/adenroll.c b/library/adenroll.c
776d17
index 6b1aae5..d64c2c0 100644
776d17
--- a/library/adenroll.c
776d17
+++ b/library/adenroll.c
776d17
@@ -42,6 +42,10 @@
776d17
 #include <stdio.h>
776d17
 #include <unistd.h>
776d17
 
776d17
+#ifndef SAMBA_DATA_TOOL
776d17
+#define SAMBA_DATA_TOOL "/usr/bin/net"
776d17
+#endif
776d17
+
776d17
 static krb5_enctype v60_later_enctypes[] = {
776d17
 	ENCTYPE_AES256_CTS_HMAC_SHA1_96,
776d17
 	ENCTYPE_AES128_CTS_HMAC_SHA1_96,
776d17
@@ -100,6 +104,7 @@ struct _adcli_enroll {
776d17
 	int keytab_enctypes_explicit;
776d17
 	unsigned int computer_password_lifetime;
776d17
 	int computer_password_lifetime_explicit;
776d17
+	char *samba_data_tool;
776d17
 };
776d17
 
776d17
 static adcli_result
776d17
@@ -1537,26 +1542,33 @@ static adcli_result
776d17
 update_samba_data (adcli_enroll *enroll)
776d17
 {
776d17
 	int ret;
776d17
-	char *argv_pw[] = { "/usr/bin/net", "changesecretpw", "-i", "-f", NULL };
776d17
-	char *argv_sid[] = { "/usr/bin/net", "setdomainsid", NULL, NULL };
776d17
+	char *argv_pw[] = { NULL, "changesecretpw", "-i", "-f", NULL };
776d17
+	char *argv_sid[] = { NULL, "setdomainsid", NULL, NULL };
776d17
+
776d17
+	argv_pw[0] = (char *) adcli_enroll_get_samba_data_tool (enroll);
776d17
+	if (argv_pw[0] ==NULL) {
776d17
+		_adcli_err ("Samba data tool not available.");
776d17
+		return ADCLI_ERR_FAIL;
776d17
+	}
776d17
+	argv_sid[0] = argv_pw[0];
776d17
 
776d17
-	_adcli_info ("Trying to set Samba secret.\n");
776d17
+	_adcli_info ("Trying to set Samba secret.");
776d17
 	ret = _adcli_call_external_program (argv_pw[0], argv_pw,
776d17
 	                                    enroll->computer_password, NULL, NULL);
776d17
 	if (ret != ADCLI_SUCCESS) {
776d17
-		_adcli_err ("Failed to set Samba computer account password.\n");
776d17
+		_adcli_err ("Failed to set Samba computer account password.");
776d17
 	}
776d17
 
776d17
 	argv_sid[2] = (char *) adcli_conn_get_domain_sid (enroll->conn);
776d17
 	if (argv_sid[2] == NULL) {
776d17
-		_adcli_err ("Domain SID not available.\n");
776d17
+		_adcli_err ("Domain SID not available.");
776d17
 	} else {
776d17
-		_adcli_info ("Trying to set domain SID %s for Samba.\n",
776d17
+		_adcli_info ("Trying to set domain SID %s for Samba.",
776d17
 		             argv_sid[2]);
776d17
 		ret = _adcli_call_external_program (argv_sid[0], argv_sid,
776d17
 		                                    NULL, NULL, NULL);
776d17
 		if (ret != ADCLI_SUCCESS) {
776d17
-			_adcli_err ("Failed to set Samba domain SID.\n");
776d17
+			_adcli_err ("Failed to set Samba domain SID.");
776d17
 		}
776d17
 	}
776d17
 
776d17
@@ -1951,6 +1963,9 @@ adcli_enroll_new (adcli_conn *conn)
776d17
 	enroll->os_name = strdup (value);
776d17
 	return_val_if_fail (enroll->os_name != NULL, NULL);
776d17
 
776d17
+	enroll->samba_data_tool = strdup (SAMBA_DATA_TOOL);
776d17
+	return_val_if_fail (enroll->samba_data_tool != NULL, NULL);
776d17
+
776d17
 	return enroll;
776d17
 }
776d17
 
776d17
@@ -1978,6 +1993,7 @@ enroll_free (adcli_enroll *enroll)
776d17
 	free (enroll->os_name);
776d17
 	free (enroll->os_version);
776d17
 	free (enroll->os_service_pack);
776d17
+	free (enroll->samba_data_tool);
776d17
 
776d17
 	free (enroll->user_principal);
776d17
 	_adcli_strv_free (enroll->service_names);
776d17
@@ -2343,3 +2359,19 @@ adcli_enroll_set_computer_password_lifetime (adcli_enroll *enroll,
776d17
 
776d17
 	enroll->computer_password_lifetime_explicit = 1;
776d17
 }
776d17
+
776d17
+void
776d17
+adcli_enroll_set_samba_data_tool (adcli_enroll *enroll, const char *value)
776d17
+{
776d17
+	return_if_fail (enroll != NULL);
776d17
+	if (value != NULL && value[0] != '\0') {
776d17
+		_adcli_str_set (&enroll->samba_data_tool, value);
776d17
+	}
776d17
+}
776d17
+
776d17
+const char *
776d17
+adcli_enroll_get_samba_data_tool (adcli_enroll *enroll)
776d17
+{
776d17
+	return_val_if_fail (enroll != NULL, NULL);
776d17
+	return enroll->samba_data_tool;
776d17
+}
776d17
diff --git a/library/adenroll.h b/library/adenroll.h
776d17
index 32c9764..31ca0bc 100644
776d17
--- a/library/adenroll.h
776d17
+++ b/library/adenroll.h
776d17
@@ -141,4 +141,9 @@ const char *       adcli_enroll_get_os_service_pack     (adcli_enroll *enroll);
776d17
 void               adcli_enroll_set_os_service_pack     (adcli_enroll *enroll,
776d17
                                                          const char *value);
776d17
 
776d17
+void               adcli_enroll_set_samba_data_tool     (adcli_enroll *enroll,
776d17
+                                                         const char *value);
776d17
+
776d17
+const char *       adcli_enroll_get_samba_data_tool     (adcli_enroll *enroll);
776d17
+
776d17
 #endif /* ADENROLL_H_ */
776d17
diff --git a/tools/computer.c b/tools/computer.c
776d17
index fc646f2..f86548b 100644
776d17
--- a/tools/computer.c
776d17
+++ b/tools/computer.c
776d17
@@ -30,6 +30,7 @@
776d17
 #include <err.h>
776d17
 #include <stdio.h>
776d17
 #include <errno.h>
776d17
+#include <unistd.h>
776d17
 
776d17
 static void
776d17
 dump_details (adcli_conn *conn,
776d17
@@ -107,6 +108,7 @@ typedef enum {
776d17
 	opt_user_principal,
776d17
 	opt_computer_password_lifetime,
776d17
 	opt_add_samba_data,
776d17
+	opt_samba_data_tool,
776d17
 } Option;
776d17
 
776d17
 static adcli_tool_desc common_usages[] = {
776d17
@@ -145,6 +147,7 @@ static adcli_tool_desc common_usages[] = {
776d17
 	                     "successful join" },
776d17
 	{ opt_add_samba_data, "add domain SID and computer account password\n"
776d17
 	                      "to the Samba specific configuration database" },
776d17
+	{ opt_samba_data_tool, "Absolute path to the tool used for add-samba-data" },
776d17
 	{ opt_verbose, "show verbose progress and failure messages", },
776d17
 	{ 0 },
776d17
 };
776d17
@@ -160,6 +163,7 @@ parse_option (Option opt,
776d17
 	static int stdin_password = 0;
776d17
 	char *endptr;
776d17
 	unsigned int lifetime;
776d17
+	int ret;
776d17
 
776d17
 	switch (opt) {
776d17
 	case opt_login_ccache:
776d17
@@ -265,6 +269,16 @@ parse_option (Option opt,
776d17
 
776d17
 		adcli_enroll_set_computer_password_lifetime (enroll, lifetime);
776d17
 		return;
776d17
+	case opt_samba_data_tool:
776d17
+		errno = 0;
776d17
+		ret = access (optarg, X_OK);
776d17
+		if (ret != 0) {
776d17
+			ret = errno;
776d17
+			errx (EUSAGE, "Failed to access tool to add Samba data: %s", strerror (ret));
776d17
+		} else {
776d17
+			adcli_enroll_set_samba_data_tool (enroll, optarg);
776d17
+		}
776d17
+		return;
776d17
 	case opt_verbose:
776d17
 		return;
776d17
 
776d17
@@ -331,6 +345,7 @@ adcli_tool_computer_join (adcli_conn *conn,
776d17
 		{ "show-details", no_argument, NULL, opt_show_details },
776d17
 		{ "show-password", no_argument, NULL, opt_show_password },
776d17
 		{ "add-samba-data", no_argument, NULL, opt_add_samba_data },
776d17
+		{ "samba-data-tool", no_argument, NULL, opt_samba_data_tool },
776d17
 		{ "verbose", no_argument, NULL, opt_verbose },
776d17
 		{ "help", no_argument, NULL, 'h' },
776d17
 		{ 0 },
776d17
@@ -434,6 +449,7 @@ adcli_tool_computer_update (adcli_conn *conn,
776d17
 		{ "show-details", no_argument, NULL, opt_show_details },
776d17
 		{ "show-password", no_argument, NULL, opt_show_password },
776d17
 		{ "add-samba-data", no_argument, NULL, opt_add_samba_data },
776d17
+		{ "samba-data-tool", no_argument, NULL, opt_samba_data_tool },
776d17
 		{ "verbose", no_argument, NULL, opt_verbose },
776d17
 		{ "help", no_argument, NULL, 'h' },
776d17
 		{ 0 },
776d17
-- 
776d17
2.14.4
776d17