Fixed changing service password.
authorIain Patterson <me@iain.cx>
Sat, 28 Dec 2013 16:30:42 +0000 (16:30 +0000)
committerIain Patterson <me@iain.cx>
Sat, 28 Dec 2013 17:12:12 +0000 (17:12 +0000)
Ensure that we still process a password change even if the username is
the same.
Ensure we handle all errors from edit_service().

gui.cpp

diff --git a/gui.cpp b/gui.cpp
index 6fc5162..6832129 100644 (file)
--- a/gui.cpp
+++ b/gui.cpp
@@ -327,82 +327,86 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
       service->username = 0;\r
       service->usernamelen = 0;\r
     }\r
-    else if (! orig_service || ! orig_service->username || ! str_equiv(service->username, orig_service->username)) {\r
+    else {\r
       /* Password. */\r
       service->passwordlen = SendMessage(GetDlgItem(tablist[NSSM_TAB_LOGON], IDC_PASSWORD1), WM_GETTEXTLENGTH, 0, 0);\r
-      if (! service->passwordlen) {\r
-        popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_PASSWORD);\r
-        return 6;\r
-      }\r
-      if (SendMessage(GetDlgItem(tablist[NSSM_TAB_LOGON], IDC_PASSWORD2), WM_GETTEXTLENGTH, 0, 0) != service->passwordlen) {\r
-        popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_PASSWORD);\r
-        return 6;\r
-      }\r
-      service->passwordlen++;\r
-\r
-      /* Temporary buffer for password validation. */\r
-      TCHAR *password = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, service->passwordlen * sizeof(TCHAR));\r
-      if (! password) {\r
-        HeapFree(GetProcessHeap(), 0, service->username);\r
-        service->username = 0;\r
-        service->usernamelen = 0;\r
-        popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("password confirmation"), _T("install()"));\r
-        return 6;\r
-      }\r
+      size_t passwordlen = SendMessage(GetDlgItem(tablist[NSSM_TAB_LOGON], IDC_PASSWORD2), WM_GETTEXTLENGTH, 0, 0);\r
 \r
-      /* Actual password buffer. */\r
-      service->password = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, service->passwordlen * sizeof(TCHAR));\r
-      if (! service->password) {\r
-        HeapFree(GetProcessHeap(), 0, password);\r
-        HeapFree(GetProcessHeap(), 0, service->username);\r
-        service->username = 0;\r
-        service->usernamelen = 0;\r
-        popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("password"), _T("install()"));\r
-        return 6;\r
-      }\r
+      if (! orig_service || ! orig_service->username || ! str_equiv(service->username, orig_service->username) || service->passwordlen || passwordlen) {\r
+        if (! service->passwordlen) {\r
+          popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_PASSWORD);\r
+          return 6;\r
+        }\r
+        if (passwordlen != service->passwordlen) {\r
+          popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_PASSWORD);\r
+          return 6;\r
+        }\r
+        service->passwordlen++;\r
+\r
+        /* Temporary buffer for password validation. */\r
+        TCHAR *password = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, service->passwordlen * sizeof(TCHAR));\r
+        if (! password) {\r
+          HeapFree(GetProcessHeap(), 0, service->username);\r
+          service->username = 0;\r
+          service->usernamelen = 0;\r
+          popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("password confirmation"), _T("install()"));\r
+          return 6;\r
+        }\r
 \r
-      /* Get first password. */\r
-      if (! GetDlgItemText(tablist[NSSM_TAB_LOGON], IDC_PASSWORD1, service->password, (int) service->passwordlen)) {\r
-        HeapFree(GetProcessHeap(), 0, password);\r
-        SecureZeroMemory(service->password, service->passwordlen);\r
-        HeapFree(GetProcessHeap(), 0, service->password);\r
-        service->password = 0;\r
-        service->passwordlen = 0;\r
-        HeapFree(GetProcessHeap(), 0, service->username);\r
-        service->username = 0;\r
-        service->usernamelen = 0;\r
-        popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_PASSWORD);\r
-        return 6;\r
-      }\r
+        /* Actual password buffer. */\r
+        service->password = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, service->passwordlen * sizeof(TCHAR));\r
+        if (! service->password) {\r
+          HeapFree(GetProcessHeap(), 0, password);\r
+          HeapFree(GetProcessHeap(), 0, service->username);\r
+          service->username = 0;\r
+          service->usernamelen = 0;\r
+          popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("password"), _T("install()"));\r
+          return 6;\r
+        }\r
 \r
-      /* Get confirmation. */\r
-      if (! GetDlgItemText(tablist[NSSM_TAB_LOGON], IDC_PASSWORD2, password, (int) service->passwordlen)) {\r
-        SecureZeroMemory(password, service->passwordlen);\r
-        HeapFree(GetProcessHeap(), 0, password);\r
-        SecureZeroMemory(service->password, service->passwordlen);\r
-        HeapFree(GetProcessHeap(), 0, service->password);\r
-        service->password = 0;\r
-        service->passwordlen = 0;\r
-        HeapFree(GetProcessHeap(), 0, service->username);\r
-        service->username = 0;\r
-        service->usernamelen = 0;\r
-        popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_PASSWORD);\r
-        return 6;\r
-      }\r
+        /* Get first password. */\r
+        if (! GetDlgItemText(tablist[NSSM_TAB_LOGON], IDC_PASSWORD1, service->password, (int) service->passwordlen)) {\r
+          HeapFree(GetProcessHeap(), 0, password);\r
+          SecureZeroMemory(service->password, service->passwordlen);\r
+          HeapFree(GetProcessHeap(), 0, service->password);\r
+          service->password = 0;\r
+          service->passwordlen = 0;\r
+          HeapFree(GetProcessHeap(), 0, service->username);\r
+          service->username = 0;\r
+          service->usernamelen = 0;\r
+          popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_PASSWORD);\r
+          return 6;\r
+        }\r
 \r
-      /* Compare. */\r
-      if (_tcsncmp(password, service->password, service->passwordlen)) {\r
-        popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_PASSWORD);\r
-        SecureZeroMemory(password, service->passwordlen);\r
-        HeapFree(GetProcessHeap(), 0, password);\r
-        SecureZeroMemory(service->password, service->passwordlen);\r
-        HeapFree(GetProcessHeap(), 0, service->password);\r
-        service->password = 0;\r
-        service->passwordlen = 0;\r
-        HeapFree(GetProcessHeap(), 0, service->username);\r
-        service->username = 0;\r
-        service->usernamelen = 0;\r
-        return 6;\r
+        /* Get confirmation. */\r
+        if (! GetDlgItemText(tablist[NSSM_TAB_LOGON], IDC_PASSWORD2, password, (int) service->passwordlen)) {\r
+          SecureZeroMemory(password, service->passwordlen);\r
+          HeapFree(GetProcessHeap(), 0, password);\r
+          SecureZeroMemory(service->password, service->passwordlen);\r
+          HeapFree(GetProcessHeap(), 0, service->password);\r
+          service->password = 0;\r
+          service->passwordlen = 0;\r
+          HeapFree(GetProcessHeap(), 0, service->username);\r
+          service->username = 0;\r
+          service->usernamelen = 0;\r
+          popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_PASSWORD);\r
+          return 6;\r
+        }\r
+\r
+        /* Compare. */\r
+        if (_tcsncmp(password, service->password, service->passwordlen)) {\r
+          popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_PASSWORD);\r
+          SecureZeroMemory(password, service->passwordlen);\r
+          HeapFree(GetProcessHeap(), 0, password);\r
+          SecureZeroMemory(service->password, service->passwordlen);\r
+          HeapFree(GetProcessHeap(), 0, service->password);\r
+          service->password = 0;\r
+          service->passwordlen = 0;\r
+          HeapFree(GetProcessHeap(), 0, service->username);\r
+          service->username = 0;\r
+          service->usernamelen = 0;\r
+          return 6;\r
+        }\r
       }\r
     }\r
   }\r
@@ -628,6 +632,7 @@ int edit(HWND window, nssm_service_t *orig_service) {
       cleanup_nssm_service(service);\r
       return 4;\r
 \r
+    case 5:\r
     case 6:\r
       popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_EDIT_PARAMETERS_FAILED);\r
       cleanup_nssm_service(service);\r