Don't complain if the service has no ObjectName.
authorIain Patterson <me@iain.cx>
Mon, 3 Feb 2014 18:40:27 +0000 (18:40 +0000)
committerIain Patterson <me@iain.cx>
Mon, 3 Feb 2014 18:40:27 +0000 (18:40 +0000)
Not all service types run under an account.

service.cpp

index ecd1419..fe67262 100644 (file)
@@ -472,17 +472,19 @@ int get_service_username(const TCHAR *service_name, const QUERY_SERVICE_CONFIG *
 \r
   if (! qsc) return 1;\r
 \r
-  if (is_localsystem(qsc->lpServiceStartName)) return 0;\r
+  if (qsc->lpServiceStartName[0]) {\r
+    if (is_localsystem(qsc->lpServiceStartName)) return 0;\r
 \r
-  size_t len = _tcslen(qsc->lpServiceStartName);\r
-  *username = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(TCHAR));\r
-  if (! *username) {\r
-    print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("username"), _T("get_service_username()"));\r
-    return 2;\r
-  }\r
+    size_t len = _tcslen(qsc->lpServiceStartName);\r
+    *username = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(TCHAR));\r
+    if (! *username) {\r
+      print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("username"), _T("get_service_username()"));\r
+      return 2;\r
+    }\r
 \r
-  memmove(*username, qsc->lpServiceStartName, (len + 1) * sizeof(TCHAR));\r
-  *usernamelen = len;\r
+    memmove(*username, qsc->lpServiceStartName, (len + 1) * sizeof(TCHAR));\r
+    *usernamelen = len;\r
+  }\r
 \r
   return 0;\r
 }\r