Blame SOURCES/0003-enroll-use-computer-or-service-in-debug-messages.patch

436d93
From eea6a8071b5e5df74808903bb15b30acf820ce3f Mon Sep 17 00:00:00 2001
436d93
From: Sumit Bose <sbose@redhat.com>
436d93
Date: Fri, 23 Oct 2020 16:55:11 +0200
436d93
Subject: [PATCH 3/7] enroll: use 'computer' or 'service' in debug messages
436d93
436d93
Use proper account type in debug messages.
436d93
436d93
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1854112
436d93
---
436d93
 library/adenroll.c | 115 ++++++++++++++++++++++++++++-----------------
436d93
 1 file changed, 72 insertions(+), 43 deletions(-)
436d93
436d93
diff --git a/library/adenroll.c b/library/adenroll.c
436d93
index dbfda36..9cdc79b 100644
436d93
--- a/library/adenroll.c
436d93
+++ b/library/adenroll.c
436d93
@@ -155,6 +155,12 @@ struct _adcli_enroll {
436d93
 	char *description;
436d93
 };
436d93
 
436d93
+static const char *
436d93
+s_or_c (adcli_enroll *enroll)
436d93
+{
436d93
+	return enroll->is_service ? "service" : "computer";
436d93
+}
436d93
+
436d93
 static void
436d93
 check_if_service (adcli_enroll *enroll,
436d93
                   LDAP *ldap,
436d93
@@ -203,13 +209,15 @@ ensure_computer_name (adcli_result res,
436d93
 		return res;
436d93
 
436d93
 	if (enroll->computer_name) {
436d93
-		_adcli_info ("Enrolling computer name: %s",
436d93
+		_adcli_info ("Enrolling %s name: %s",
436d93
+		             s_or_c (enroll),
436d93
 		             enroll->computer_name);
436d93
 		return ADCLI_SUCCESS;
436d93
 	}
436d93
 
436d93
 	if (!enroll->host_fqdn) {
436d93
-		_adcli_err ("No host name from which to determine the computer name");
436d93
+		_adcli_err ("No host name from which to determine the %s name",
436d93
+		            s_or_c (enroll));
436d93
 		return ADCLI_ERR_CONFIG;
436d93
 	}
436d93
 
436d93
@@ -603,7 +611,8 @@ lookup_computer_container (adcli_enroll *enroll,
436d93
 
436d93
 	} else if (ret != LDAP_SUCCESS) {
436d93
 		return _adcli_ldap_handle_failure (ldap, ADCLI_ERR_DIRECTORY,
436d93
-		                                   "Couldn't lookup computer container: %s", base);
436d93
+		                                   "Couldn't lookup %s container: %s",
436d93
+		                                   s_or_c (enroll), base);
436d93
 	}
436d93
 
436d93
 	values = _adcli_ldap_parse_values (ldap, results, attrs[0]);
436d93
@@ -614,8 +623,8 @@ lookup_computer_container (adcli_enroll *enroll,
436d93
 		if (strncmp (values[i], prefix, prefix_len) == 0) {
436d93
 			enroll->computer_container = strdup (values[i] + prefix_len);
436d93
 			return_unexpected_if_fail (enroll->computer_container != NULL);
436d93
-			_adcli_info ("Found well known computer container at: %s",
436d93
-			             enroll->computer_container);
436d93
+			_adcli_info ("Found well known %s container at: %s",
436d93
+			             s_or_c (enroll), enroll->computer_container);
436d93
 			break;
436d93
 		}
436d93
 	}
436d93
@@ -629,8 +638,9 @@ lookup_computer_container (adcli_enroll *enroll,
436d93
 		if (ret == LDAP_SUCCESS) {
436d93
 			enroll->computer_container = _adcli_ldap_parse_dn (ldap, results);
436d93
 			if (enroll->computer_container) {
436d93
-				_adcli_info ("Well known computer container not "
436d93
+				_adcli_info ("Well known %s container not "
436d93
 				             "found, but found suitable one at: %s",
436d93
+				             s_or_c (enroll),
436d93
 				             enroll->computer_container);
436d93
 			}
436d93
 		}
436d93
@@ -646,7 +656,8 @@ lookup_computer_container (adcli_enroll *enroll,
436d93
 	}
436d93
 
436d93
 	if (!enroll->computer_container) {
436d93
-		_adcli_err ("Couldn't find location to create computer accounts");
436d93
+		_adcli_err ("Couldn't find location to create %s accounts",
436d93
+		            s_or_c (enroll));
436d93
 		return ADCLI_ERR_DIRECTORY;
436d93
 	}
436d93
 
436d93
@@ -674,7 +685,8 @@ calculate_computer_account (adcli_enroll *enroll,
436d93
 	if (asprintf (&enroll->computer_dn, "CN=%s,%s", enroll->computer_name, enroll->computer_container) < 0)
436d93
 		return_unexpected_if_reached ();
436d93
 
436d93
-	_adcli_info ("Calculated computer account: %s", enroll->computer_dn);
436d93
+	_adcli_info ("Calculated %s account: %s",
436d93
+	             s_or_c (enroll), enroll->computer_dn);
436d93
 	return ADCLI_SUCCESS;
436d93
 }
436d93
 
436d93
@@ -861,7 +873,8 @@ create_computer_account (adcli_enroll *enroll,
436d93
 		                                   enroll->computer_dn);
436d93
 	}
436d93
 
436d93
-	_adcli_info ("Created computer account: %s", enroll->computer_dn);
436d93
+	_adcli_info ("Created %s account: %s", s_or_c (enroll),
436d93
+	                                       enroll->computer_dn);
436d93
 	return ADCLI_SUCCESS;
436d93
 }
436d93
 
436d93
@@ -908,17 +921,17 @@ validate_computer_account (adcli_enroll *enroll,
436d93
 	assert (enroll->computer_dn != NULL);
436d93
 
436d93
 	if (already_exists && !allow_overwrite) {
436d93
-		_adcli_err ("The computer account %s already exists",
436d93
-		            enroll->computer_name);
436d93
+		_adcli_err ("The %s account %s already exists",
436d93
+		            s_or_c (enroll), enroll->computer_name);
436d93
 		return ADCLI_ERR_CONFIG;
436d93
 	}
436d93
 
436d93
 	/* Do we have an explicitly requested ou? */
436d93
 	if (enroll->domain_ou && enroll->domain_ou_explicit && already_exists) {
436d93
 		if (!_adcli_ldap_dn_has_ancestor (enroll->computer_dn, enroll->domain_ou)) {
436d93
-			_adcli_err ("The computer account %s already exists, "
436d93
+			_adcli_err ("The %s account %s already exists, "
436d93
 			            "but is not in the desired organizational unit.",
436d93
-			            enroll->computer_name);
436d93
+			            s_or_c (enroll), enroll->computer_name);
436d93
 			return ADCLI_ERR_CONFIG;
436d93
 		}
436d93
 	}
436d93
@@ -943,7 +956,8 @@ delete_computer_account (adcli_enroll *enroll,
436d93
 		                                   "Couldn't delete computer account: %s",
436d93
 		                                   enroll->computer_dn);
436d93
 	} else {
436d93
-		_adcli_info ("Deleted computer account at: %s", enroll->computer_dn);
436d93
+		_adcli_info ("Deleted %s account at: %s", s_or_c (enroll),
436d93
+		                                          enroll->computer_dn);
436d93
 	}
436d93
 
436d93
 	return ADCLI_SUCCESS;
436d93
@@ -992,20 +1006,21 @@ locate_computer_account (adcli_enroll *enroll,
436d93
 			free (enroll->computer_dn);
436d93
 			enroll->computer_dn = strdup (dn);
436d93
 			return_unexpected_if_fail (enroll->computer_dn != NULL);
436d93
-			_adcli_info ("Found computer account for %s at: %s",
436d93
-			             enroll->computer_sam, dn);
436d93
+			_adcli_info ("Found %s account for %s at: %s",
436d93
+			             s_or_c (enroll), enroll->computer_sam, dn);
436d93
 			ldap_memfree (dn);
436d93
 
436d93
 		} else {
436d93
 			ldap_msgfree (results);
436d93
 			results = NULL;
436d93
-			_adcli_info ("Computer account for %s does not exist",
436d93
-			             enroll->computer_sam);
436d93
+			_adcli_info ("A %s account for %s does not exist",
436d93
+			             s_or_c (enroll), enroll->computer_sam);
436d93
 		}
436d93
 
436d93
 	} else {
436d93
 		return _adcli_ldap_handle_failure (ldap, ADCLI_ERR_DIRECTORY,
436d93
-		                                   "Couldn't lookup computer account: %s",
436d93
+		                                   "Couldn't lookup %s account: %s",
436d93
+		                                   s_or_c (enroll),
436d93
 		                                   enroll->computer_sam);
436d93
 	}
436d93
 
436d93
@@ -1039,7 +1054,9 @@ load_computer_account (adcli_enroll *enroll,
436d93
 	if (ret == LDAP_SUCCESS) {
436d93
 		entry = ldap_first_entry (ldap, results);
436d93
 		if (entry) {
436d93
-			_adcli_info ("Found computer account for %s at: %s",
436d93
+			check_if_service (enroll, ldap, results);
436d93
+			_adcli_info ("Found %s account for %s at: %s",
436d93
+			             s_or_c (enroll),
436d93
 			             enroll->computer_sam, enroll->computer_dn);
436d93
 		}
436d93
 
436d93
@@ -1146,7 +1163,8 @@ set_password_with_user_creds (adcli_enroll *enroll)
436d93
 	                                       &result_code_string, &result_string);
436d93
 
436d93
 	if (code != 0) {
436d93
-		_adcli_err ("Couldn't set password for computer account: %s: %s",
436d93
+		_adcli_err ("Couldn't set password for %s account: %s: %s",
436d93
+		            s_or_c (enroll),
436d93
 		            enroll->computer_sam, krb5_get_error_message (k5, code));
436d93
 		/* TODO: Parse out these values */
436d93
 		res = ADCLI_ERR_DIRECTORY;
436d93
@@ -1160,7 +1178,8 @@ set_password_with_user_creds (adcli_enroll *enroll)
436d93
 		if (result_string.length)
436d93
 			message = _adcli_str_dupn (result_string.data, result_string.length);
436d93
 #endif
436d93
-		_adcli_err ("Cannot set computer password: %.*s%s%s",
436d93
+		_adcli_err ("Cannot set %s password: %.*s%s%s",
436d93
+		            s_or_c (enroll),
436d93
 		            (int)result_code_string.length, result_code_string.data,
436d93
 		            message ? ": " : "", message ? message : "");
436d93
 		res = ADCLI_ERR_CREDENTIALS;
436d93
@@ -1170,7 +1189,7 @@ set_password_with_user_creds (adcli_enroll *enroll)
436d93
 		free (message);
436d93
 #endif
436d93
 	} else {
436d93
-		_adcli_info ("Set computer password");
436d93
+		_adcli_info ("Set %s password", s_or_c (enroll));
436d93
 		if (enroll->kvno > 0) {
436d93
 			enroll->kvno++;
436d93
 			_adcli_info ("kvno incremented to %d", enroll->kvno);
436d93
@@ -1203,7 +1222,8 @@ set_password_with_computer_creds (adcli_enroll *enroll)
436d93
 
436d93
 	code = _adcli_kinit_computer_creds (enroll->conn, "kadmin/changepw", NULL, &creds);
436d93
 	if (code != 0) {
436d93
-		_adcli_err ("Couldn't get change password ticket for computer account: %s: %s",
436d93
+		_adcli_err ("Couldn't get change password ticket for %s account: %s: %s",
436d93
+		            s_or_c (enroll),
436d93
 		            enroll->computer_sam, krb5_get_error_message (k5, code));
436d93
 		return ADCLI_ERR_DIRECTORY;
436d93
 	}
436d93
@@ -1214,7 +1234,8 @@ set_password_with_computer_creds (adcli_enroll *enroll)
436d93
 	krb5_free_cred_contents (k5, &creds);
436d93
 
436d93
 	if (code != 0) {
436d93
-		_adcli_err ("Couldn't change password for computer account: %s: %s",
436d93
+		_adcli_err ("Couldn't change password for %s account: %s: %s",
436d93
+		            s_or_c (enroll),
436d93
 		            enroll->computer_sam, krb5_get_error_message (k5, code));
436d93
 		/* TODO: Parse out these values */
436d93
 		res = ADCLI_ERR_DIRECTORY;
436d93
@@ -1284,7 +1305,8 @@ retrieve_computer_account (adcli_enroll *enroll)
436d93
 
436d93
 	if (ret != LDAP_SUCCESS) {
436d93
 		return _adcli_ldap_handle_failure (ldap, ADCLI_ERR_DIRECTORY,
436d93
-		                                   "Couldn't retrieve computer account info: %s",
436d93
+		                                   "Couldn't retrieve %s account info: %s",
436d93
+		                                   s_or_c (enroll),
436d93
 		                                   enroll->computer_dn);
436d93
 	}
436d93
 
436d93
@@ -1294,15 +1316,15 @@ retrieve_computer_account (adcli_enroll *enroll)
436d93
 		if (value != NULL) {
436d93
 			kvno = strtoul (value, &end, 10);
436d93
 			if (end == NULL || *end != '\0') {
436d93
-				_adcli_err ("Invalid kvno '%s' for computer account in directory: %s",
436d93
-				            value, enroll->computer_dn);
436d93
+				_adcli_err ("Invalid kvno '%s' for %s account in directory: %s",
436d93
+				            value, s_or_c (enroll), enroll->computer_dn);
436d93
 				res = ADCLI_ERR_DIRECTORY;
436d93
 
436d93
 			} else {
436d93
 				enroll->kvno = kvno;
436d93
 
436d93
-				_adcli_info ("Retrieved kvno '%s' for computer account in directory: %s",
436d93
-				             value, enroll->computer_dn);
436d93
+				_adcli_info ("Retrieved kvno '%s' for %s account in directory: %s",
436d93
+				             value, s_or_c (enroll), enroll->computer_dn);
436d93
 			}
436d93
 
436d93
 			free (value);
436d93
@@ -1311,8 +1333,8 @@ retrieve_computer_account (adcli_enroll *enroll)
436d93
 			/* Apparently old AD didn't have this attribute, use zero */
436d93
 			enroll->kvno = 0;
436d93
 
436d93
-			_adcli_info ("No kvno found for computer account in directory: %s",
436d93
-			             enroll->computer_dn);
436d93
+			_adcli_info ("No kvno found for %s account in directory: %s",
436d93
+			             s_or_c (enroll), enroll->computer_dn);
436d93
 		}
436d93
 	}
436d93
 
436d93
@@ -1353,12 +1375,14 @@ update_and_calculate_enctypes (adcli_enroll *enroll)
436d93
 
436d93
 	if (ret == LDAP_INSUFFICIENT_ACCESS) {
436d93
 		return _adcli_ldap_handle_failure (ldap, ADCLI_ERR_CREDENTIALS,
436d93
-		                                   "Insufficient permissions to set encryption types on computer account: %s",
436d93
+		                                   "Insufficient permissions to set encryption types on %s account: %s",
436d93
+		                                   s_or_c (enroll),
436d93
 		                                   enroll->computer_dn);
436d93
 
436d93
 	} else if (ret != LDAP_SUCCESS) {
436d93
 		return _adcli_ldap_handle_failure (ldap, ADCLI_ERR_DIRECTORY,
436d93
-		                                   "Couldn't set encryption types on computer account: %s",
436d93
+		                                   "Couldn't set encryption types on %s account: %s",
436d93
+		                                   s_or_c (enroll),
436d93
 		                                   enroll->computer_dn);
436d93
 	}
436d93
 
436d93
@@ -1381,13 +1405,14 @@ update_computer_attribute (adcli_enroll *enroll,
436d93
 	string = _adcli_ldap_mods_to_string (mods);
436d93
 	return_unexpected_if_fail (string != NULL);
436d93
 
436d93
-	_adcli_info ("Modifying computer account: %s", string);
436d93
+	_adcli_info ("Modifying %s account: %s", s_or_c (enroll), string);
436d93
 
436d93
 	ret = ldap_modify_ext_s (ldap, enroll->computer_dn, mods, NULL, NULL);
436d93
 
436d93
 	if (ret != LDAP_SUCCESS) {
436d93
-		_adcli_warn ("Couldn't set %s on computer account: %s: %s",
436d93
-		             string, enroll->computer_dn, ldap_err2string (ret));
436d93
+		_adcli_warn ("Couldn't set %s on %s account: %s: %s",
436d93
+		             string, s_or_c (enroll), enroll->computer_dn,
436d93
+		             ldap_err2string (ret));
436d93
 		res = ADCLI_ERR_DIRECTORY;
436d93
 	}
436d93
 
436d93
@@ -1411,8 +1436,8 @@ static char *get_user_account_control (adcli_enroll *enroll)
436d93
 
436d93
 		attr_val = strtoul (uac_str, &end, 10);
436d93
 		if (*end != '\0' || attr_val > UINT32_MAX) {
436d93
-			_adcli_warn ("Invalid userAccountControl '%s' for computer account in directory: %s, assuming 0",
436d93
-			            uac_str, enroll->computer_dn);
436d93
+			_adcli_warn ("Invalid userAccountControl '%s' for %s account in directory: %s, assuming 0",
436d93
+			            uac_str, s_or_c (enroll), enroll->computer_dn);
436d93
 		} else {
436d93
 			uac = attr_val;
436d93
 		}
436d93
@@ -1653,7 +1678,8 @@ load_keytab_entry (krb5_context k5,
436d93
 		    _adcli_str_has_suffix (name, "$") && !strchr (name, '/')) {
436d93
 			enroll->computer_name = name;
436d93
 			name[len - 1] = '\0';
436d93
-			_adcli_info ("Found computer name in keytab: %s", name);
436d93
+			_adcli_info ("Found %s name in keytab: %s",
436d93
+			             s_or_c (enroll), name);
436d93
 			adcli_conn_set_computer_name (enroll->conn,
436d93
 			                              enroll->computer_name);
436d93
 			name = NULL;
436d93
@@ -2348,7 +2374,8 @@ adcli_enroll_read_computer_account (adcli_enroll *enroll,
436d93
 		if (res != ADCLI_SUCCESS)
436d93
 			return res;
436d93
 		if (!enroll->computer_dn) {
436d93
-			_adcli_err ("No computer account for %s exists", enroll->computer_sam);
436d93
+			_adcli_err ("No %s account for %s exists",
436d93
+			            s_or_c (enroll), enroll->computer_sam);
436d93
 			return ADCLI_ERR_CONFIG;
436d93
 		}
436d93
 	}
436d93
@@ -2460,7 +2487,8 @@ adcli_enroll_delete (adcli_enroll *enroll,
436d93
 		if (res != ADCLI_SUCCESS)
436d93
 			return res;
436d93
 		if (!enroll->computer_dn) {
436d93
-			_adcli_err ("No computer account for %s exists",
436d93
+			_adcli_err ("No %s account for %s exists",
436d93
+			            s_or_c (enroll),
436d93
 			            enroll->computer_sam);
436d93
 			return ADCLI_ERR_CONFIG;
436d93
 		}
436d93
@@ -2503,7 +2531,8 @@ adcli_enroll_password (adcli_enroll *enroll,
436d93
 		if (res != ADCLI_SUCCESS)
436d93
 			return res;
436d93
 		if (!enroll->computer_dn) {
436d93
-			_adcli_err ("No computer account for %s exists",
436d93
+			_adcli_err ("No %s account for %s exists",
436d93
+			            s_or_c (enroll),
436d93
 			            enroll->computer_sam);
436d93
 			return ADCLI_ERR_CONFIG;
436d93
 		}
436d93
-- 
436d93
2.28.0
436d93