From 303c70efd4cb54ad673bed5a0c438670ae2b97ad Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Sat, 1 Nov 2008 03:37:56 +0000 Subject: [PATCH] windows-prevent-wow64-execution-20081031 LICENSE MIT prevent the 32-bit build from being executed in the wow64 environment --- src/WINNT/afsd/afsd_init.c | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/WINNT/afsd/afsd_init.c b/src/WINNT/afsd/afsd_init.c index a056519a6..5c6525795 100644 --- a/src/WINNT/afsd/afsd_init.c +++ b/src/WINNT/afsd/afsd_init.c @@ -543,6 +543,38 @@ static void afsd_InitServerPreferences(void) } } + +#ifndef _WIN64 +typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); + +static BOOL +is_wow64(void) +{ + static BOOL bChecked = FALSE; + static BOOL bIsWow64 = FALSE; + + if (!bChecked) + { + HANDLE h1 = NULL; + LPFN_ISWOW64PROCESS fnIsWow64Process = NULL; + + h1 = GetModuleHandle("kernel32.dll"); + fnIsWow64Process = + (LPFN_ISWOW64PROCESS)GetProcAddress(h1, "IsWow64Process"); + + /* If we don't find the fnIsWow64Process function then we + * are not running in a broken Wow64 + */ + if (fnIsWow64Process) + fnIsWow64Process(GetCurrentProcess(), &bIsWow64); + + bChecked = TRUE; + } + + return bIsWow64; +} +#endif /* _WIN64 */ + /* * AFSD Initialization */ @@ -595,6 +627,14 @@ int afsd_InitCM(char **reasonP) code = osi_InitDebug(&debugID); afsi_log("osi_InitDebug code %d", code); +#ifndef _WIN64 + if (is_wow64()) + { + *reasonP = "32-bit OpenAFS Service is incompatible with the WOW64 environment"; + return -1; + } +#endif + // osi_LockTypeSetDefault("stat"); /* comment this out for speed */ if (code != 0) { if (code == RPC_S_NO_PROTSEQS) -- 2.39.5