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

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