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

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