2 * Copyright (c) 2005 Massachusetts Institute of Technology
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 HINSTANCE hKrb5_KFW_32
= 0;
35 HINSTANCE hKrb524
= 0;
36 HINSTANCE hSecur32
= 0;
37 HINSTANCE hComErr
= 0;
38 HINSTANCE hService
= 0;
39 HINSTANCE hProfile
= 0;
41 HINSTANCE hToolHelp32
= 0;
44 DWORD AfsAvailable
= 0;
47 DECL_FUNC_PTR(cc_initialize
);
48 DECL_FUNC_PTR(cc_shutdown
);
49 DECL_FUNC_PTR(cc_get_NC_info
);
50 DECL_FUNC_PTR(cc_free_NC_info
);
53 DECL_FUNC_PTR(get_krb_err_txt_entry
);
54 DECL_FUNC_PTR(k_isinst
);
55 DECL_FUNC_PTR(k_isname
);
56 DECL_FUNC_PTR(k_isrealm
);
57 DECL_FUNC_PTR(kadm_change_your_password
);
58 DECL_FUNC_PTR(kname_parse
);
59 DECL_FUNC_PTR(krb_get_cred
);
60 DECL_FUNC_PTR(krb_get_krbhst
);
61 DECL_FUNC_PTR(krb_get_lrealm
);
62 DECL_FUNC_PTR(krb_get_pw_in_tkt
);
63 DECL_FUNC_PTR(krb_get_tf_realm
);
64 DECL_FUNC_PTR(krb_mk_req
);
65 DECL_FUNC_PTR(krb_realmofhost
);
66 DECL_FUNC_PTR(tf_init
);
67 DECL_FUNC_PTR(tf_close
);
68 DECL_FUNC_PTR(tf_get_cred
);
69 DECL_FUNC_PTR(tf_get_pname
);
70 DECL_FUNC_PTR(tf_get_pinst
);
71 DECL_FUNC_PTR(LocalHostAddr
);
72 DECL_FUNC_PTR(tkt_string
);
73 DECL_FUNC_PTR(krb_set_tkt_string
);
74 DECL_FUNC_PTR(initialize_krb_error_func
);
75 DECL_FUNC_PTR(initialize_kadm_error_table
);
76 DECL_FUNC_PTR(dest_tkt
);
77 DECL_FUNC_PTR(krb_in_tkt
);
78 DECL_FUNC_PTR(krb_save_credentials
);
79 DECL_FUNC_PTR(krb_get_krbconf2
);
80 DECL_FUNC_PTR(krb_get_krbrealm2
);
81 DECL_FUNC_PTR(krb_life_to_time
);
84 DECL_FUNC_PTR(krb5_change_password
);
85 DECL_FUNC_PTR(krb5_get_init_creds_opt_init
);
86 DECL_FUNC_PTR(krb5_get_init_creds_opt_set_tkt_life
);
87 DECL_FUNC_PTR(krb5_get_init_creds_opt_set_renew_life
);
88 DECL_FUNC_PTR(krb5_get_init_creds_opt_set_forwardable
);
89 DECL_FUNC_PTR(krb5_get_init_creds_opt_set_proxiable
);
90 DECL_FUNC_PTR(krb5_get_init_creds_opt_set_address_list
);
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
);
148 // Krb5 (3.2) functions
149 DECL_FUNC_PTR(krb5_get_error_message
);
150 DECL_FUNC_PTR(krb5_free_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_values
);
168 DECL_FUNC_PTR(profile_get_relation_names
);
169 DECL_FUNC_PTR(profile_clear_relation
);
170 DECL_FUNC_PTR(profile_add_relation
);
171 DECL_FUNC_PTR(profile_update_relation
);
172 DECL_FUNC_PTR(profile_release_string
);
175 DECL_FUNC_PTR(OpenSCManagerA
);
176 DECL_FUNC_PTR(OpenServiceA
);
177 DECL_FUNC_PTR(QueryServiceStatus
);
178 DECL_FUNC_PTR(CloseServiceHandle
);
179 DECL_FUNC_PTR(LsaNtStatusToWinError
);
182 DECL_FUNC_PTR(LsaConnectUntrusted
);
183 DECL_FUNC_PTR(LsaLookupAuthenticationPackage
);
184 DECL_FUNC_PTR(LsaCallAuthenticationPackage
);
185 DECL_FUNC_PTR(LsaFreeReturnBuffer
);
186 DECL_FUNC_PTR(LsaGetLogonSessionData
);
189 FUNC_INFO ccapi_fi
[] = {
190 MAKE_FUNC_INFO(cc_initialize
),
191 MAKE_FUNC_INFO(cc_shutdown
),
192 MAKE_FUNC_INFO(cc_get_NC_info
),
193 MAKE_FUNC_INFO(cc_free_NC_info
),
197 FUNC_INFO k4_fi
[] = {
198 MAKE_FUNC_INFO(get_krb_err_txt_entry
),
199 MAKE_FUNC_INFO(k_isinst
),
200 MAKE_FUNC_INFO(k_isname
),
201 MAKE_FUNC_INFO(k_isrealm
),
202 MAKE_FUNC_INFO(kadm_change_your_password
),
203 MAKE_FUNC_INFO(kname_parse
),
204 MAKE_FUNC_INFO(krb_get_cred
),
205 MAKE_FUNC_INFO(krb_get_krbhst
),
206 MAKE_FUNC_INFO(krb_get_lrealm
),
207 MAKE_FUNC_INFO(krb_get_pw_in_tkt
),
208 MAKE_FUNC_INFO(krb_get_tf_realm
),
209 MAKE_FUNC_INFO(krb_mk_req
),
210 MAKE_FUNC_INFO(krb_realmofhost
),
211 MAKE_FUNC_INFO(tf_init
),
212 MAKE_FUNC_INFO(tf_close
),
213 MAKE_FUNC_INFO(tf_get_cred
),
214 MAKE_FUNC_INFO(tf_get_pname
),
215 MAKE_FUNC_INFO(tf_get_pinst
),
216 MAKE_FUNC_INFO(LocalHostAddr
),
217 MAKE_FUNC_INFO(tkt_string
),
218 MAKE_FUNC_INFO(krb_set_tkt_string
),
219 MAKE_FUNC_INFO(initialize_krb_error_func
),
220 MAKE_FUNC_INFO(initialize_kadm_error_table
),
221 MAKE_FUNC_INFO(dest_tkt
),
222 /* MAKE_FUNC_INFO(lsh_LoadKrb4LeashErrorTables), */// XXX
223 MAKE_FUNC_INFO(krb_in_tkt
),
224 MAKE_FUNC_INFO(krb_save_credentials
),
225 MAKE_FUNC_INFO(krb_get_krbconf2
),
226 MAKE_FUNC_INFO(krb_get_krbrealm2
),
227 MAKE_FUNC_INFO(krb_life_to_time
),
231 FUNC_INFO k5_fi
[] = {
232 MAKE_FUNC_INFO(krb5_change_password
),
233 MAKE_FUNC_INFO(krb5_get_init_creds_opt_init
),
234 MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_tkt_life
),
235 MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_renew_life
),
236 MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_forwardable
),
237 MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_proxiable
),
238 MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_address_list
),
239 MAKE_FUNC_INFO(krb5_get_init_creds_password
),
240 MAKE_FUNC_INFO(krb5_get_prompt_types
),
241 MAKE_FUNC_INFO(krb5_build_principal_ext
),
242 MAKE_FUNC_INFO(krb5_cc_get_name
),
243 MAKE_FUNC_INFO(krb5_cc_get_type
),
244 MAKE_FUNC_INFO(krb5_cc_resolve
),
245 MAKE_FUNC_INFO(krb5_cc_default
),
246 MAKE_FUNC_INFO(krb5_cc_default_name
),
247 MAKE_FUNC_INFO(krb5_cc_set_default_name
),
248 MAKE_FUNC_INFO(krb5_cc_initialize
),
249 MAKE_FUNC_INFO(krb5_cc_destroy
),
250 MAKE_FUNC_INFO(krb5_cc_close
),
251 MAKE_FUNC_INFO(krb5_cc_copy_creds
),
252 MAKE_FUNC_INFO(krb5_cc_store_cred
),
253 MAKE_FUNC_INFO(krb5_cc_retrieve_cred
),
254 MAKE_FUNC_INFO(krb5_cc_get_principal
),
255 MAKE_FUNC_INFO(krb5_cc_start_seq_get
),
256 MAKE_FUNC_INFO(krb5_cc_next_cred
),
257 MAKE_FUNC_INFO(krb5_cc_end_seq_get
),
258 MAKE_FUNC_INFO(krb5_cc_remove_cred
),
259 MAKE_FUNC_INFO(krb5_cc_set_flags
),
260 // MAKE_FUNC_INFO(krb5_cc_get_type),
261 MAKE_FUNC_INFO(krb5_free_context
),
262 MAKE_FUNC_INFO(krb5_free_cred_contents
),
263 MAKE_FUNC_INFO(krb5_free_principal
),
264 MAKE_FUNC_INFO(krb5_get_in_tkt_with_password
),
265 MAKE_FUNC_INFO(krb5_init_context
),
266 MAKE_FUNC_INFO(krb5_parse_name
),
267 MAKE_FUNC_INFO(krb5_timeofday
),
268 MAKE_FUNC_INFO(krb5_timestamp_to_sfstring
),
269 MAKE_FUNC_INFO(krb5_unparse_name
),
270 MAKE_FUNC_INFO(krb5_get_credentials
),
271 MAKE_FUNC_INFO(krb5_mk_req
),
272 MAKE_FUNC_INFO(krb5_sname_to_principal
),
273 MAKE_FUNC_INFO(krb5_get_credentials_renew
),
274 MAKE_FUNC_INFO(krb5_free_data
),
275 MAKE_FUNC_INFO(krb5_free_data_contents
),
276 // MAKE_FUNC_INFO(krb5_get_realm_domain),
277 MAKE_FUNC_INFO(krb5_free_unparsed_name
),
278 MAKE_FUNC_INFO(krb5_os_localaddr
),
279 MAKE_FUNC_INFO(krb5_copy_keyblock_contents
),
280 MAKE_FUNC_INFO(krb5_copy_data
),
281 MAKE_FUNC_INFO(krb5_free_creds
),
282 MAKE_FUNC_INFO(krb5_build_principal
),
283 MAKE_FUNC_INFO(krb5_get_renewed_creds
),
284 MAKE_FUNC_INFO(krb5_free_addresses
),
285 MAKE_FUNC_INFO(krb5_get_default_config_files
),
286 MAKE_FUNC_INFO(krb5_free_config_files
),
287 MAKE_FUNC_INFO(krb5_get_default_realm
),
288 MAKE_FUNC_INFO(krb5_set_default_realm
),
289 MAKE_FUNC_INFO(krb5_free_ticket
),
290 MAKE_FUNC_INFO(krb5_decode_ticket
),
291 MAKE_FUNC_INFO(krb5_get_host_realm
),
292 MAKE_FUNC_INFO(krb5_free_host_realm
),
293 MAKE_FUNC_INFO(krb5_c_random_make_octets
),
294 MAKE_FUNC_INFO(krb5_free_default_realm
),
298 FUNC_INFO k5_kfw_32_fi
[] = {
299 MAKE_FUNC_INFO(krb5_get_error_message
),
300 MAKE_FUNC_INFO(krb5_free_error_message
),
304 FUNC_INFO k524_fi
[] = {
305 MAKE_FUNC_INFO(krb524_init_ets
),
306 MAKE_FUNC_INFO(krb524_convert_creds_kdc
),
310 FUNC_INFO profile_fi
[] = {
311 MAKE_FUNC_INFO(profile_init
),
312 MAKE_FUNC_INFO(profile_flush
),
313 MAKE_FUNC_INFO(profile_release
),
314 MAKE_FUNC_INFO(profile_get_subsection_names
),
315 MAKE_FUNC_INFO(profile_free_list
),
316 MAKE_FUNC_INFO(profile_get_string
),
317 MAKE_FUNC_INFO(profile_get_values
),
318 MAKE_FUNC_INFO(profile_get_relation_names
),
319 MAKE_FUNC_INFO(profile_clear_relation
),
320 MAKE_FUNC_INFO(profile_add_relation
),
321 MAKE_FUNC_INFO(profile_update_relation
),
322 MAKE_FUNC_INFO(profile_release_string
),
326 FUNC_INFO ce_fi
[] = {
327 MAKE_FUNC_INFO(com_err
),
328 MAKE_FUNC_INFO(error_message
),
332 FUNC_INFO service_fi
[] = {
333 MAKE_FUNC_INFO(OpenSCManagerA
),
334 MAKE_FUNC_INFO(OpenServiceA
),
335 MAKE_FUNC_INFO(QueryServiceStatus
),
336 MAKE_FUNC_INFO(CloseServiceHandle
),
337 MAKE_FUNC_INFO(LsaNtStatusToWinError
),
341 FUNC_INFO lsa_fi
[] = {
342 MAKE_FUNC_INFO(LsaConnectUntrusted
),
343 MAKE_FUNC_INFO(LsaLookupAuthenticationPackage
),
344 MAKE_FUNC_INFO(LsaCallAuthenticationPackage
),
345 MAKE_FUNC_INFO(LsaFreeReturnBuffer
),
346 MAKE_FUNC_INFO(LsaGetLogonSessionData
),
351 DECL_FUNC_PTR(GetModuleFileNameExA
);
352 DECL_FUNC_PTR(EnumProcessModules
);
354 FUNC_INFO psapi_fi
[] = {
355 MAKE_FUNC_INFO(GetModuleFileNameExA
),
356 MAKE_FUNC_INFO(EnumProcessModules
),
360 // toolhelp functions
361 DECL_FUNC_PTR(CreateToolhelp32Snapshot
);
362 DECL_FUNC_PTR(Module32First
);
363 DECL_FUNC_PTR(Module32Next
);
365 FUNC_INFO toolhelp_fi
[] = {
366 MAKE_FUNC_INFO(CreateToolhelp32Snapshot
),
367 MAKE_FUNC_INFO(Module32First
),
368 MAKE_FUNC_INFO(Module32Next
),
372 khm_int32
init_imports(void) {
376 #define CKRV if(!imp_rv) goto _err_ret
379 imp_rv
= LoadFuncs(KRB4_DLL
, k4_fi
, &hKrb4
, 0, 1, 1, 1);
383 imp_rv
= LoadFuncs(KRB5_DLL
, k5_fi
, &hKrb5
, 0, 1, 0, 0);
386 imp_rv
= LoadFuncs(COMERR_DLL
, ce_fi
, &hComErr
, 0, 0, 1, 0);
389 imp_rv
= LoadFuncs(SERVICE_DLL
, service_fi
, &hService
, 0, 1, 0, 0);
392 imp_rv
= LoadFuncs(SECUR32_DLL
, lsa_fi
, &hSecur32
, 0, 1, 1, 1);
395 imp_rv
= LoadFuncs(KRB524_DLL
, k524_fi
, &hKrb524
, 0, 1, 1, 1);
398 imp_rv
= LoadFuncs(PROFILE_DLL
, profile_fi
, &hProfile
, 0, 1, 0, 0);
401 imp_rv
= LoadFuncs(CCAPI_DLL
, ccapi_fi
, &hCCAPI
, 0, 1, 0, 0);
402 /* CCAPI_DLL is optional. No error check. */
404 imp_rv
= LoadFuncs(KRB5_DLL
, k5_kfw_32_fi
, &hKrb5_KFW_32
, 0, 1, 0, 0);
405 /* KFW 3.2 krb5 functions are optional. No error check. */
407 memset(&osvi
, 0, sizeof(OSVERSIONINFO
));
408 osvi
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
411 // XXX: We should really use feature testing, first
412 // checking for CreateToolhelp32Snapshot. If that's
413 // not around, we try the psapi stuff.
415 // Only load LSA functions if on NT/2000/XP
416 if(osvi
.dwPlatformId
== VER_PLATFORM_WIN32_WINDOWS
)
419 imp_rv
= LoadFuncs(TOOLHELPDLL
, toolhelp_fi
, &hToolHelp32
, 0, 1, 0, 0);
424 else if(osvi
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
427 imp_rv
= LoadFuncs(PSAPIDLL
, psapi_fi
, &hPsapi
, 0, 1, 0, 0);
433 AfsAvailable
= TRUE
; //afscompat_init();
435 return KHM_ERROR_SUCCESS
;
438 return KHM_ERROR_NOT_FOUND
;
441 khm_int32
exit_imports(void) {
449 FreeLibrary(hKrb5_KFW_32
);
451 FreeLibrary(hProfile
);
453 FreeLibrary(hComErr
);
455 FreeLibrary(hService
);
457 FreeLibrary(hSecur32
);
459 FreeLibrary(hKrb524
);
463 FreeLibrary(hToolHelp32
);
465 return KHM_ERROR_SUCCESS
;
468 int (*Lcom_err
)(LPSTR
,long,LPSTR
,...);
469 LPSTR (*Lerror_message
)(long);
470 LPSTR (*Lerror_table_name
)(long);
472 #pragma warning (disable: 4213)
473 void Leash_load_com_err_callback(FARPROC ce
,
477 (FARPROC
)Lcom_err
=ce
;
478 (FARPROC
)Lerror_message
=em
;
479 (FARPROC
)Lerror_table_name
=etn
;