advapi32: Fix ADVAPI_GetComputerSid to work correctly if a sid doesn't exist in the registry.
This makes the tests run correctly on first invocation.
This commit is contained in:
parent
7dbda7a9f5
commit
38d33e33ae
@ -386,6 +386,7 @@ BOOL ADVAPI_GetComputerSid(PSID sid)
|
|||||||
{
|
{
|
||||||
HKEY key;
|
HKEY key;
|
||||||
LONG ret;
|
LONG ret;
|
||||||
|
BOOL retval = FALSE;
|
||||||
static const WCHAR Account[] = { 'S','E','C','U','R','I','T','Y','\\','S','A','M','\\','D','o','m','a','i','n','s','\\','A','c','c','o','u','n','t',0 };
|
static const WCHAR Account[] = { 'S','E','C','U','R','I','T','Y','\\','S','A','M','\\','D','o','m','a','i','n','s','\\','A','c','c','o','u','n','t',0 };
|
||||||
static const WCHAR V[] = { 'V',0 };
|
static const WCHAR V[] = { 'V',0 };
|
||||||
|
|
||||||
@ -404,9 +405,7 @@ BOOL ADVAPI_GetComputerSid(PSID sid)
|
|||||||
{
|
{
|
||||||
/* the SID is in the last 24 bytes of the binary data */
|
/* the SID is in the last 24 bytes of the binary data */
|
||||||
CopyMemory(sid, &data[size-24], 24);
|
CopyMemory(sid, &data[size-24], 24);
|
||||||
HeapFree(GetProcessHeap(), 0, data);
|
retval = TRUE;
|
||||||
RegCloseKey(key);
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
HeapFree(GetProcessHeap(), 0, data);
|
HeapFree(GetProcessHeap(), 0, data);
|
||||||
}
|
}
|
||||||
@ -414,6 +413,8 @@ BOOL ADVAPI_GetComputerSid(PSID sid)
|
|||||||
RegCloseKey(key);
|
RegCloseKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(retval == TRUE) return retval;
|
||||||
|
|
||||||
/* create a new random SID */
|
/* create a new random SID */
|
||||||
if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, Account,
|
if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, Account,
|
||||||
0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL) == ERROR_SUCCESS)
|
0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL) == ERROR_SUCCESS)
|
||||||
@ -427,18 +428,15 @@ BOOL ADVAPI_GetComputerSid(PSID sid)
|
|||||||
if (AllocateAndInitializeSid(&identifierAuthority, 4, SECURITY_NT_NON_UNIQUE, id[0], id[1], id[2], 0, 0, 0, 0, &new_sid))
|
if (AllocateAndInitializeSid(&identifierAuthority, 4, SECURITY_NT_NON_UNIQUE, id[0], id[1], id[2], 0, 0, 0, 0, &new_sid))
|
||||||
{
|
{
|
||||||
if (RegSetValueExW(key, V, 0, REG_BINARY, new_sid, GetLengthSid(new_sid)) == ERROR_SUCCESS)
|
if (RegSetValueExW(key, V, 0, REG_BINARY, new_sid, GetLengthSid(new_sid)) == ERROR_SUCCESS)
|
||||||
{
|
retval = CopySid(GetLengthSid(new_sid), sid, new_sid);
|
||||||
FreeSid(new_sid);
|
|
||||||
RegCloseKey(key);
|
|
||||||
return CopySid(GetLengthSid(new_sid), sid, &new_sid);
|
|
||||||
}
|
|
||||||
FreeSid(new_sid);
|
FreeSid(new_sid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RegCloseKey(key);
|
RegCloseKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ##############################
|
/* ##############################
|
||||||
|
Loading…
x
Reference in New Issue
Block a user