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.
master
Iain Patterson 11 years ago
parent 67795adae0
commit db1d114d82

@ -315,12 +315,15 @@
Severity = Informational Severity = Informational
Language = English Language = English
Error creating service! Error creating service!
CreateService(): %s
. .
Language = French Language = French
Erreur à la création du service! Erreur à la création du service!
CreateService(): %s
. .
Language = Italian Language = Italian
Errore creazione servizio! Errore creazione servizio!
CreateService(): %s
. .
MessageId = +1 MessageId = +1

@ -262,6 +262,7 @@ int get_service_username(const TCHAR *service_name, const QUERY_SERVICE_CONFIG *
} }
int grant_logon_as_service(const TCHAR *username) { int grant_logon_as_service(const TCHAR *username) {
if (! username) return 0;
if (str_equiv(username, NSSM_LOCALSYSTEM_ACCOUNT)) return 0; if (str_equiv(username, NSSM_LOCALSYSTEM_ACCOUNT)) return 0;
/* Open Policy object. */ /* Open Policy object. */
@ -781,9 +782,9 @@ int install_service(nssm_service_t *service) {
GetModuleFileName(0, service->image, _countof(service->image)); GetModuleFileName(0, service->image, _countof(service->image));
/* Create the service - settings will be changed in edit_service() */ /* 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) { if (! service->handle) {
print_message(stderr, NSSM_MESSAGE_CREATESERVICE_FAILED); print_message(stderr, NSSM_MESSAGE_CREATESERVICE_FAILED, error_string(GetLastError()));
CloseServiceHandle(services); CloseServiceHandle(services);
return 5; return 5;
} }

Loading…
Cancel
Save