1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
|
/*
* adcli
*
* Copyright (C) 2012 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* Author: Stef Walter <stefw@gnome.org>
*/
#ifndef ADPRIVATE_H_
#define ADPRIVATE_H_
#include "adattrs.h"
#include "adconn.h"
#include <stdarg.h>
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <ldap.h>
#ifndef HOST_NAME_MAX
#define HOST_NAME_MAX 255
#endif
/* Some constants for the userAccountControl AD LDAP attribute, see e.g.
* https://support.microsoft.com/en-us/help/305144/how-to-use-the-useraccountcontrol-flags-to-manipulate-user-account-pro
* for details. */
#define UAC_ACCOUNTDISABLE 0x0002
#define UAC_WORKSTATION_TRUST_ACCOUNT 0x1000
#define UAC_DONT_EXPIRE_PASSWORD 0x10000
#define UAC_TRUSTED_FOR_DELEGATION 0x80000
/* Utilities */
#if !defined(__cplusplus) && (__GNUC__ > 2)
#define GNUC_PRINTF(x, y) __attribute__((__format__(__printf__, x, y)))
#define GNUC_WARN_UNUSED __attribute__((warn_unused_result))
#else
#define GNUC_PRINTF(x, y)
#define GNUC_WARN_UNUSED
#endif
/* For detecting clang features */
#ifndef __has_feature
#define __has_feature(x) 0
#endif
#ifndef CLANG_ANALYZER_NORETURN
#if __has_feature(attribute_analyzer_noreturn)
#define CLANG_ANALYZER_NORETURN __attribute__((analyzer_noreturn))
#else
#define CLANG_ANALYZER_NORETURN
#endif
#endif
#define return_val_if_fail(x, v) \
do { if (!(x)) { \
_adcli_precond_failed ("adcli: '%s' not true at %s\n", #x, __func__); \
return v; \
} } while (0)
#define return_unexpected_if_fail(x) \
return_val_if_fail ((x), ADCLI_ERR_UNEXPECTED)
#define return_if_fail(x) \
do { if (!(x)) { \
_adcli_precond_failed ("adcli: '%s' not true at %s\n", #x, __func__); \
return; \
} } while (0)
#define return_if_reached() \
do { \
_adcli_precond_failed ("adcli: shouldn't be reached at %s\n", __func__); \
return; \
} while (0)
#define return_val_if_reached(v) \
do { \
_adcli_precond_failed ("adcli: shouldn't be reached at %s\n", __func__); \
return v; \
} while (0)
#define return_unexpected_if_reached() \
return_val_if_reached (ADCLI_ERR_UNEXPECTED)
void _adcli_precond_failed (const char *message,
...) GNUC_PRINTF (1, 2)
CLANG_ANALYZER_NORETURN;
void _adcli_err (const char *format,
...) GNUC_PRINTF(1, 2);
void _adcli_warn (const char *format,
...) GNUC_PRINTF(1, 2);
void _adcli_info (const char *format,
...) GNUC_PRINTF(1, 2);
int _adcli_strv_len (char **strv);
char ** _adcli_strv_add (char **strv,
char *string,
int *length) GNUC_WARN_UNUSED;
char ** _adcli_strv_add_unique (char **strv,
char *string,
int *length,
bool case_sensitive) GNUC_WARN_UNUSED;
void _adcli_strv_remove_unsorted (char **strv,
const char *string,
int *length);
void _adcli_strv_free (char **strv);
int _adcli_strv_has (char **strv,
const char *str);
int _adcli_strv_has_ex (char **strv,
const char *str,
int (* compare) (const char *match, const char*value));
char ** _adcli_strv_dup (char **strv) GNUC_WARN_UNUSED;
char * _adcli_strv_join (char **strv,
const char *delim);
void _adcli_str_up (char *str);
void _adcli_str_down (char *str);
int _adcli_str_is_up (const char *str);
int _adcli_str_has_prefix (const char *str,
const char *prefix);
int _adcli_str_has_suffix (const char *str,
const char *suffix);
char * _adcli_bin_sid_to_str (const uint8_t *data,
size_t len);
char * _adcli_str_dupn (void *data,
size_t len);
void _adcli_str_set (char **field,
const char *value);
void _adcli_strv_set (char ***field,
const char **value);
int _adcli_password_free (char *password);
int _adcli_write_all (int fd,
const char *buf,
int len);
/* Connection helpers */
char * _adcli_calc_reset_password (const char *computer_name);
char * _adcli_calc_netbios_name (const char *host_fqdn);
krb5_error_code _adcli_kinit_computer_creds (adcli_conn *conn,
const char *in_tkt_service,
krb5_ccache ccache,
krb5_creds *creds);
krb5_error_code _adcli_kinit_user_creds (adcli_conn *conn,
const char *in_tkt_service,
krb5_ccache ccache,
krb5_creds *creds);
/* LDAP helpers */
adcli_result _adcli_ldap_handle_failure (LDAP *ldap,
adcli_result defres,
const char *desc,
...) GNUC_PRINTF(3, 4);
char * _adcli_ldap_parse_sid (LDAP *ldap,
LDAPMessage *results,
const char *attr_name);
char * _adcli_ldap_parse_value (LDAP *ldap,
LDAPMessage *results,
const char *attr_name);
char ** _adcli_ldap_parse_values (LDAP *ldap,
LDAPMessage *results,
const char *attr_name);
char * _adcli_ldap_parse_dn (LDAP *ldap,
LDAPMessage *results);
int _adcli_ldap_ber_case_equal (struct berval *one,
struct berval *two);
int _adcli_ldap_have_vals (struct berval **want,
struct berval **have);
int _adcli_ldap_have_in_mod (LDAPMod *want,
struct berval **have);
char * _adcli_ldap_escape_filter (const char *value);
int _adcli_ldap_dn_has_ancestor (const char *dn,
const char *ancestor);
int _adcli_ldap_mod_compar (void *match,
void *mod);
int _adcli_ldap_filter_for_add (void *unused,
void *mod);
LDAPMod * _adcli_ldap_mod_new (int mod_op,
const char *type,
const char **values);
LDAPMod * _adcli_ldap_mod_new1 (int mod_op,
const char *type,
const char *value);
void _adcli_ldap_mod_free (void *mod);
char * _adcli_ldap_mods_to_string (LDAPMod **mods);
/* KRB5 helpers */
adcli_result _adcli_krb5_init_context (krb5_context *k5);
adcli_result _adcli_krb5_open_keytab (krb5_context k5,
const char *keytab_name,
krb5_keytab *keytab);
krb5_error_code _adcli_krb5_build_principal (krb5_context k5,
const char *user,
const char *realm,
krb5_principal *principal);
krb5_error_code _adcli_krb5_keytab_clear (krb5_context k5,
krb5_keytab keytab,
krb5_boolean (* match_func) (krb5_context,
krb5_keytab_entry *, void *),
void *match_data);
krb5_error_code _adcli_krb5_keytab_clear_all (krb5_context k5,
krb5_keytab keytab);
krb5_error_code _adcli_krb5_keytab_enumerate (krb5_context k5,
krb5_keytab keytab,
krb5_boolean (* match_func) (krb5_context,
krb5_keytab_entry *, void *),
void *match_data);
krb5_error_code _adcli_krb5_keytab_add_entries (krb5_context k5,
krb5_keytab keytab,
krb5_principal princpal,
krb5_kvno kvno,
krb5_data *password,
krb5_enctype *enctypes,
krb5_data *salt);
krb5_error_code _adcli_krb5_keytab_test_salt (krb5_context k5,
krb5_keytab scratch,
krb5_principal principal,
krb5_kvno kvno,
krb5_data *password,
krb5_enctype *enctypes,
krb5_data *salt);
krb5_error_code _adcli_krb5_keytab_discover_salt (krb5_context k5,
krb5_principal principal,
krb5_kvno kvno,
krb5_data *password,
krb5_enctype *enctypes,
krb5_data *salts,
int *discovered);
krb5_error_code _adcli_krb5_w2k3_salt (krb5_context k5,
krb5_principal principal,
const char *host_netbios,
krb5_data *salt);
krb5_enctype * _adcli_krb5_parse_enctypes (const char *value);
char * _adcli_krb5_format_enctypes (krb5_enctype *enctypes);
krb5_error_code _adcli_krb5_keytab_copy_entries (krb5_context k5,
krb5_keytab keytab,
krb5_principal principal,
krb5_kvno kvno,
krb5_enctype *enctypes);
struct _adcli_attrs {
LDAPMod **mods;
int len;
};
bool _adcli_check_nt_time_string_lifetime (const char *nt_time_string, unsigned int lifetime);
adcli_result _adcli_call_external_program (const char *binary,
char * const *argv,
char * const *envp,
const char *stdin_data,
uint8_t **stdout_data,
size_t *stdout_data_len);
const char *adcli_krb5_get_error_message (krb5_context ctx,
krb5_error_code code);
#endif /* ADPRIVATE_H_ */
|