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

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