Really get canonical name in open_service().
authorIain Patterson <me@iain.cx>
Sun, 2 Mar 2014 14:22:53 +0000 (14:22 +0000)
committerIain Patterson <me@iain.cx>
Sun, 2 Mar 2014 18:24:24 +0000 (18:24 +0000)
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.

service.cpp

index 3205dcc..4b14d17 100644 (file)
@@ -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);\r
   if (service_handle) {\r
     if (canonical_name && canonical_name != service_name) {\r
-      if (_sntprintf_s(canonical_name, canonical_namelen, _TRUNCATE, _T("%s"), service_name) < 0) {\r
-        print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("canonical_name"), _T("open_service()"));\r
-        return 0;\r
-      }\r
+      TCHAR displayname[SERVICE_NAME_LENGTH];\r
+      unsigned long displayname_len = (unsigned long) _countof(displayname);\r
+      GetServiceDisplayName(services, service_name, displayname, &displayname_len);\r
+      unsigned long keyname_len = canonical_namelen;\r
+      GetServiceKeyName(services, displayname, canonical_name, &keyname_len);\r
     }\r
     return service_handle;\r
   }\r