1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
27 // necessary to include system headers without warnings
29 #pragma warning(disable:4668 4917)
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
);
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
) )
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
,
72 bResult
= !bAccessible
;
75 CloseHandle( hImpersonationToken
);
78 CloseHandle( hToken
);
91 #include <sal/types.h>
93 sal_Bool
IsReadonlyAccordingACL( const sal_Unicode
* )
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */