File 0013-Add-trusted-for-delegation-option.patch of Package adcli (Revision ce46d0e7322eb68daa00b5c190e5847d)
Currently displaying revision ce46d0e7322eb68daa00b5c190e5847d , Show latest
xxxxxxxxxx
1
From 327f6bdd5c03406d7c3d1945a8d433eb45123369 Mon Sep 17 00:00:00 2001
2
From: Sumit Bose <sbose@redhat.com>
3
Date: Thu, 31 May 2018 18:27:37 +0200
4
Subject: [PATCH 13/25] Add trusted-for-delegation option
5
6
Resolves https://bugzilla.redhat.com/show_bug.cgi?id=1538730
7
---
8
doc/adcli.xml | 14 ++++++++++
9
library/adenroll.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
10
library/adenroll.h | 4 +++
11
tools/computer.c | 12 ++++++++
12
4 files changed, 108 insertions(+), 2 deletions(-)
13
14
diff --git a/doc/adcli.xml b/doc/adcli.xml
15
index c54cc1b..2cd56fb 100644
16
--- a/doc/adcli.xml
17
+++ b/doc/adcli.xml
18
19
<option>--login-type=computer</option> and providing a
20
password as input.</para></listitem>
21
</varlistentry>
22
+ <varlistentry>
23
+ <term><option>--trusted-for-delegation=<parameter>yes|no|true|false</parameter></option></term>
24
+ <listitem><para>Set or unset the TRUSTED_FOR_DELEGATION
25
+ flag in the userAccountControl attribute to allow or
26
+ not allow that Kerberos tickets can be forwarded to the
27
+ host.</para></listitem>
28
+ </varlistentry>
29
<varlistentry>
30
<term><option>--show-details</option></term>
31
<listitem><para>After a successful join print out information
32
33
in days. By default the password is updated if it is
34
older than 30 days.</para></listitem>
35
</varlistentry>
36
+ <varlistentry>
37
+ <term><option>--trusted-for-delegation=<parameter>yes|no|true|false</parameter></option></term>
38
+ <listitem><para>Set or unset the TRUSTED_FOR_DELEGATION
39
+ flag in the userAccountControl attribute to allow or
40
+ not allow that Kerberos tickets can be forwarded to the
41
+ host.</para></listitem>
42
+ </varlistentry>
43
<varlistentry>
44
<term><option>--show-details</option></term>
45
<listitem><para>After a successful join print out information
46
diff --git a/library/adenroll.c b/library/adenroll.c
47
index bb970d1..691d993 100644
48
--- a/library/adenroll.c
49
+++ b/library/adenroll.c
50
51
0
52
};
53
54
+/* Some constants for the userAccountControl AD LDAP attribute, see e.g.
55
+ * https://support.microsoft.com/en-us/help/305144/how-to-use-the-useraccountcontrol-flags-to-manipulate-user-account-pro
56
+ * for details. */
57
+#define UAC_WORKSTATION_TRUST_ACCOUNT 0x1000
58
+#define UAC_DONT_EXPIRE_PASSWORD 0x10000
59
+#define UAC_TRUSTED_FOR_DELEGATION 0x80000
60
+
61
struct _adcli_enroll {
62
int refs;
63
adcli_conn *conn;
64
65
int keytab_enctypes_explicit;
66
unsigned int computer_password_lifetime;
67
int computer_password_lifetime_explicit;
68
+ bool trusted_for_delegation;
69
};
70
71
static adcli_result
72
73
NULL,
74
};
75
76
+ if (adcli_enroll_get_trusted_for_delegation (enroll)) {
77
+ vals_userAccountControl[0] = "593920"; /* WORKSTATION_TRUST_ACCOUNT | DONT_EXPIRE_PASSWD | TRUSTED_FOR_DELEGATION */
78
+ }
79
+
80
ret = ldap_add_ext_s (ldap, enroll->computer_dn, mods, NULL, NULL);
81
82
/*
83
84
"operatingSystemVersion",
85
"operatingSystemServicePack",
86
"pwdLastSet",
87
+ "userAccountControl",
88
NULL,
89
};
90
91
92
return res;
93
}
94
95
+static char *get_user_account_control (adcli_enroll *enroll)
96
+{
97
+ uint32_t uac = 0;
98
+ unsigned long attr_val;
99
+ char *uac_str;
100
+ LDAP *ldap;
101
+ char *end;
102
+
103
+ ldap = adcli_conn_get_ldap_connection (enroll->conn);
104
+ return_val_if_fail (ldap != NULL, NULL);
105
+
106
+ uac_str = _adcli_ldap_parse_value (ldap, enroll->computer_attributes, "userAccountControl");
107
+ if (uac_str != NULL) {
108
+
109
+ attr_val = strtoul (uac_str, &end, 10);
110
+ if (*end != '\0' || attr_val > UINT32_MAX) {
111
+ _adcli_warn ("Invalid userAccountControl '%s' for computer account in directory: %s, assuming 0",
112
+ uac_str, enroll->computer_dn);
113
+ } else {
114
+ uac = attr_val;
115
+ }
116
+ free (uac_str);
117
+ }
118
+
119
+ if (uac == 0) {
120
+ uac = UAC_WORKSTATION_TRUST_ACCOUNT | UAC_DONT_EXPIRE_PASSWORD;
121
+ }
122
+
123
+ if (adcli_enroll_get_trusted_for_delegation (enroll)) {
124
+ uac |= UAC_TRUSTED_FOR_DELEGATION;
125
+ } else {
126
+ uac &= ~(UAC_TRUSTED_FOR_DELEGATION);
127
+ }
128
+
129
+ if (asprintf (&uac_str, "%d", uac) < 0) {
130
+ return_val_if_reached (NULL);
131
+ }
132
+
133
+ return uac_str;
134
+}
135
+
136
static void
137
update_computer_account (adcli_enroll *enroll)
138
{
139
140
}
141
142
if (res == ADCLI_SUCCESS) {
143
- char *vals_userAccountControl[] = { "69632", NULL }; /* WORKSTATION_TRUST_ACCOUNT | DONT_EXPIRE_PASSWD */
144
+ char *vals_userAccountControl[] = { NULL , NULL };
145
LDAPMod userAccountControl = { LDAP_MOD_REPLACE, "userAccountControl", { vals_userAccountControl, } };
146
LDAPMod *mods[] = { &userAccountControl, NULL };
147
148
- res |= update_computer_attribute (enroll, ldap, mods);
149
+ vals_userAccountControl[0] = get_user_account_control (enroll);
150
+ if (vals_userAccountControl[0] != NULL) {
151
+ res |= update_computer_attribute (enroll, ldap, mods);
152
+ } else {
153
+ _adcli_warn ("Cannot update userAccountControl");
154
+ }
155
}
156
157
if (res == ADCLI_SUCCESS) {
158
159
160
enroll->computer_password_lifetime_explicit = 1;
161
}
162
+
163
+bool
164
+adcli_enroll_get_trusted_for_delegation (adcli_enroll *enroll)
165
+{
166
+ return_val_if_fail (enroll != NULL, false);
167
+
168
+ return enroll->trusted_for_delegation;
169
+}
170
+
171
+void
172
+adcli_enroll_set_trusted_for_delegation (adcli_enroll *enroll,
173
+ bool value)
174
+{
175
+ return_if_fail (enroll != NULL);
176
+
177
+ enroll->trusted_for_delegation = value;
178
+}
179
diff --git a/library/adenroll.h b/library/adenroll.h
180
index 9a107ab..ccf19e7 100644
181
--- a/library/adenroll.h
182
+++ b/library/adenroll.h
183
184
void adcli_enroll_set_computer_password_lifetime (adcli_enroll *enroll,
185
unsigned int lifetime);
186
187
+bool adcli_enroll_get_trusted_for_delegation (adcli_enroll *enroll);
188
+void adcli_enroll_set_trusted_for_delegation (adcli_enroll *enroll,
189
+ bool value);
190
+
191
krb5_kvno adcli_enroll_get_kvno (adcli_enroll *enroll);
192
193
void adcli_enroll_set_kvno (adcli_enroll *enroll,
194
diff --git a/tools/computer.c b/tools/computer.c
195
index a3d0f03..5348648 100644
196
--- a/tools/computer.c
197
+++ b/tools/computer.c
198
199
opt_os_service_pack,
200
opt_user_principal,
201
opt_computer_password_lifetime,
202
+ opt_trusted_for_delegation,
203
} Option;
204
205
static adcli_tool_desc common_usages[] = {
206
207
{ opt_os_service_pack, "the computer operating system service pack", },
208
{ opt_user_principal, "add an authentication principal to the account", },
209
{ opt_computer_password_lifetime, "lifetime of the host accounts password in days", },
210
+ { opt_trusted_for_delegation, "set/unset the TRUSTED_FOR_DELEGATION flag\n"
211
+ "in the userAccountControl attribute", },
212
{ opt_no_password, "don't prompt for or read a password" },
213
{ opt_prompt_password, "prompt for a password if necessary" },
214
{ opt_stdin_password, "read a password from stdin (until EOF) if\n"
215
216
217
adcli_enroll_set_computer_password_lifetime (enroll, lifetime);
218
return;
219
+ case opt_trusted_for_delegation:
220
+ if (strcasecmp (optarg, "true") == 0 || strcasecmp (optarg, "yes") == 0) {
221
+ adcli_enroll_set_trusted_for_delegation (enroll, true);
222
+ } else {
223
+ adcli_enroll_set_trusted_for_delegation (enroll, false);
224
+ }
225
+ return;
226
case opt_verbose:
227
return;
228
229
230
{ "os-version", required_argument, NULL, opt_os_version },
231
{ "os-service-pack", optional_argument, NULL, opt_os_service_pack },
232
{ "user-principal", optional_argument, NULL, opt_user_principal },
233
+ { "trusted-for-delegation", required_argument, NULL, opt_trusted_for_delegation },
234
{ "show-details", no_argument, NULL, opt_show_details },
235
{ "show-password", no_argument, NULL, opt_show_password },
236
{ "verbose", no_argument, NULL, opt_verbose },
237
238
{ "os-service-pack", optional_argument, NULL, opt_os_service_pack },
239
{ "user-principal", optional_argument, NULL, opt_user_principal },
240
{ "computer-password-lifetime", optional_argument, NULL, opt_computer_password_lifetime },
241
+ { "trusted-for-delegation", required_argument, NULL, opt_trusted_for_delegation },
242
{ "show-details", no_argument, NULL, opt_show_details },
243
{ "show-password", no_argument, NULL, opt_show_password },
244
{ "verbose", no_argument, NULL, opt_verbose },
245
--
246
2.16.4
247
248