#include "nssm.h"\r
\r
-static enum { NSSM_TAB_APPLICATION, NSSM_TAB_DETAILS, NSSM_TAB_SHUTDOWN, NSSM_TAB_EXIT, NSSM_TAB_IO, NSSM_TAB_ROTATION, NSSM_TAB_ENVIRONMENT, NSSM_NUM_TABS };\r
+static enum { NSSM_TAB_APPLICATION, NSSM_TAB_DETAILS, NSSM_TAB_LOGON, NSSM_TAB_SHUTDOWN, NSSM_TAB_EXIT, NSSM_TAB_IO, NSSM_TAB_ROTATION, NSSM_TAB_ENVIRONMENT, NSSM_NUM_TABS };\r
static HWND tablist[NSSM_NUM_TABS];\r
static int selected_tab;\r
\r
\r
/* Find window size */\r
if (! GetWindowRect(window, &size)) return;\r
- \r
+\r
/* Find desktop window */\r
desktop = GetDesktopWindow();\r
if (! desktop) return;\r
EnableWindow(GetDlgItem(tablist[NSSM_TAB_SHUTDOWN], dependent), enabled);\r
}\r
\r
+static inline void set_logon_enabled(unsigned char enabled) {\r
+ EnableWindow(GetDlgItem(tablist[NSSM_TAB_LOGON], IDC_USERNAME), enabled);\r
+ EnableWindow(GetDlgItem(tablist[NSSM_TAB_LOGON], IDC_PASSWORD1), enabled);\r
+ EnableWindow(GetDlgItem(tablist[NSSM_TAB_LOGON], IDC_PASSWORD2), enabled);\r
+}\r
+\r
static inline void set_rotation_enabled(unsigned char enabled) {\r
EnableWindow(GetDlgItem(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_SECONDS), enabled);\r
EnableWindow(GetDlgItem(tablist[NSSM_TAB_ROTATION], IDC_ROTATE_BYTES_LOW), enabled);\r
service->startup = (unsigned long) SendMessage(combo, CB_GETCURSEL, 0, 0);\r
if (service->startup == CB_ERR) service->startup = 0;\r
\r
+ /* Get logon stuff. */\r
+ if (SendDlgItemMessage(tablist[NSSM_TAB_LOGON], IDC_LOCALSYSTEM, BM_GETCHECK, 0, 0) & BST_CHECKED) {\r
+ if (SendDlgItemMessage(tablist[NSSM_TAB_LOGON], IDC_INTERACT, BM_GETCHECK, 0, 0) & BST_CHECKED) {\r
+ service->type |= SERVICE_INTERACTIVE_PROCESS;\r
+ }\r
+ }\r
+ else {\r
+ /* Username. */\r
+ service->usernamelen = SendMessage(GetDlgItem(tablist[NSSM_TAB_LOGON], IDC_USERNAME), WM_GETTEXTLENGTH, 0, 0);\r
+ if (! service->usernamelen) {\r
+ popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_USERNAME);\r
+ return 6;\r
+ }\r
+ service->usernamelen++;\r
+\r
+ service->username = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, service->usernamelen * sizeof(TCHAR));\r
+ if (! service->username) {\r
+ popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("account name"), _T("install()"));\r
+ return 6;\r
+ }\r
+ if (! GetDlgItemText(tablist[NSSM_TAB_LOGON], IDC_USERNAME, service->username, (int) service->usernamelen)) {\r
+ HeapFree(GetProcessHeap(), 0, service->username);\r
+ service->username = 0;\r
+ service->usernamelen = 0;\r
+ popup_message(MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_INVALID_USERNAME);\r
+ return 6;\r
+ }\r
+\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
+\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 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
+ /* 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
/* Get stop method stuff. */\r
check_stop_method(service, NSSM_STOP_METHOD_CONSOLE, IDC_METHOD_CONSOLE);\r
check_stop_method(service, NSSM_STOP_METHOD_WINDOW, IDC_METHOD_WINDOW);\r
browse(dlg, buffer, OFN_NOVALIDATE, NSSM_GUI_BROWSE_FILTER_DIRECTORIES, 0);\r
break;\r
\r
+ /* Log on. */\r
+ case IDC_LOCALSYSTEM:\r
+ set_logon_enabled(0);\r
+ break;\r
+\r
+ case IDC_ACCOUNT:\r
+ set_logon_enabled(1);\r
+ break;\r
+\r
/* Shutdown methods. */\r
case IDC_METHOD_CONSOLE:\r
set_timeout_enabled(LOWORD(w), IDC_KILL_CONSOLE);\r
SendMessage(combo, CB_INSERTSTRING, NSSM_STARTUP_DISABLED, (LPARAM) message_string(NSSM_GUI_STARTUP_DISABLED));\r
SendMessage(combo, CB_SETCURSEL, NSSM_STARTUP_AUTOMATIC, 0);\r
\r
+ /* Logon tab. */\r
+ tab.pszText = message_string(NSSM_GUI_TAB_LOGON);\r
+ tab.cchTextMax = (int) _tcslen(tab.pszText);\r
+ SendMessage(tabs, TCM_INSERTITEM, NSSM_TAB_LOGON, (LPARAM) &tab);\r
+ tablist[NSSM_TAB_LOGON] = CreateDialog(0, MAKEINTRESOURCE(IDD_LOGON), window, tab_dlg);\r
+ ShowWindow(tablist[NSSM_TAB_LOGON], SW_HIDE);\r
+\r
+ /* Set defaults. */\r
+ CheckRadioButton(tablist[NSSM_TAB_LOGON], IDC_LOCALSYSTEM, IDC_ACCOUNT, IDC_LOCALSYSTEM);\r
+ set_logon_enabled(0);\r
+\r
/* Shutdown tab. */\r
tab.pszText = message_string(NSSM_GUI_TAB_SHUTDOWN);\r
tab.cchTextMax = (int) _tcslen(tab.pszText);\r
}\r
\r
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL\r
+IDD_LOGON DIALOG 9, 20, 261, 75\r
+STYLE DS_SHELLFONT | WS_VISIBLE | WS_CHILD | DS_CONTROL\r
+FONT 8, "MS Sans Serif"\r
+{\r
+ GROUPBOX "Log on as", IDC_STATIC, 7, 7, 251, 68\r
+ AUTORADIOBUTTON "Local System account", IDC_LOCALSYSTEM, 13, 18, 86, 8\r
+ AUTOCHECKBOX "Allow service to interact with desktop", IDC_INTERACT, 101, 18, 133, 8\r
+ AUTORADIOBUTTON "This account:", IDC_ACCOUNT, 13, 32, 59, 8\r
+ EDITTEXT IDC_USERNAME, 75, 30, 178, 12, ES_AUTOHSCROLL\r
+ LTEXT "Password:", IDC_STATIC, 25, 46, 32, 8, SS_LEFT\r
+ EDITTEXT IDC_PASSWORD1, 75, 44, 178, 12, ES_AUTOHSCROLL | ES_PASSWORD\r
+ LTEXT "Confirm:", IDC_STATIC, 25, 60, 26, 8, SS_LEFT\r
+ EDITTEXT IDC_PASSWORD2, 75, 58, 178, 12, ES_AUTOHSCROLL | ES_PASSWORD\r
+}\r
+\r
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL\r
IDD_SHUTDOWN DIALOG 9, 20, 261, 75\r
STYLE DS_SHELLFONT | WS_VISIBLE | WS_CHILD | DS_CONTROL\r
FONT 8, "MS Sans Serif"\r
void set_nssm_service_defaults(nssm_service_t *service) {\r
if (! service) return;\r
\r
+ service->type = SERVICE_WIN32_OWN_PROCESS;\r
service->stdin_sharing = NSSM_STDIN_SHARING;\r
service->stdin_disposition = NSSM_STDIN_DISPOSITION;\r
service->stdin_flags = NSSM_STDIN_FLAGS;\r
/* Free memory for a service. */\r
void cleanup_nssm_service(nssm_service_t *service) {\r
if (! service) return;\r
+ if (service->username) HeapFree(GetProcessHeap(), 0, service->username);\r
+ if (service->password) {\r
+ SecureZeroMemory(service->password, service->passwordlen);\r
+ HeapFree(GetProcessHeap(), 0, service->password);\r
+ }\r
if (service->env) HeapFree(GetProcessHeap(), 0, service->env);\r
if (service->env_extra) HeapFree(GetProcessHeap(), 0, service->env_extra);\r
if (service->handle) CloseServiceHandle(service->handle);\r
TCHAR command[MAX_PATH];\r
GetModuleFileName(0, command, _countof(command));\r
\r
+ /*\r
+ The only two valid flags for service type are SERVICE_WIN32_OWN_PROCESS\r
+ and SERVICE_INTERACTIVE_PROCESS.\r
+ */\r
+ service->type &= SERVICE_INTERACTIVE_PROCESS;\r
+ service->type |= SERVICE_WIN32_OWN_PROCESS;\r
+\r
/* Startup type. */\r
unsigned long startup;\r
switch (service->startup) {\r
if (! service->displayname[0]) _sntprintf_s(service->displayname, _countof(service->displayname), _TRUNCATE, _T("%s"), service->name);\r
\r
/* Create the service */\r
- service->handle = CreateService(services, service->name, service->displayname, SC_MANAGER_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, startup, SERVICE_ERROR_NORMAL, command, 0, 0, 0, 0, 0);\r
+ service->handle = CreateService(services, service->name, service->displayname, SC_MANAGER_ALL_ACCESS, service->type, startup, SERVICE_ERROR_NORMAL, command, 0, 0, 0, service->username, service->password);\r
if (! service->handle) {\r
print_message(stderr, NSSM_MESSAGE_CREATESERVICE_FAILED);\r
CloseServiceHandle(services);\r