|
|
419917 |
From cd5b6cdcf3e6bfc5776f2865f460f608421dfa3f Mon Sep 17 00:00:00 2001
|
|
|
419917 |
From: Sumit Bose <sbose@redhat.com>
|
|
|
419917 |
Date: Mon, 14 Jun 2021 08:42:21 +0200
|
|
|
419917 |
Subject: [PATCH 2/2] Add delattr option
|
|
|
419917 |
|
|
|
419917 |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1690920
|
|
|
419917 |
---
|
|
|
419917 |
doc/adcli.xml | 11 ++++++++
|
|
|
419917 |
library/adenroll.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
419917 |
library/adenroll.h | 4 +++
|
|
|
419917 |
tools/computer.c | 9 +++++++
|
|
|
419917 |
4 files changed, 90 insertions(+)
|
|
|
419917 |
|
|
|
419917 |
diff --git a/doc/adcli.xml b/doc/adcli.xml
|
|
|
419917 |
index 8383aa7..bcf4857 100644
|
|
|
419917 |
--- a/doc/adcli.xml
|
|
|
419917 |
+++ b/doc/adcli.xml
|
|
|
419917 |
@@ -577,6 +577,17 @@ $ adcli update --login-ccache=/tmp/krbcc_123
|
|
|
419917 |
adcli options cannot be set with this option.</para>
|
|
|
419917 |
</listitem>
|
|
|
419917 |
</varlistentry>
|
|
|
419917 |
+ <varlistentry>
|
|
|
419917 |
+ <term><option>--delattr=<parameter>name</parameter></option></term>
|
|
|
419917 |
+ <listitem><para>Remove the LDAP attribute
|
|
|
419917 |
+ <option><parameter>name</parameter></option> from the
|
|
|
419917 |
+ LDAP host object. This option can be used multiple
|
|
|
419917 |
+ times to remove multiple different attributes.</para>
|
|
|
419917 |
+ <para>Please note that the account used to update the
|
|
|
419917 |
+ host object must have the required privileges to delete
|
|
|
419917 |
+ the given attributes. Attributes managed by other adcli
|
|
|
419917 |
+ options cannot be removed.</para></listitem>
|
|
|
419917 |
+ </varlistentry>
|
|
|
419917 |
<varlistentry>
|
|
|
419917 |
<term><option>--show-details</option></term>
|
|
|
419917 |
<listitem><para>After a successful join print out information
|
|
|
419917 |
diff --git a/library/adenroll.c b/library/adenroll.c
|
|
|
419917 |
index dd51567..9a06d52 100644
|
|
|
419917 |
--- a/library/adenroll.c
|
|
|
419917 |
+++ b/library/adenroll.c
|
|
|
419917 |
@@ -151,5 +151,6 @@ struct _adcli_enroll {
|
|
|
419917 |
char *description;
|
|
|
419917 |
char **setattr;
|
|
|
419917 |
+ char **delattr;
|
|
|
419917 |
};
|
|
|
419917 |
|
|
|
419917 |
static const char *
|
|
|
419917 |
@@ -845,6 +846,39 @@ get_mods_for_attrs (adcli_enroll *enroll, int mod_op)
|
|
|
419917 |
return mods;
|
|
|
419917 |
}
|
|
|
419917 |
|
|
|
419917 |
+static LDAPMod **
|
|
|
419917 |
+get_del_mods_for_attrs (adcli_enroll *enroll, int mod_op)
|
|
|
419917 |
+{
|
|
|
419917 |
+ size_t len;
|
|
|
419917 |
+ size_t c;
|
|
|
419917 |
+ LDAPMod **mods = NULL;
|
|
|
419917 |
+
|
|
|
419917 |
+ len = _adcli_strv_len (enroll->delattr);
|
|
|
419917 |
+ if (len == 0) {
|
|
|
419917 |
+ return NULL;
|
|
|
419917 |
+ }
|
|
|
419917 |
+
|
|
|
419917 |
+ mods = calloc (len + 1, sizeof (LDAPMod *));
|
|
|
419917 |
+ return_val_if_fail (mods != NULL, NULL);
|
|
|
419917 |
+
|
|
|
419917 |
+ for (c = 0; c < len; c++) {
|
|
|
419917 |
+ mods[c] = calloc (1, sizeof (LDAPMod));
|
|
|
419917 |
+ if (mods[c] == NULL) {
|
|
|
419917 |
+ ldap_mods_free (mods, 1);
|
|
|
419917 |
+ return NULL;
|
|
|
419917 |
+ }
|
|
|
419917 |
+
|
|
|
419917 |
+ mods[c]->mod_op = mod_op;
|
|
|
419917 |
+ mods[c]->mod_type = strdup (enroll->delattr[c]);
|
|
|
419917 |
+ mods[c]->mod_values = NULL;
|
|
|
419917 |
+ if (mods[c]->mod_type == NULL) {
|
|
|
419917 |
+ ldap_mods_free (mods, 1);
|
|
|
419917 |
+ return NULL;
|
|
|
419917 |
+ }
|
|
|
419917 |
+ }
|
|
|
419917 |
+
|
|
|
419917 |
+ return mods;
|
|
|
419917 |
+}
|
|
|
419917 |
|
|
|
419917 |
static adcli_result
|
|
|
419917 |
create_computer_account (adcli_enroll *enroll,
|
|
|
419917 |
@@ -1775,6 +1809,14 @@ update_computer_account (adcli_enroll *enroll)
|
|
|
419917 |
}
|
|
|
419917 |
}
|
|
|
419917 |
|
|
|
419917 |
+ if (res == ADCLI_SUCCESS && enroll->delattr != NULL) {
|
|
|
419917 |
+ LDAPMod **mods = get_del_mods_for_attrs (enroll, LDAP_MOD_DELETE);
|
|
|
419917 |
+ if (mods != NULL) {
|
|
|
419917 |
+ res |= update_computer_attribute (enroll, ldap, mods);
|
|
|
419917 |
+ ldap_mods_free (mods, 1);
|
|
|
419917 |
+ }
|
|
|
419917 |
+ }
|
|
|
419917 |
+
|
|
|
419917 |
if (res != 0)
|
|
|
419917 |
_adcli_info ("Updated existing computer account: %s", enroll->computer_dn);
|
|
|
419917 |
}
|
|
|
419917 |
@@ -3475,6 +3517,30 @@ adcli_enroll_get_setattr (adcli_enroll *enroll)
|
|
|
419917 |
return (const char **) enroll->setattr;
|
|
|
419917 |
}
|
|
|
419917 |
|
|
|
419917 |
+adcli_result
|
|
|
419917 |
+adcli_enroll_add_delattr (adcli_enroll *enroll, const char *value)
|
|
|
419917 |
+{
|
|
|
419917 |
+ return_val_if_fail (enroll != NULL, ADCLI_ERR_CONFIG);
|
|
|
419917 |
+ return_val_if_fail (value != NULL, ADCLI_ERR_CONFIG);
|
|
|
419917 |
+
|
|
|
419917 |
+ if (_adcli_strv_has_ex (default_ad_ldap_attrs, value, strcasecmp) == 1) {
|
|
|
419917 |
+ _adcli_err ("Attribute [%s] cannot be removed with delattr", value);
|
|
|
419917 |
+ return ADCLI_ERR_CONFIG;
|
|
|
419917 |
+ }
|
|
|
419917 |
+
|
|
|
419917 |
+ enroll->delattr = _adcli_strv_add (enroll->delattr, strdup (value),
|
|
|
419917 |
+ NULL);
|
|
|
419917 |
+ return_val_if_fail (enroll->delattr != NULL, ADCLI_ERR_CONFIG);
|
|
|
419917 |
+
|
|
|
419917 |
+ return ADCLI_SUCCESS;
|
|
|
419917 |
+}
|
|
|
419917 |
+
|
|
|
419917 |
+const char **
|
|
|
419917 |
+adcli_enroll_get_delattr (adcli_enroll *enroll)
|
|
|
419917 |
+{
|
|
|
419917 |
+ return_val_if_fail (enroll != NULL, NULL);
|
|
|
419917 |
+ return (const char **) enroll->delattr;
|
|
|
419917 |
+}
|
|
|
419917 |
|
|
|
419917 |
#ifdef ADENROLL_TESTS
|
|
|
419917 |
|
|
|
419917 |
diff --git a/library/adenroll.h b/library/adenroll.h
|
|
|
419917 |
index 862bb60..e3ada33 100644
|
|
|
419917 |
--- a/library/adenroll.h
|
|
|
419917 |
+++ b/library/adenroll.h
|
|
|
419917 |
@@ -142,6 +142,10 @@ const char ** adcli_enroll_get_setattr (adcli_enroll *enroll);
|
|
|
419917 |
adcli_result adcli_enroll_add_setattr (adcli_enroll *enroll,
|
|
|
419917 |
const char *value);
|
|
|
419917 |
|
|
|
419917 |
+const char ** adcli_enroll_get_delattr (adcli_enroll *enroll);
|
|
|
419917 |
+adcli_result adcli_enroll_add_delattr (adcli_enroll *enroll,
|
|
|
419917 |
+ const char *value);
|
|
|
419917 |
+
|
|
|
419917 |
bool adcli_enroll_get_is_service (adcli_enroll *enroll);
|
|
|
419917 |
void adcli_enroll_set_is_service (adcli_enroll *enroll,
|
|
|
419917 |
bool value);
|
|
|
419917 |
diff --git a/tools/computer.c b/tools/computer.c
|
|
|
419917 |
index af38894..dffeecb 100644
|
|
|
419917 |
--- a/tools/computer.c
|
|
|
419917 |
+++ b/tools/computer.c
|
|
|
419917 |
@@ -115,6 +115,7 @@ typedef enum {
|
|
|
419917 |
opt_remove_service_principal,
|
|
|
419917 |
opt_description,
|
|
|
419917 |
opt_setattr,
|
|
|
419917 |
+ opt_delattr,
|
|
|
419917 |
opt_use_ldaps,
|
|
|
419917 |
} Option;
|
|
|
419917 |
|
|
|
419917 |
@@ -154,6 +155,7 @@ static adcli_tool_desc common_usages[] = {
|
|
|
419917 |
{ opt_remove_service_principal, "remove the given service principal from the account\n" },
|
|
|
419917 |
{ opt_description, "add a description to the account\n" },
|
|
|
419917 |
{ opt_setattr, "add an attribute with a value\n" },
|
|
|
419917 |
+ { opt_delattr, "remove an attribute\n" },
|
|
|
419917 |
{ opt_no_password, "don't prompt for or read a password" },
|
|
|
419917 |
{ opt_prompt_password, "prompt for a password if necessary" },
|
|
|
419917 |
{ opt_stdin_password, "read a password from stdin (until EOF) if\n"
|
|
|
419917 |
@@ -341,6 +343,12 @@ parse_option (Option opt,
|
|
|
419917 |
warnx ("parsing setattr option failed");
|
|
|
419917 |
}
|
|
|
419917 |
return ret;
|
|
|
419917 |
+ case opt_delattr:
|
|
|
419917 |
+ ret = adcli_enroll_add_delattr (enroll, optarg);
|
|
|
419917 |
+ if (ret != ADCLI_SUCCESS) {
|
|
|
419917 |
+ warnx ("parsing delattr option failed");
|
|
|
419917 |
+ }
|
|
|
419917 |
+ return ret;
|
|
|
419917 |
case opt_use_ldaps:
|
|
|
419917 |
adcli_conn_set_use_ldaps (conn, true);
|
|
|
419917 |
return ADCLI_SUCCESS;
|
|
|
419917 |
@@ -534,6 +542,7 @@ adcli_tool_computer_update (adcli_conn *conn,
|
|
|
419917 |
{ "os-service-pack", optional_argument, NULL, opt_os_service_pack },
|
|
|
419917 |
{ "description", optional_argument, NULL, opt_description },
|
|
|
419917 |
{ "setattr", required_argument, NULL, opt_setattr },
|
|
|
419917 |
+ { "delattr", required_argument, NULL, opt_delattr },
|
|
|
419917 |
{ "user-principal", optional_argument, NULL, opt_user_principal },
|
|
|
419917 |
{ "computer-password-lifetime", optional_argument, NULL, opt_computer_password_lifetime },
|
|
|
419917 |
{ "trusted-for-delegation", required_argument, NULL, opt_trusted_for_delegation },
|
|
|
419917 |
--
|
|
|
419917 |
2.31.1
|
|
|
419917 |
|