diff options
Diffstat (limited to 'os/win32')
-rw-r--r-- | os/win32/ap_regkey.c | 3 | ||||
-rw-r--r-- | os/win32/os.h | 55 | ||||
-rw-r--r-- | os/win32/util_win32.c | 115 |
3 files changed, 170 insertions, 3 deletions
diff --git a/os/win32/ap_regkey.c b/os/win32/ap_regkey.c index 629be525d7..245e71e988 100644 --- a/os/win32/ap_regkey.c +++ b/os/win32/ap_regkey.c @@ -58,9 +58,10 @@ #ifdef WIN32 -#include "ap_regkey.h" +#include "apr.h" #include "arch/win32/fileio.h" #include "arch/win32/misc.h" +#include "ap_regkey.h" struct ap_regkey_t { apr_pool_t *pool; diff --git a/os/win32/os.h b/os/win32/os.h index c6f6200f00..a05b42c0e8 100644 --- a/os/win32/os.h +++ b/os/win32/os.h @@ -97,8 +97,63 @@ AP_DECLARE_DATA extern int real_exit_code; #define exit(status) ((exit)((real_exit_code==2) ? (real_exit_code = (status)) \ : ((real_exit_code = 0), (status)))) + +/* Defined in util_win32.c + */ + AP_DECLARE(apr_status_t) ap_os_proc_filepath(char **binpath, apr_pool_t *p); +typedef enum { + AP_DLL_WINBASEAPI = 0, // kernel32 From WinBase.h + AP_DLL_WINADVAPI = 1, // advapi32 From WinBase.h + AP_DLL_WINSOCKAPI = 2, // mswsock From WinSock.h + AP_DLL_WINSOCK2API = 3, // ws2_32 From WinSock2.h + AP_DLL_defined = 4 // must define as last idx_ + 1 +} ap_dlltoken_e; + +FARPROC ap_load_dll_func(ap_dlltoken_e fnLib, char* fnName, int ordinal); + +PSECURITY_ATTRIBUTES GetNullACL(); +void CleanNullACL(void *sa); + +DWORD wait_for_many_objects(DWORD nCount, CONST HANDLE *lpHandles, + DWORD dwSeconds); + +int set_listeners_noninheritable(apr_pool_t *p); + + +#define AP_DECLARE_LATE_DLL_FUNC(lib, rettype, calltype, fn, ord, args, names) \ + typedef rettype (calltype *ap_winapi_fpt_##fn) args; \ + static ap_winapi_fpt_##fn ap_winapi_pfn_##fn = NULL; \ + __inline rettype ap_winapi_##fn args \ + { if (!ap_winapi_pfn_##fn) \ + ap_winapi_pfn_##fn = (ap_winapi_fpt_##fn) ap_load_dll_func(lib, #fn, ord); \ + return (*(ap_winapi_pfn_##fn)) names; }; \ + +/* Win2K kernel only */ +AP_DECLARE_LATE_DLL_FUNC(AP_DLL_WINADVAPI, BOOL, WINAPI, ChangeServiceConfig2A, 0, ( + SC_HANDLE hService, + DWORD dwInfoLevel, + LPVOID lpInfo), + (hService, dwInfoLevel, lpInfo)); +#undef ChangeServiceConfig2 +#define ChangeServiceConfig2 ap_winapi_ChangeServiceConfig2A + +/* WinNT kernel only */ +AP_DECLARE_LATE_DLL_FUNC(AP_DLL_WINBASEAPI, BOOL, WINAPI, CancelIo, 0, ( + IN HANDLE hFile), + (hFile)); +#undef CancelIo +#define CancelIo ap_winapi_CancelIo + +/* Win9x kernel only */ +AP_DECLARE_LATE_DLL_FUNC(AP_DLL_WINBASEAPI, DWORD, WINAPI, RegisterServiceProcess, 0, ( + DWORD dwProcessId, + DWORD dwType), + (dwProcessId, dwType)); +#define RegisterServiceProcess ap_winapi_RegisterServiceProcess + + #ifdef __cplusplus } #endif diff --git a/os/win32/util_win32.c b/os/win32/util_win32.c index 0dfce99ffb..021a8c7f0b 100644 --- a/os/win32/util_win32.c +++ b/os/win32/util_win32.c @@ -56,12 +56,13 @@ * University of Illinois, Urbana-Champaign. */ -#include "httpd.h" -#include "http_log.h" #include "apr_strings.h" #include "arch/win32/fileio.h" #include "arch/win32/misc.h" +#include "httpd.h" +#include "http_log.h" + #include <stdarg.h> #include <time.h> #include <stdlib.h> @@ -115,3 +116,113 @@ AP_DECLARE(apr_status_t) ap_os_create_privileged_process( { return apr_proc_create(newproc, progname, args, env, attr, p); } + + +/* This code is stolen from misc/win32/misc.c and apr_private.h + * This helper code resolves late bound entry points + * missing from one or more releases of the Win32 API... + * but it sure would be nice if we didn't duplicate this code + * from the APR ;-) + */ +static const char* const lateDllName[DLL_defined] = { + "kernel32", "advapi32", "mswsock", "ws2_32" }; +static HMODULE lateDllHandle[DLL_defined] = { + NULL, NULL, NULL, NULL }; + + +FARPROC ap_load_dll_func(ap_dlltoken_e fnLib, char* fnName, int ordinal) +{ + if (!lateDllHandle[fnLib]) { + lateDllHandle[fnLib] = LoadLibrary(lateDllName[fnLib]); + if (!lateDllHandle[fnLib]) + return NULL; + } + if (ordinal) + return GetProcAddress(lateDllHandle[fnLib], (char *) ordinal); + else + return GetProcAddress(lateDllHandle[fnLib], fnName); +} + + +/* To share the semaphores with other processes, we need a NULL ACL + * Code from MS KB Q106387 + */ +PSECURITY_ATTRIBUTES GetNullACL() +{ + PSECURITY_DESCRIPTOR pSD; + PSECURITY_ATTRIBUTES sa; + + sa = (PSECURITY_ATTRIBUTES) LocalAlloc(LPTR, sizeof(SECURITY_ATTRIBUTES)); + sa->nLength = sizeof(sizeof(SECURITY_ATTRIBUTES)); + + pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH); + sa->lpSecurityDescriptor = pSD; + + if (pSD == NULL || sa == NULL) { + return NULL; + } + apr_set_os_error(0); + if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION) + || apr_get_os_error()) { + LocalFree( pSD ); + LocalFree( sa ); + return NULL; + } + if (!SetSecurityDescriptorDacl(pSD, TRUE, (PACL) NULL, FALSE) + || apr_get_os_error()) { + LocalFree( pSD ); + LocalFree( sa ); + return NULL; + } + + sa->bInheritHandle = TRUE; + return sa; +} + + +void CleanNullACL(void *sa) +{ + if (sa) { + LocalFree(((PSECURITY_ATTRIBUTES)sa)->lpSecurityDescriptor); + LocalFree(sa); + } +} + + +/* + * The Win32 call WaitForMultipleObjects will only allow you to wait for + * a maximum of MAXIMUM_WAIT_OBJECTS (current 64). Since the threading + * model in the multithreaded version of apache wants to use this call, + * we are restricted to a maximum of 64 threads. This is a simplistic + * routine that will increase this size. + */ +DWORD wait_for_many_objects(DWORD nCount, CONST HANDLE *lpHandles, + DWORD dwSeconds) +{ + time_t tStopTime; + DWORD dwRet = WAIT_TIMEOUT; + DWORD dwIndex=0; + BOOL bFirst = TRUE; + + tStopTime = time(NULL) + dwSeconds; + + do { + if (!bFirst) + Sleep(1000); + else + bFirst = FALSE; + + for (dwIndex = 0; dwIndex * MAXIMUM_WAIT_OBJECTS < nCount; dwIndex++) { + dwRet = WaitForMultipleObjects( + min(MAXIMUM_WAIT_OBJECTS, nCount - (dwIndex * MAXIMUM_WAIT_OBJECTS)), + lpHandles + (dwIndex * MAXIMUM_WAIT_OBJECTS), + 0, 0); + + if (dwRet != WAIT_TIMEOUT) { + break; + } + } + } while((time(NULL) < tStopTime) && (dwRet == WAIT_TIMEOUT)); + + return dwRet; +} |