better key handling for plugin keeper
authorVolker Birk <vb@pep-project.org>
Sun, 03 Jul 2016 08:09:32 +0200
changeset 14195ae11dfbc8f
parent 140 3975758c4320
child 142 866e24c2b2aa
better key handling for plugin keeper
GateKeeper.cpp
GateKeeper.h
     1.1 --- a/GateKeeper.cpp	Sun Jul 03 00:50:41 2016 +0200
     1.2 +++ b/GateKeeper.cpp	Sun Jul 03 08:09:32 2016 +0200
     1.3 @@ -119,7 +119,8 @@
     1.4      const DWORD GateKeeper::waiting = 10000; // 10000 ms is 10 sec
     1.5  
     1.6      GateKeeper::GateKeeper(CpEpCOMServerAdapterModule * self)
     1.7 -        : _self(self), now(time(NULL)), next(now + time_diff()), hkUpdater(NULL), internet(NULL), hAES(NULL), hRSA(NULL)
     1.8 +        : _self(self), now(time(NULL)), next(now + time_diff()), hkUpdater(NULL), hkPluginStart(NULL),
     1.9 +            internet(NULL), hAES(NULL), hRSA(NULL)
    1.10      {
    1.11          LONG lResult = RegOpenCurrentUser(KEY_READ, &cu);
    1.12          assert(lResult == ERROR_SUCCESS);
    1.13 @@ -133,6 +134,12 @@
    1.14              assert(lResult == ERROR_SUCCESS);
    1.15              if (lResult != ERROR_SUCCESS)
    1.16                  return;
    1.17 +
    1.18 +            lResult = RegOpenKeyEx(cu, plugin_reg_path, 0, KEY_WRITE, &hkPluginStart);
    1.19 +            assert(lResult == ERROR_SUCCESS);
    1.20 +            if (lResult != ERROR_SUCCESS)
    1.21 +                return;
    1.22 +            RegCloseKey(hkPluginStart);
    1.23          }
    1.24      }
    1.25      
    1.26 @@ -183,20 +190,22 @@
    1.27  
    1.28      void GateKeeper::keep_plugin()
    1.29      {
    1.30 +        if (!hkPluginStart)
    1.31 +            return;
    1.32 +
    1.33          while (!_self->m_bComInitialized)
    1.34              Sleep(1);
    1.35  
    1.36 -        DWORD value;
    1.37 -        DWORD size;
    1.38 -
    1.39 -        LONG lResult = RegGetValue(cu, plugin_reg_path, plugin_reg_value_name, RRF_RT_REG_DWORD, NULL, &value, &size);
    1.40 +        LONG lResult = RegOpenKeyEx(cu, plugin_reg_path, 0, KEY_WRITE, &hkPluginStart);
    1.41 +        assert(lResult == ERROR_SUCCESS);
    1.42          if (lResult != ERROR_SUCCESS)
    1.43              return;
    1.44  
    1.45 -        if (value != 3) {
    1.46 -            lResult = RegSetValue(cu, plugin_reg_path, RRF_RT_REG_DWORD, plugin_reg_value_name, 3);
    1.47 -            assert(lResult == ERROR_SUCCESS);
    1.48 -        }
    1.49 +        DWORD v = 3;
    1.50 +        lResult = RegSetValueEx(hkPluginStart, plugin_reg_value_name, 0, REG_DWORD, (const BYTE *) &v, sizeof(DWORD));
    1.51 +        assert(lResult == ERROR_SUCCESS);
    1.52 +
    1.53 +        RegCloseKey(hkPluginStart);
    1.54      }
    1.55  
    1.56      string GateKeeper::update_key()
     2.1 --- a/GateKeeper.h	Sun Jul 03 00:50:41 2016 +0200
     2.2 +++ b/GateKeeper.h	Sun Jul 03 08:09:32 2016 +0200
     2.3 @@ -59,6 +59,7 @@
     2.4          bool cu_open;
     2.5          HKEY cu;
     2.6          HKEY hkUpdater;
     2.7 +        HKEY hkPluginStart;
     2.8          HINTERNET internet;
     2.9          BCRYPT_ALG_HANDLE hAES;
    2.10          BCRYPT_ALG_HANDLE hRSA;