Imported Upstream version 2.7
[ossec-hids.git] / src / win32 / win_service.c
index d17d7b8..1989c4e 100755 (executable)
@@ -1,4 +1,5 @@
-/* @(#) $Id$ */
+/* @(#) $Id: ./src/win32/win_service.c, 2011/09/08 dcid Exp $
+ */
 
 /* Copyright (C) 2009 Trend Micro Inc.
  * All rights reserved.
@@ -8,7 +9,7 @@
  * License (version 2) as published by the FSF - Free Software
  * Foundation.
  *
- * License details at the LICENSE file included with OSSEC or 
+ * License details at the LICENSE file included with OSSEC or
  * online at: http://www.ossec.net/en/licensing.html
  */
 
@@ -24,8 +25,8 @@
 #endif
 
 static LPTSTR g_lpszServiceName        = "OssecSvc";
-static LPTSTR g_lpszServiceDisplayName = "OSSEC Hids";
-static LPTSTR g_lpszServiceDescription = "OSSEC Hids Windows Agent";
+static LPTSTR g_lpszServiceDisplayName = "OSSEC HIDS";
+static LPTSTR g_lpszServiceDescription = "OSSEC HIDS Windows Agent";
 
 static SERVICE_STATUS          ossecServiceStatus;
 static SERVICE_STATUS_HANDLE   ossecServiceStatusHandle;
@@ -62,7 +63,7 @@ int os_start_service()
                     rc = -1;
                 }
             }
-            
+
             CloseServiceHandle(schService);
         }
 
@@ -89,13 +90,13 @@ int os_stop_service()
         if(schService)
         {
             SERVICE_STATUS lpServiceStatus;
-            
-            if(ControlService(schService, 
+
+            if(ControlService(schService,
                               SERVICE_CONTROL_STOP, &lpServiceStatus))
             {
                 rc = 1;
             }
-            
+
             CloseServiceHandle(schService);
         }
 
@@ -123,7 +124,7 @@ int CheckServiceRunning()
         {
             /* Checking status */
             SERVICE_STATUS lpServiceStatus;
-            
+
             if(QueryServiceStatus(schService, &lpServiceStatus))
             {
                 if(lpServiceStatus.dwCurrentState == SERVICE_RUNNING)
@@ -133,14 +134,14 @@ int CheckServiceRunning()
             }
             CloseServiceHandle(schService);
         }
-        
+
         CloseServiceHandle(schSCManager);
     }
 
     return(rc);
 }
 
-                    
+
 /* int InstallService()
  * Install the OSSEC HIDS agent service.
  */
@@ -151,17 +152,17 @@ int InstallService(char *path)
     SC_HANDLE schSCManager, schService;
     LPCTSTR lpszBinaryPathName = NULL;
     SERVICE_DESCRIPTION sdBuf;
-    
+
 
     /* Cleaning up some variables */
     buffer[MAX_PATH] = '\0';
-    
-    
+
+
     /* Executable path -- it must be called with the
      * full path
      */
     lpszBinaryPathName = path;
+
     /* Opening the services database */
     schSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
 
@@ -171,7 +172,7 @@ int InstallService(char *path)
     }
 
     /* Creating the service */
-    schService = CreateService(schSCManager, 
+    schService = CreateService(schSCManager,
                                g_lpszServiceName,
                                g_lpszServiceDisplayName,
                                SERVICE_ALL_ACCESS,
@@ -180,7 +181,7 @@ int InstallService(char *path)
                                SERVICE_ERROR_NORMAL,
                                lpszBinaryPathName,
                                NULL, NULL, NULL, NULL, NULL);
-    
+
     if (schService == NULL)
     {
         goto install_error;
@@ -192,7 +193,7 @@ int InstallService(char *path)
     {
         goto install_error;
     }
-    
+
     CloseServiceHandle(schService);
     CloseServiceHandle(schSCManager);
 
@@ -204,7 +205,7 @@ int InstallService(char *path)
     {
         char local_msg[1025];
         LPVOID lpMsgBuf;
-        
+
         memset(local_msg, 0, 1025);
 
         FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
@@ -227,11 +228,11 @@ int InstallService(char *path)
 /* int UninstallService()
  * Uninstall the OSSEC HIDS agent service.
  */
-int UninstallService() 
+int UninstallService()
 {
     SC_HANDLE schSCManager, schService;
 
-    
+
     /* Removing from the services database */
     schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
     if (schSCManager)
@@ -256,7 +257,7 @@ int UninstallService()
 
     fprintf(stderr, " [%s] Error removing from "
                     "the Services database.\n", ARGV0);
-    
+
     return(0);
 }
 
@@ -284,7 +285,7 @@ VOID WINAPI OssecServiceCtrlHandler(DWORD dwOpcode)
     }
     return;
 }
+
 
 /** void WinSetError()
  * Sets the error code in the services
@@ -294,11 +295,11 @@ void WinSetError()
     OssecServiceCtrlHandler(SERVICE_CONTROL_STOP);
 }
 
+
 /** int os_WinMain(int argc, char **argv)
  * Initializes OSSEC dispatcher
  */
-int os_WinMain(int argc, char **argv) 
+int os_WinMain(int argc, char **argv)
 {
     SERVICE_TABLE_ENTRY   steDispatchTable[] =
     {
@@ -329,8 +330,8 @@ void WINAPI OssecServiceStart (DWORD argc, LPTSTR *argv)
     ossecServiceStatus.dwCheckPoint             = 0;
     ossecServiceStatus.dwWaitHint               = 0;
 
-    ossecServiceStatusHandle = 
-        RegisterServiceCtrlHandler(g_lpszServiceName, 
+    ossecServiceStatusHandle =
+        RegisterServiceCtrlHandler(g_lpszServiceName,
                                    OssecServiceCtrlHandler);
 
     if (ossecServiceStatusHandle == (SERVICE_STATUS_HANDLE)0)