File 0014-Only-update-attributes-given-on-the-command-line.patch of Package adcli
127
1
From 4bffff31b08347dccf13cdf43776ac7d36e58d1f Mon Sep 17 00:00:00 2001
2
From: Sumit Bose <sbose@redhat.com>
3
Date: Fri, 1 Jun 2018 21:26:47 +0200
4
Subject: [PATCH 14/25] Only update attributes given on the command line
5
6
When updating attributes of the LDAP computer object we only want to
7
update attributes which are related to options given on the command
8
line. Otherwise a simple call of 'adcli update' to check if the machine
9
account password needs an update might unexpectedly reset other
10
attributes as well.
11
12
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1547013
13
https://bugzilla.redhat.com/show_bug.cgi?id=1545568
14
https://bugzilla.redhat.com/show_bug.cgi?id=1538730
15
---
16
library/adenroll.c | 35 ++++++++++++++++++++++++++++++-----
17
1 file changed, 30 insertions(+), 5 deletions(-)
18
19
diff --git a/library/adenroll.c b/library/adenroll.c
20
index 691d993..1cc8ffc 100644
21
--- a/library/adenroll.c
22
+++ b/library/adenroll.c
23
24
int user_princpal_generate;
25
26
char *os_name;
27
+ int os_name_explicit;
28
char *os_version;
29
+ int os_version_explicit;
30
char *os_service_pack;
31
+ int os_service_pack_explicit;
32
33
krb5_kvno kvno;
34
char *keytab_name;
35
36
unsigned int computer_password_lifetime;
37
int computer_password_lifetime_explicit;
38
bool trusted_for_delegation;
39
+ int trusted_for_delegation_explicit;
40
};
41
42
static adcli_result
43
44
ldap = adcli_conn_get_ldap_connection (enroll->conn);
45
return_if_fail (ldap != NULL);
46
47
- {
48
+ /* Only update attributes which are explicitly given on the command
49
+ * line. Otherwise 'adcli update' must be always called with the same
50
+ * set of options to make sure existing attributes are not deleted or
51
+ * overwritten with different values. */
52
+ if (enroll->host_fqdn_explicit) {
53
char *vals_dNSHostName[] = { enroll->host_fqdn, NULL };
54
LDAPMod dNSHostName = { LDAP_MOD_REPLACE, "dNSHostName", { vals_dNSHostName, } };
55
LDAPMod *mods[] = { &dNSHostName, NULL };
56
57
res |= update_computer_attribute (enroll, ldap, mods);
58
}
59
60
- if (res == ADCLI_SUCCESS) {
61
+ if (res == ADCLI_SUCCESS && enroll->trusted_for_delegation_explicit) {
62
char *vals_userAccountControl[] = { NULL , NULL };
63
LDAPMod userAccountControl = { LDAP_MOD_REPLACE, "userAccountControl", { vals_userAccountControl, } };
64
LDAPMod *mods[] = { &userAccountControl, NULL };
65
66
LDAPMod operatingSystemVersion = { LDAP_MOD_REPLACE, "operatingSystemVersion", { vals_operatingSystemVersion, } };
67
char *vals_operatingSystemServicePack[] = { enroll->os_service_pack, NULL };
68
LDAPMod operatingSystemServicePack = { LDAP_MOD_REPLACE, "operatingSystemServicePack", { vals_operatingSystemServicePack, } };
69
- LDAPMod *mods[] = { &operatingSystem, &operatingSystemVersion, &operatingSystemServicePack, NULL };
70
+ LDAPMod *mods[] = { NULL, NULL, NULL, NULL };
71
+ size_t c = 0;
72
73
- res |= update_computer_attribute (enroll, ldap, mods);
74
+ if (enroll->os_name_explicit) {
75
+ mods[c++] = &operatingSystem;
76
+ }
77
+ if (enroll->os_version_explicit) {
78
+ mods[c++] = &operatingSystemVersion;
79
+ }
80
+ if (enroll->os_service_pack_explicit) {
81
+ mods[c++] = &operatingSystemServicePack;
82
+ }
83
+
84
+ if (c != 0) {
85
+ res |= update_computer_attribute (enroll, ldap, mods);
86
+ }
87
}
88
89
- if (res == ADCLI_SUCCESS) {
90
+ if (res == ADCLI_SUCCESS && !enroll->user_princpal_generate) {
91
char *vals_userPrincipalName[] = { enroll->user_principal, NULL };
92
LDAPMod userPrincipalName = { LDAP_MOD_REPLACE, "userPrincipalName", { vals_userPrincipalName, }, };
93
LDAPMod *mods[] = { &userPrincipalName, NULL, };
94
95
if (value && value[0] == '\0')
96
value = NULL;
97
_adcli_str_set (&enroll->os_name, value);
98
+ enroll->os_name_explicit = 1;
99
}
100
101
const char *
102
103
if (value && value[0] == '\0')
104
value = NULL;
105
_adcli_str_set (&enroll->os_version, value);
106
+ enroll->os_version_explicit = 1;
107
}
108
109
const char *
110
111
if (value && value[0] == '\0')
112
value = NULL;
113
_adcli_str_set (&enroll->os_service_pack, value);
114
+ enroll->os_service_pack_explicit = 1;
115
}
116
117
const char *
118
119
return_if_fail (enroll != NULL);
120
121
enroll->trusted_for_delegation = value;
122
+ enroll->trusted_for_delegation_explicit = 1;
123
}
124
--
125
2.16.4
126
127