Handle well-known account names.
[nssm.git] / gui.cpp
diff --git a/gui.cpp b/gui.cpp
index 888ef02..9f6f9ba 100644 (file)
--- a/gui.cpp
+++ b/gui.cpp
@@ -367,13 +367,33 @@ 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
+    if (! requires_password(service->username)) {\r
+      if (is_localsystem(service->username)) {
+        HeapFree(GetProcessHeap(), 0, service->username);\r
+        service->username = 0;\r
+        service->usernamelen = 0;\r
+      }
+      else {
+        TCHAR *canon = canonical_username(service->username);
+        HeapFree(GetProcessHeap(), 0, service->username);\r
+        service->username = 0;\r
+        service->usernamelen = 0;\r
+        if (canon) {
+          service->usernamelen = _tcslen(canon) + 1;
+          service->username = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, service->usernamelen * sizeof(TCHAR));
+          if (! service->username) {
+            LocalFree(canon);
+            print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("canon"), _T("install()"));
+            return 6;
+          }
+          memmove(service->username, canon, service->usernamelen * sizeof(TCHAR));
+          LocalFree(canon);
+        }
+        else return 6;
+      }
     }\r
     else {\r
       /* Password. */\r