Implement ADVAPI SystemFunction036

Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
Sun May 22 11:54:13 CDT 2005


Changelog:
	dlls/advapi32/crypt.c:
	Implement SystemFunction036, it si documented and exported as RtlGenRandom
-- 
Uwe Bonnes                bon at elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
Index: wine/include/ntsecapi.h
===================================================================
RCS file: /home/wine/wine/include/ntsecapi.h,v
retrieving revision 1.14
diff -u -r1.14 ntsecapi.h
--- wine/include/ntsecapi.h	21 Jan 2005 10:15:50 -0000	1.14
+++ wine/include/ntsecapi.h	22 May 2005 10:40:23 -0000
@@ -196,6 +196,7 @@
     LONG DomainIndex;
 } LSA_TRANSLATED_SID, *PLSA_TRANSLATED_SID;
 
+BOOLEAN  WINAPI RtlGenRandom(PVOID, ULONG);
 NTSTATUS WINAPI LsaClose(LSA_HANDLE);
 NTSTATUS WINAPI LsaEnumerateTrustedDomains(LSA_HANDLE,PLSA_ENUMERATION_HANDLE,PVOID*,ULONG,PULONG);
 NTSTATUS WINAPI LsaFreeMemory(PVOID);
Index: wine/dlls/advapi32/advapi32.spec
===================================================================
RCS file: /home/wine/wine/dlls/advapi32/advapi32.spec,v
retrieving revision 1.71
diff -u -r1.71 advapi32.spec
--- wine/dlls/advapi32/advapi32.spec	11 May 2005 13:00:18 -0000	1.71
+++ wine/dlls/advapi32/advapi32.spec	22 May 2005 10:40:24 -0000
@@ -343,7 +343,7 @@
 @ stub SystemFunction033
 @ stub SystemFunction034
 @ stub SystemFunction035
-@ stub SystemFunction036
+@ stdcall SystemFunction036(ptr long) RtlGenRandom
 @ stdcall SystemFunction040(ptr long long) # RtlEncryptMemory
 @ stdcall SystemFunction041(ptr long long) # RtlDecryptMemory
 @ stub TraceEvent
Index: wine/dlls/advapi32/crypt.c
===================================================================
RCS file: /home/wine/wine/dlls/advapi32/crypt.c,v
retrieving revision 1.64
diff -u -r1.64 crypt.c
--- wine/dlls/advapi32/crypt.c	20 Apr 2005 15:18:43 -0000	1.64
+++ wine/dlls/advapi32/crypt.c	22 May 2005 10:40:31 -0000
@@ -27,6 +27,11 @@
 #include <time.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
 
 #include "crypt.h"
 #include "winnls.h"
@@ -1891,6 +1896,39 @@
 	return result;
 }
 
+/******************************************************************************
+ * SystemFunction036   (ADVAPI32.@)
+ *
+ * MSDN documents this function as RtlGenRandom and declares it in ntsecapi.h
+ *
+ * PARAMS
+ *  pbBufer [O] Pointer to memory to receive random bytes.
+ *  dwLen   [I] Number of random bytes to fetch.
+ */
+
+BOOL WINAPI RtlGenRandom (PVOID pbBuffer, ULONG dwLen)
+{
+    int dev_random;
+
+    /* FIXME: /dev/urandom does not provide random numbers of a sufficient
+     * quality for cryptographic applications. /dev/random is much better,  
+     * but it blocks if the kernel has not yet collected enough entropy for
+     * the request, which will suspend the calling thread for an indefinite
+     * amount of time. */
+    dev_random = open("/dev/urandom", O_RDONLY);
+    if (dev_random != -1)
+    {
+        if (read(dev_random, pbBuffer, dwLen) == (ssize_t)dwLen)
+        {
+            close(dev_random);
+            return TRUE;
+        }
+        close(dev_random);
+    }
+    SetLastError(NTE_FAIL);
+    return FALSE;
+}    
+    
 /*
    These functions have nearly identical prototypes to CryptProtectMemory and CryptUnprotectMemory,
    in crypt32.dll.



More information about the wine-patches mailing list