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

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