Bump version to 4.2-24
[LibreOffice.git] / sfx2 / source / doc / sfxacldetect.cxx
blobc829c1d763f554dc66bae1a7e20ad00775ef7aa4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "sfxacldetect.hxx"
23 #if EXTRA_ACL_CHECK
25 #ifdef WNT
27 // necessary to include system headers without warnings
28 #ifdef _MSC_VER
29 #pragma warning(disable:4668 4917)
30 #endif
32 #include <windows.h>
33 #include <lmaccess.h>
34 #include <sal/types.h>
36 sal_Bool IsReadonlyAccordingACL( const sal_Unicode* pFilePath )
38 sal_Bool bResult = sal_False;
40 sal_uInt32 nFDSize = 0;
41 GetFileSecurityW( reinterpret_cast< LPCWSTR >(pFilePath), DACL_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|OWNER_SECURITY_INFORMATION, NULL, 0, &nFDSize );
42 if ( nFDSize )
44 PSECURITY_DESCRIPTOR pFileDescr = reinterpret_cast< PSECURITY_DESCRIPTOR >( malloc( nFDSize ) );
45 if ( GetFileSecurityW( reinterpret_cast< LPCWSTR >(pFilePath), DACL_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|OWNER_SECURITY_INFORMATION, pFileDescr, nFDSize, &nFDSize ) )
47 HANDLE hToken = NULL;
48 if ( OpenThreadToken( GetCurrentThread(), TOKEN_DUPLICATE|TOKEN_QUERY, TRUE, &hToken )
49 || OpenProcessToken( GetCurrentProcess(), TOKEN_DUPLICATE|TOKEN_QUERY, &hToken) )
51 HANDLE hImpersonationToken = NULL;
52 if ( DuplicateToken( hToken, SecurityImpersonation, &hImpersonationToken) )
54 sal_uInt32 nDesiredAccess = ACCESS_WRITE;
55 GENERIC_MAPPING aGenericMapping = { ACCESS_READ, ACCESS_WRITE, 0, ACCESS_READ | ACCESS_WRITE };
56 MapGenericMask( &nDesiredAccess, &aGenericMapping );
58 PRIVILEGE_SET aPrivilegeSet;
59 sal_uInt32 nPrivilegeSetSize = sizeof( PRIVILEGE_SET );
61 sal_uInt32 nGrantedAccess;
62 BOOL bAccessible = TRUE;
63 if ( AccessCheck( pFileDescr,
64 hImpersonationToken,
65 nDesiredAccess,
66 &aGenericMapping,
67 &aPrivilegeSet,
68 &nPrivilegeSetSize,
69 &nGrantedAccess,
70 &bAccessible ) )
72 bResult = !bAccessible;
75 CloseHandle( hImpersonationToken );
78 CloseHandle( hToken );
82 free( pFileDescr );
85 return bResult;
88 #else // this is UNX
91 #include <sal/types.h>
93 sal_Bool IsReadonlyAccordingACL( const sal_Unicode* )
95 // to be implemented
96 return sal_False;
99 #endif
101 #endif
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */