xref: /aoo41x/main/sfx2/source/doc/sfxacldetect.cxx (revision 79aad27f)
1*d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d119d52dSAndrew Rist  * distributed with this work for additional information
6*d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9*d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d119d52dSAndrew Rist  *
11*d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d119d52dSAndrew Rist  *
13*d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15*d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*d119d52dSAndrew Rist  * specific language governing permissions and limitations
18*d119d52dSAndrew Rist  * under the License.
19*d119d52dSAndrew Rist  *
20*d119d52dSAndrew Rist  *************************************************************/
21*d119d52dSAndrew Rist 
22*d119d52dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #ifdef WNT
29cdf0e10cSrcweir 
30cdf0e10cSrcweir // necessary to include system headers without warnings
31cdf0e10cSrcweir #ifdef _MSC_VER
32cdf0e10cSrcweir #pragma warning(disable:4668 4917)
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <windows.h>
36cdf0e10cSrcweir #include <lmaccess.h>
37cdf0e10cSrcweir #include <sal/types.h>
38cdf0e10cSrcweir 
IsReadonlyAccordingACL(const sal_Unicode * pFilePath)39cdf0e10cSrcweir sal_Bool IsReadonlyAccordingACL( const sal_Unicode* pFilePath )
40cdf0e10cSrcweir {
41cdf0e10cSrcweir     sal_Bool bResult = sal_False;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir     sal_uInt32 nFDSize = 0;
44cdf0e10cSrcweir     GetFileSecurityW( reinterpret_cast< LPCWSTR >(pFilePath), DACL_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|OWNER_SECURITY_INFORMATION, NULL, 0, &nFDSize );
45cdf0e10cSrcweir     if ( nFDSize )
46cdf0e10cSrcweir     {
47cdf0e10cSrcweir         PSECURITY_DESCRIPTOR pFileDescr = reinterpret_cast< PSECURITY_DESCRIPTOR >( malloc( nFDSize ) );
48cdf0e10cSrcweir         if ( GetFileSecurityW( reinterpret_cast< LPCWSTR >(pFilePath), DACL_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|OWNER_SECURITY_INFORMATION, pFileDescr, nFDSize, &nFDSize ) )
49cdf0e10cSrcweir         {
50cdf0e10cSrcweir             HANDLE hToken = NULL;
51cdf0e10cSrcweir             if ( OpenThreadToken( GetCurrentThread(), TOKEN_DUPLICATE|TOKEN_QUERY, TRUE, &hToken )
52cdf0e10cSrcweir               || OpenProcessToken( GetCurrentProcess(), TOKEN_DUPLICATE|TOKEN_QUERY, &hToken) )
53cdf0e10cSrcweir             {
54cdf0e10cSrcweir                 HANDLE hImpersonationToken = NULL;
55cdf0e10cSrcweir                 if ( DuplicateToken( hToken, SecurityImpersonation, &hImpersonationToken) )
56cdf0e10cSrcweir                 {
57cdf0e10cSrcweir                     sal_uInt32 nDesiredAccess = ACCESS_WRITE;
58cdf0e10cSrcweir                     GENERIC_MAPPING aGenericMapping = { ACCESS_READ, ACCESS_WRITE, 0, ACCESS_READ | ACCESS_WRITE };
59cdf0e10cSrcweir                     MapGenericMask( &nDesiredAccess, &aGenericMapping );
60cdf0e10cSrcweir 
61cdf0e10cSrcweir                     PRIVILEGE_SET aPrivilegeSet;
62cdf0e10cSrcweir                     sal_uInt32 nPrivilegeSetSize = sizeof( PRIVILEGE_SET );
63cdf0e10cSrcweir 
64cdf0e10cSrcweir                     sal_uInt32 nGrantedAccess;
65cdf0e10cSrcweir                     BOOL bAccessible = TRUE;
66cdf0e10cSrcweir                     if ( AccessCheck( pFileDescr,
67cdf0e10cSrcweir                                       hImpersonationToken,
68cdf0e10cSrcweir                                       nDesiredAccess,
69cdf0e10cSrcweir                                       &aGenericMapping,
70cdf0e10cSrcweir                                       &aPrivilegeSet,
71cdf0e10cSrcweir                                       &nPrivilegeSetSize,
72cdf0e10cSrcweir                                       &nGrantedAccess,
73cdf0e10cSrcweir                                       &bAccessible ) )
74cdf0e10cSrcweir                     {
75cdf0e10cSrcweir                         bResult = !bAccessible;
76cdf0e10cSrcweir                     }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir                     CloseHandle( hImpersonationToken );
79cdf0e10cSrcweir                 }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir                 CloseHandle( hToken );
82cdf0e10cSrcweir             }
83cdf0e10cSrcweir         }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         free( pFileDescr );
86cdf0e10cSrcweir     }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     return bResult;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir #else // this is UNX
92cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
93cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 
96cdf0e10cSrcweir #include <sal/types.h>
97cdf0e10cSrcweir 
IsReadonlyAccordingACL(const sal_Unicode *)98cdf0e10cSrcweir sal_Bool IsReadonlyAccordingACL( const sal_Unicode* )
99cdf0e10cSrcweir {
100cdf0e10cSrcweir     // to be implemented
101cdf0e10cSrcweir     return sal_False;
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir #endif
105cdf0e10cSrcweir 
106