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

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