From 362a21d3a129b90149f6ef645c127f5e86e0ba61 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Tue, 26 Sep 2017 11:28:57 +0300 Subject: Use explicit function names for fooA/fooW WinAPI; prefer fooW We should only use generic foo function name when it takes params that are also dependent on UNICODE define, like LoadCursor( nullptr, IDC_ARROW ) where IDC_ARROW is defined in MSVC headers synchronised with LoadCursor definition. We should always use Unicode API for any file paths operations, because otherwise we will get "?" for any character in path that is not in current non-unicode codepage, which will result in failed file operations. Change-Id: I3a7f453ca0f893002d8a9764318919709fd8b633 Reviewed-on: https://gerrit.libreoffice.org/42935 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- sal/osl/w32/security.cxx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'sal') diff --git a/sal/osl/w32/security.cxx b/sal/osl/w32/security.cxx index 02f9c02e82b6..b25e3076af70 100644 --- a/sal/osl/w32/security.cxx +++ b/sal/osl/w32/security.cxx @@ -66,7 +66,9 @@ typedef BOOL (STDMETHODCALLTYPE FAR * LPFNGETUSERPROFILEDIR) ( #define TOKEN_DUP_QUERY (TOKEN_QUERY|TOKEN_DUPLICATE) static bool GetSpecialFolder(rtl_uString **strPath,int nFolder); -static BOOL Privilege(LPCWSTR pszPrivilege, BOOL bEnable); +// We use LPCTSTR here, because we use it with SE_foo_NAME constants +// which are defined in winnt.h as UNICODE-dependent TEXT("PrivilegeName") +static BOOL Privilege(LPCTSTR pszPrivilege, BOOL bEnable); static bool SAL_CALL getUserNameImpl(oslSecurity Security, rtl_uString **strName, bool bIncludeDomain); oslSecurity SAL_CALL osl_getCurrentSecurity(void) @@ -99,7 +101,7 @@ oslSecurityError SAL_CALL osl_loginUser( rtl_uString *strUserName, rtl_uString * } // this process must have the right: 'act as a part of operatingsystem' - OSL_ASSERT(LookupPrivilegeValueW(nullptr, L"SeTcbPrivilege", &luid)); + 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)), @@ -510,7 +512,7 @@ sal_Bool SAL_CALL osl_loadUserProfile(oslSecurity Security) RegCloseKey(HKEY_CURRENT_USER); - if (Privilege(L"SeRestorePrivilege", TRUE)) + if (Privilege(SE_RESTORE_NAME, TRUE)) { HMODULE hUserEnvLib = nullptr; LPFNLOADUSERPROFILE fLoadUserProfile = nullptr; @@ -712,7 +714,9 @@ static bool GetSpecialFolder(rtl_uString **strPath, int nFolder) return bRet; } -static BOOL Privilege(LPCWSTR strPrivilege, BOOL bEnable) +// We use LPCTSTR here, because we use it with SE_foo_NAME constants +// which are defined in winnt.h as UNICODE-dependent TEXT("PrivilegeName") +static BOOL Privilege(LPCTSTR strPrivilege, BOOL bEnable) { HANDLE hToken; TOKEN_PRIVILEGES tp; @@ -722,7 +726,7 @@ static BOOL Privilege(LPCWSTR strPrivilege, BOOL bEnable) return FALSE; // get the luid - if (!LookupPrivilegeValueW(nullptr, strPrivilege, &tp.Privileges[0].Luid)) + if (!LookupPrivilegeValue(nullptr, strPrivilege, &tp.Privileges[0].Luid)) return FALSE; tp.PrivilegeCount = 1; -- cgit