Commit 9d435046 authored by Robert Reif's avatar Robert Reif Committed by Alexandre Julliard

advapi32: Add more helper functions.

Add ADVAPI_GetComputerSid.
parent e10f5b1d
......@@ -22,5 +22,6 @@
const char * debugstr_sid(PSID sid);
BOOL ADVAPI_IsLocalComputer(LPCWSTR ServerName);
BOOL ADVAPI_GetComputerSid(PSID sid);
#endif /* __WINE_ADVAPI32MISC_H */
......@@ -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 ######
##############################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment