diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2017-10-05 06:19:56 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2017-10-05 16:02:52 +0200 |
commit | 1944e3ddc0b2247de3138d2a441cd6999e21fd9a (patch) | |
tree | b59f213e245e151ee792ca424fd06b5a11c88857 /sal/osl/w32/security.cxx | |
parent | 81d404803f477eb71b74eb9c7a67bba6b1af95d1 (diff) |
Rename and move SAL_U/W to o3tl::toU/W
Previosly (since commit 9ac98e6e3488e434bf4864ecfb13a121784f640b)
it was expected to gradually remove SAL_U/W usage in Windows code
by replacing with reinterpret_cast or changing to some bettertypes.
But as it's useful to make use of fact that LibreOffice and Windows
use compatible representation of strings, this commit puts these
functions to a better-suited o3tl, and recommends that the functions
be consistently used throughout Windows-specific code to reflect the
compatibility and keep the casts safe.
Change-Id: I2f7c65606d0e2d0c01a00f08812bb4ab7659c5f6
Reviewed-on: https://gerrit.libreoffice.org/43150
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sal/osl/w32/security.cxx')
-rw-r--r-- | sal/osl/w32/security.cxx | 77 |
1 files changed, 39 insertions, 38 deletions
diff --git a/sal/osl/w32/security.cxx b/sal/osl/w32/security.cxx index b25e3076af70..120b5c98258d 100644 --- a/sal/osl/w32/security.cxx +++ b/sal/osl/w32/security.cxx @@ -25,6 +25,7 @@ #include <osl/file.h> #include <systools/win32/uwinapi.h> #include <sal/macros.h> +#include <o3tl/char16_t2wchar_t.hxx> #include "secimpl.hxx" /* Data for use in (un)LoadProfile Functions */ @@ -88,11 +89,11 @@ oslSecurityError SAL_CALL osl_loginUser( rtl_uString *strUserName, rtl_uString * oslSecurityError ret; sal_Unicode* strUser; - sal_Unicode* strDomain = SAL_U(_wcsdup(SAL_W(rtl_uString_getStr(strUserName)))); + sal_Unicode* strDomain = o3tl::toU(_wcsdup(o3tl::toW(rtl_uString_getStr(strUserName)))); HANDLE hUserToken; LUID luid; - if (nullptr != (strUser = SAL_U(wcschr(SAL_W(strDomain), L'/')))) + if (nullptr != (strUser = o3tl::toU(wcschr(o3tl::toW(strDomain), L'/')))) *strUser++ = L'\0'; else { @@ -104,7 +105,7 @@ oslSecurityError SAL_CALL osl_loginUser( rtl_uString *strUserName, rtl_uString * OSL_ASSERT(LookupPrivilegeValue(nullptr, SE_TCB_NAME, &luid)); (void) luid; - if (LogonUserW(SAL_W(strUser), strDomain ? SAL_W(strDomain) : L"", SAL_W(rtl_uString_getStr(strPasswd)), + if (LogonUserW(o3tl::toW(strUser), strDomain ? o3tl::toW(strDomain) : L"", o3tl::toW(rtl_uString_getStr(strPasswd)), LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &hUserToken)) { @@ -113,7 +114,7 @@ oslSecurityError SAL_CALL osl_loginUser( rtl_uString *strUserName, rtl_uString * pSecImpl->m_pNetResource = nullptr; pSecImpl->m_hToken = hUserToken; pSecImpl->m_hProfile = nullptr; - wcscpy(SAL_W(pSecImpl->m_User), SAL_W(strUser)); + wcscpy(o3tl::toW(pSecImpl->m_User), o3tl::toW(strUser)); *pSecurity = pSecImpl; ret = osl_Security_E_None; @@ -145,25 +146,25 @@ oslSecurityError SAL_CALL osl_loginUserOnFileServer(rtl_uString *strUserName, remoteName = static_cast<sal_Unicode *>(malloc((rtl_uString_getLength(strFileServer) + rtl_uString_getLength(strUserName) + 4) * sizeof(sal_Unicode))); userName = static_cast<sal_Unicode *>(malloc((rtl_uString_getLength(strFileServer) + rtl_uString_getLength(strUserName) + 2) * sizeof(sal_Unicode))); - wcscpy(SAL_W(remoteName), L"\\\\"); - wcscat(SAL_W(remoteName), SAL_W(rtl_uString_getStr(strFileServer))); - wcscat(SAL_W(remoteName), L"\\"); - wcscat(SAL_W(remoteName), SAL_W(rtl_uString_getStr(strUserName))); + wcscpy(o3tl::toW(remoteName), L"\\\\"); + wcscat(o3tl::toW(remoteName), o3tl::toW(rtl_uString_getStr(strFileServer))); + wcscat(o3tl::toW(remoteName), L"\\"); + wcscat(o3tl::toW(remoteName), o3tl::toW(rtl_uString_getStr(strUserName))); - wcscpy(SAL_W(userName), SAL_W(rtl_uString_getStr(strFileServer))); - wcscat(SAL_W(userName), L"\\"); - wcscat(SAL_W(userName), SAL_W(rtl_uString_getStr(strUserName))); + wcscpy(o3tl::toW(userName), o3tl::toW(rtl_uString_getStr(strFileServer))); + wcscat(o3tl::toW(userName), L"\\"); + wcscat(o3tl::toW(userName), o3tl::toW(rtl_uString_getStr(strUserName))); netResource.dwScope = RESOURCE_GLOBALNET; netResource.dwType = RESOURCETYPE_DISK; netResource.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE; netResource.dwUsage = RESOURCEUSAGE_CONNECTABLE; netResource.lpLocalName = nullptr; - netResource.lpRemoteName = SAL_W(remoteName); + netResource.lpRemoteName = o3tl::toW(remoteName); netResource.lpComment = nullptr; netResource.lpProvider = nullptr; - err = WNetAddConnection2W(&netResource, SAL_W(rtl_uString_getStr(strPasswd)), SAL_W(userName), 0); + err = WNetAddConnection2W(&netResource, o3tl::toW(rtl_uString_getStr(strPasswd)), o3tl::toW(userName), 0); if ((err == NO_ERROR) || (err == ERROR_ALREADY_ASSIGNED)) { @@ -174,7 +175,7 @@ oslSecurityError SAL_CALL osl_loginUserOnFileServer(rtl_uString *strUserName, pSecImpl->m_hToken = nullptr; pSecImpl->m_hProfile = nullptr; - wcscpy(SAL_W(pSecImpl->m_User), SAL_W(rtl_uString_getStr(strUserName))); + wcscpy(o3tl::toW(pSecImpl->m_User), o3tl::toW(rtl_uString_getStr(strUserName))); *pSecurity = pSecImpl; @@ -346,12 +347,12 @@ sal_Bool SAL_CALL osl_getUserIdent(oslSecurity Security, rtl_uString **strIdent) sal_Unicode *Ident=static_cast<sal_Unicode *>(malloc(88*sizeof(sal_Unicode))); /* prepare S-SID_REVISION- */ - dwSidSize=wsprintfW(SAL_W(Ident), L"S-%lu-", 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(SAL_W(Ident) + wcslen(SAL_W(Ident)), + dwSidSize+=wsprintfW(o3tl::toW(Ident) + wcslen(o3tl::toW(Ident)), L"0x%02hx%02hx%02hx%02hx%02hx%02hx", (USHORT)psia->Value[0], (USHORT)psia->Value[1], @@ -362,7 +363,7 @@ sal_Bool SAL_CALL osl_getUserIdent(oslSecurity Security, rtl_uString **strIdent) } else { - dwSidSize+=wsprintfW(SAL_W(Ident) + wcslen(SAL_W(Ident)), + dwSidSize+=wsprintfW(o3tl::toW(Ident) + wcslen(o3tl::toW(Ident)), L"%lu", (ULONG)(psia->Value[5] ) + (ULONG)(psia->Value[4] << 8) + @@ -373,7 +374,7 @@ sal_Bool SAL_CALL osl_getUserIdent(oslSecurity Security, rtl_uString **strIdent) /* loop through SidSubAuthorities */ for (dwCounter=0; dwCounter < dwSubAuthorities; dwCounter++) { - dwSidSize+=wsprintfW(SAL_W(Ident) + dwSidSize, L"-%lu", + dwSidSize+=wsprintfW(o3tl::toW(Ident) + dwSidSize, L"-%lu", *GetSidSubAuthority(pSid, dwCounter) ); } @@ -396,9 +397,9 @@ sal_Bool SAL_CALL osl_getUserIdent(oslSecurity Security, rtl_uString **strIdent) Ident = static_cast<sal_Unicode *>(malloc(needed*sizeof(sal_Unicode))); - if (WNetGetUserW(nullptr, SAL_W(Ident), &needed) != NO_ERROR) + if (WNetGetUserW(nullptr, o3tl::toW(Ident), &needed) != NO_ERROR) { - wcscpy(SAL_W(Ident), L"unknown"); + wcscpy(o3tl::toW(Ident), L"unknown"); Ident[7] = L'\0'; } @@ -434,7 +435,7 @@ sal_Bool SAL_CALL osl_getHomeDir(oslSecurity Security, rtl_uString **pustrDirect if (pSecImpl->m_pNetResource != nullptr) { - rtl_uString_newFromStr( &ustrSysDir, SAL_U(pSecImpl->m_pNetResource->lpRemoteName)); + rtl_uString_newFromStr( &ustrSysDir, o3tl::toU(pSecImpl->m_pNetResource->lpRemoteName)); bSuccess = osl_File_E_None == osl_getFileURLFromSystemPath( ustrSysDir, pustrDirectory ); } @@ -463,7 +464,7 @@ sal_Bool SAL_CALL osl_getConfigDir(oslSecurity Security, rtl_uString **pustrDire { rtl_uString *ustrSysDir = nullptr; - rtl_uString_newFromStr( &ustrSysDir, SAL_U(pSecImpl->m_pNetResource->lpRemoteName)); + rtl_uString_newFromStr( &ustrSysDir, o3tl::toU(pSecImpl->m_pNetResource->lpRemoteName)); bSuccess = osl_File_E_None == osl_getFileURLFromSystemPath( ustrSysDir, pustrDirectory); if ( ustrSysDir ) @@ -483,7 +484,7 @@ sal_Bool SAL_CALL osl_getConfigDir(oslSecurity Security, rtl_uString **pustrDire if ( !GetSpecialFolder( &ustrFile, CSIDL_APPDATA) ) { - OSL_VERIFY(GetWindowsDirectoryW(SAL_W(sFile), _MAX_DIR) > 0); + OSL_VERIFY(GetWindowsDirectoryW(o3tl::toW(sFile), _MAX_DIR) > 0); rtl_uString_newFromStr( &ustrFile, sFile); } @@ -549,7 +550,7 @@ sal_Bool SAL_CALL osl_loadUserProfile(oslSecurity Security) ZeroMemory(&pi, sizeof(pi)); pi.dwSize = sizeof(pi); - pi.lpUserName = SAL_W(rtl_uString_getStr(buffer)); + pi.lpUserName = o3tl::toW(rtl_uString_getStr(buffer)); pi.dwFlags = PI_NOUI; if (fLoadUserProfile(hAccessToken, &pi)) @@ -627,7 +628,7 @@ static bool GetSpecialFolder(rtl_uString **strPath, int nFolder) if (pSHGetSpecialFolderPathW) { - if (pSHGetSpecialFolderPathW(GetActiveWindow(), SAL_W(PathW), nFolder, TRUE)) + if (pSHGetSpecialFolderPathW(GetActiveWindow(), o3tl::toW(PathW), nFolder, TRUE)) { rtl_uString_newFromStr( strPath, PathW); bRet = true; @@ -677,8 +678,8 @@ static bool GetSpecialFolder(rtl_uString **strPath, int nFolder) if ((lRet == ERROR_SUCCESS) && (Type == REG_SZ)) { - if (_waccess(SAL_W(PathW), 0) < 0) - CreateDirectoryW(SAL_W(PathW), nullptr); + if (_waccess(o3tl::toW(PathW), 0) < 0) + CreateDirectoryW(o3tl::toW(PathW), nullptr); hr = pSHGetSpecialFolderLocation(GetActiveWindow(), nFolder, &pidl); } @@ -689,11 +690,11 @@ static bool GetSpecialFolder(rtl_uString **strPath, int nFolder) if (SUCCEEDED(hr)) { - if (pSHGetPathFromIDListW(pidl, SAL_W(PathW))) + if (pSHGetPathFromIDListW(pidl, o3tl::toW(PathW))) { /* if directory does not exist, create it */ - if (_waccess(SAL_W(PathW), 0) < 0) - CreateDirectoryW(SAL_W(PathW), nullptr); + if (_waccess(o3tl::toW(PathW), 0) < 0) + CreateDirectoryW(o3tl::toW(PathW), nullptr); rtl_uString_newFromStr( strPath, PathW); bRet = true; @@ -790,18 +791,18 @@ static bool SAL_CALL getUserNameImpl(oslSecurity Security, rtl_uString **strName SID_NAME_USE sUse; if (LookupAccountSidW(nullptr, reinterpret_cast<PTOKEN_USER>(pInfoBuffer)->User.Sid, - SAL_W(UserName), &nUserName, - SAL_W(DomainName), &nDomainName, &sUse)) + o3tl::toW(UserName), &nUserName, + o3tl::toW(DomainName), &nDomainName, &sUse)) { if (bIncludeDomain) { - wcscpy(SAL_W(Name), SAL_W(DomainName)); - wcscat(SAL_W(Name), L"/"); - wcscat(SAL_W(Name), SAL_W(UserName)); + wcscpy(o3tl::toW(Name), o3tl::toW(DomainName)); + wcscat(o3tl::toW(Name), L"/"); + wcscat(o3tl::toW(Name), o3tl::toW(UserName)); } else { - wcscpy(SAL_W(Name), SAL_W(UserName)); + wcscpy(o3tl::toW(Name), o3tl::toW(UserName)); } } @@ -820,7 +821,7 @@ static bool SAL_CALL getUserNameImpl(oslSecurity Security, rtl_uString **strName WNetGetUserW(nullptr, nullptr, &needed); pNameW = static_cast<sal_Unicode *>(malloc (needed*sizeof(sal_Unicode))); - if (WNetGetUserW(nullptr, SAL_W(pNameW), &needed) == NO_ERROR) + if (WNetGetUserW(nullptr, o3tl::toW(pNameW), &needed) == NO_ERROR) { rtl_uString_newFromStr( strName, pNameW); @@ -830,7 +831,7 @@ static bool SAL_CALL getUserNameImpl(oslSecurity Security, rtl_uString **strName } else if (pSecImpl->m_User[0] != '\0') { - rtl_uString_newFromStr(strName, SAL_U(pSecImpl->m_pNetResource->lpRemoteName)); + rtl_uString_newFromStr(strName, o3tl::toU(pSecImpl->m_pNetResource->lpRemoteName)); if (pNameW) free(pNameW); |