2
* Copyright (c) 2005 Massachusetts Institute of Technology
3
* Copyright (c) 2007 Secure Endpoints Inc.
5
* Permission is hereby granted, free of charge, to any person
6
* obtaining a copy of this software and associated documentation
7
* files (the "Software"), to deal in the Software without
8
* restriction, including without limitation the rights to use, copy,
9
* modify, merge, publish, distribute, sublicense, and/or sell copies
10
* of the Software, and to permit persons to whom the Software is
11
* furnished to do so, subject to the following conditions:
13
* The above copyright notice and this permission notice shall be
14
* included in all copies or substantial portions of the Software.
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34
HINSTANCE hKrb524 = 0;
35
HINSTANCE hSecur32 = 0;
36
HINSTANCE hComErr = 0;
37
HINSTANCE hService = 0;
38
HINSTANCE hProfile = 0;
40
HINSTANCE hToolHelp32 = 0;
43
DWORD AfsAvailable = 0;
46
DECL_FUNC_PTR(cc_initialize);
47
DECL_FUNC_PTR(cc_shutdown);
48
DECL_FUNC_PTR(cc_get_NC_info);
49
DECL_FUNC_PTR(cc_free_NC_info);
52
DECL_FUNC_PTR(get_krb_err_txt_entry);
53
DECL_FUNC_PTR(k_isinst);
54
DECL_FUNC_PTR(k_isname);
55
DECL_FUNC_PTR(k_isrealm);
56
DECL_FUNC_PTR(kadm_change_your_password);
57
DECL_FUNC_PTR(kname_parse);
58
DECL_FUNC_PTR(krb_get_cred);
59
DECL_FUNC_PTR(krb_get_krbhst);
60
DECL_FUNC_PTR(krb_get_lrealm);
61
DECL_FUNC_PTR(krb_get_pw_in_tkt);
62
DECL_FUNC_PTR(krb_get_tf_realm);
63
DECL_FUNC_PTR(krb_mk_req);
64
DECL_FUNC_PTR(krb_realmofhost);
65
DECL_FUNC_PTR(tf_init);
66
DECL_FUNC_PTR(tf_close);
67
DECL_FUNC_PTR(tf_get_cred);
68
DECL_FUNC_PTR(tf_get_pname);
69
DECL_FUNC_PTR(tf_get_pinst);
70
DECL_FUNC_PTR(LocalHostAddr);
71
DECL_FUNC_PTR(tkt_string);
72
DECL_FUNC_PTR(krb_set_tkt_string);
73
DECL_FUNC_PTR(initialize_krb_error_func);
74
DECL_FUNC_PTR(initialize_kadm_error_table);
75
DECL_FUNC_PTR(dest_tkt);
76
DECL_FUNC_PTR(krb_in_tkt);
77
DECL_FUNC_PTR(krb_save_credentials);
78
DECL_FUNC_PTR(krb_get_krbconf2);
79
DECL_FUNC_PTR(krb_get_krbrealm2);
80
DECL_FUNC_PTR(krb_life_to_time);
83
DECL_FUNC_PTR(krb5_change_password);
84
DECL_FUNC_PTR(krb5_get_init_creds_opt_init);
85
DECL_FUNC_PTR(krb5_get_init_creds_opt_set_tkt_life);
86
DECL_FUNC_PTR(krb5_get_init_creds_opt_set_renew_life);
87
DECL_FUNC_PTR(krb5_get_init_creds_opt_set_forwardable);
88
DECL_FUNC_PTR(krb5_get_init_creds_opt_set_proxiable);
89
DECL_FUNC_PTR(krb5_get_init_creds_opt_set_address_list);
90
DECL_FUNC_PTR(krb5_get_init_creds_opt_set_change_password_prompt);
91
DECL_FUNC_PTR(krb5_get_init_creds_password);
92
DECL_FUNC_PTR(krb5_get_prompt_types);
93
DECL_FUNC_PTR(krb5_build_principal_ext);
94
DECL_FUNC_PTR(krb5_cc_get_name);
95
DECL_FUNC_PTR(krb5_cc_get_type);
96
DECL_FUNC_PTR(krb5_cc_resolve);
97
DECL_FUNC_PTR(krb5_cc_default);
98
DECL_FUNC_PTR(krb5_cc_default_name);
99
DECL_FUNC_PTR(krb5_cc_set_default_name);
100
DECL_FUNC_PTR(krb5_cc_initialize);
101
DECL_FUNC_PTR(krb5_cc_destroy);
102
DECL_FUNC_PTR(krb5_cc_close);
103
DECL_FUNC_PTR(krb5_cc_store_cred);
104
DECL_FUNC_PTR(krb5_cc_copy_creds);
105
DECL_FUNC_PTR(krb5_cc_retrieve_cred);
106
DECL_FUNC_PTR(krb5_cc_get_principal);
107
DECL_FUNC_PTR(krb5_cc_start_seq_get);
108
DECL_FUNC_PTR(krb5_cc_next_cred);
109
DECL_FUNC_PTR(krb5_cc_end_seq_get);
110
DECL_FUNC_PTR(krb5_cc_remove_cred);
111
DECL_FUNC_PTR(krb5_cc_set_flags);
112
// DECL_FUNC_PTR(krb5_cc_get_type);
113
DECL_FUNC_PTR(krb5_free_context);
114
DECL_FUNC_PTR(krb5_free_cred_contents);
115
DECL_FUNC_PTR(krb5_free_principal);
116
DECL_FUNC_PTR(krb5_get_in_tkt_with_password);
117
DECL_FUNC_PTR(krb5_init_context);
118
DECL_FUNC_PTR(krb5_parse_name);
119
DECL_FUNC_PTR(krb5_timeofday);
120
DECL_FUNC_PTR(krb5_timestamp_to_sfstring);
121
DECL_FUNC_PTR(krb5_unparse_name);
122
DECL_FUNC_PTR(krb5_get_credentials);
123
DECL_FUNC_PTR(krb5_mk_req);
124
DECL_FUNC_PTR(krb5_sname_to_principal);
125
DECL_FUNC_PTR(krb5_get_credentials_renew);
126
DECL_FUNC_PTR(krb5_free_data);
127
DECL_FUNC_PTR(krb5_free_data_contents);
128
// DECL_FUNC_PTR(krb5_get_realm_domain);
129
DECL_FUNC_PTR(krb5_free_unparsed_name);
130
DECL_FUNC_PTR(krb5_os_localaddr);
131
DECL_FUNC_PTR(krb5_copy_keyblock_contents);
132
DECL_FUNC_PTR(krb5_copy_data);
133
DECL_FUNC_PTR(krb5_free_creds);
134
DECL_FUNC_PTR(krb5_build_principal);
135
DECL_FUNC_PTR(krb5_get_renewed_creds);
136
DECL_FUNC_PTR(krb5_get_default_config_files);
137
DECL_FUNC_PTR(krb5_free_config_files);
138
DECL_FUNC_PTR(krb5_get_default_realm);
139
DECL_FUNC_PTR(krb5_set_default_realm);
140
DECL_FUNC_PTR(krb5_free_ticket);
141
DECL_FUNC_PTR(krb5_decode_ticket);
142
DECL_FUNC_PTR(krb5_get_host_realm);
143
DECL_FUNC_PTR(krb5_free_host_realm);
144
DECL_FUNC_PTR(krb5_c_random_make_octets);
145
DECL_FUNC_PTR(krb5_free_addresses);
146
DECL_FUNC_PTR(krb5_free_default_realm);
147
DECL_FUNC_PTR(krb5_string_to_deltat);
148
DECL_FUNC_PTR(krb5_get_error_message);
149
DECL_FUNC_PTR(krb5_free_error_message);
150
DECL_FUNC_PTR(krb5_clear_error_message);
153
DECL_FUNC_PTR(krb524_init_ets);
154
DECL_FUNC_PTR(krb524_convert_creds_kdc);
157
DECL_FUNC_PTR(com_err);
158
DECL_FUNC_PTR(error_message);
161
DECL_FUNC_PTR(profile_init);
162
DECL_FUNC_PTR(profile_flush);
163
DECL_FUNC_PTR(profile_release);
164
DECL_FUNC_PTR(profile_get_subsection_names);
165
DECL_FUNC_PTR(profile_free_list);
166
DECL_FUNC_PTR(profile_get_string);
167
DECL_FUNC_PTR(profile_get_integer);
168
DECL_FUNC_PTR(profile_get_values);
169
DECL_FUNC_PTR(profile_get_relation_names);
170
DECL_FUNC_PTR(profile_clear_relation);
171
DECL_FUNC_PTR(profile_add_relation);
172
DECL_FUNC_PTR(profile_update_relation);
173
DECL_FUNC_PTR(profile_release_string);
174
DECL_FUNC_PTR(profile_rename_section);
177
DECL_FUNC_PTR(OpenSCManagerA);
178
DECL_FUNC_PTR(OpenServiceA);
179
DECL_FUNC_PTR(QueryServiceStatus);
180
DECL_FUNC_PTR(CloseServiceHandle);
181
DECL_FUNC_PTR(LsaNtStatusToWinError);
184
DECL_FUNC_PTR(LsaConnectUntrusted);
185
DECL_FUNC_PTR(LsaLookupAuthenticationPackage);
186
DECL_FUNC_PTR(LsaCallAuthenticationPackage);
187
DECL_FUNC_PTR(LsaFreeReturnBuffer);
188
DECL_FUNC_PTR(LsaGetLogonSessionData);
191
FUNC_INFO ccapi_fi[] = {
192
MAKE_FUNC_INFO(cc_initialize),
193
MAKE_FUNC_INFO(cc_shutdown),
194
MAKE_FUNC_INFO(cc_get_NC_info),
195
MAKE_FUNC_INFO(cc_free_NC_info),
199
FUNC_INFO k4_fi[] = {
200
MAKE_FUNC_INFO(get_krb_err_txt_entry),
201
MAKE_FUNC_INFO(k_isinst),
202
MAKE_FUNC_INFO(k_isname),
203
MAKE_FUNC_INFO(k_isrealm),
204
MAKE_FUNC_INFO(kadm_change_your_password),
205
MAKE_FUNC_INFO(kname_parse),
206
MAKE_FUNC_INFO(krb_get_cred),
207
MAKE_FUNC_INFO(krb_get_krbhst),
208
MAKE_FUNC_INFO(krb_get_lrealm),
209
MAKE_FUNC_INFO(krb_get_pw_in_tkt),
210
MAKE_FUNC_INFO(krb_get_tf_realm),
211
MAKE_FUNC_INFO(krb_mk_req),
212
MAKE_FUNC_INFO(krb_realmofhost),
213
MAKE_FUNC_INFO(tf_init),
214
MAKE_FUNC_INFO(tf_close),
215
MAKE_FUNC_INFO(tf_get_cred),
216
MAKE_FUNC_INFO(tf_get_pname),
217
MAKE_FUNC_INFO(tf_get_pinst),
218
MAKE_FUNC_INFO(LocalHostAddr),
219
MAKE_FUNC_INFO(tkt_string),
220
MAKE_FUNC_INFO(krb_set_tkt_string),
221
MAKE_FUNC_INFO(initialize_krb_error_func),
222
MAKE_FUNC_INFO(initialize_kadm_error_table),
223
MAKE_FUNC_INFO(dest_tkt),
224
/* MAKE_FUNC_INFO(lsh_LoadKrb4LeashErrorTables), */// XXX
225
MAKE_FUNC_INFO(krb_in_tkt),
226
MAKE_FUNC_INFO(krb_save_credentials),
227
MAKE_FUNC_INFO(krb_get_krbconf2),
228
MAKE_FUNC_INFO(krb_get_krbrealm2),
229
MAKE_FUNC_INFO(krb_life_to_time),
233
FUNC_INFO k5_fi[] = {
234
MAKE_FUNC_INFO(krb5_change_password),
235
MAKE_FUNC_INFO(krb5_get_init_creds_opt_init),
236
MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_tkt_life),
237
MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_renew_life),
238
MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_forwardable),
239
MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_proxiable),
240
MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_address_list),
241
MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_change_password_prompt),
242
MAKE_FUNC_INFO(krb5_get_init_creds_password),
243
MAKE_FUNC_INFO(krb5_get_prompt_types),
244
MAKE_FUNC_INFO(krb5_build_principal_ext),
245
MAKE_FUNC_INFO(krb5_cc_get_name),
246
MAKE_FUNC_INFO(krb5_cc_get_type),
247
MAKE_FUNC_INFO(krb5_cc_resolve),
248
MAKE_FUNC_INFO(krb5_cc_default),
249
MAKE_FUNC_INFO(krb5_cc_default_name),
250
MAKE_FUNC_INFO(krb5_cc_set_default_name),
251
MAKE_FUNC_INFO(krb5_cc_initialize),
252
MAKE_FUNC_INFO(krb5_cc_destroy),
253
MAKE_FUNC_INFO(krb5_cc_close),
254
MAKE_FUNC_INFO(krb5_cc_copy_creds),
255
MAKE_FUNC_INFO(krb5_cc_store_cred),
256
MAKE_FUNC_INFO(krb5_cc_retrieve_cred),
257
MAKE_FUNC_INFO(krb5_cc_get_principal),
258
MAKE_FUNC_INFO(krb5_cc_start_seq_get),
259
MAKE_FUNC_INFO(krb5_cc_next_cred),
260
MAKE_FUNC_INFO(krb5_cc_end_seq_get),
261
MAKE_FUNC_INFO(krb5_cc_remove_cred),
262
MAKE_FUNC_INFO(krb5_cc_set_flags),
263
// MAKE_FUNC_INFO(krb5_cc_get_type),
264
MAKE_FUNC_INFO(krb5_free_context),
265
MAKE_FUNC_INFO(krb5_free_cred_contents),
266
MAKE_FUNC_INFO(krb5_free_principal),
267
MAKE_FUNC_INFO(krb5_get_in_tkt_with_password),
268
MAKE_FUNC_INFO(krb5_init_context),
269
MAKE_FUNC_INFO(krb5_parse_name),
270
MAKE_FUNC_INFO(krb5_timeofday),
271
MAKE_FUNC_INFO(krb5_timestamp_to_sfstring),
272
MAKE_FUNC_INFO(krb5_unparse_name),
273
MAKE_FUNC_INFO(krb5_get_credentials),
274
MAKE_FUNC_INFO(krb5_mk_req),
275
MAKE_FUNC_INFO(krb5_sname_to_principal),
276
MAKE_FUNC_INFO(krb5_get_credentials_renew),
277
MAKE_FUNC_INFO(krb5_free_data),
278
MAKE_FUNC_INFO(krb5_free_data_contents),
279
// MAKE_FUNC_INFO(krb5_get_realm_domain),
280
MAKE_FUNC_INFO(krb5_free_unparsed_name),
281
MAKE_FUNC_INFO(krb5_os_localaddr),
282
MAKE_FUNC_INFO(krb5_copy_keyblock_contents),
283
MAKE_FUNC_INFO(krb5_copy_data),
284
MAKE_FUNC_INFO(krb5_free_creds),
285
MAKE_FUNC_INFO(krb5_build_principal),
286
MAKE_FUNC_INFO(krb5_get_renewed_creds),
287
MAKE_FUNC_INFO(krb5_free_addresses),
288
MAKE_FUNC_INFO(krb5_get_default_config_files),
289
MAKE_FUNC_INFO(krb5_free_config_files),
290
MAKE_FUNC_INFO(krb5_get_default_realm),
291
MAKE_FUNC_INFO(krb5_set_default_realm),
292
MAKE_FUNC_INFO(krb5_free_ticket),
293
MAKE_FUNC_INFO(krb5_decode_ticket),
294
MAKE_FUNC_INFO(krb5_get_host_realm),
295
MAKE_FUNC_INFO(krb5_free_host_realm),
296
MAKE_FUNC_INFO(krb5_c_random_make_octets),
297
MAKE_FUNC_INFO(krb5_free_default_realm),
298
MAKE_FUNC_INFO(krb5_string_to_deltat),
299
MAKE_FUNC_INFO(krb5_get_error_message),
300
MAKE_FUNC_INFO(krb5_free_error_message),
301
MAKE_FUNC_INFO(krb5_clear_error_message),
305
FUNC_INFO k524_fi[] = {
306
MAKE_FUNC_INFO(krb524_init_ets),
307
MAKE_FUNC_INFO(krb524_convert_creds_kdc),
311
FUNC_INFO profile_fi[] = {
312
MAKE_FUNC_INFO(profile_init),
313
MAKE_FUNC_INFO(profile_flush),
314
MAKE_FUNC_INFO(profile_release),
315
MAKE_FUNC_INFO(profile_get_subsection_names),
316
MAKE_FUNC_INFO(profile_free_list),
317
MAKE_FUNC_INFO(profile_get_string),
318
MAKE_FUNC_INFO(profile_get_integer),
319
MAKE_FUNC_INFO(profile_get_values),
320
MAKE_FUNC_INFO(profile_get_relation_names),
321
MAKE_FUNC_INFO(profile_clear_relation),
322
MAKE_FUNC_INFO(profile_add_relation),
323
MAKE_FUNC_INFO(profile_update_relation),
324
MAKE_FUNC_INFO(profile_release_string),
325
MAKE_FUNC_INFO(profile_rename_section),
329
FUNC_INFO ce_fi[] = {
330
MAKE_FUNC_INFO(com_err),
331
MAKE_FUNC_INFO(error_message),
335
FUNC_INFO service_fi[] = {
336
MAKE_FUNC_INFO(OpenSCManagerA),
337
MAKE_FUNC_INFO(OpenServiceA),
338
MAKE_FUNC_INFO(QueryServiceStatus),
339
MAKE_FUNC_INFO(CloseServiceHandle),
340
MAKE_FUNC_INFO(LsaNtStatusToWinError),
344
FUNC_INFO lsa_fi[] = {
345
MAKE_FUNC_INFO(LsaConnectUntrusted),
346
MAKE_FUNC_INFO(LsaLookupAuthenticationPackage),
347
MAKE_FUNC_INFO(LsaCallAuthenticationPackage),
348
MAKE_FUNC_INFO(LsaFreeReturnBuffer),
349
MAKE_FUNC_INFO(LsaGetLogonSessionData),
354
DECL_FUNC_PTR(GetModuleFileNameExA);
355
DECL_FUNC_PTR(EnumProcessModules);
357
FUNC_INFO psapi_fi[] = {
358
MAKE_FUNC_INFO(GetModuleFileNameExA),
359
MAKE_FUNC_INFO(EnumProcessModules),
363
// toolhelp functions
364
DECL_FUNC_PTR(CreateToolhelp32Snapshot);
365
DECL_FUNC_PTR(Module32First);
366
DECL_FUNC_PTR(Module32Next);
368
FUNC_INFO toolhelp_fi[] = {
369
MAKE_FUNC_INFO(CreateToolhelp32Snapshot),
370
MAKE_FUNC_INFO(Module32First),
371
MAKE_FUNC_INFO(Module32Next),
375
khm_int32 init_imports(void) {
382
_reportf(L"Can't locate all required exports from module [%S]", (m)); \
388
imp_rv = LoadFuncs(KRB4_DLL, k4_fi, &hKrb4, 0, 1, 0, 0);
392
imp_rv = LoadFuncs(KRB5_DLL, k5_fi, &hKrb5, 0, 1, 0, 0);
395
imp_rv = LoadFuncs(COMERR_DLL, ce_fi, &hComErr, 0, 0, 1, 0);
398
imp_rv = LoadFuncs(SERVICE_DLL, service_fi, &hService, 0, 1, 0, 0);
401
imp_rv = LoadFuncs(SECUR32_DLL, lsa_fi, &hSecur32, 0, 1, 1, 1);
405
imp_rv = LoadFuncs(KRB524_DLL, k524_fi, &hKrb524, 0, 1, 1, 1);
409
imp_rv = LoadFuncs(PROFILE_DLL, profile_fi, &hProfile, 0, 1, 0, 0);
412
imp_rv = LoadFuncs(CCAPI_DLL, ccapi_fi, &hCCAPI, 0, 1, 0, 0);
413
/* CCAPI_DLL is optional. No error check. */
415
memset(&osvi, 0, sizeof(OSVERSIONINFO));
416
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
419
// XXX: We should really use feature testing, first
420
// checking for CreateToolhelp32Snapshot. If that's
421
// not around, we try the psapi stuff.
423
// Only load LSA functions if on NT/2000/XP
424
if(osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
427
imp_rv = LoadFuncs(TOOLHELPDLL, toolhelp_fi, &hToolHelp32, 0, 1, 0, 0);
432
else if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
435
imp_rv = LoadFuncs(PSAPIDLL, psapi_fi, &hPsapi, 0, 1, 0, 0);
441
AfsAvailable = TRUE; //afscompat_init();
443
return KHM_ERROR_SUCCESS;
446
return KHM_ERROR_NOT_FOUND;
449
khm_int32 exit_imports(void) {
457
FreeLibrary(hProfile);
459
FreeLibrary(hComErr);
461
FreeLibrary(hService);
463
FreeLibrary(hSecur32);
465
FreeLibrary(hKrb524);
469
FreeLibrary(hToolHelp32);
471
return KHM_ERROR_SUCCESS;
474
int (*Lcom_err)(LPSTR,long,LPSTR,...);
475
LPSTR (*Lerror_message)(long);
476
LPSTR (*Lerror_table_name)(long);
478
void Leash_load_com_err_callback(FARPROC ce,
482
Lcom_err = (int (*)(LPSTR,long,LPSTR,...)) ce;
483
Lerror_message = (LPSTR (*)(long)) em;
484
Lerror_table_name = (LPSTR (*)(long)) etn;