diff options
author | Fredrik Orderud <fredrik.orderud@ge.com> | 2019-06-07 14:13:27 +0200 |
---|---|---|
committer | Fredrik Orderud <fredrik.orderud@ge.com> | 2019-06-19 08:37:14 +0200 |
commit | f2b9781e4dab88b191d73378deedfa7fb0d5ae02 (patch) | |
tree | a94e19c00074c7be61f0653fb16e651f514f36bc | |
parent | e453d6720d185da8b882f71572b1130659f16262 (diff) |
Remove fallback to per-user registration
Only register DLL/EXE COM servers in the machine-wide part of the registry for now.
Will add an option for per-user registration in a follow-up commit.
Task-number: QTBUG-76269
Change-Id: I77265166e87776c5f8a9e7fc571d783e3b41a00e
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r-- | src/activeqt/control/qaxserver.cpp | 33 | ||||
-rw-r--r-- | src/activeqt/control/qaxserverdll.cpp | 6 | ||||
-rw-r--r-- | src/activeqt/control/qaxservermain.cpp | 6 |
3 files changed, 23 insertions, 22 deletions
diff --git a/src/activeqt/control/qaxserver.cpp b/src/activeqt/control/qaxserver.cpp index 55f9862..bc93ee3 100644 --- a/src/activeqt/control/qaxserver.cpp +++ b/src/activeqt/control/qaxserver.cpp @@ -427,7 +427,7 @@ static void UpdateRegistryKeys(bool bRegister, const QString keyPath, QScopedPoi // (Un)Register the ActiveX server in the registry. // The QAxFactory implementation provides the information. -HRESULT UpdateRegistry(bool bRegister) +HRESULT UpdateRegistry(bool bRegister, bool perUser) { qAxIsServer = false; QString file = QString::fromWCharArray(qAxModuleFilename); @@ -443,37 +443,38 @@ HRESULT UpdateRegistry(bool bRegister) return SELFREG_E_TYPELIB; auto libAttr_cleanup = qScopeGuard([libAttr] { qAxTypeLibrary->ReleaseTLibAttr(libAttr); }); - bool userFallback = false; if (bRegister) { - if (RegisterTypeLib(qAxTypeLibrary, - reinterpret_cast<wchar_t *>(const_cast<ushort *>(libFile.utf16())), nullptr) == TYPE_E_REGISTRYACCESS) { + if (!perUser) { + HRESULT hr = RegisterTypeLib(qAxTypeLibrary, reinterpret_cast<wchar_t *>(const_cast<ushort *>(libFile.utf16())), nullptr); + if (FAILED(hr)) { + qWarning("Failing to register %s due to insufficient permission.", qPrintable(module)); + return hr; + } + } else { #ifndef Q_CC_MINGW // MinGW does not have RegisterTypeLibForUser() implemented so we cannot fallback in this case RegisterTypeLibForUser(qAxTypeLibrary, reinterpret_cast<wchar_t *>(const_cast<ushort *>(libFile.utf16())), nullptr); - userFallback = true; #endif } } else { - if (UnRegisterTypeLib(libAttr->guid, libAttr->wMajorVerNum, libAttr->wMinorVerNum, libAttr->lcid, - libAttr->syskind) == TYPE_E_REGISTRYACCESS) { + if (!perUser) { + HRESULT hr = UnRegisterTypeLib(libAttr->guid, libAttr->wMajorVerNum, libAttr->wMinorVerNum, libAttr->lcid, libAttr->syskind); + if (FAILED(hr)) { + qWarning("Failing to register %s due to insufficient permission.", qPrintable(module)); + return hr; + } + } else { #ifndef Q_CC_MINGW // MinGW does not have RegisterTypeLibForUser() implemented so we cannot fallback in this case UnRegisterTypeLibForUser(libAttr->guid, libAttr->wMajorVerNum, libAttr->wMinorVerNum, libAttr->lcid, libAttr->syskind); - userFallback = true; #endif } } - if (userFallback) - qWarning("QAxServer: Falling back to registering as user for %s due to insufficient permission.", qPrintable(module)); - // check whether the user has permission to write to HKLM\Software\Classes - // if not, use HKCU\Software\Classes QString keyPath(QLatin1String("HKEY_LOCAL_MACHINE\\Software\\Classes")); - QScopedPointer<QSettings> settings(new QSettings(keyPath, QSettings::NativeFormat)); - if (userFallback || !settings->isWritable()) { + if (perUser) keyPath = QLatin1String("HKEY_CURRENT_USER\\Software\\Classes"); - settings.reset(new QSettings(keyPath, QSettings::NativeFormat)); - } + QScopedPointer<QSettings> settings(new QSettings(keyPath, QSettings::NativeFormat)); // we try to create the ActiveX widgets later on... bool delete_qApp = false; diff --git a/src/activeqt/control/qaxserverdll.cpp b/src/activeqt/control/qaxserverdll.cpp index e9d3ede..c15c506 100644 --- a/src/activeqt/control/qaxserverdll.cpp +++ b/src/activeqt/control/qaxserverdll.cpp @@ -72,17 +72,17 @@ extern void qAxCleanup(); extern HANDLE qAxInstance; static uint qAxThreadId = 0; -extern HRESULT UpdateRegistry(bool bRegister); +extern HRESULT UpdateRegistry(bool bRegister, bool perUser); extern HRESULT GetClassObject(const GUID &clsid, const GUID &iid, void **ppUnk); STDAPI DllRegisterServer() { - return UpdateRegistry(true); + return UpdateRegistry(true, false); } STDAPI DllUnregisterServer() { - return UpdateRegistry(false); + return UpdateRegistry(false, false); } STDAPI DllGetClassObject(const GUID &clsid, const GUID &iid, void** ppv) diff --git a/src/activeqt/control/qaxservermain.cpp b/src/activeqt/control/qaxservermain.cpp index f431f2a..a637704 100644 --- a/src/activeqt/control/qaxservermain.cpp +++ b/src/activeqt/control/qaxservermain.cpp @@ -78,7 +78,7 @@ extern bool qAxOutProcServer; extern wchar_t qAxModuleFilename[MAX_PATH]; extern QString qAxInit(); extern void qAxCleanup(); -extern HRESULT UpdateRegistry(bool bRegister); +extern HRESULT UpdateRegistry(bool bRegister, bool perUser); extern HRESULT GetClassObject(const GUID &clsid, const GUID &iid, void **ppUnk); extern ulong qAxLockCount(); extern bool qax_winEventFilter(void *message); @@ -252,11 +252,11 @@ EXTERN_C int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, if (matchesOption(cmd, "activex") || matchesOption(cmd, "embedding")) { runServer = true; } else if (matchesOption(cmd, "unregserver")) { - nRet = UpdateRegistry(false); + nRet = UpdateRegistry(false, false); run = false; break; } else if (matchesOption(cmd, "regserver")) { - nRet = UpdateRegistry(true); + nRet = UpdateRegistry(true, false); run = false; break; } else if (matchesOption(cmd, "dumpidl")) { |