[Libreoffice-commits] .: 4 commits - sal/osl
Tor Lillqvist
tml at kemper.freedesktop.org
Sun Jan 23 16:47:27 PST 2011
sal/osl/w32/MAKEFILE.MK | 1
sal/osl/w32/file.cxx | 7 -
sal/osl/w32/mutex.c | 109 ++--------------------------
sal/osl/w32/security.c | 183 +++++++++++++++++-------------------------------
4 files changed, 78 insertions(+), 222 deletions(-)
New commits:
commit cdc878578a15aa9bd439507763535879ff5ef02c
Author: Tor Lillqvist <tlillqvist at novell.com>
Date: Mon Jan 24 02:37:27 2011 +0200
Kill Win9x code in file.cxx
diff --git a/sal/osl/w32/file.cxx b/sal/osl/w32/file.cxx
index 1a30f12..1bb6764 100644
--- a/sal/osl/w32/file.cxx
+++ b/sal/osl/w32/file.cxx
@@ -827,13 +827,6 @@ SAL_CALL osl_mapFile(
return osl_File_E_OVERFLOW;
SIZE_T const nLength = sal::static_int_cast< SIZE_T >(uLength);
- OSVERSIONINFO osinfo;
- osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- (void)::GetVersionEx(&osinfo);
-
- if (VER_PLATFORM_WIN32_NT != osinfo.dwPlatformId)
- return osl_File_E_NOSYS; // Unsupported
-
FileMapping aMap( ::CreateFileMapping (pImpl->m_hFile, NULL, SEC_COMMIT | PAGE_READONLY, 0, 0, NULL) );
if (!IsValidHandle(aMap.m_handle))
return oslTranslateFileError( GetLastError() );
commit dc7e4b58fda7f9a70934d70538fbc7c46dbc871c
Author: Tor Lillqvist <tlillqvist at novell.com>
Date: Mon Jan 24 02:34:47 2011 +0200
Kill Win9x security code
diff --git a/sal/osl/w32/security.c b/sal/osl/w32/security.c
index 7d339ba..1f1e188 100644
--- a/sal/osl/w32/security.c
+++ b/sal/osl/w32/security.c
@@ -85,7 +85,6 @@ typedef BOOL (STDMETHODCALLTYPE FAR * LPFNGETUSERPROFILEDIR) (
/* Static Module Function Declarations */
/*****************************************************************************/
-static sal_Bool isWNT(void);
static sal_Bool GetSpecialFolder(rtl_uString **strPath,int nFolder);
static BOOL Privilege(LPTSTR pszPrivilege, BOOL bEnable);
static sal_Bool SAL_CALL getUserNameImpl(oslSecurity Security, rtl_uString **strName, sal_Bool bIncludeDomain);
@@ -110,54 +109,46 @@ oslSecurityError SAL_CALL osl_loginUser( rtl_uString *strUserName, rtl_uString *
{
oslSecurityError ret;
- if (!isWNT())
- {
- *pSecurity = osl_getCurrentSecurity();
- ret = osl_Security_E_None;
- }
+ sal_Unicode* strUser;
+ sal_Unicode* strDomain = _wcsdup(rtl_uString_getStr(strUserName));
+ HANDLE hUserToken;
+
+ #if OSL_DEBUG_LEVEL > 0
+ LUID luid;
+ #endif
+
+ if (NULL != (strUser = wcschr(strDomain, L'/')))
+ *strUser++ = L'\0';
else
{
- sal_Unicode* strUser;
- sal_Unicode* strDomain = _wcsdup(rtl_uString_getStr(strUserName));
- HANDLE hUserToken;
-
- #if OSL_DEBUG_LEVEL > 0
- LUID luid;
- #endif
-
- if (NULL != (strUser = wcschr(strDomain, L'/')))
- *strUser++ = L'\0';
- else
- {
- strUser = strDomain;
- strDomain = NULL;
- }
-
- // this process must have the right: 'act as a part of operatingsystem'
- OSL_ASSERT(LookupPrivilegeValue(NULL, SE_TCB_NAME, &luid));
+ strUser = strDomain;
+ strDomain = NULL;
+ }
- if (LogonUserW(strUser, strDomain ? strDomain : L"", rtl_uString_getStr(strPasswd),
- LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT,
- &hUserToken))
- {
- oslSecurityImpl* pSecImpl = malloc(sizeof(oslSecurityImpl));
+ // this process must have the right: 'act as a part of operatingsystem'
+ OSL_ASSERT(LookupPrivilegeValue(NULL, SE_TCB_NAME, &luid));
- pSecImpl->m_pNetResource = NULL;
- pSecImpl->m_hToken = hUserToken;
- pSecImpl->m_hProfile = NULL;
- wcscpy(pSecImpl->m_User, strUser);
+ if (LogonUserW(strUser, strDomain ? strDomain : L"", rtl_uString_getStr(strPasswd),
+ LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT,
+ &hUserToken))
+ {
+ oslSecurityImpl* pSecImpl = malloc(sizeof(oslSecurityImpl));
- *pSecurity = (oslSecurity)pSecImpl;
- ret = osl_Security_E_None;
- }
- else
- ret = osl_Security_E_UserUnknown;
+ pSecImpl->m_pNetResource = NULL;
+ pSecImpl->m_hToken = hUserToken;
+ pSecImpl->m_hProfile = NULL;
+ wcscpy(pSecImpl->m_User, strUser);
- if (strDomain)
- free(strDomain);
- else
- free(strUser);
+ *pSecurity = (oslSecurity)pSecImpl;
+ ret = osl_Security_E_None;
}
+ else
+ ret = osl_Security_E_UserUnknown;
+
+ if (strDomain)
+ free(strDomain);
+ else
+ free(strUser);
return ret;
}
@@ -252,56 +243,48 @@ sal_Bool SAL_CALL osl_isAdministrator(oslSecurity Security)
{
if (Security != NULL)
{
- /* ts: on Window 95 systems any user seems to be an adminstrator */
- if (!isWNT())
- {
- return(sal_True);
- }
- else
- {
- HANDLE hImpersonationToken = NULL;
- PSID psidAdministrators;
- SID_IDENTIFIER_AUTHORITY siaNtAuthority = SECURITY_NT_AUTHORITY;
- sal_Bool bSuccess = sal_False;
+ HANDLE hImpersonationToken = NULL;
+ PSID psidAdministrators;
+ SID_IDENTIFIER_AUTHORITY siaNtAuthority = SECURITY_NT_AUTHORITY;
+ sal_Bool bSuccess = sal_False;
- /* If Security contains an access token we need to duplicate it to an impersonation
- access token. NULL works with CheckTokenMembership() as the current effective
- impersonation token
- */
+ /* If Security contains an access token we need to duplicate it to an impersonation
+ access token. NULL works with CheckTokenMembership() as the current effective
+ impersonation token
+ */
- if ( ((oslSecurityImpl*)Security)->m_hToken )
- {
- if ( !DuplicateToken (((oslSecurityImpl*)Security)->m_hToken, SecurityImpersonation, &hImpersonationToken) )
- return sal_False;
- }
-
- /* CheckTokenMembership() can be used on W2K and higher (NT4 no longer supported by OOo)
- and also works on Vista to retrieve the effective user rights. Just checking for
- membership of Administrators group is not enough on Vista this would require additional
- complicated checks as described in KB arcticle Q118626: http://support.microsoft.com/kb/118626/en-us
- */
+ if ( ((oslSecurityImpl*)Security)->m_hToken )
+ {
+ if ( !DuplicateToken (((oslSecurityImpl*)Security)->m_hToken, SecurityImpersonation, &hImpersonationToken) )
+ return sal_False;
+ }
- if (AllocateAndInitializeSid(&siaNtAuthority,
- 2,
- SECURITY_BUILTIN_DOMAIN_RID,
- DOMAIN_ALIAS_RID_ADMINS,
- 0, 0, 0, 0, 0, 0,
- &psidAdministrators))
- {
- BOOL fSuccess = FALSE;
+ /* CheckTokenMembership() can be used on W2K and higher (NT4 no longer supported by OOo)
+ and also works on Vista to retrieve the effective user rights. Just checking for
+ membership of Administrators group is not enough on Vista this would require additional
+ complicated checks as described in KB arcticle Q118626: http://support.microsoft.com/kb/118626/en-us
+ */
+
+ if (AllocateAndInitializeSid(&siaNtAuthority,
+ 2,
+ SECURITY_BUILTIN_DOMAIN_RID,
+ DOMAIN_ALIAS_RID_ADMINS,
+ 0, 0, 0, 0, 0, 0,
+ &psidAdministrators))
+ {
+ BOOL fSuccess = FALSE;
- if ( CheckTokenMembership_Stub( hImpersonationToken, psidAdministrators, &fSuccess ) && fSuccess )
- bSuccess = sal_True;
+ if ( CheckTokenMembership_Stub( hImpersonationToken, psidAdministrators, &fSuccess ) && fSuccess )
+ bSuccess = sal_True;
- FreeSid(psidAdministrators);
- }
+ FreeSid(psidAdministrators);
+ }
- if ( hImpersonationToken )
- CloseHandle( hImpersonationToken );
+ if ( hImpersonationToken )
+ CloseHandle( hImpersonationToken );
- return (bSuccess);
- }
+ return (bSuccess);
}
else
return (sal_False);
@@ -835,38 +818,6 @@ static sal_Bool GetSpecialFolder(rtl_uString **strPath, int nFolder)
}
-static sal_Bool isWNT(void)
-{
- static sal_Bool isInit = sal_False;
- static sal_Bool isWNT = sal_False;
-
- if (!isInit)
- {
- OSVERSIONINFO VersionInformation =
-
- {
- sizeof(OSVERSIONINFO),
- 0,
- 0,
- 0,
- 0,
- "",
- };
-
- if (
- GetVersionEx(&VersionInformation) &&
- (VersionInformation.dwPlatformId == VER_PLATFORM_WIN32_NT)
- )
- {
- isWNT = sal_True;
- }
-
- isInit = sal_True;
- }
-
- return(isWNT);
-}
-
static BOOL Privilege(LPTSTR strPrivilege, BOOL bEnable)
{
HANDLE hToken;
commit 3d8320ec8f8e778d4adc240009a7bb784b3d286e
Author: Tor Lillqvist <tlillqvist at novell.com>
Date: Mon Jan 24 02:26:49 2011 +0200
Kill Win9x mutex code
diff --git a/sal/osl/w32/mutex.c b/sal/osl/w32/mutex.c
index 0090623..009670c 100644
--- a/sal/osl/w32/mutex.c
+++ b/sal/osl/w32/mutex.c
@@ -37,66 +37,18 @@
CRITICAL_SECTION structure.
*/
-typedef struct _oslMutexImpl {
- CRITICAL_SECTION m_Mutex;
- int m_Locks;
- DWORD m_Owner;
- DWORD m_Requests;
-} oslMutexImpl;
-
-static BOOL (WINAPI *lpfTryEnterCriticalSection)(LPCRITICAL_SECTION)
- = (BOOL (WINAPI *)(LPCRITICAL_SECTION))0xFFFFFFFF;
-
-static CRITICAL_SECTION MutexLock;
-
/*****************************************************************************/
/* osl_createMutex */
/*****************************************************************************/
oslMutex SAL_CALL osl_createMutex(void)
{
- oslMutexImpl *pMutexImpl;
+ CRITICAL_SECTION *pMutexImpl;
- /* Window 95 does not support "TryEnterCriticalSection" */
-
- if (lpfTryEnterCriticalSection ==
- (BOOL (WINAPI *)(LPCRITICAL_SECTION))0xFFFFFFFF)
- {
- OSVERSIONINFO VersionInformation =
-
- {
- sizeof(OSVERSIONINFO),
- 0,
- 0,
- 0,
- 0,
- "",
- };
-
- /* ts: Window 98 does not support "TryEnterCriticalSection" but export the symbol !!!
- calls to that symbol always returns FALSE */
- if (
- GetVersionEx(&VersionInformation) &&
- (VersionInformation.dwPlatformId == VER_PLATFORM_WIN32_NT)
- )
- {
- lpfTryEnterCriticalSection = (BOOL (WINAPI *)(LPCRITICAL_SECTION))
- GetProcAddress(GetModuleHandle("KERNEL32"),
- "TryEnterCriticalSection");
- }
- else
- {
- lpfTryEnterCriticalSection = (BOOL (WINAPI *)(LPCRITICAL_SECTION))NULL;
- }
-
-
- InitializeCriticalSection(&MutexLock);
- }
-
- pMutexImpl= calloc(sizeof(oslMutexImpl), 1);
+ pMutexImpl = calloc(sizeof(CRITICAL_SECTION), 1);
OSL_ASSERT(pMutexImpl); /* alloc successful? */
- InitializeCriticalSection(&pMutexImpl->m_Mutex);
+ InitializeCriticalSection(pMutexImpl);
return (oslMutex)pMutexImpl;
}
@@ -106,11 +58,11 @@ oslMutex SAL_CALL osl_createMutex(void)
/*****************************************************************************/
void SAL_CALL osl_destroyMutex(oslMutex Mutex)
{
- oslMutexImpl *pMutexImpl = (oslMutexImpl *)Mutex;
+ CRITICAL_SECTION *pMutexImpl = (CRITICAL_SECTION *)Mutex;
if (pMutexImpl)
{
- DeleteCriticalSection(&pMutexImpl->m_Mutex);
+ DeleteCriticalSection(pMutexImpl);
free(pMutexImpl);
}
}
@@ -120,26 +72,11 @@ void SAL_CALL osl_destroyMutex(oslMutex Mutex)
/*****************************************************************************/
sal_Bool SAL_CALL osl_acquireMutex(oslMutex Mutex)
{
- oslMutexImpl *pMutexImpl = (oslMutexImpl *)Mutex;
+ CRITICAL_SECTION *pMutexImpl = (CRITICAL_SECTION *)Mutex;
OSL_ASSERT(Mutex);
- if (lpfTryEnterCriticalSection == NULL)
- {
- EnterCriticalSection(&MutexLock);
- pMutexImpl->m_Requests++;
- LeaveCriticalSection(&MutexLock);
-
- EnterCriticalSection(&pMutexImpl->m_Mutex);
-
- EnterCriticalSection(&MutexLock);
- pMutexImpl->m_Requests--;
- if (pMutexImpl->m_Locks++ == 0)
- pMutexImpl->m_Owner = GetCurrentThreadId();
- LeaveCriticalSection(&MutexLock);
- }
- else
- EnterCriticalSection(&pMutexImpl->m_Mutex);
+ EnterCriticalSection(pMutexImpl);
return sal_True;
}
@@ -149,25 +86,11 @@ sal_Bool SAL_CALL osl_acquireMutex(oslMutex Mutex)
/*****************************************************************************/
sal_Bool SAL_CALL osl_tryToAcquireMutex(oslMutex Mutex)
{
- sal_Bool ret = sal_False;
- oslMutexImpl *pMutexImpl = (oslMutexImpl *)Mutex;
+ CRITICAL_SECTION *pMutexImpl = (CRITICAL_SECTION *)Mutex;
OSL_ASSERT(Mutex);
- if (lpfTryEnterCriticalSection != NULL)
- return (sal_Bool)(lpfTryEnterCriticalSection(&pMutexImpl->m_Mutex) != FALSE);
- else
- {
- EnterCriticalSection(&MutexLock);
-
- if ( ((pMutexImpl->m_Requests == 0) && (pMutexImpl->m_Locks == 0)) ||
- (pMutexImpl->m_Owner == GetCurrentThreadId()) )
- ret = osl_acquireMutex(Mutex);
-
- LeaveCriticalSection(&MutexLock);
- }
-
- return ret;
+ return (sal_Bool)(TryEnterCriticalSection(pMutexImpl) != FALSE);
}
/*****************************************************************************/
@@ -175,21 +98,11 @@ sal_Bool SAL_CALL osl_tryToAcquireMutex(oslMutex Mutex)
/*****************************************************************************/
sal_Bool SAL_CALL osl_releaseMutex(oslMutex Mutex)
{
- oslMutexImpl *pMutexImpl = (oslMutexImpl *)Mutex;
+ CRITICAL_SECTION *pMutexImpl = (CRITICAL_SECTION *)Mutex;
OSL_ASSERT(Mutex);
- if (lpfTryEnterCriticalSection == NULL)
- {
- EnterCriticalSection(&MutexLock);
-
- if (--(pMutexImpl->m_Locks) == 0)
- pMutexImpl->m_Owner = 0;
-
- LeaveCriticalSection(&MutexLock);
- }
-
- LeaveCriticalSection(&pMutexImpl->m_Mutex);
+ LeaveCriticalSection(pMutexImpl);
return sal_True;
}
commit 1504bd4343e4af4e9a94a6ea8751fd4885adf6a1
Author: Tor Lillqvist <tlillqvist at novell.com>
Date: Mon Jan 24 02:25:41 2011 +0200
Drop pipeimpl.obj from SLOFILES, too
diff --git a/sal/osl/w32/MAKEFILE.MK b/sal/osl/w32/MAKEFILE.MK
index a760171..9dd1d0c 100644
--- a/sal/osl/w32/MAKEFILE.MK
+++ b/sal/osl/w32/MAKEFILE.MK
@@ -70,7 +70,6 @@ SLOFILES= $(SLO)$/conditn.obj \
$(SLO)$/profile.obj \
$(SLO)$/time.obj \
$(SLO)$/signal.obj \
- $(SLO)$/pipeimpl.obj \
$(SLO)$/pipe.obj \
$(SLO)$/util.obj \
$(SLO)$/file.obj\
More information about the Libreoffice-commits
mailing list