Browse Source

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.
Iain Patterson 8 years ago
parent
commit
db1d114d82
2 changed files with 3 additions and 2 deletions
  1. BIN
      messages.mc
  2. 3 2
      service.cpp

BIN
messages.mc


+ 3 - 2
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;
   }