[Libreoffice-commits] core.git: sal/osl sal/qa

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Aug 29 06:40:26 UTC 2018


 sal/osl/w32/security.cxx             |   58 +++++++----------------------------
 sal/qa/osl/security/osl_Security.cxx |   52 +++----------------------------
 2 files changed, 19 insertions(+), 91 deletions(-)

New commits:
commit d8d310dcac8ddfdb16756cc863552ef788cfc393
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Tue Aug 28 23:22:29 2018 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Wed Aug 29 08:40:01 2018 +0200

    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 at collabora.com>

diff --git a/sal/osl/w32/security.cxx b/sal/osl/w32/security.cxx
index 8192dbbb6ded..c70ad92f2931 100644
--- a/sal/osl/w32/security.cxx
+++ b/sal/osl/w32/security.cxx
@@ -24,7 +24,9 @@
 #include <osl/thread.h>
 #include <osl/file.h>
 #include <systools/win32/uwinapi.h>
+#include <sddl.h>
 #include <sal/macros.h>
+#include <sal/log.hxx>
 #include <o3tl/char16_t2wchar_t.hxx>
 #include "secimpl.hxx"
 
@@ -305,60 +307,26 @@ sal_Bool SAL_CALL osl_getUserIdent(oslSecurity Security, rtl_uString **strIdent)
             if (pInfoBuffer)
             {
                 PSID pSid = reinterpret_cast<PTOKEN_USER>(pInfoBuffer)->User.Sid;
-                PSID_IDENTIFIER_AUTHORITY psia;
-                DWORD dwSubAuthorities;
-                DWORD dwCounter;
-                DWORD dwSidSize;
-                PUCHAR pSSACount;
 
-                /* obtain SidIdentifierAuthority */
-                psia=GetSidIdentifierAuthority(pSid);
-
-                /* 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))
+                LPWSTR pSidStr = nullptr;
+                BOOL bResult = ConvertSidToStringSidW(pSid, &pSidStr);
+                if (bResult)
                 {
-                    dwSidSize+=wsprintfW(o3tl::toW(Ident) + wcslen(o3tl::toW(Ident)),
-                                L"0x%02hx%02hx%02hx%02hx%02hx%02hx",
-                                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]));
+                    rtl_uString_newFromStr(strIdent, o3tl::toU(pSidStr));
+                    LocalFree(pSidStr);
                 }
                 else
                 {
-                    dwSidSize+=wsprintfW(o3tl::toW(Ident) + wcslen(o3tl::toW(Ident)),
-                                L"%lu",
-                                static_cast<ULONG>(psia->Value[5]      )   +
-                                static_cast<ULONG>(psia->Value[4] <<  8)   +
-                                static_cast<ULONG>(psia->Value[3] << 16)   +
-                                static_cast<ULONG>(psia->Value[2] << 24)   );
+                    const DWORD dwError = GetLastError();
+                    char sBuf[100];
+                    sprintf(sBuf, "ConvertSidToStringSidW failed. GetLastError returned: %d",
+                            dwError);
+                    SAL_WARN("sal.osl", sBuf);
                 }
 
-                /* 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(Ident);
 
-                return true;
+                return bResult;
             }
         }
         else
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;
 


More information about the Libreoffice-commits mailing list