1 #include <windows.h>
2 #include "leashdll.h"
3 #include <leashwin.h>
4 #include "leash-int.h"
5
6 HINSTANCE hLeashInst;
7
8 HINSTANCE hKrb5 = 0;
9 HINSTANCE hKrb524 = 0;
10 HINSTANCE hSecur32 = 0;
11 HINSTANCE hComErr = 0;
12 HINSTANCE hService = 0;
13 HINSTANCE hProfile = 0;
14 HINSTANCE hPsapi = 0;
15 HINSTANCE hToolHelp32 = 0;
16 HINSTANCE hCcapi = 0;
17
18 // krb5 functions
19 DECL_FUNC_PTR(krb5_change_password);
20 DECL_FUNC_PTR(krb5_get_init_creds_opt_alloc);
21 DECL_FUNC_PTR(krb5_get_init_creds_opt_free);
22 DECL_FUNC_PTR(krb5_get_init_creds_opt_init);
23 DECL_FUNC_PTR(krb5_get_init_creds_opt_set_tkt_life);
24 DECL_FUNC_PTR(krb5_get_init_creds_opt_set_renew_life);
25 DECL_FUNC_PTR(krb5_get_init_creds_opt_set_forwardable);
26 DECL_FUNC_PTR(krb5_get_init_creds_opt_set_proxiable);
27 DECL_FUNC_PTR(krb5_get_init_creds_opt_set_address_list);
28 DECL_FUNC_PTR(krb5_get_init_creds_opt_set_out_ccache);
29 DECL_FUNC_PTR(krb5_get_init_creds_password);
30 DECL_FUNC_PTR(krb5_build_principal_ext);
31 DECL_FUNC_PTR(krb5_cc_get_name);
32 DECL_FUNC_PTR(krb5_cc_resolve);
33 DECL_FUNC_PTR(krb5_cc_default);
34 DECL_FUNC_PTR(krb5_cc_default_name);
35 DECL_FUNC_PTR(krb5_cc_set_default_name);
36 DECL_FUNC_PTR(krb5_cc_initialize);
37 DECL_FUNC_PTR(krb5_cc_destroy);
38 DECL_FUNC_PTR(krb5_cc_close);
39 DECL_FUNC_PTR(krb5_cc_store_cred);
40 DECL_FUNC_PTR(krb5_cc_copy_creds);
41 // DECL_FUNC_PTR(krb5_cc_retrieve_cred);
42 DECL_FUNC_PTR(krb5_cc_get_principal);
43 DECL_FUNC_PTR(krb5_cc_start_seq_get);
44 DECL_FUNC_PTR(krb5_cc_next_cred);
45 DECL_FUNC_PTR(krb5_cc_end_seq_get);
46 // DECL_FUNC_PTR(krb5_cc_remove_cred);
47 DECL_FUNC_PTR(krb5_cc_set_flags);
48 // DECL_FUNC_PTR(krb5_cc_get_type);
49 DECL_FUNC_PTR(krb5_free_context);
50 DECL_FUNC_PTR(krb5_free_cred_contents);
51 DECL_FUNC_PTR(krb5_free_principal);
52 DECL_FUNC_PTR(krb5_get_in_tkt_with_password);
53 DECL_FUNC_PTR(krb5_init_context);
54 DECL_FUNC_PTR(krb5_parse_name);
55 DECL_FUNC_PTR(krb5_timeofday);
56 DECL_FUNC_PTR(krb5_timestamp_to_sfstring);
57 DECL_FUNC_PTR(krb5_unparse_name);
58 DECL_FUNC_PTR(krb5_get_credentials);
59 DECL_FUNC_PTR(krb5_mk_req);
60 DECL_FUNC_PTR(krb5_sname_to_principal);
61 DECL_FUNC_PTR(krb5_get_credentials_renew);
62 DECL_FUNC_PTR(krb5_free_data);
63 DECL_FUNC_PTR(krb5_free_data_contents);
64 // DECL_FUNC_PTR(krb5_get_realm_domain);
65 DECL_FUNC_PTR(krb5_free_unparsed_name);
66 DECL_FUNC_PTR(krb5_os_localaddr);
67 DECL_FUNC_PTR(krb5_copy_keyblock_contents);
68 DECL_FUNC_PTR(krb5_copy_data);
69 DECL_FUNC_PTR(krb5_free_creds);
70 DECL_FUNC_PTR(krb5_build_principal);
71 DECL_FUNC_PTR(krb5_get_renewed_creds);
72 DECL_FUNC_PTR(krb5_get_default_config_files);
73 DECL_FUNC_PTR(krb5_free_config_files);
74 DECL_FUNC_PTR(krb5_get_default_realm);
75 DECL_FUNC_PTR(krb5_free_ticket);
76 DECL_FUNC_PTR(krb5_decode_ticket);
77 DECL_FUNC_PTR(krb5_get_host_realm);
78 DECL_FUNC_PTR(krb5_free_host_realm);
79 DECL_FUNC_PTR(krb5_c_random_make_octets);
80 DECL_FUNC_PTR(krb5_free_addresses);
81 DECL_FUNC_PTR(krb5_free_default_realm);
82 DECL_FUNC_PTR(krb5_principal_compare);
83 DECL_FUNC_PTR(krb5_string_to_deltat);
84 DECL_FUNC_PTR(krb5_is_config_principal);
85 DECL_FUNC_PTR(krb5_cccol_cursor_new);
86 DECL_FUNC_PTR(krb5_cccol_cursor_free);
87 DECL_FUNC_PTR(krb5_cccol_cursor_next);
88 DECL_FUNC_PTR(krb5_cc_cache_match);
89 DECL_FUNC_PTR(krb5_cc_get_type);
90 DECL_FUNC_PTR(krb5_cc_new_unique);
91 DECL_FUNC_PTR(krb5_cc_support_switch);
92 DECL_FUNC_PTR(krb5_cc_switch);
93 DECL_FUNC_PTR(krb5_cc_get_full_name);
94 DECL_FUNC_PTR(krb5_free_string);
95 DECL_FUNC_PTR(krb5int_cc_user_set_default_name);
96
97 // ComErr functions
98 DECL_FUNC_PTR(com_err);
99 DECL_FUNC_PTR(error_message);
100
101 // Profile functions
102 DECL_FUNC_PTR(profile_init);
103 DECL_FUNC_PTR(profile_release);
104 DECL_FUNC_PTR(profile_get_subsection_names);
105 DECL_FUNC_PTR(profile_free_list);
106 DECL_FUNC_PTR(profile_get_string);
107 DECL_FUNC_PTR(profile_release_string);
108 DECL_FUNC_PTR(profile_get_integer);
109
110 // Service functions
111 DECL_FUNC_PTR(OpenSCManagerA);
112 DECL_FUNC_PTR(OpenServiceA);
113 DECL_FUNC_PTR(QueryServiceStatus);
114 DECL_FUNC_PTR(CloseServiceHandle);
115 DECL_FUNC_PTR(LsaNtStatusToWinError);
116
117 // LSA Functions
118 DECL_FUNC_PTR(LsaConnectUntrusted);
119 DECL_FUNC_PTR(LsaLookupAuthenticationPackage);
120 DECL_FUNC_PTR(LsaCallAuthenticationPackage);
121 DECL_FUNC_PTR(LsaFreeReturnBuffer);
122 DECL_FUNC_PTR(LsaGetLogonSessionData);
123
124 // CCAPI Functions
125 DECL_FUNC_PTR(cc_initialize);
126 DECL_FUNC_PTR(cc_shutdown);
127 DECL_FUNC_PTR(cc_get_NC_info);
128 DECL_FUNC_PTR(cc_free_NC_info);
129
130 FUNC_INFO k5_fi[] = {
131 MAKE_FUNC_INFO(krb5_change_password),
132 MAKE_FUNC_INFO(krb5_get_init_creds_opt_alloc),
133 MAKE_FUNC_INFO(krb5_get_init_creds_opt_free),
134 MAKE_FUNC_INFO(krb5_get_init_creds_opt_init),
135 MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_tkt_life),
136 MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_renew_life),
137 MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_forwardable),
138 MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_proxiable),
139 MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_address_list),
140 MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_out_ccache),
141 MAKE_FUNC_INFO(krb5_get_init_creds_password),
142 MAKE_FUNC_INFO(krb5_build_principal_ext),
143 MAKE_FUNC_INFO(krb5_cc_get_name),
144 MAKE_FUNC_INFO(krb5_cc_resolve),
145 MAKE_FUNC_INFO(krb5_cc_default),
146 MAKE_FUNC_INFO(krb5_cc_default_name),
147 MAKE_FUNC_INFO(krb5_cc_set_default_name),
148 MAKE_FUNC_INFO(krb5_cc_initialize),
149 MAKE_FUNC_INFO(krb5_cc_destroy),
150 MAKE_FUNC_INFO(krb5_cc_close),
151 MAKE_FUNC_INFO(krb5_cc_copy_creds),
152 MAKE_FUNC_INFO(krb5_cc_store_cred),
153 // MAKE_FUNC_INFO(krb5_cc_retrieve_cred),
154 MAKE_FUNC_INFO(krb5_cc_get_principal),
155 MAKE_FUNC_INFO(krb5_cc_start_seq_get),
156 MAKE_FUNC_INFO(krb5_cc_next_cred),
157 MAKE_FUNC_INFO(krb5_cc_end_seq_get),
158 // MAKE_FUNC_INFO(krb5_cc_remove_cred),
159 MAKE_FUNC_INFO(krb5_cc_set_flags),
160 // MAKE_FUNC_INFO(krb5_cc_get_type),
161 MAKE_FUNC_INFO(krb5_free_context),
162 MAKE_FUNC_INFO(krb5_free_cred_contents),
163 MAKE_FUNC_INFO(krb5_free_principal),
164 MAKE_FUNC_INFO(krb5_get_in_tkt_with_password),
165 MAKE_FUNC_INFO(krb5_init_context),
166 MAKE_FUNC_INFO(krb5_parse_name),
167 MAKE_FUNC_INFO(krb5_timeofday),
168 MAKE_FUNC_INFO(krb5_timestamp_to_sfstring),
169 MAKE_FUNC_INFO(krb5_unparse_name),
170 MAKE_FUNC_INFO(krb5_get_credentials),
171 MAKE_FUNC_INFO(krb5_mk_req),
172 MAKE_FUNC_INFO(krb5_sname_to_principal),
173 MAKE_FUNC_INFO(krb5_get_credentials_renew),
174 MAKE_FUNC_INFO(krb5_free_data),
175 MAKE_FUNC_INFO(krb5_free_data_contents),
176 // MAKE_FUNC_INFO(krb5_get_realm_domain),
177 MAKE_FUNC_INFO(krb5_free_unparsed_name),
178 MAKE_FUNC_INFO(krb5_os_localaddr),
179 MAKE_FUNC_INFO(krb5_copy_keyblock_contents),
180 MAKE_FUNC_INFO(krb5_copy_data),
181 MAKE_FUNC_INFO(krb5_free_creds),
182 MAKE_FUNC_INFO(krb5_build_principal),
183 MAKE_FUNC_INFO(krb5_get_renewed_creds),
184 MAKE_FUNC_INFO(krb5_free_addresses),
185 MAKE_FUNC_INFO(krb5_get_default_config_files),
186 MAKE_FUNC_INFO(krb5_free_config_files),
187 MAKE_FUNC_INFO(krb5_get_default_realm),
188 MAKE_FUNC_INFO(krb5_free_ticket),
189 MAKE_FUNC_INFO(krb5_decode_ticket),
190 MAKE_FUNC_INFO(krb5_get_host_realm),
191 MAKE_FUNC_INFO(krb5_free_host_realm),
192 MAKE_FUNC_INFO(krb5_c_random_make_octets),
193 MAKE_FUNC_INFO(krb5_free_default_realm),
194 MAKE_FUNC_INFO(krb5_principal_compare),
195 MAKE_FUNC_INFO(krb5_string_to_deltat),
196 MAKE_FUNC_INFO(krb5_is_config_principal),
197 MAKE_FUNC_INFO(krb5_cccol_cursor_new),
198 MAKE_FUNC_INFO(krb5_cccol_cursor_next),
199 MAKE_FUNC_INFO(krb5_cccol_cursor_free),
200 MAKE_FUNC_INFO(krb5_cc_cache_match),
201 MAKE_FUNC_INFO(krb5_cc_get_type),
202 MAKE_FUNC_INFO(krb5_cc_new_unique),
203 MAKE_FUNC_INFO(krb5_cc_support_switch),
204 MAKE_FUNC_INFO(krb5_cc_switch),
205 MAKE_FUNC_INFO(krb5_cc_get_full_name),
206 MAKE_FUNC_INFO(krb5_free_string),
207 MAKE_FUNC_INFO(krb5int_cc_user_set_default_name),
208 END_FUNC_INFO
209 };
210
211 FUNC_INFO profile_fi[] = {
212 MAKE_FUNC_INFO(profile_init),
213 MAKE_FUNC_INFO(profile_release),
214 MAKE_FUNC_INFO(profile_get_subsection_names),
215 MAKE_FUNC_INFO(profile_free_list),
216 MAKE_FUNC_INFO(profile_get_string),
217 MAKE_FUNC_INFO(profile_release_string),
218 MAKE_FUNC_INFO(profile_get_integer),
219 END_FUNC_INFO
220 };
221
222 FUNC_INFO ce_fi[] = {
223 MAKE_FUNC_INFO(com_err),
224 MAKE_FUNC_INFO(error_message),
225 END_FUNC_INFO
226 };
227
228 FUNC_INFO service_fi[] = {
229 MAKE_FUNC_INFO(OpenSCManagerA),
230 MAKE_FUNC_INFO(OpenServiceA),
231 MAKE_FUNC_INFO(QueryServiceStatus),
232 MAKE_FUNC_INFO(CloseServiceHandle),
233 MAKE_FUNC_INFO(LsaNtStatusToWinError),
234 END_FUNC_INFO
235 };
236
237 FUNC_INFO lsa_fi[] = {
238 MAKE_FUNC_INFO(LsaConnectUntrusted),
239 MAKE_FUNC_INFO(LsaLookupAuthenticationPackage),
240 MAKE_FUNC_INFO(LsaCallAuthenticationPackage),
241 MAKE_FUNC_INFO(LsaFreeReturnBuffer),
242 MAKE_FUNC_INFO(LsaGetLogonSessionData),
243 END_FUNC_INFO
244 };
245
246 // CCAPI v2
247 FUNC_INFO ccapi_fi[] = {
248 MAKE_FUNC_INFO(cc_initialize),
249 MAKE_FUNC_INFO(cc_shutdown),
250 MAKE_FUNC_INFO(cc_get_NC_info),
251 MAKE_FUNC_INFO(cc_free_NC_info),
252 END_FUNC_INFO
253 };
254
255 // psapi functions
256 DECL_FUNC_PTR(GetModuleFileNameExA);
257 DECL_FUNC_PTR(EnumProcessModules);
258
259 FUNC_INFO psapi_fi[] = {
260 MAKE_FUNC_INFO(GetModuleFileNameExA),
261 MAKE_FUNC_INFO(EnumProcessModules),
262 END_FUNC_INFO
263 };
264
265 // toolhelp functions
266 DECL_FUNC_PTR(CreateToolhelp32Snapshot);
267 DECL_FUNC_PTR(Module32First);
268 DECL_FUNC_PTR(Module32Next);
269
270 FUNC_INFO toolhelp_fi[] = {
271 MAKE_FUNC_INFO(CreateToolhelp32Snapshot),
272 MAKE_FUNC_INFO(Module32First),
273 MAKE_FUNC_INFO(Module32Next),
274 END_FUNC_INFO
275 };
276
277 BOOL WINAPI
DllMain(HANDLE hinstDLL,DWORD fdwReason,LPVOID lpReserved)278 DllMain(
279 HANDLE hinstDLL,
280 DWORD fdwReason,
281 LPVOID lpReserved
282 )
283 {
284 hLeashInst = hinstDLL;
285
286 switch (fdwReason)
287 {
288 case DLL_PROCESS_ATTACH:
289 {
290 OSVERSIONINFO osvi;
291 LoadFuncs(KRB5_DLL, k5_fi, &hKrb5, 0, 1, 0, 0);
292 LoadFuncs(COMERR_DLL, ce_fi, &hComErr, 0, 0, 1, 0);
293 LoadFuncs(SERVICE_DLL, service_fi, &hService, 0, 1, 0, 0);
294 LoadFuncs(SECUR32_DLL, lsa_fi, &hSecur32, 0, 1, 1, 1);
295 LoadFuncs(PROFILE_DLL, profile_fi, &hProfile, 0, 1, 0, 0);
296 LoadFuncs(CCAPI_DLL, ccapi_fi, &hCcapi, 0, 1, 0, 0);
297
298 memset(&osvi, 0, sizeof(OSVERSIONINFO));
299 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
300 GetVersionEx(&osvi);
301
302 // XXX: We should really use feature testing, first
303 // checking for CreateToolhelp32Snapshot. If that's
304 // not around, we try the psapi stuff.
305 //
306 // Only load LSA functions if on NT/2000/XP
307 if(osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
308 {
309 // Windows 9x
310 LoadFuncs(TOOLHELPDLL, toolhelp_fi, &hToolHelp32, 0, 1, 0, 0);
311 hPsapi = 0;
312 }
313 else if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
314 {
315 // Windows NT
316 LoadFuncs(PSAPIDLL, psapi_fi, &hPsapi, 0, 1, 0, 0);
317 hToolHelp32 = 0;
318 }
319
320
321 /*
322 * Register window class for the MITPasswordControl that
323 * replaces normal edit controls for password input.
324 * zero any fields we don't explicitly set
325 */
326 hLeashInst = hinstDLL;
327
328 Register_MITPasswordEditControl(hLeashInst);
329
330 return TRUE;
331 }
332 case DLL_PROCESS_DETACH:
333 if (hKrb5)
334 FreeLibrary(hKrb5);
335 if (hCcapi)
336 FreeLibrary(hCcapi);
337 if (hProfile)
338 FreeLibrary(hProfile);
339 if (hComErr)
340 FreeLibrary(hComErr);
341 if (hService)
342 FreeLibrary(hService);
343 if (hSecur32)
344 FreeLibrary(hSecur32);
345 if (hPsapi)
346 FreeLibrary(hPsapi);
347 if (hToolHelp32)
348 FreeLibrary(hToolHelp32);
349
350 return TRUE;
351 default:
352 return TRUE;
353 }
354 }
355