Bug 709598 - If no registry keys exist for the install dir, don't try to use the maintenance service for updates. r=rstrong.
authorBrian R. Bondy <netzen@gmail.com>
Wed, 04 Jan 2012 23:19:16 -0500
changeset 85001 bd49fc438b1bb13cc007dd282f5a0061b0c22a0a
parent 85000 c20c8ef8f0f4d989105dbd10984090ffea14dcee
child 85002 d4043fc86503bac5192a9afb740d0f3ffd93d919
push idunknown
push userunknown
push dateunknown
reviewersrstrong
bugs709598
milestone12.0a1
Bug 709598 - If no registry keys exist for the install dir, don't try to use the maintenance service for updates. r=rstrong.
toolkit/components/maintenanceservice/Makefile.in
toolkit/components/maintenanceservice/pathhash.cpp
toolkit/components/maintenanceservice/pathhash.h
toolkit/mozapps/update/common/Makefile.in
toolkit/mozapps/update/common/pathhash.cpp
toolkit/mozapps/update/common/pathhash.h
toolkit/mozapps/update/updater/updater.cpp
--- a/toolkit/components/maintenanceservice/Makefile.in
+++ b/toolkit/components/maintenanceservice/Makefile.in
@@ -44,17 +44,16 @@ include $(DEPTH)/config/autoconf.mk
 
 CPPSRCS = \
   maintenanceservice.cpp \
   serviceinstall.cpp \
   workmonitor.cpp \
   certificatecheck.cpp \
   servicebase.cpp \
   registrycertificates.cpp \
-  pathhash.cpp \
   $(NULL)
 
 # For debugging purposes only
 #DEFINES += -DDISABLE_UPDATER_AUTHENTICODE_CHECK
 
 PROGRAM = maintenanceservice$(BIN_SUFFIX)
 DIST_PROGRAM = maintenanceservice$(BIN_SUFFIX)
 
--- a/toolkit/mozapps/update/common/Makefile.in
+++ b/toolkit/mozapps/update/common/Makefile.in
@@ -56,17 +56,19 @@ CPPSRCS = \
 
 EXPORTS = updatelogging.h \
   updatedefines.h \
   $(NULL)
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
 CPPSRCS += updatehelper.cpp \
   uachelper.cpp \
+  pathhash.cpp \
   $(NULL)
 
 EXPORTS = updatehelper.h \
   uachelper.h \
+  pathhash.h \
   $(NULL)
 endif
 
 include $(topsrcdir)/config/rules.mk
 
rename from toolkit/components/maintenanceservice/pathhash.cpp
rename to toolkit/mozapps/update/common/pathhash.cpp
rename from toolkit/components/maintenanceservice/pathhash.h
rename to toolkit/mozapps/update/common/pathhash.h
--- a/toolkit/mozapps/update/updater/updater.cpp
+++ b/toolkit/mozapps/update/updater/updater.cpp
@@ -1378,16 +1378,17 @@ PatchIfFile::Finish(int status)
   PatchFile::Finish(status);
 }
 
 //-----------------------------------------------------------------------------
 
 #ifdef XP_WIN
 #include "nsWindowsRestart.cpp"
 #include "uachelper.h"
+#include "pathhash.h"
 #endif
 
 static void
 LaunchCallbackApp(const NS_tchar *workingDir, int argc, NS_tchar **argv)
 {
   putenv(const_cast<char*>("NO_EM_RESTART="));
   putenv(const_cast<char*>("MOZ_LAUNCHED_CHILD=1"));
 
@@ -1710,16 +1711,42 @@ int NS_main(int argc, NS_tchar **argv)
       }
 
       PRUnichar *cmdLine = MakeCommandLine(argc - 1, argv + 1);
       if (!cmdLine) {
         CloseHandle(elevatedFileHandle);
         return 1;
       }
 
+      // Make sure the service registry entries for the instsallation path
+      // are available.  If not don't use the service.
+      if (useService) {
+        WCHAR maintenanceServiceKey[MAX_PATH + 1];
+        if (CalculateRegistryPathFromFilePath(argv[2], maintenanceServiceKey)) {
+          HKEY baseKey;
+          LSTATUS retCode = RegOpenKeyExW(HKEY_LOCAL_MACHINE, 
+                                          maintenanceServiceKey, 0, 
+                                          KEY_READ | KEY_WOW64_64KEY, 
+                                          &baseKey);
+          if (retCode != ERROR_SUCCESS) {
+            // Our tests run with a different apply directory for each test.
+            // We use this registry key on our test slaves to store the 
+            // allowed name/issuers.
+            retCode = RegOpenKeyExW(HKEY_LOCAL_MACHINE, 
+                                    L"SOFTWARE\\Mozilla\\MaintenanceService"
+                                    L"\\3932ecacee736d366d6436db0f55bce4", 0,
+                                    KEY_READ | KEY_WOW64_64KEY, &baseKey);
+          }
+          useService = retCode == ERROR_SUCCESS;
+          RegCloseKey(baseKey);
+        } else {
+          useService = FALSE;
+        }
+      }
+
       HANDLE serviceInUseEvent = NULL;
       if (useService) {
         // Make sure the service isn't already busy processing another work item.
         // This event will also be used by the service who will signal it when
         // it is done with the udpate.
         serviceInUseEvent = CreateEventW(NULL, TRUE, 
                                          FALSE, SERVICE_EVENT_NAME);