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

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