Kaydet (Commit) 88829fd9 authored tarafından Mike Kaganski's avatar Mike Kaganski

tdf#103058: allow optional registration for MS ProgIDs

To allow in-place replacement of OWSSUPP.dll, we need to be able
to handle the same ProgIDs that it handles, namely:
SharePoint.OpenDocuments and its versions. This allows to use
the SharePoint integration capabilities of LO without the need to
reconfigure SharePoint server's DOCICON.xml (the system would
start the component with same name as MS Office uses).

But this cannot be the default mode, since if MS Office is installed
on the same system, we would hijack the registration, that could be
undesirable.

So, this commit adds an option to use
regsvr32 [/u] /i:Substitute_OWSSUPP path\to\spsupp.dll
to also [un]register SharePoint.OpenDocuments in addition to normal
LOSPSupport.OpenDocuments.

Change-Id: Icc284f9aa8f97ecf04594dd55b99bc1e3d20740d
Reviewed-on: https://gerrit.libreoffice.org/36389Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 5fb961ad
......@@ -213,7 +213,6 @@ private:
static long m_nObjCount;
static ITypeInfo* m_pTypeInfo;
static wchar_t m_szLOPath[MAX_PATH];
COMObjectSafety m_aObjectSafety;
};
......
......@@ -11,6 +11,7 @@
#define INCLUDED_SHELL_INC_SPSUPP_COMREFCOUNTED_HPP
#include "objbase.h"
#include "assert.h"
template <class Interface>
class COMRefCounted : public Interface
......@@ -28,9 +29,13 @@ public:
ULONG STDMETHODCALLTYPE Release() override
{
assert(m_nRef > 0);
if (::InterlockedDecrement(&m_nRef) == 0)
{
delete this;
return (m_nRef > 0) ? static_cast<ULONG>(m_nRef) : 0;
return 0;
}
return static_cast<ULONG>(m_nRef);
}
private:
......
......@@ -12,14 +12,23 @@
#include "windows.h"
namespace Registrar {
HRESULT RegisterObject(REFIID riidCLSID,
REFIID riidTypeLib,
class Registrar {
public:
explicit Registrar(REFIID riidCLSID);
HRESULT RegisterObject(REFIID riidTypeLib,
const wchar_t* sProgram,
const wchar_t* sComponent,
const wchar_t* Path);
HRESULT UnRegisterObject(REFIID riidCLSID, const wchar_t* LibId, const wchar_t* ClassId);
}
int nVersion,
const wchar_t* Path,
bool bSetDefault);
HRESULT UnRegisterObject(const wchar_t* sProgram, const wchar_t* sComponent, int nVersion);
HRESULT RegisterProgID(const wchar_t* sProgram, const wchar_t* sComponent, int nVersion, bool bSetDefault);
HRESULT UnRegisterProgID(const wchar_t* sProgram, const wchar_t* sComponent, int nVersion);
private:
static const size_t nGUIDlen = 40;
wchar_t m_sCLSID[nGUIDlen];
HRESULT m_ConstructionResult;
};
#endif
......
......@@ -29,14 +29,24 @@ bool SecurityWarning(const wchar_t* sProgram, const wchar_t* sDocument)
}
// Returns S_OK if successful
HRESULT LOStart(wchar_t* sCommandLine)
HRESULT LOStart(const wchar_t* sModeArg, const wchar_t* sFilePath, bool bDoSecurityWarning)
{
const wchar_t* sProgram = GetLOPath();
if (bDoSecurityWarning && !SecurityWarning(sProgram, sFilePath))
{
// Return success to avoid downloading in browser
return S_OK;
}
STARTUPINFOW si;
std::memset(&si, 0, sizeof si);
si.cb = sizeof si;
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW;
PROCESS_INFORMATION pi = {};
const size_t cchCommandLine = 32768;
wchar_t sCommandLine[cchCommandLine];
swprintf(sCommandLine, cchCommandLine, L"\"%s\" %s \"%s\"", sProgram, sModeArg, sFilePath);
if (CreateProcessW(nullptr, sCommandLine, nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si, &pi) == FALSE)
{
DWORD dwError = GetLastError();
......@@ -133,7 +143,6 @@ HRESULT STDMETHODCALLTYPE COMOpenDocuments::COMObjectSafety::SetInterfaceSafetyO
long COMOpenDocuments::m_nObjCount = 0;
ITypeInfo* COMOpenDocuments::m_pTypeInfo = nullptr;
wchar_t COMOpenDocuments::m_szLOPath[MAX_PATH] = {0};
COMOpenDocuments::COMOpenDocuments()
: m_aObjectSafety(this)
......@@ -299,19 +308,7 @@ STDMETHODIMP COMOpenDocuments::CreateNewDocument2(
VARIANT_BOOL* pbResult) // true if the document creation succeeds; otherwise false
{
// TODO: resolve the program from varProgID (nullptr -> default?)
const wchar_t* sProgram = GetLOPath();
if (m_aObjectSafety.GetSafe_forUntrustedCaller() || m_aObjectSafety.GetSafe_forUntrustedData())
{
if (!SecurityWarning(sProgram, bstrTemplateLocation))
{
// Set result to true and return success to avoid downloading in browser
*pbResult = TRUE;
return S_OK;
}
}
wchar_t sCommandLine[32768];
swprintf(sCommandLine, sizeof(sCommandLine) / sizeof(*sCommandLine), L"\"%s\" -n \"%s\"", sProgram, bstrTemplateLocation);
HRESULT hr = LOStart(sCommandLine);
HRESULT hr = LOStart(L"-n", bstrTemplateLocation, m_aObjectSafety.GetSafe_forUntrustedCaller() || m_aObjectSafety.GetSafe_forUntrustedData());
*pbResult = VARIANT_BOOL(SUCCEEDED(hr));
return hr;
}
......@@ -349,19 +346,7 @@ STDMETHODIMP COMOpenDocuments::ViewDocument3(
VARIANT_BOOL *pbResult) // true if the document was successfully opened; otherwise false
{
// TODO: resolve the program from varProgID (nullptr -> default?)
const wchar_t* sProgram = GetLOPath();
if (m_aObjectSafety.GetSafe_forUntrustedCaller() || m_aObjectSafety.GetSafe_forUntrustedData())
{
if (!SecurityWarning(sProgram, bstrDocumentLocation))
{
// Set result to true and return success to avoid downloading in browser
*pbResult = TRUE;
return S_OK;
}
}
wchar_t sCommandLine[32768];
swprintf(sCommandLine, sizeof(sCommandLine) / sizeof(*sCommandLine), L"\"%s\" --view \"%s\"", sProgram, bstrDocumentLocation);
HRESULT hr = LOStart(sCommandLine);
HRESULT hr = LOStart(L"--view", bstrDocumentLocation, m_aObjectSafety.GetSafe_forUntrustedCaller() || m_aObjectSafety.GetSafe_forUntrustedData());
*pbResult = VARIANT_BOOL(SUCCEEDED(hr));
return hr;
}
......@@ -423,19 +408,7 @@ STDMETHODIMP COMOpenDocuments::EditDocument3(
VARIANT_BOOL *pbResult) // true if the document was successfully opened; otherwise false
{
// TODO: resolve the program from varProgID (nullptr -> default?)
const wchar_t* sProgram = GetLOPath();
if (m_aObjectSafety.GetSafe_forUntrustedCaller() || m_aObjectSafety.GetSafe_forUntrustedData())
{
if (!SecurityWarning(sProgram, bstrDocumentLocation))
{
// Set result to true and return success to avoid downloading in browser
*pbResult = TRUE;
return S_OK;
}
}
wchar_t sCommandLine[32768];
swprintf(sCommandLine, sizeof(sCommandLine) / sizeof(*sCommandLine), L"\"%s\" -o \"%s\"", sProgram, bstrDocumentLocation);
HRESULT hr = LOStart(sCommandLine);
HRESULT hr = LOStart(L"-o", bstrDocumentLocation, m_aObjectSafety.GetSafe_forUntrustedCaller() || m_aObjectSafety.GetSafe_forUntrustedData());
*pbResult = VARIANT_BOOL(SUCCEEDED(hr));
return hr;
}
......
......@@ -5,3 +5,4 @@ EXPORTS
DllUnregisterServer PRIVATE
DllCanUnloadNow PRIVATE
DllGetClassObject PRIVATE
DllInstall PRIVATE
......@@ -20,6 +20,7 @@
#include <memory>
#include "olectl.h"
#include "wchar.h"
#include "spsuppServ.hpp"
#include "spsuppClassFactory.hpp"
#include "COMOpenDocuments.hpp"
......@@ -126,7 +127,7 @@ STDAPI DllRegisterServer(void)
if (FAILED(hr))
return hr;
return Registrar::RegisterObject(CLSID_spsupp, LIBID_spsupp, L"LOSPSupport", L"OpenDocuments", szFile);
return Registrar(CLSID_spsupp).RegisterObject(LIBID_spsupp, L"LOSPSupport", L"OpenDocuments", 1, szFile, true);
}
STDAPI DllUnregisterServer(void)
......@@ -146,7 +147,37 @@ STDAPI DllUnregisterServer(void)
if (FAILED(hr))
return hr;
return Registrar::UnRegisterObject(CLSID_spsupp, L"LOSPSupport", L"OpenDocuments");
return Registrar(CLSID_spsupp).UnRegisterObject(L"LOSPSupport", L"OpenDocuments", 1);
}
// This is called when regsvr32.exe is called with "/i" flag
// pszCmdLine is the string passed to "/i:<string>"
// See https://msdn.microsoft.com/library/windows/desktop/bb759846
STDAPI DllInstall(BOOL bInstall, _In_opt_ PCWSTR pszCmdLine)
{
if (wcscmp(pszCmdLine, L"Substitute_OWSSUPP") == 0)
{
HRESULT hr;
Registrar registrar(CLSID_spsupp);
if (bInstall)
{
hr = registrar.RegisterProgID(L"SharePoint", L"OpenDocuments", 3, true);
if (SUCCEEDED(hr))
hr = registrar.RegisterProgID(L"SharePoint", L"OpenDocuments", 2, false);
if (SUCCEEDED(hr))
hr = registrar.RegisterProgID(L"SharePoint", L"OpenDocuments", 1, false);
}
else
{
// Try all ProgIDs regardless of error, but make sure to return failure result if at least one failed
hr = registrar.UnRegisterProgID(L"SharePoint", L"OpenDocuments", 1);
HRESULT hrLast;
hr = SUCCEEDED(hrLast = registrar.UnRegisterProgID(L"SharePoint", L"OpenDocuments", 2)) ? hr : hrLast;
hr = SUCCEEDED(hrLast = registrar.UnRegisterProgID(L"SharePoint", L"OpenDocuments", 3)) ? hr : hrLast;
}
return hr;
}
return E_INVALIDARG;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment