Kaydet (Commit) d8d310dc authored tarafından Mike Kaganski's avatar Mike Kaganski

Use ConvertSidToStringSidW instead of composing SID string manually

Change-Id: I0dc22130b5dec5eb2250c9625773b6c9720182a9
Reviewed-on: https://gerrit.libreoffice.org/59740
Tested-by: Jenkins
Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst b4c00339
...@@ -24,7 +24,9 @@ ...@@ -24,7 +24,9 @@
#include <osl/thread.h> #include <osl/thread.h>
#include <osl/file.h> #include <osl/file.h>
#include <systools/win32/uwinapi.h> #include <systools/win32/uwinapi.h>
#include <sddl.h>
#include <sal/macros.h> #include <sal/macros.h>
#include <sal/log.hxx>
#include <o3tl/char16_t2wchar_t.hxx> #include <o3tl/char16_t2wchar_t.hxx>
#include "secimpl.hxx" #include "secimpl.hxx"
...@@ -305,60 +307,26 @@ sal_Bool SAL_CALL osl_getUserIdent(oslSecurity Security, rtl_uString **strIdent) ...@@ -305,60 +307,26 @@ sal_Bool SAL_CALL osl_getUserIdent(oslSecurity Security, rtl_uString **strIdent)
if (pInfoBuffer) if (pInfoBuffer)
{ {
PSID pSid = reinterpret_cast<PTOKEN_USER>(pInfoBuffer)->User.Sid; PSID pSid = reinterpret_cast<PTOKEN_USER>(pInfoBuffer)->User.Sid;
PSID_IDENTIFIER_AUTHORITY psia;
DWORD dwSubAuthorities;
DWORD dwCounter;
DWORD dwSidSize;
PUCHAR pSSACount;
/* obtain SidIdentifierAuthority */ LPWSTR pSidStr = nullptr;
psia=GetSidIdentifierAuthority(pSid); BOOL bResult = ConvertSidToStringSidW(pSid, &pSidStr);
if (bResult)
/* obtain sidsubauthority count */
pSSACount = GetSidSubAuthorityCount(pSid);
dwSubAuthorities = (*pSSACount < 5) ? *pSSACount : 5;
/* buffer length: S-SID_REVISION- + identifierauthority- + subauthorities- + NULL */
sal_Unicode *Ident=static_cast<sal_Unicode *>(malloc(88*sizeof(sal_Unicode)));
/* prepare S-SID_REVISION- */
dwSidSize=wsprintfW(o3tl::toW(Ident), L"S-%lu-", SID_REVISION);
/* prepare SidIdentifierAuthority */
if ((psia->Value[0] != 0) || (psia->Value[1] != 0))
{ {
dwSidSize+=wsprintfW(o3tl::toW(Ident) + wcslen(o3tl::toW(Ident)), rtl_uString_newFromStr(strIdent, o3tl::toU(pSidStr));
L"0x%02hx%02hx%02hx%02hx%02hx%02hx", LocalFree(pSidStr);
static_cast<USHORT>(psia->Value[0]),
static_cast<USHORT>(psia->Value[1]),
static_cast<USHORT>(psia->Value[2]),
static_cast<USHORT>(psia->Value[3]),
static_cast<USHORT>(psia->Value[4]),
static_cast<USHORT>(psia->Value[5]));
} }
else else
{ {
dwSidSize+=wsprintfW(o3tl::toW(Ident) + wcslen(o3tl::toW(Ident)), const DWORD dwError = GetLastError();
L"%lu", char sBuf[100];
static_cast<ULONG>(psia->Value[5] ) + sprintf(sBuf, "ConvertSidToStringSidW failed. GetLastError returned: %d",
static_cast<ULONG>(psia->Value[4] << 8) + dwError);
static_cast<ULONG>(psia->Value[3] << 16) + SAL_WARN("sal.osl", sBuf);
static_cast<ULONG>(psia->Value[2] << 24) );
} }
/* loop through SidSubAuthorities */
for (dwCounter=0; dwCounter < dwSubAuthorities; dwCounter++)
{
dwSidSize+=wsprintfW(o3tl::toW(Ident) + dwSidSize, L"-%lu",
*GetSidSubAuthority(pSid, dwCounter) );
}
rtl_uString_newFromStr( strIdent, Ident );
free(pInfoBuffer); free(pInfoBuffer);
free(Ident);
return true; return bResult;
} }
} }
else else
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
# define WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN
#endif #endif
#include <windows.h> #include <windows.h>
#include <sddl.h>
#undef min #undef min
#endif #endif
#include "osl_Security_Const.h" #include "osl_Security_Const.h"
...@@ -477,58 +478,17 @@ void MyTestPlugInImpl::initialize( CPPUNIT_NS::TestFactoryRegistry *, ...@@ -477,58 +478,17 @@ void MyTestPlugInImpl::initialize( CPPUNIT_NS::TestFactoryRegistry *,
} }
} }
// now got SID successfully, only need to compare SID, so I copied the rest lines from source to convert SID to OUString. LPWSTR pSidStr = nullptr;
PSID_IDENTIFIER_AUTHORITY psia; if (ConvertSidToStringSidW(pSid, &pSidStr))
DWORD dwSubAuthorities;
DWORD dwSidRev=SID_REVISION;
DWORD dwCounter;
DWORD dwSidSize;
wchar_t *Ident;
/* obtain SidIdentifierAuthority */
psia=GetSidIdentifierAuthority(pSid);
/* obtain sidsubauthority count */
dwSubAuthorities=std::min(static_cast<int>(*GetSidSubAuthorityCount(pSid)), 5);
/* buffer length: S-SID_REVISION- + identifierauthority- + subauthorities- + NULL */
Ident=static_cast<wchar_t *>(malloc(88*sizeof(wchar_t)));
/* prepare S-SID_REVISION- */
dwSidSize=wsprintfW(Ident, L"S-%lu-", dwSidRev);
/* prepare SidIdentifierAuthority */
if ((psia->Value[0] != 0) || (psia->Value[1] != 0))
{ {
dwSidSize+=wsprintfW(Ident + wcslen(Ident), strUserID = o3tl::toU(pSidStr);
L"0x%02hx%02hx%02hx%02hx%02hx%02hx", LocalFree(pSidStr);
static_cast<sal_uInt16>(psia->Value[0]),
static_cast<sal_uInt16>(psia->Value[1]),
static_cast<sal_uInt16>(psia->Value[2]),
static_cast<sal_uInt16>(psia->Value[3]),
static_cast<sal_uInt16>(psia->Value[4]),
static_cast<sal_uInt16>(psia->Value[5]));
} }
else else
{ {
dwSidSize+=wsprintfW(Ident + wcslen(Ident), wprintf(L"# ConvertSidToStringSidW failed. GetLastError returned: %d\n", GetLastError());
L"%lu",
static_cast<sal_uInt32>(psia->Value[5] ) +
static_cast<sal_uInt32>(psia->Value[4] << 8) +
static_cast<sal_uInt32>(psia->Value[3] << 16) +
static_cast<sal_uInt32>(psia->Value[2] << 24) );
} }
/* loop through SidSubAuthorities */
for (dwCounter=0; dwCounter < dwSubAuthorities; dwCounter++)
{
dwSidSize+=wsprintfW(Ident + dwSidSize, L"-%lu",
*GetSidSubAuthority(pSid, dwCounter) );
}
strUserID = o3tl::toU(Ident);
free(Ident);
delete [] static_cast<BYTE*>(pSid); delete [] static_cast<BYTE*>(pSid);
delete [] wszDomainName; delete [] wszDomainName;
......
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