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

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