From: Iain Patterson Date: Fri, 2 Jan 2015 11:31:19 +0000 (+0000) Subject: Fixed permissions check in open_registry(). X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=2dbaf62e06018a7d0a934c79bd9f39b81dc43694;p=nssm.git 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. --- diff --git a/registry.cpp b/registry.cpp index 42c5425..4abf595 100644 --- a/registry.cpp +++ b/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;