Browse Source

Really get canonical name in open_service().

The open_service() function would return the canonical service name if
passed a display name but would return the requested name as-is when
called with a valid service name.  We now retrieve the display name and
map back to the key name so that the returned string is capitalised
exactly as it appears in the services database.
Iain Patterson 8 years ago
parent
commit
14d5a10605
1 changed files with 5 additions and 4 deletions
  1. 5 4
      service.cpp

+ 5 - 4
service.cpp

@@ -268,10 +268,11 @@ SC_HANDLE open_service(SC_HANDLE services, TCHAR *service_name, unsigned long ac
   SC_HANDLE service_handle = OpenService(services, service_name, access);
   if (service_handle) {
     if (canonical_name && canonical_name != service_name) {
-      if (_sntprintf_s(canonical_name, canonical_namelen, _TRUNCATE, _T("%s"), service_name) < 0) {
-        print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("canonical_name"), _T("open_service()"));
-        return 0;
-      }
+      TCHAR displayname[SERVICE_NAME_LENGTH];
+      unsigned long displayname_len = (unsigned long) _countof(displayname);
+      GetServiceDisplayName(services, service_name, displayname, &displayname_len);
+      unsigned long keyname_len = canonical_namelen;
+      GetServiceKeyName(services, displayname, canonical_name, &keyname_len);
     }
     return service_handle;
   }