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

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