Windows: No rand_s on Windows 2000
authorJeffrey Altman <jaltman@secure-endpoints.com>
Fri, 18 Sep 2009 14:01:10 +0000 (10:01 -0400)
committerJeffrey Altman <jaltman|account-1000011@unknown>
Sat, 19 Sep 2009 18:11:46 +0000 (11:11 -0700)
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>

src/WINNT/afsd/rpc_srvsvc.c

index a63a40c..9a36bb3 100644 (file)
@@ -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