X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=service.cpp;h=c9f47000515e4a4a65ce63b2e2ce47a9bca81600;hb=71764fe41e37f36bcbc89ac62f664aeda4240790;hp=88c1820d670aca20be0a166f7ee4fd87217828a6;hpb=adda6b2aaf2a5631d0dfa0371f8f93855176a9c8;p=nssm.git diff --git a/service.cpp b/service.cpp index 88c1820..c9f4700 100644 --- a/service.cpp +++ b/service.cpp @@ -1274,19 +1274,33 @@ int edit_service(nssm_service_t *service, bool editing) { TCHAR *username = 0; TCHAR *canon = 0; TCHAR *password = 0; + boolean virtual_account = false; if (service->usernamelen) { username = service->username; - if (canonicalise_username(username, &canon)) return 5; - if (service->passwordlen) password = service->password; + if (is_virtual_account(service->name, username)) { + virtual_account = true; + canon = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, (service->usernamelen + 1) * sizeof(TCHAR)); + if (! canon) { + print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY, _T("canon"), _T("edit_service()")); + return 5; + } + memmove(canon, username, (service->usernamelen + 1) * sizeof(TCHAR)); + } + else { + if (canonicalise_username(username, &canon)) return 5; + if (service->passwordlen) password = service->password; + } } else if (editing) username = canon = NSSM_LOCALSYSTEM_ACCOUNT; - if (well_known_username(canon)) password = _T(""); - else { - if (grant_logon_as_service(canon)) { - if (canon != username) HeapFree(GetProcessHeap(), 0, canon); - print_message(stderr, NSSM_MESSAGE_GRANT_LOGON_AS_SERVICE_FAILED, username); - return 5; + if (! virtual_account) { + if (well_known_username(canon)) password = _T(""); + else { + if (grant_logon_as_service(canon)) { + if (canon != username) HeapFree(GetProcessHeap(), 0, canon); + print_message(stderr, NSSM_MESSAGE_GRANT_LOGON_AS_SERVICE_FAILED, username); + return 5; + } } } @@ -2078,7 +2092,7 @@ void CALLBACK end_service(void *arg, unsigned char why) { stop_service(service, exitcode, false, default_action); wait_for_hooks(service, false); free_imports(); - exit(exitcode); + nssm_exit(exitcode); } } @@ -2212,7 +2226,9 @@ awaited: return ret; } -int list_nssm_services() { +int list_nssm_services(int argc, TCHAR **argv) { + bool including_native = (argc > 0 && str_equiv(argv[0], _T("all"))); + /* Open service manager. */ SC_HANDLE services = open_service_manager(SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE); if (! services) { @@ -2259,7 +2275,7 @@ int list_nssm_services() { get_parameters(service, 0); /* We manage the service if we have an Application. */ - if (service->exe[0]) _tprintf(_T("%s\n"), service->name); + if (including_native || service->exe[0]) _tprintf(_T("%s\n"), service->name); cleanup_nssm_service(service); }