mirror of
https://github.com/reactos/reactos.git
synced 2024-09-15 23:28:15 +00:00
[ADVAPI32]
Use LSA functions to query the account domain SID. svn path=/trunk/; revision=56581
This commit is contained in:
parent
be92b4851b
commit
319e0c17df
|
@ -307,75 +307,59 @@ SamGetUserSid(LPCWSTR UserName,
|
||||||
|
|
||||||
|
|
||||||
static BOOL WINAPI
|
static BOOL WINAPI
|
||||||
SamGetDomainSid(PSID *Sid)
|
GetDomainSid(PSID *Sid)
|
||||||
{
|
{
|
||||||
|
PPOLICY_ACCOUNT_DOMAIN_INFO Info = NULL;
|
||||||
|
LSA_OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
|
LSA_HANDLE PolicyHandle;
|
||||||
PSID lpSid;
|
PSID lpSid;
|
||||||
DWORD dwLength;
|
ULONG Length;
|
||||||
HKEY hDomainKey;
|
NTSTATUS Status;
|
||||||
|
|
||||||
TRACE("SamGetDomainSid() called\n");
|
|
||||||
|
|
||||||
if (Sid != NULL)
|
|
||||||
*Sid = NULL;
|
*Sid = NULL;
|
||||||
|
|
||||||
/* Open the account domain key */
|
memset(&ObjectAttributes, 0, sizeof(LSA_OBJECT_ATTRIBUTES));
|
||||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
ObjectAttributes.Length = sizeof(LSA_OBJECT_ATTRIBUTES);
|
||||||
L"SAM\\SAM\\Domains\\Account",
|
|
||||||
0,
|
Status = LsaOpenPolicy(NULL,
|
||||||
KEY_READ,
|
&ObjectAttributes,
|
||||||
&hDomainKey))
|
POLICY_TRUST_ADMIN,
|
||||||
|
&PolicyHandle);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
ERR("Failed to open the account domain key! (Error %lu)\n", GetLastError());
|
ERR("LsaOpenPolicy failed (Status: 0x%08lx)\n", Status);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get SID size */
|
Status = LsaQueryInformationPolicy(PolicyHandle,
|
||||||
dwLength = 0;
|
PolicyAccountDomainInformation,
|
||||||
if (RegQueryValueExW(hDomainKey,
|
(PVOID *)&Info);
|
||||||
L"Sid",
|
if (!NT_SUCCESS(Status))
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
&dwLength))
|
|
||||||
{
|
{
|
||||||
ERR("Failed to read the SID size! (Error %lu)\n", GetLastError());
|
ERR("LsaQueryInformationPolicy failed (Status: 0x%08lx)\n", Status);
|
||||||
RegCloseKey(hDomainKey);
|
LsaClose(PolicyHandle);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate sid buffer */
|
Length = RtlLengthSid(Info->DomainSid);
|
||||||
TRACE("Required SID buffer size: %lu\n", dwLength);
|
|
||||||
lpSid = (PSID)RtlAllocateHeap(RtlGetProcessHeap(),
|
lpSid = RtlAllocateHeap(RtlGetProcessHeap(),
|
||||||
0,
|
0,
|
||||||
dwLength);
|
Length);
|
||||||
if (lpSid == NULL)
|
if (lpSid == NULL)
|
||||||
{
|
{
|
||||||
ERR("Failed to allocate SID buffer!\n");
|
ERR("Failed to allocate SID buffer!\n");
|
||||||
RegCloseKey(hDomainKey);
|
LsaFreeMemory(Info);
|
||||||
|
LsaClose(PolicyHandle);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read sid */
|
memcpy(lpSid, Info->DomainSid, Length);
|
||||||
if (RegQueryValueExW(hDomainKey,
|
|
||||||
L"Sid",
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
(LPBYTE)lpSid,
|
|
||||||
&dwLength))
|
|
||||||
{
|
|
||||||
ERR("Failed to read the SID! (Error %lu)\n", GetLastError());
|
|
||||||
RtlFreeHeap(RtlGetProcessHeap(),
|
|
||||||
0,
|
|
||||||
lpSid);
|
|
||||||
RegCloseKey(hDomainKey);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
RegCloseKey(hDomainKey);
|
|
||||||
|
|
||||||
*Sid = lpSid;
|
*Sid = lpSid;
|
||||||
|
|
||||||
TRACE("SamGetDomainSid() done\n");
|
LsaFreeMemory(Info);
|
||||||
|
LsaClose(PolicyHandle);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -435,7 +419,7 @@ AllocateGroupSids(OUT PSID *PrimaryGroupSid,
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!SamGetDomainSid(&DomainSid))
|
if (!GetDomainSid(&DomainSid))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
TokenGroups = RtlAllocateHeap(
|
TokenGroups = RtlAllocateHeap(
|
||||||
|
|
Loading…
Reference in a new issue