From ccb02bf6eb7395bbb3d66c11b99a576c19d033d4 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Fri, 18 Sep 2009 10:01:10 -0400 Subject: [PATCH] Windows: No rand_s on Windows 2000 Even if the rand_s() function is supported by the compiler it is not supported on Windows 2000 because the kernel level functionality it requires does not exist on that platform. Calling rand_s() on Windows 2000 will throw an exception and terminate the service. LICENSE MIT Reviewed-on: http://gerrit.openafs.org/464 Reviewed-by: Derrick Brashear Tested-by: Asanka Herath Reviewed-by: Asanka Herath Tested-by: Jeffrey Altman Reviewed-by: Jeffrey Altman --- src/WINNT/afsd/rpc_srvsvc.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/WINNT/afsd/rpc_srvsvc.c b/src/WINNT/afsd/rpc_srvsvc.c index a63a40c23..9a36bb3e1 100644 --- a/src/WINNT/afsd/rpc_srvsvc.c +++ b/src/WINNT/afsd/rpc_srvsvc.c @@ -328,14 +328,31 @@ static DWORD shareEnum_next_handle=1; void RPC_SRVSVC_Init(void) { +#if _MSC_VER >= 1400 + int hasRand_s = -1; + OSVERSIONINFO osInfo; + + osInfo.dwOSVersionInfoSize = sizeof(osInfo); + if (GetVersionEx(&osInfo)) { + if ((osInfo.dwMajorVersion > 5) || + (osInfo.dwMajorVersion == 5) && (osInfo.dwMinorVersion >= 1)) + hasRand_s = 1; + else + hasRand_s = 0; + } +#endif + lock_InitializeMutex(&shareEnum_mx, "NetrShareEnum", 0); shareEnumQ = NULL; -#if _MSC_VER < 1400 - srand((unsigned) time( NULL )); - shareEnum_next_handle = rand(); -#else - rand_s(&shareEnum_next_handle); +#if _MSC_VER >= 1400 + if (hasRand_s > 0) { + rand_s(&shareEnum_next_handle); + } else #endif + { + srand((unsigned) time( NULL )); + shareEnum_next_handle = rand(); + } } void -- 2.39.5