From 9d435046550dd44801784f96cb3a9ee94c112e7c Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Mon, 31 Jul 2006 06:59:43 -0400 Subject: [PATCH] advapi32: Add more helper functions. Add ADVAPI_GetComputerSid. --- dlls/advapi32/advapi32_misc.h | 1 + dlls/advapi32/security.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/dlls/advapi32/advapi32_misc.h b/dlls/advapi32/advapi32_misc.h index 436c0fe46fc..35f806e538f 100644 --- a/dlls/advapi32/advapi32_misc.h +++ b/dlls/advapi32/advapi32_misc.h @@ -22,5 +22,6 @@ const char * debugstr_sid(PSID sid); BOOL ADVAPI_IsLocalComputer(LPCWSTR ServerName); +BOOL ADVAPI_GetComputerSid(PSID sid); #endif /* __WINE_ADVAPI32MISC_H */ diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c index d2a5d810e37..3ff208122d8 100644 --- a/dlls/advapi32/security.c +++ b/dlls/advapi32/security.c @@ -342,6 +342,43 @@ BOOL ADVAPI_IsLocalComputer(LPCWSTR ServerName) return Result; } +/************************************************************ + * ADVAPI_GetComputerSid + * + * Reads the computer SID from the registry. + */ +BOOL ADVAPI_GetComputerSid(PSID sid) +{ + HKEY key; + LONG ret; + + if ((ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, + "SECURITY\\SAM\\Domains\\Account", 0, + KEY_READ, &key)) == ERROR_SUCCESS) + { + static const WCHAR V[] = { 'V',0 }; + DWORD size = 0; + ret = RegQueryValueExW(key, V, NULL, NULL, NULL, &size); + if (ret == ERROR_MORE_DATA || ret == ERROR_SUCCESS) + { + BYTE * data = HeapAlloc(GetProcessHeap(), 0, size); + if (data) + { + if ((ret = RegQueryValueExW(key, V, NULL, NULL, + data, &size)) == ERROR_SUCCESS) + { + /* the SID is in the last 24 bytes of the binary data */ + CopyMemory(sid, &data[size-24], 24); + return TRUE; + } + } + } + RegCloseKey(key); + } + + return FALSE; +} + /* ############################## ###### TOKEN FUNCTIONS ###### ############################## -- 2.11.4.GIT