diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2018-08-28 23:22:29 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2018-08-29 08:40:01 +0200 |
commit | d8d310dcac8ddfdb16756cc863552ef788cfc393 (patch) | |
tree | c0411b4a651b2e146aa414c72cfca19e6a7693d7 /sal/qa | |
parent | b4c003397eb29beff055044091c1d088acda2bae (diff) |
Use ConvertSidToStringSidW instead of composing SID string manually
Change-Id: I0dc22130b5dec5eb2250c9625773b6c9720182a9
Reviewed-on: https://gerrit.libreoffice.org/59740
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sal/qa')
-rw-r--r-- | sal/qa/osl/security/osl_Security.cxx | 52 |
1 files changed, 6 insertions, 46 deletions
diff --git a/sal/qa/osl/security/osl_Security.cxx b/sal/qa/osl/security/osl_Security.cxx index 5c24b8260c4c..a1dff025ce70 100644 --- a/sal/qa/osl/security/osl_Security.cxx +++ b/sal/qa/osl/security/osl_Security.cxx @@ -23,6 +23,7 @@ # define WIN32_LEAN_AND_MEAN #endif #include <windows.h> +#include <sddl.h> #undef min #endif #include "osl_Security_Const.h" @@ -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. - PSID_IDENTIFIER_AUTHORITY psia; - 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)) + LPWSTR pSidStr = nullptr; + if (ConvertSidToStringSidW(pSid, &pSidStr)) { - dwSidSize+=wsprintfW(Ident + wcslen(Ident), - L"0x%02hx%02hx%02hx%02hx%02hx%02hx", - 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])); + strUserID = o3tl::toU(pSidStr); + LocalFree(pSidStr); } else { - dwSidSize+=wsprintfW(Ident + wcslen(Ident), - 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) ); + wprintf(L"# ConvertSidToStringSidW failed. GetLastError returned: %d\n", GetLastError()); } - /* 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 [] wszDomainName; |