diff options
author | Vasily Melenchuk <vasily.melenchuk@cib.de> | 2022-12-05 20:32:41 +0300 |
---|---|---|
committer | Thorsten Behrens <thorsten.behrens@allotropia.de> | 2022-12-07 07:33:52 +0000 |
commit | a8017a020430857524138ff0ee72c425e8c7486d (patch) | |
tree | e9b5b03b26d962309cd7c319759485c7f74ccd97 /sfx2/source/doc | |
parent | 6a2c128a55997a576cd5bc0692d6bf67426a45db (diff) |
Support for Windows Security Zones for macro enable/disable
In Windows, files have security zones (local, from intranet, from
internet, etc) used by MS Word to decide in which mode it is safe to
open file.
This patch implements basic support for similar feature: it is now
possible to use expert configuration options to set up default
behavior and configure for example automatic disabling of macros, if
a file is downloaded from Internet or other unsafe location.
Changed defaults: files from untrusted zones, or the internet, get
macros disabled unconditionally. Can be overridden via
officecfg::Office::Common::Security::Scripting::WindowsSecurityZone.*
in the expert config dialog.
Change-Id: I0bf1ae4e54d75dd5d07cab309124a67a85ef2d4d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143750
Tested-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
Diffstat (limited to 'sfx2/source/doc')
-rw-r--r-- | sfx2/source/doc/docmacromode.cxx | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/sfx2/source/doc/docmacromode.cxx b/sfx2/source/doc/docmacromode.cxx index 2fa7b968fc41..4d15ad30cb01 100644 --- a/sfx2/source/doc/docmacromode.cxx +++ b/sfx2/source/doc/docmacromode.cxx @@ -40,6 +40,10 @@ #include <tools/diagnose_ex.h> #include <tools/urlobj.hxx> +#if defined(_WIN32) +#include <systools/win32/comtools.hxx> +#include <urlmon.h> +#endif namespace sfx2 { @@ -288,6 +292,56 @@ namespace sfx2 } } +#if defined(_WIN32) + // Windows specific: try to decide macros loading depending on Windows Security Zones + // (file is local, or it was downloaded from internet, etc) + OUString sURL(m_xData->m_rDocumentAccess.getDocumentLocation()); + sal::systools::COMReference<IZoneIdentifier> pZoneId; + auto e1 = CoCreateInstance( + CLSID_PersistentZoneIdentifier, nullptr, CLSCTX_ALL, IID_PPV_ARGS(&pZoneId)); + if (FAILED(e1)) + return disallowMacroExecution(); + sal::systools::COMReference<IPersistFile> pPersist(pZoneId.QueryInterface<IPersistFile>(IID_IPersistFile)); + DWORD dwZone; + OUString sFilePath; + osl::FileBase::getSystemPathFromFileURL(sURL, sFilePath); + if (SUCCEEDED(pPersist->Load(reinterpret_cast<LPCOLESTR>(sFilePath.getStr()), STGM_READ)) && + SUCCEEDED(pZoneId->GetId(&dwZone))) { + // We got zone id + sal_Int32 nAction = 0; + switch (dwZone) { + case 0: + nAction = officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneLocal::get(); + break; + case 1: + nAction = officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneIntranet::get(); + break; + case 2: + nAction = officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneTrusted::get(); + break; + case 3: + nAction = officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneInternet::get(); + break; + case 4: + nAction = officecfg::Office::Common::Security::Scripting::WindowsSecurityZone::ZoneUntrusted::get(); + break; + default: + nAction = 0; + break; + } + switch (nAction) + { + case 0: // Ask + break; + case 1: // Allow + return allowMacroExecution(); + default: + [[fallthrough]]; + case 2: // Deny + return disallowMacroExecution(); + } + } +#endif // confirmation is required bool bSecure = false; |