From a4ef8f7646beda733ad926911d0ab7c8ab42f69f Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Wed, 18 Apr 2018 00:42:17 +0300 Subject: tdf#116420: Windows: Test if a filepath redirects to a WebDAV resource In Windows, filesystem redirectors can map WebDAV resources to UNC paths, or to drive-based "local" paths; so a WebDAV URI of the form "http://WebDADServer/root/directory/File.ext" may be accessed using "\\WebDADServer\root\directory\File.ext" or "Z:\directory\File.ext". When using these paths, failure to create a lockfile aside the opened document should not be considered an error; so this patch checks for this. Regression from commit 6ca3b3648e25ae9d4d2d29a0df83349198ec3f5e. Change-Id: I1de55b66447dc91d22b6d2b5b121de96bf32e4ee Reviewed-on: https://gerrit.libreoffice.org/53070 Tested-by: Jenkins Reviewed-by: Stephan Bergmann (cherry picked from commit 642a49e8d3006d000bc6c58def34d4e96764c6cc) Reviewed-on: https://gerrit.libreoffice.org/53084 Tested-by: Mike Kaganski Reviewed-by: Aron Budea --- include/tools/fileutil.hxx | 27 +++++++++++++++ sfx2/source/doc/docfile.cxx | 9 ++++- tools/Library_tl.mk | 1 + tools/source/fsys/fileutil.cxx | 77 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 include/tools/fileutil.hxx create mode 100644 tools/source/fsys/fileutil.cxx diff --git a/include/tools/fileutil.hxx b/include/tools/fileutil.hxx new file mode 100644 index 000000000000..06e7bf820992 --- /dev/null +++ b/include/tools/fileutil.hxx @@ -0,0 +1,27 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_TOOLS_FILEUTIL_HXX +#define INCLUDED_TOOLS_FILEUTIL_HXX + +#include + +class INetURLObject; + +namespace tools +{ +// Tests if the path is a UNC or local (drive-based) path that redirects to +// a WebDAV resource (e.g., using redirectors on Windows). +// Currently only implemented for Windows; on other platforms, returns false. +TOOLS_DLLPUBLIC bool IsMappedWebDAVPath(const INetURLObject& aURL); +} + +#endif // INCLUDED_TOOLS_FILEUTIL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index dfcf9d94d09f..bf637cbb1bfe 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -70,6 +70,7 @@ #include #include #include +#include #include #include #include @@ -1287,7 +1288,13 @@ SfxMedium::LockFileResult SfxMedium::LockOrigFileOnDemand( bool bLoading, bool b } catch (const uno::Exception&) { - if (bLoading && !bNoUI) + if (tools::IsMappedWebDAVPath(GetURLObject())) + { + // This is a path that redirects to a WebDAV resource; + // so failure creating lockfile is not an error here. + bResult = true; + } + else if (bLoading && !bNoUI) { bIoErr = true; ShowLockFileProblemDialog(MessageDlg::LockFileIgnore); diff --git a/tools/Library_tl.mk b/tools/Library_tl.mk index 6ebf57ef40b5..b18bd40edd9d 100644 --- a/tools/Library_tl.mk +++ b/tools/Library_tl.mk @@ -49,6 +49,7 @@ $(eval $(call gb_Library_add_exception_objects,tl,\ tools/source/datetime/tdate \ tools/source/datetime/ttime \ tools/source/debug/debug \ + tools/source/fsys/fileutil \ tools/source/fsys/urlobj \ tools/source/fsys/wldcrd \ tools/source/generic/b3dtrans \ diff --git a/tools/source/fsys/fileutil.cxx b/tools/source/fsys/fileutil.cxx new file mode 100644 index 000000000000..c4937be92473 --- /dev/null +++ b/tools/source/fsys/fileutil.cxx @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#if defined _WIN32 +#include +#include +#include +#define WIN32_LEAN_AND_MEAN +#include +#endif + +namespace tools +{ +bool IsMappedWebDAVPath(const INetURLObject& aURL) +{ +#if defined _WIN32 + if (aURL.GetProtocol() == INetProtocol::File) + { + OUString sURL = aURL.GetMainURL(INetURLObject::DecodeMechanism::NO_DECODE); + OUString aSystemPath; + if (osl::FileBase::getSystemPathFromFileURL(sURL, aSystemPath) == osl::FileBase::E_None) + { + DWORD nSize = MAX_PATH; + std::unique_ptr bufUNC(new char[nSize]); + DWORD nResult = WNetGetUniversalNameW(static_cast(aSystemPath.getStr()), + UNIVERSAL_NAME_INFO_LEVEL, bufUNC.get(), &nSize); + if (nResult == ERROR_MORE_DATA) + { + bufUNC.reset(new char[nSize]); + nResult = WNetGetUniversalNameW(static_cast(aSystemPath.getStr()), + UNIVERSAL_NAME_INFO_LEVEL, bufUNC.get(), &nSize); + } + if (nResult == NO_ERROR || nResult == ERROR_BAD_DEVICE) + { + NETRESOURCEW aReq{}; + if (nResult == ERROR_BAD_DEVICE) // The path could already be an UNC + aReq.lpRemoteName = const_cast(static_cast(aSystemPath.getStr())); + else + { + auto pInfo = reinterpret_cast(bufUNC.get()); + aReq.lpRemoteName = pInfo->lpUniversalName; + } + nSize = 1024; + std::unique_ptr bufInfo(new char[nSize]); + LPWSTR pSystem = nullptr; + nResult = WNetGetResourceInformationW(&aReq, bufInfo.get(), &nSize, &pSystem); + if (nResult == ERROR_MORE_DATA) + { + bufInfo.reset(new char[nSize]); + nResult = WNetGetResourceInformationW(&aReq, bufInfo.get(), &nSize, &pSystem); + } + if (nResult == NO_ERROR) + { + LPNETRESOURCEW pInfo = reinterpret_cast(bufInfo.get()); + if (wcscmp(pInfo->lpProvider, L"Web Client Network") == 0) + return true; + } + } + } + } +#else + (void)aURL; +#endif + return false; +} + +} // namespace tools + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3