From db1d114d828b28fe91196d0f72e27502a052119b Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Wed, 1 Jan 2014 21:44:48 +0000 Subject: [PATCH] Fixed bugs when creating a service. A null argument to grant_logon_as_service() would cause a crash. We were calling CreateService() with the wrong access mask. We weren't printing any error message when CreateService() failed. --- messages.mc | Bin 120226 -> 120346 bytes service.cpp | 5 +++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/messages.mc b/messages.mc index 376132ffdf4c88d1ea3a9dfdc68b1e8bac9d9f67..b67d79bfd77c8e85ccd182d508367ee1b03e4a35 100644 GIT binary patch delta 90 zcmZ3qntj$9_6^6(xSbh_7*ZJ$8A=#ZC-;}SPQOsg$TrzVm2WbWxgMIN`Q!(Ma+5R6 VHPFNrC%Hs4zcJtb#+-56TmU7I9ufcm delta 65 zcmV-H0KWg4tOug22e8IAlR%>=lfYR9lQ2sTl6wS`E;lNZK%*Lya84SN&`Si9xHl-1 Xj-*VJ;298;{yGYSZaBAYI03AkZ<`vH diff --git a/service.cpp b/service.cpp index d7c7e6e..eaeb797 100644 --- a/service.cpp +++ b/service.cpp @@ -262,6 +262,7 @@ int get_service_username(const TCHAR *service_name, const QUERY_SERVICE_CONFIG * } int grant_logon_as_service(const TCHAR *username) { + if (! username) return 0; if (str_equiv(username, NSSM_LOCALSYSTEM_ACCOUNT)) return 0; /* Open Policy object. */ @@ -781,9 +782,9 @@ int install_service(nssm_service_t *service) { GetModuleFileName(0, service->image, _countof(service->image)); /* Create the service - settings will be changed in edit_service() */ - service->handle = CreateService(services, service->name, service->name, SC_MANAGER_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, service->image, 0, 0, 0, 0, 0); + service->handle = CreateService(services, service->name, service->name, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, service->image, 0, 0, 0, 0, 0); if (! service->handle) { - print_message(stderr, NSSM_MESSAGE_CREATESERVICE_FAILED); + print_message(stderr, NSSM_MESSAGE_CREATESERVICE_FAILED, error_string(GetLastError())); CloseServiceHandle(services); return 5; } -- 2.7.4