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

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