Blame SOURCES/0005-enroll-make-adcli_enroll_add_keytab_for_service_acco.patch

436d93
From 81c98e367ba4bc8d77668acd31e462ad31cf12be Mon Sep 17 00:00:00 2001
436d93
From: Sumit Bose <sbose@redhat.com>
436d93
Date: Tue, 27 Oct 2020 14:47:31 +0100
436d93
Subject: [PATCH 5/7] enroll: make adcli_enroll_add_keytab_for_service_account
436d93
 public
436d93
436d93
Determine keytab name more early to catch errors more early.
436d93
436d93
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1854112
436d93
---
436d93
 library/adenroll.c | 13 +++++++------
436d93
 library/adenroll.h |  2 ++
436d93
 tools/computer.c   |  6 ++++++
436d93
 3 files changed, 15 insertions(+), 6 deletions(-)
436d93
436d93
diff --git a/library/adenroll.c b/library/adenroll.c
436d93
index 44383cc..05bb085 100644
436d93
--- a/library/adenroll.c
436d93
+++ b/library/adenroll.c
436d93
@@ -2276,9 +2276,10 @@ adcli_enroll_add_description_for_service_account (adcli_enroll *enroll)
436d93
 	return ADCLI_SUCCESS;
436d93
 }
436d93
 
436d93
-static adcli_result
436d93
+adcli_result
436d93
 adcli_enroll_add_keytab_for_service_account (adcli_enroll *enroll)
436d93
 {
436d93
+	adcli_result res;
436d93
 	krb5_context k5;
436d93
 	krb5_error_code code;
436d93
 	char def_keytab_name[MAX_KEYTAB_NAME_LEN];
436d93
@@ -2286,11 +2287,14 @@ adcli_enroll_add_keytab_for_service_account (adcli_enroll *enroll)
436d93
 	int ret;
436d93
 
436d93
 	if (adcli_enroll_get_keytab_name (enroll) == NULL) {
436d93
-		k5 = adcli_conn_get_krb5_context (enroll->conn);
436d93
-		return_unexpected_if_fail (k5 != NULL);
436d93
+		res = _adcli_krb5_init_context (&k5;;
436d93
+		if (res != ADCLI_SUCCESS) {
436d93
+			return res;
436d93
+		}
436d93
 
436d93
 		code = krb5_kt_default_name (k5, def_keytab_name,
436d93
 		                             sizeof (def_keytab_name));
436d93
+		krb5_free_context (k5);
436d93
 		return_unexpected_if_fail (code == 0);
436d93
 
436d93
 		lc_dom_name = strdup (adcli_conn_get_domain_name (enroll->conn));
436d93
@@ -2326,9 +2330,6 @@ adcli_enroll_join (adcli_enroll *enroll,
436d93
 
436d93
 	if (enroll->is_service) {
436d93
 		res = adcli_enroll_add_description_for_service_account (enroll);
436d93
-		if (res == ADCLI_SUCCESS) {
436d93
-			res = adcli_enroll_add_keytab_for_service_account (enroll);
436d93
-		}
436d93
 	} else {
436d93
 		res = ensure_default_service_names (enroll);
436d93
 	}
436d93
diff --git a/library/adenroll.h b/library/adenroll.h
436d93
index 7765ed4..11a30c8 100644
436d93
--- a/library/adenroll.h
436d93
+++ b/library/adenroll.h
436d93
@@ -146,6 +146,8 @@ const char *       adcli_enroll_get_keytab_name         (adcli_enroll *enroll);
436d93
 void               adcli_enroll_set_keytab_name         (adcli_enroll *enroll,
436d93
                                                          const char *value);
436d93
 
436d93
+adcli_result       adcli_enroll_add_keytab_for_service_account (adcli_enroll *enroll);
436d93
+
436d93
 krb5_enctype *     adcli_enroll_get_keytab_enctypes     (adcli_enroll *enroll);
436d93
 
436d93
 void               adcli_enroll_set_keytab_enctypes     (adcli_enroll *enroll,
436d93
diff --git a/tools/computer.c b/tools/computer.c
436d93
index 63fd374..98a0472 100644
436d93
--- a/tools/computer.c
436d93
+++ b/tools/computer.c
436d93
@@ -1166,6 +1166,12 @@ adcli_tool_computer_managed_service_account (adcli_conn *conn,
436d93
 
436d93
 	adcli_enroll_set_is_service (enroll, true);
436d93
 	adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
436d93
+	res = adcli_enroll_add_keytab_for_service_account (enroll);
436d93
+	if (res != ADCLI_SUCCESS) {
436d93
+		warnx ("Failed to set domain specific keytab name");
436d93
+		adcli_enroll_unref (enroll);
436d93
+		return 2;
436d93
+	}
436d93
 
436d93
 	res = adcli_enroll_load (enroll);
436d93
 	if (res != ADCLI_SUCCESS) {
436d93
-- 
436d93
2.28.0
436d93