Blame SOURCES/0014-tools-store-Samba-data-if-requested.patch

f441eb
From c090131e4f912f6f6c4f79eb40fbe500eb31c171 Mon Sep 17 00:00:00 2001
f441eb
From: Sumit Bose <sbose@redhat.com>
f441eb
Date: Tue, 30 Jan 2018 18:24:15 +0100
f441eb
Subject: [PATCH 14/23] tools: store Samba data if requested
f441eb
f441eb
Use Samba's net utility to add the machine account password and the
f441eb
domain SID to the Samba configuration.
f441eb
f441eb
https://bugs.freedesktop.org/show_bug.cgi?id=100118
f441eb
f441eb
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
f441eb
---
f441eb
 library/adenroll.c | 39 +++++++++++++++++++++++++++++++++++++++
f441eb
 1 file changed, 39 insertions(+)
f441eb
f441eb
diff --git a/library/adenroll.c b/library/adenroll.c
f441eb
index bb970d1..20731cd 100644
f441eb
--- a/library/adenroll.c
f441eb
+++ b/library/adenroll.c
f441eb
@@ -1533,6 +1533,36 @@ update_keytab_for_principals (adcli_enroll *enroll)
f441eb
 	return ADCLI_SUCCESS;
f441eb
 }
f441eb
 
f441eb
+static adcli_result
f441eb
+update_samba_data (adcli_enroll *enroll)
f441eb
+{
f441eb
+	int ret;
f441eb
+	char *argv_pw[] = { "/usr/bin/net", "changesecretpw", "-i", "-f", NULL };
f441eb
+	char *argv_sid[] = { "/usr/bin/net", "setdomainsid", NULL, NULL };
f441eb
+
f441eb
+	_adcli_info ("Trying to set Samba secret.\n");
f441eb
+	ret = _adcli_call_external_program (argv_pw[0], argv_pw,
f441eb
+	                                    enroll->computer_password, NULL, NULL);
f441eb
+	if (ret != ADCLI_SUCCESS) {
f441eb
+		_adcli_err ("Failed to set Samba computer account password.\n");
f441eb
+	}
f441eb
+
f441eb
+	argv_sid[2] = (char *) adcli_conn_get_domain_sid (enroll->conn);
f441eb
+	if (argv_sid[2] == NULL) {
f441eb
+		_adcli_err ("Domain SID not available.\n");
f441eb
+	} else {
f441eb
+		_adcli_info ("Trying to set domain SID %s for Samba.\n",
f441eb
+		             argv_sid[2]);
f441eb
+		ret = _adcli_call_external_program (argv_sid[0], argv_sid,
f441eb
+		                                    NULL, NULL, NULL);
f441eb
+		if (ret != ADCLI_SUCCESS) {
f441eb
+			_adcli_err ("Failed to set Samba domain SID.\n");
f441eb
+		}
f441eb
+	}
f441eb
+
f441eb
+	return ret;
f441eb
+}
f441eb
+
f441eb
 static void
f441eb
 enroll_clear_state (adcli_enroll *enroll)
f441eb
 {
f441eb
@@ -1687,6 +1717,15 @@ enroll_join_or_update_tasks (adcli_enroll *enroll,
f441eb
 	update_computer_account (enroll);
f441eb
 	update_service_principals (enroll);
f441eb
 
f441eb
+	if ( (flags & ADCLI_ENROLL_ADD_SAMBA_DATA) && ! (flags & ADCLI_ENROLL_PASSWORD_VALID)) {
f441eb
+		res = update_samba_data (enroll);
f441eb
+		if (res != ADCLI_SUCCESS) {
f441eb
+			_adcli_info ("Failed to add Samba specific data, smbd "
f441eb
+			             "or winbindd might not work as "
f441eb
+			             "expected.\n");
f441eb
+		}
f441eb
+	}
f441eb
+
f441eb
 	if (flags & ADCLI_ENROLL_NO_KEYTAB)
f441eb
 		return ADCLI_SUCCESS;
f441eb
 
f441eb
-- 
f441eb
2.14.4
f441eb