Blame SOURCES/0002-add-description-option-to-join-and-update.patch

48b328
From 3937a2a7db90611aa7a93248233b0c5d31e85a3e Mon Sep 17 00:00:00 2001
48b328
From: Sumit Bose <sbose@redhat.com>
48b328
Date: Wed, 27 Nov 2019 14:48:32 +0100
48b328
Subject: [PATCH 2/2] add description option to join and update
48b328
48b328
This new option allows to set the description LDAP attribute for the AD
48b328
computer object.
48b328
48b328
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1737342
48b328
---
48b328
 doc/adcli.xml      | 10 ++++++++++
48b328
 library/adenroll.c | 29 +++++++++++++++++++++++++++++
48b328
 library/adenroll.h |  4 ++++
48b328
 tools/computer.c   |  7 +++++++
48b328
 4 files changed, 50 insertions(+)
48b328
48b328
diff --git a/doc/adcli.xml b/doc/adcli.xml
48b328
index 1f93186..dd30435 100644
48b328
--- a/doc/adcli.xml
48b328
+++ b/doc/adcli.xml
48b328
@@ -275,6 +275,11 @@ Password for Administrator:
48b328
 			<listitem><para>Set the operating system version on the computer
48b328
 			account. Not set by default.</para></listitem>
48b328
 		</varlistentry>
48b328
+		<varlistentry>
48b328
+			<term><option>--description=<parameter>description</parameter></option></term>
48b328
+			<listitem><para>Set the description attribute on the computer
48b328
+			account. Not set by default.</para></listitem>
48b328
+		</varlistentry>
48b328
 		<varlistentry>
48b328
 			<term><option>--service-name=<parameter>service</parameter></option></term>
48b328
 			<listitem><para>Additional service name for a kerberos
48b328
@@ -416,6 +421,11 @@ $ adcli update --login-ccache=/tmp/krbcc_123
48b328
 			<listitem><para>Set the operating system version on the computer
48b328
 			account. Not set by default.</para></listitem>
48b328
 		</varlistentry>
48b328
+		<varlistentry>
48b328
+			<term><option>--description=<parameter>description</parameter></option></term>
48b328
+			<listitem><para>Set the description attribute on the computer
48b328
+			account. Not set by default.</para></listitem>
48b328
+		</varlistentry>
48b328
 		<varlistentry>
48b328
 			<term><option>--service-name=<parameter>service</parameter></option></term>
48b328
 			<listitem><para>Additional service name for a Kerberos
48b328
diff --git a/library/adenroll.c b/library/adenroll.c
48b328
index 8d2adeb..246f658 100644
48b328
--- a/library/adenroll.c
48b328
+++ b/library/adenroll.c
48b328
@@ -83,6 +83,7 @@ static char *default_ad_ldap_attrs[] =  {
48b328
 	"operatingSystemServicePack",
48b328
 	"pwdLastSet",
48b328
 	"userAccountControl",
48b328
+	"description",
48b328
 	NULL,
48b328
 };
48b328
 
48b328
@@ -143,6 +144,7 @@ struct _adcli_enroll {
48b328
 	char *samba_data_tool;
48b328
 	bool trusted_for_delegation;
48b328
 	int trusted_for_delegation_explicit;
48b328
+	char *description;
48b328
 };
48b328
 
48b328
 static adcli_result
48b328
@@ -756,6 +758,8 @@ create_computer_account (adcli_enroll *enroll,
48b328
 	char *vals_userPrincipalName[] = { enroll->user_principal, NULL };
48b328
 	LDAPMod userPrincipalName = { LDAP_MOD_ADD, "userPrincipalName", { vals_userPrincipalName, }, };
48b328
 	LDAPMod servicePrincipalName = { LDAP_MOD_ADD, "servicePrincipalName", { enroll->service_principals, } };
48b328
+	char *vals_description[] = { enroll->description, NULL };
48b328
+	LDAPMod description = { LDAP_MOD_ADD, "description", { vals_description, }, };
48b328
 
48b328
 	char *val = NULL;
48b328
 
48b328
@@ -774,6 +778,7 @@ create_computer_account (adcli_enroll *enroll,
48b328
 		&operatingSystemServicePack,
48b328
 		&userPrincipalName,
48b328
 		&servicePrincipalName,
48b328
+		&description,
48b328
 		NULL
48b328
 	};
48b328
 
48b328
@@ -1460,6 +1465,14 @@ update_computer_account (adcli_enroll *enroll)
48b328
 		res |= update_computer_attribute (enroll, ldap, mods);
48b328
 	}
48b328
 
48b328
+	if (res == ADCLI_SUCCESS && enroll->description != NULL) {
48b328
+		char *vals_description[] = { enroll->description, NULL };
48b328
+		LDAPMod description = { LDAP_MOD_REPLACE, "description", { vals_description, }, };
48b328
+		LDAPMod *mods[] = { &description, NULL, };
48b328
+
48b328
+		res |= update_computer_attribute (enroll, ldap, mods);
48b328
+	}
48b328
+
48b328
 	if (res != 0)
48b328
 		_adcli_info ("Updated existing computer account: %s", enroll->computer_dn);
48b328
 }
48b328
@@ -2899,6 +2912,22 @@ adcli_enroll_set_trusted_for_delegation (adcli_enroll *enroll,
48b328
 	enroll->trusted_for_delegation_explicit = 1;
48b328
 }
48b328
 
48b328
+void
48b328
+adcli_enroll_set_description (adcli_enroll *enroll, const char *value)
48b328
+{
48b328
+	return_if_fail (enroll != NULL);
48b328
+	if (value != NULL && value[0] != '\0') {
48b328
+		_adcli_str_set (&enroll->description, value);
48b328
+	}
48b328
+}
48b328
+
48b328
+const char *
48b328
+adcli_enroll_get_desciption (adcli_enroll *enroll)
48b328
+{
48b328
+	return_val_if_fail (enroll != NULL, NULL);
48b328
+	return enroll->description;
48b328
+}
48b328
+
48b328
 const char **
48b328
 adcli_enroll_get_service_principals_to_add (adcli_enroll *enroll)
48b328
 {
48b328
diff --git a/library/adenroll.h b/library/adenroll.h
48b328
index 11eb517..0606169 100644
48b328
--- a/library/adenroll.h
48b328
+++ b/library/adenroll.h
48b328
@@ -126,6 +126,10 @@ bool               adcli_enroll_get_trusted_for_delegation (adcli_enroll *enroll
48b328
 void               adcli_enroll_set_trusted_for_delegation (adcli_enroll *enroll,
48b328
                                                             bool value);
48b328
 
48b328
+const char *       adcli_enroll_get_desciption          (adcli_enroll *enroll);
48b328
+void               adcli_enroll_set_description         (adcli_enroll *enroll,
48b328
+                                                         const char *value);
48b328
+
48b328
 krb5_kvno          adcli_enroll_get_kvno                (adcli_enroll *enroll);
48b328
 
48b328
 void               adcli_enroll_set_kvno                (adcli_enroll *enroll,
48b328
diff --git a/tools/computer.c b/tools/computer.c
48b328
index c8b96a4..840e334 100644
48b328
--- a/tools/computer.c
48b328
+++ b/tools/computer.c
48b328
@@ -112,6 +112,7 @@ typedef enum {
48b328
 	opt_trusted_for_delegation,
48b328
 	opt_add_service_principal,
48b328
 	opt_remove_service_principal,
48b328
+	opt_description,
48b328
 } Option;
48b328
 
48b328
 static adcli_tool_desc common_usages[] = {
48b328
@@ -142,6 +143,7 @@ static adcli_tool_desc common_usages[] = {
48b328
 	                              "in the userAccountControl attribute", },
48b328
 	{ opt_add_service_principal, "add the given service principal to the account\n" },
48b328
 	{ opt_remove_service_principal, "remove the given service principal from the account\n" },
48b328
+	{ opt_description, "add a description to the account\n" },
48b328
 	{ opt_no_password, "don't prompt for or read a password" },
48b328
 	{ opt_prompt_password, "prompt for a password if necessary" },
48b328
 	{ opt_stdin_password, "read a password from stdin (until EOF) if\n"
48b328
@@ -306,6 +308,9 @@ parse_option (Option opt,
48b328
 	case opt_remove_service_principal:
48b328
 		adcli_enroll_add_service_principal_to_remove (enroll, optarg);
48b328
 		return ADCLI_SUCCESS;
48b328
+	case opt_description:
48b328
+		adcli_enroll_set_description (enroll, optarg);
48b328
+		return ADCLI_SUCCESS;
48b328
 	case opt_verbose:
48b328
 		return ADCLI_SUCCESS;
48b328
 
48b328
@@ -369,6 +374,7 @@ adcli_tool_computer_join (adcli_conn *conn,
48b328
 		{ "os-name", required_argument, NULL, opt_os_name },
48b328
 		{ "os-version", required_argument, NULL, opt_os_version },
48b328
 		{ "os-service-pack", optional_argument, NULL, opt_os_service_pack },
48b328
+		{ "description", optional_argument, NULL, opt_description },
48b328
 		{ "user-principal", optional_argument, NULL, opt_user_principal },
48b328
 		{ "trusted-for-delegation", required_argument, NULL, opt_trusted_for_delegation },
48b328
 		{ "add-service-principal", required_argument, NULL, opt_add_service_principal },
48b328
@@ -487,6 +493,7 @@ adcli_tool_computer_update (adcli_conn *conn,
48b328
 		{ "os-name", required_argument, NULL, opt_os_name },
48b328
 		{ "os-version", required_argument, NULL, opt_os_version },
48b328
 		{ "os-service-pack", optional_argument, NULL, opt_os_service_pack },
48b328
+		{ "description", optional_argument, NULL, opt_description },
48b328
 		{ "user-principal", optional_argument, NULL, opt_user_principal },
48b328
 		{ "computer-password-lifetime", optional_argument, NULL, opt_computer_password_lifetime },
48b328
 		{ "trusted-for-delegation", required_argument, NULL, opt_trusted_for_delegation },
48b328
-- 
48b328
2.21.0
48b328