Browse Source

Fixed permissions check in open_registry().

We were checking for the presence of KEY_WRITE in the SAM to decide
whether to call RegCreateKeyEx() or RegOpenKeyEx().  KEY_WRITE is an
alias for STANDARD_RIGHTS_WRITE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY so
the function was incorrectly calling RegCreateKeyEx() even when
RegOpenKeyEx() would be more appropriate.
Iain Patterson 7 years ago
parent
commit
2dbaf62e06
1 changed files with 1 additions and 1 deletions
  1. 1 1
      registry.cpp

+ 1 - 1
registry.cpp

@@ -470,7 +470,7 @@ HKEY open_registry(const TCHAR *service_name, const TCHAR *sub, REGSAM sam) {
     return 0;
   }
 
-  if (sam & KEY_WRITE) {
+  if (sam & KEY_SET_VALUE) {
     if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, registry, 0, 0, REG_OPTION_NON_VOLATILE, sam, 0, &key, 0) != ERROR_SUCCESS) {
       log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OPENKEY_FAILED, registry, error_string(GetLastError()), 0);
       return 0;