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

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