Juan Lang : advapi32: Create MachineGuid value if it doesn't exist.
Alexandre Julliard
julliard at winehq.org
Tue Mar 25 14:20:06 CDT 2008
Module: wine
Branch: master
Commit: 9ea9eaaa81dbd852962aedaf341a48634cfe6ae6
URL: http://source.winehq.org/git/wine.git/?a=commit;h=9ea9eaaa81dbd852962aedaf341a48634cfe6ae6
Author: Juan Lang <juan.lang at gmail.com>
Date: Tue Mar 25 10:39:22 2008 -0700
advapi32: Create MachineGuid value if it doesn't exist.
---
dlls/advapi32/crypt.c | 52 +++++++++++++++++++++++++++++++++++++++++++
dlls/advapi32/tests/crypt.c | 2 -
2 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/dlls/advapi32/crypt.c b/dlls/advapi32/crypt.c
index 601d095..0fadc78 100644
--- a/dlls/advapi32/crypt.c
+++ b/dlls/advapi32/crypt.c
@@ -44,6 +44,7 @@
#include "crypt.h"
#include "winnls.h"
#include "winreg.h"
+#include "rpc.h"
#include "wine/debug.h"
#include "wine/unicode.h"
#include "winternl.h"
@@ -266,6 +267,54 @@ error:
#undef CRYPT_GetProvFuncOpt
+static void CRYPT_CreateMachineGuid(void)
+{
+ static const WCHAR cryptographyW[] = {
+ 'S','o','f','t','w','a','r','e','\\',
+ 'M','i','c','r','o','s','o','f','t','\\',
+ 'C','r','y','p','t','o','g','r','a','p','h','y',0 };
+ static const WCHAR machineGuidW[] = {
+ 'M','a','c','h','i','n','e','G','u','i','d',0 };
+ LONG r;
+ HKEY key;
+
+ r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, cryptographyW, 0, KEY_ALL_ACCESS,
+ &key);
+ if (!r)
+ {
+ DWORD size;
+
+ r = RegQueryValueExW(key, machineGuidW, NULL, NULL, NULL, &size);
+ if (r == ERROR_FILE_NOT_FOUND)
+ {
+ static const WCHAR rpcrt4[] = {
+ 'r','p','c','r','t','4',0 };
+ HMODULE lib = LoadLibraryW(rpcrt4);
+
+ if (lib)
+ {
+ RPC_STATUS (RPC_ENTRY *pUuidCreate)(UUID *);
+ RPC_STATUS (RPC_ENTRY *pUuidToString)(UUID *, WCHAR **);
+ RPC_STATUS (RPC_ENTRY *pRpcStringFree)(WCHAR **);
+ UUID uuid;
+ WCHAR *uuidStr;
+
+ pUuidCreate = GetProcAddress(lib, "UuidCreate");
+ pUuidToString = GetProcAddress(lib, "UuidToStringW");
+ pRpcStringFree = GetProcAddress(lib, "RpcStringFreeW");
+ pUuidCreate(&uuid);
+ pUuidToString(&uuid, &uuidStr);
+ RegSetValueExW(key, machineGuidW, 0, REG_SZ,
+ (const BYTE *)uuidStr,
+ (lstrlenW(uuidStr)+1)*sizeof(WCHAR));
+ pRpcStringFree(&uuidStr);
+ FreeLibrary(lib);
+ }
+ }
+ RegCloseKey(key);
+ }
+}
+
/******************************************************************************
* CryptAcquireContextW (ADVAPI32.@)
*
@@ -309,6 +358,9 @@ BOOL WINAPI CryptAcquireContextW (HCRYPTPROV *phProv, LPCWSTR pszContainer,
return FALSE;
}
+ /* Make sure the MachineGuid value exists */
+ CRYPT_CreateMachineGuid();
+
if (!pszProvider || !*pszProvider)
{
/* No CSP name specified so try the user default CSP first
diff --git a/dlls/advapi32/tests/crypt.c b/dlls/advapi32/tests/crypt.c
index 1832ca1..63163dd 100644
--- a/dlls/advapi32/tests/crypt.c
+++ b/dlls/advapi32/tests/crypt.c
@@ -907,10 +907,8 @@ static void test_machine_guid(void)
/* Check that MachineGuid was created */
size = sizeof(guid);
r = RegQueryValueExA(key, "MachineGuid", NULL, NULL, (BYTE *)guid, &size);
- todo_wine
ok(!r, "expected to find MachineGuid: %d\n", r);
r = RegDeleteValueA(key, "MachineGuid");
- todo_wine
ok(!r, "RegDeleteValueA failed: %d\n", r);
if (restoreGuid)
RegSetValueExA(key, "MachineGuid", 0, REG_SZ, (const BYTE *)originalGuid,
More information about the wine-cvs
mailing list