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 <shadow@dementia.org>
Tested-by: Asanka Herath <asanka@secure-endpoints.com>
Reviewed-by: Asanka Herath <asanka@secure-endpoints.com>
Tested-by: Jeffrey Altman <jaltman@openafs.org>
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>
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