mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 06:43:01 +00:00
[ADVAPI32]
* Update ConvertStringSidToSid{A,W}(). * Fixes some advapi32:security tests. CORE-8540 svn path=/trunk/; revision=65030
This commit is contained in:
parent
68f176a03b
commit
531323417d
1 changed files with 47 additions and 147 deletions
|
@ -279,6 +279,19 @@ static const RECORD SidTable[] =
|
||||||
{ NULL, 0 },
|
{ NULL, 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static LPWSTR SERV_dup( LPCSTR str )
|
||||||
|
{
|
||||||
|
UINT len;
|
||||||
|
LPWSTR wstr;
|
||||||
|
|
||||||
|
if( !str )
|
||||||
|
return NULL;
|
||||||
|
len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
|
||||||
|
wstr = heap_alloc( len*sizeof (WCHAR) );
|
||||||
|
MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, len );
|
||||||
|
return wstr;
|
||||||
|
}
|
||||||
|
|
||||||
/************************************************************
|
/************************************************************
|
||||||
* ADVAPI_IsLocalComputer
|
* ADVAPI_IsLocalComputer
|
||||||
*
|
*
|
||||||
|
@ -3203,162 +3216,49 @@ ConvertSecurityDescriptorToStringSecurityDescriptorA(PSECURITY_DESCRIPTOR Securi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/******************************************************************************
|
||||||
* @implemented
|
* ConvertStringSidToSidW [ADVAPI32.@]
|
||||||
*/
|
*/
|
||||||
BOOL
|
BOOL WINAPI ConvertStringSidToSidW(LPCWSTR StringSid, PSID* Sid)
|
||||||
WINAPI
|
|
||||||
ConvertStringSidToSidW(IN LPCWSTR StringSid,
|
|
||||||
OUT PSID* sid)
|
|
||||||
{
|
{
|
||||||
DWORD size;
|
BOOL bret = FALSE;
|
||||||
DWORD i, cBytes, identAuth, csubauth;
|
DWORD cBytes;
|
||||||
BOOL ret;
|
|
||||||
SID* pisid;
|
|
||||||
|
|
||||||
TRACE("%s %p\n", debugstr_w(StringSid), sid);
|
TRACE("%s, %p\n", debugstr_w(StringSid), Sid);
|
||||||
|
|
||||||
if (!StringSid)
|
|
||||||
{
|
|
||||||
SetLastError(ERROR_INVALID_SID);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < sizeof(SidTable) / sizeof(SidTable[0]) - 1; i++)
|
|
||||||
{
|
|
||||||
if (wcscmp(StringSid, SidTable[i].key) == 0)
|
|
||||||
{
|
|
||||||
WELL_KNOWN_SID_TYPE knownSid = (WELL_KNOWN_SID_TYPE)SidTable[i].value;
|
|
||||||
size = SECURITY_MAX_SID_SIZE;
|
|
||||||
*sid = LocalAlloc(0, size);
|
|
||||||
if (!*sid)
|
|
||||||
{
|
|
||||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
ret = CreateWellKnownSid(knownSid,
|
|
||||||
NULL,
|
|
||||||
*sid,
|
|
||||||
&size);
|
|
||||||
if (!ret)
|
|
||||||
{
|
|
||||||
SetLastError(ERROR_INVALID_SID);
|
|
||||||
LocalFree(*sid);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* That's probably a string S-R-I-S-S... */
|
|
||||||
if (StringSid[0] != 'S' || StringSid[1] != '-')
|
|
||||||
{
|
|
||||||
SetLastError(ERROR_INVALID_SID);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
cBytes = ComputeStringSidSize(StringSid);
|
|
||||||
pisid = (SID*)LocalAlloc( 0, cBytes );
|
|
||||||
if (!pisid)
|
|
||||||
{
|
|
||||||
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
i = 0;
|
|
||||||
ret = FALSE;
|
|
||||||
csubauth = ((cBytes - GetSidLengthRequired(0)) / sizeof(DWORD));
|
|
||||||
|
|
||||||
StringSid += 2; /* Advance to Revision */
|
|
||||||
pisid->Revision = atoiW(StringSid);
|
|
||||||
|
|
||||||
if (pisid->Revision != SDDL_REVISION)
|
|
||||||
{
|
|
||||||
TRACE("Revision %d is unknown\n", pisid->Revision);
|
|
||||||
goto lend; /* ERROR_INVALID_SID */
|
|
||||||
}
|
|
||||||
if (csubauth == 0)
|
|
||||||
{
|
|
||||||
TRACE("SubAuthorityCount is 0\n");
|
|
||||||
goto lend; /* ERROR_INVALID_SID */
|
|
||||||
}
|
|
||||||
|
|
||||||
pisid->SubAuthorityCount = csubauth;
|
|
||||||
|
|
||||||
/* Advance to identifier authority */
|
|
||||||
while (*StringSid && *StringSid != '-')
|
|
||||||
StringSid++;
|
|
||||||
if (*StringSid == '-')
|
|
||||||
StringSid++;
|
|
||||||
|
|
||||||
/* MS' implementation can't handle values greater than 2^32 - 1, so
|
|
||||||
* we don't either; assume most significant bytes are always 0
|
|
||||||
*/
|
|
||||||
pisid->IdentifierAuthority.Value[0] = 0;
|
|
||||||
pisid->IdentifierAuthority.Value[1] = 0;
|
|
||||||
identAuth = atoiW(StringSid);
|
|
||||||
pisid->IdentifierAuthority.Value[5] = identAuth & 0xff;
|
|
||||||
pisid->IdentifierAuthority.Value[4] = (identAuth & 0xff00) >> 8;
|
|
||||||
pisid->IdentifierAuthority.Value[3] = (identAuth & 0xff0000) >> 16;
|
|
||||||
pisid->IdentifierAuthority.Value[2] = (identAuth & 0xff000000) >> 24;
|
|
||||||
|
|
||||||
/* Advance to first sub authority */
|
|
||||||
while (*StringSid && *StringSid != '-')
|
|
||||||
StringSid++;
|
|
||||||
if (*StringSid == '-')
|
|
||||||
StringSid++;
|
|
||||||
|
|
||||||
while (*StringSid)
|
|
||||||
{
|
|
||||||
pisid->SubAuthority[i++] = atoiW(StringSid);
|
|
||||||
|
|
||||||
while (*StringSid && *StringSid != '-')
|
|
||||||
StringSid++;
|
|
||||||
if (*StringSid == '-')
|
|
||||||
StringSid++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i != pisid->SubAuthorityCount)
|
|
||||||
goto lend; /* ERROR_INVALID_SID */
|
|
||||||
|
|
||||||
*sid = pisid;
|
|
||||||
ret = TRUE;
|
|
||||||
|
|
||||||
lend:
|
|
||||||
if (!ret)
|
|
||||||
{
|
|
||||||
LocalFree(pisid);
|
|
||||||
SetLastError(ERROR_INVALID_SID);
|
|
||||||
}
|
|
||||||
|
|
||||||
TRACE("returning %s\n", ret ? "TRUE" : "FALSE");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @implemented
|
|
||||||
*/
|
|
||||||
BOOL
|
|
||||||
WINAPI
|
|
||||||
ConvertStringSidToSidA(IN LPCSTR StringSid,
|
|
||||||
OUT PSID* sid)
|
|
||||||
{
|
|
||||||
BOOL bRetVal = FALSE;
|
|
||||||
|
|
||||||
TRACE("%s, %p\n", debugstr_a(StringSid), sid);
|
|
||||||
if (GetVersion() & 0x80000000)
|
if (GetVersion() & 0x80000000)
|
||||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||||
else if (!StringSid || !sid)
|
else if (!StringSid || !Sid)
|
||||||
|
SetLastError(ERROR_INVALID_PARAMETER);
|
||||||
|
else if (ParseStringSidToSid(StringSid, NULL, &cBytes))
|
||||||
|
{
|
||||||
|
PSID pSid = *Sid = LocalAlloc(0, cBytes);
|
||||||
|
|
||||||
|
bret = ParseStringSidToSid(StringSid, pSid, &cBytes);
|
||||||
|
if (!bret)
|
||||||
|
LocalFree(*Sid);
|
||||||
|
}
|
||||||
|
return bret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* ConvertStringSidToSidA [ADVAPI32.@]
|
||||||
|
*/
|
||||||
|
BOOL WINAPI ConvertStringSidToSidA(LPCSTR StringSid, PSID* Sid)
|
||||||
|
{
|
||||||
|
BOOL bret = FALSE;
|
||||||
|
|
||||||
|
TRACE("%s, %p\n", debugstr_a(StringSid), Sid);
|
||||||
|
if (GetVersion() & 0x80000000)
|
||||||
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||||
|
else if (!StringSid || !Sid)
|
||||||
SetLastError(ERROR_INVALID_PARAMETER);
|
SetLastError(ERROR_INVALID_PARAMETER);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UINT len = MultiByteToWideChar(CP_ACP, 0, StringSid, -1, NULL, 0);
|
WCHAR *wStringSid = SERV_dup(StringSid);
|
||||||
LPWSTR wStringSid = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
bret = ConvertStringSidToSidW(wStringSid, Sid);
|
||||||
if (wStringSid == NULL)
|
heap_free(wStringSid);
|
||||||
return FALSE;
|
|
||||||
MultiByteToWideChar(CP_ACP, 0, StringSid, - 1, wStringSid, len);
|
|
||||||
bRetVal = ConvertStringSidToSidW(wStringSid, sid);
|
|
||||||
HeapFree(GetProcessHeap(), 0, wStringSid);
|
|
||||||
}
|
}
|
||||||
return bRetVal;
|
return bret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue