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

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