Path: blob/main/crypto/krb5/src/windows/leashdll/leashdll.c
34914 views
#include <windows.h>1#include "leashdll.h"2#include <leashwin.h>3#include "leash-int.h"45HINSTANCE hLeashInst;67HINSTANCE hKrb5 = 0;8HINSTANCE hKrb524 = 0;9HINSTANCE hSecur32 = 0;10HINSTANCE hComErr = 0;11HINSTANCE hService = 0;12HINSTANCE hProfile = 0;13HINSTANCE hPsapi = 0;14HINSTANCE hToolHelp32 = 0;15HINSTANCE hCcapi = 0;1617// krb5 functions18DECL_FUNC_PTR(krb5_change_password);19DECL_FUNC_PTR(krb5_get_init_creds_opt_alloc);20DECL_FUNC_PTR(krb5_get_init_creds_opt_free);21DECL_FUNC_PTR(krb5_get_init_creds_opt_init);22DECL_FUNC_PTR(krb5_get_init_creds_opt_set_tkt_life);23DECL_FUNC_PTR(krb5_get_init_creds_opt_set_renew_life);24DECL_FUNC_PTR(krb5_get_init_creds_opt_set_forwardable);25DECL_FUNC_PTR(krb5_get_init_creds_opt_set_proxiable);26DECL_FUNC_PTR(krb5_get_init_creds_opt_set_address_list);27DECL_FUNC_PTR(krb5_get_init_creds_opt_set_out_ccache);28DECL_FUNC_PTR(krb5_get_init_creds_password);29DECL_FUNC_PTR(krb5_build_principal_ext);30DECL_FUNC_PTR(krb5_cc_get_name);31DECL_FUNC_PTR(krb5_cc_resolve);32DECL_FUNC_PTR(krb5_cc_default);33DECL_FUNC_PTR(krb5_cc_default_name);34DECL_FUNC_PTR(krb5_cc_set_default_name);35DECL_FUNC_PTR(krb5_cc_initialize);36DECL_FUNC_PTR(krb5_cc_destroy);37DECL_FUNC_PTR(krb5_cc_close);38DECL_FUNC_PTR(krb5_cc_store_cred);39DECL_FUNC_PTR(krb5_cc_copy_creds);40// DECL_FUNC_PTR(krb5_cc_retrieve_cred);41DECL_FUNC_PTR(krb5_cc_get_principal);42DECL_FUNC_PTR(krb5_cc_start_seq_get);43DECL_FUNC_PTR(krb5_cc_next_cred);44DECL_FUNC_PTR(krb5_cc_end_seq_get);45// DECL_FUNC_PTR(krb5_cc_remove_cred);46DECL_FUNC_PTR(krb5_cc_set_flags);47// DECL_FUNC_PTR(krb5_cc_get_type);48DECL_FUNC_PTR(krb5_free_context);49DECL_FUNC_PTR(krb5_free_cred_contents);50DECL_FUNC_PTR(krb5_free_principal);51DECL_FUNC_PTR(krb5_get_in_tkt_with_password);52DECL_FUNC_PTR(krb5_init_context);53DECL_FUNC_PTR(krb5_parse_name);54DECL_FUNC_PTR(krb5_timeofday);55DECL_FUNC_PTR(krb5_timestamp_to_sfstring);56DECL_FUNC_PTR(krb5_unparse_name);57DECL_FUNC_PTR(krb5_get_credentials);58DECL_FUNC_PTR(krb5_mk_req);59DECL_FUNC_PTR(krb5_sname_to_principal);60DECL_FUNC_PTR(krb5_get_credentials_renew);61DECL_FUNC_PTR(krb5_free_data);62DECL_FUNC_PTR(krb5_free_data_contents);63// DECL_FUNC_PTR(krb5_get_realm_domain);64DECL_FUNC_PTR(krb5_free_unparsed_name);65DECL_FUNC_PTR(krb5_os_localaddr);66DECL_FUNC_PTR(krb5_copy_keyblock_contents);67DECL_FUNC_PTR(krb5_copy_data);68DECL_FUNC_PTR(krb5_free_creds);69DECL_FUNC_PTR(krb5_build_principal);70DECL_FUNC_PTR(krb5_get_renewed_creds);71DECL_FUNC_PTR(krb5_get_default_config_files);72DECL_FUNC_PTR(krb5_free_config_files);73DECL_FUNC_PTR(krb5_get_default_realm);74DECL_FUNC_PTR(krb5_free_ticket);75DECL_FUNC_PTR(krb5_decode_ticket);76DECL_FUNC_PTR(krb5_get_host_realm);77DECL_FUNC_PTR(krb5_free_host_realm);78DECL_FUNC_PTR(krb5_c_random_make_octets);79DECL_FUNC_PTR(krb5_free_addresses);80DECL_FUNC_PTR(krb5_free_default_realm);81DECL_FUNC_PTR(krb5_principal_compare);82DECL_FUNC_PTR(krb5_string_to_deltat);83DECL_FUNC_PTR(krb5_is_config_principal);84DECL_FUNC_PTR(krb5_cccol_cursor_new);85DECL_FUNC_PTR(krb5_cccol_cursor_free);86DECL_FUNC_PTR(krb5_cccol_cursor_next);87DECL_FUNC_PTR(krb5_cc_cache_match);88DECL_FUNC_PTR(krb5_cc_get_type);89DECL_FUNC_PTR(krb5_cc_new_unique);90DECL_FUNC_PTR(krb5_cc_support_switch);91DECL_FUNC_PTR(krb5_cc_switch);92DECL_FUNC_PTR(krb5_cc_get_full_name);93DECL_FUNC_PTR(krb5_free_string);94DECL_FUNC_PTR(krb5int_cc_user_set_default_name);9596// ComErr functions97DECL_FUNC_PTR(com_err);98DECL_FUNC_PTR(error_message);99100// Profile functions101DECL_FUNC_PTR(profile_init);102DECL_FUNC_PTR(profile_release);103DECL_FUNC_PTR(profile_get_subsection_names);104DECL_FUNC_PTR(profile_free_list);105DECL_FUNC_PTR(profile_get_string);106DECL_FUNC_PTR(profile_release_string);107DECL_FUNC_PTR(profile_get_integer);108109// Service functions110DECL_FUNC_PTR(OpenSCManagerA);111DECL_FUNC_PTR(OpenServiceA);112DECL_FUNC_PTR(QueryServiceStatus);113DECL_FUNC_PTR(CloseServiceHandle);114DECL_FUNC_PTR(LsaNtStatusToWinError);115116// LSA Functions117DECL_FUNC_PTR(LsaConnectUntrusted);118DECL_FUNC_PTR(LsaLookupAuthenticationPackage);119DECL_FUNC_PTR(LsaCallAuthenticationPackage);120DECL_FUNC_PTR(LsaFreeReturnBuffer);121DECL_FUNC_PTR(LsaGetLogonSessionData);122123// CCAPI Functions124DECL_FUNC_PTR(cc_initialize);125DECL_FUNC_PTR(cc_shutdown);126DECL_FUNC_PTR(cc_get_NC_info);127DECL_FUNC_PTR(cc_free_NC_info);128129FUNC_INFO k5_fi[] = {130MAKE_FUNC_INFO(krb5_change_password),131MAKE_FUNC_INFO(krb5_get_init_creds_opt_alloc),132MAKE_FUNC_INFO(krb5_get_init_creds_opt_free),133MAKE_FUNC_INFO(krb5_get_init_creds_opt_init),134MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_tkt_life),135MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_renew_life),136MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_forwardable),137MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_proxiable),138MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_address_list),139MAKE_FUNC_INFO(krb5_get_init_creds_opt_set_out_ccache),140MAKE_FUNC_INFO(krb5_get_init_creds_password),141MAKE_FUNC_INFO(krb5_build_principal_ext),142MAKE_FUNC_INFO(krb5_cc_get_name),143MAKE_FUNC_INFO(krb5_cc_resolve),144MAKE_FUNC_INFO(krb5_cc_default),145MAKE_FUNC_INFO(krb5_cc_default_name),146MAKE_FUNC_INFO(krb5_cc_set_default_name),147MAKE_FUNC_INFO(krb5_cc_initialize),148MAKE_FUNC_INFO(krb5_cc_destroy),149MAKE_FUNC_INFO(krb5_cc_close),150MAKE_FUNC_INFO(krb5_cc_copy_creds),151MAKE_FUNC_INFO(krb5_cc_store_cred),152// MAKE_FUNC_INFO(krb5_cc_retrieve_cred),153MAKE_FUNC_INFO(krb5_cc_get_principal),154MAKE_FUNC_INFO(krb5_cc_start_seq_get),155MAKE_FUNC_INFO(krb5_cc_next_cred),156MAKE_FUNC_INFO(krb5_cc_end_seq_get),157// MAKE_FUNC_INFO(krb5_cc_remove_cred),158MAKE_FUNC_INFO(krb5_cc_set_flags),159// MAKE_FUNC_INFO(krb5_cc_get_type),160MAKE_FUNC_INFO(krb5_free_context),161MAKE_FUNC_INFO(krb5_free_cred_contents),162MAKE_FUNC_INFO(krb5_free_principal),163MAKE_FUNC_INFO(krb5_get_in_tkt_with_password),164MAKE_FUNC_INFO(krb5_init_context),165MAKE_FUNC_INFO(krb5_parse_name),166MAKE_FUNC_INFO(krb5_timeofday),167MAKE_FUNC_INFO(krb5_timestamp_to_sfstring),168MAKE_FUNC_INFO(krb5_unparse_name),169MAKE_FUNC_INFO(krb5_get_credentials),170MAKE_FUNC_INFO(krb5_mk_req),171MAKE_FUNC_INFO(krb5_sname_to_principal),172MAKE_FUNC_INFO(krb5_get_credentials_renew),173MAKE_FUNC_INFO(krb5_free_data),174MAKE_FUNC_INFO(krb5_free_data_contents),175// MAKE_FUNC_INFO(krb5_get_realm_domain),176MAKE_FUNC_INFO(krb5_free_unparsed_name),177MAKE_FUNC_INFO(krb5_os_localaddr),178MAKE_FUNC_INFO(krb5_copy_keyblock_contents),179MAKE_FUNC_INFO(krb5_copy_data),180MAKE_FUNC_INFO(krb5_free_creds),181MAKE_FUNC_INFO(krb5_build_principal),182MAKE_FUNC_INFO(krb5_get_renewed_creds),183MAKE_FUNC_INFO(krb5_free_addresses),184MAKE_FUNC_INFO(krb5_get_default_config_files),185MAKE_FUNC_INFO(krb5_free_config_files),186MAKE_FUNC_INFO(krb5_get_default_realm),187MAKE_FUNC_INFO(krb5_free_ticket),188MAKE_FUNC_INFO(krb5_decode_ticket),189MAKE_FUNC_INFO(krb5_get_host_realm),190MAKE_FUNC_INFO(krb5_free_host_realm),191MAKE_FUNC_INFO(krb5_c_random_make_octets),192MAKE_FUNC_INFO(krb5_free_default_realm),193MAKE_FUNC_INFO(krb5_principal_compare),194MAKE_FUNC_INFO(krb5_string_to_deltat),195MAKE_FUNC_INFO(krb5_is_config_principal),196MAKE_FUNC_INFO(krb5_cccol_cursor_new),197MAKE_FUNC_INFO(krb5_cccol_cursor_next),198MAKE_FUNC_INFO(krb5_cccol_cursor_free),199MAKE_FUNC_INFO(krb5_cc_cache_match),200MAKE_FUNC_INFO(krb5_cc_get_type),201MAKE_FUNC_INFO(krb5_cc_new_unique),202MAKE_FUNC_INFO(krb5_cc_support_switch),203MAKE_FUNC_INFO(krb5_cc_switch),204MAKE_FUNC_INFO(krb5_cc_get_full_name),205MAKE_FUNC_INFO(krb5_free_string),206MAKE_FUNC_INFO(krb5int_cc_user_set_default_name),207END_FUNC_INFO208};209210FUNC_INFO profile_fi[] = {211MAKE_FUNC_INFO(profile_init),212MAKE_FUNC_INFO(profile_release),213MAKE_FUNC_INFO(profile_get_subsection_names),214MAKE_FUNC_INFO(profile_free_list),215MAKE_FUNC_INFO(profile_get_string),216MAKE_FUNC_INFO(profile_release_string),217MAKE_FUNC_INFO(profile_get_integer),218END_FUNC_INFO219};220221FUNC_INFO ce_fi[] = {222MAKE_FUNC_INFO(com_err),223MAKE_FUNC_INFO(error_message),224END_FUNC_INFO225};226227FUNC_INFO service_fi[] = {228MAKE_FUNC_INFO(OpenSCManagerA),229MAKE_FUNC_INFO(OpenServiceA),230MAKE_FUNC_INFO(QueryServiceStatus),231MAKE_FUNC_INFO(CloseServiceHandle),232MAKE_FUNC_INFO(LsaNtStatusToWinError),233END_FUNC_INFO234};235236FUNC_INFO lsa_fi[] = {237MAKE_FUNC_INFO(LsaConnectUntrusted),238MAKE_FUNC_INFO(LsaLookupAuthenticationPackage),239MAKE_FUNC_INFO(LsaCallAuthenticationPackage),240MAKE_FUNC_INFO(LsaFreeReturnBuffer),241MAKE_FUNC_INFO(LsaGetLogonSessionData),242END_FUNC_INFO243};244245// CCAPI v2246FUNC_INFO ccapi_fi[] = {247MAKE_FUNC_INFO(cc_initialize),248MAKE_FUNC_INFO(cc_shutdown),249MAKE_FUNC_INFO(cc_get_NC_info),250MAKE_FUNC_INFO(cc_free_NC_info),251END_FUNC_INFO252};253254// psapi functions255DECL_FUNC_PTR(GetModuleFileNameExA);256DECL_FUNC_PTR(EnumProcessModules);257258FUNC_INFO psapi_fi[] = {259MAKE_FUNC_INFO(GetModuleFileNameExA),260MAKE_FUNC_INFO(EnumProcessModules),261END_FUNC_INFO262};263264// toolhelp functions265DECL_FUNC_PTR(CreateToolhelp32Snapshot);266DECL_FUNC_PTR(Module32First);267DECL_FUNC_PTR(Module32Next);268269FUNC_INFO toolhelp_fi[] = {270MAKE_FUNC_INFO(CreateToolhelp32Snapshot),271MAKE_FUNC_INFO(Module32First),272MAKE_FUNC_INFO(Module32Next),273END_FUNC_INFO274};275276BOOL WINAPI277DllMain(278HANDLE hinstDLL,279DWORD fdwReason,280LPVOID lpReserved281)282{283hLeashInst = hinstDLL;284285switch (fdwReason)286{287case DLL_PROCESS_ATTACH:288{289OSVERSIONINFO osvi;290LoadFuncs(KRB5_DLL, k5_fi, &hKrb5, 0, 1, 0, 0);291LoadFuncs(COMERR_DLL, ce_fi, &hComErr, 0, 0, 1, 0);292LoadFuncs(SERVICE_DLL, service_fi, &hService, 0, 1, 0, 0);293LoadFuncs(SECUR32_DLL, lsa_fi, &hSecur32, 0, 1, 1, 1);294LoadFuncs(PROFILE_DLL, profile_fi, &hProfile, 0, 1, 0, 0);295LoadFuncs(CCAPI_DLL, ccapi_fi, &hCcapi, 0, 1, 0, 0);296297memset(&osvi, 0, sizeof(OSVERSIONINFO));298osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);299GetVersionEx(&osvi);300301// XXX: We should really use feature testing, first302// checking for CreateToolhelp32Snapshot. If that's303// not around, we try the psapi stuff.304//305// Only load LSA functions if on NT/2000/XP306if(osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)307{308// Windows 9x309LoadFuncs(TOOLHELPDLL, toolhelp_fi, &hToolHelp32, 0, 1, 0, 0);310hPsapi = 0;311}312else if(osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)313{314// Windows NT315LoadFuncs(PSAPIDLL, psapi_fi, &hPsapi, 0, 1, 0, 0);316hToolHelp32 = 0;317}318319320/*321* Register window class for the MITPasswordControl that322* replaces normal edit controls for password input.323* zero any fields we don't explicitly set324*/325hLeashInst = hinstDLL;326327Register_MITPasswordEditControl(hLeashInst);328329return TRUE;330}331case DLL_PROCESS_DETACH:332if (hKrb5)333FreeLibrary(hKrb5);334if (hCcapi)335FreeLibrary(hCcapi);336if (hProfile)337FreeLibrary(hProfile);338if (hComErr)339FreeLibrary(hComErr);340if (hService)341FreeLibrary(hService);342if (hSecur32)343FreeLibrary(hSecur32);344if (hPsapi)345FreeLibrary(hPsapi);346if (hToolHelp32)347FreeLibrary(hToolHelp32);348349return TRUE;350default:351return TRUE;352}353}354355356