Don't complain if the service has no ObjectName.
[nssm.git] / gui.cpp
diff --git a/gui.cpp b/gui.cpp
index 888ef02..4ab19d7 100644 (file)
--- a/gui.cpp
+++ b/gui.cpp
@@ -367,13 +367,25 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
     }\r
 \r
     /*\r
-      Special case LOCALSYSTEM.\r
+      Special case for well-known accounts.\r
       Ignore the password if we're editing and the username hasn't changed.\r
     */\r
-    if (str_equiv(service->username, NSSM_LOCALSYSTEM_ACCOUNT)) {\r
-      HeapFree(GetProcessHeap(), 0, service->username);\r
-      service->username = 0;\r
-      service->usernamelen = 0;\r
+    const TCHAR *well_known = well_known_username(service->username);
+    if (well_known) {\r
+      if (str_equiv(well_known, NSSM_LOCALSYSTEM_ACCOUNT)) {
+        HeapFree(GetProcessHeap(), 0, service->username);\r
+        service->username = 0;\r
+        service->usernamelen = 0;\r
+      }
+      else {
+        service->usernamelen = _tcslen(well_known) + 1;
+        service->username = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, service->usernamelen * sizeof(TCHAR));
+        if (! service->username) {
+          print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("canon"), _T("install()"));
+          return 6;
+        }
+        memmove(service->username, well_known, service->usernamelen * sizeof(TCHAR));
+      }
     }\r
     else {\r
       /* Password. */\r