[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ossec-cvs] ossec-hids: os_win.h (HEAD) ossec-installer.nsi (HEAD) win-files.txt (HEAD) win_service.c (HEAD) [dcid]
- To: ossec-cvs@xxxxxxxxx
- Subject: [ossec-cvs] ossec-hids: os_win.h (HEAD) ossec-installer.nsi (HEAD) win-files.txt (HEAD) win_service.c (HEAD) [dcid]
- From: OSSEC CVS <cvs-commit@xxxxxxxxx>
- Date: Wed, 11 Jul 2007 01:27:01 -0300 (ADT)
- Content-transfer-encoding: 8bit
Module name: ossec-hids
Changes by: dcid 07/07/11 01:26:59
Modified files:
os_win.h ossec-installer.nsi win-files.txt win_service.c
Log message:
Description: Adding start/stop/checkstatus functions to the win_service code (used by the win ui).
Reviewed by: dcid
Bug:
Index: os_win.h
===================================================================
RCS file: /usr/cvsroot/ossec-hids/src/win32/os_win.h,v
diff -u -r1.4 -r1.5
--- os_win.h 17 Jul 2006 01:02:42 -0000 1.4
+++ os_win.h 11 Jul 2007 04:26:59 -0000 1.5
@@ -1,6 +1,6 @@
/* @(#) $Id$ */
-/* Copyright (C) 2003-2006 Daniel B. Cid <dcid@xxxxxxxxx>
+/* Copyright (C) 2003-2007 Daniel B. Cid <dcid@xxxxxxxxx>
* All rights reserved.
*
* This program is a free software; you can redistribute it
@@ -23,6 +23,21 @@
* Uninstall the OSSEC HIDS agent service.
*/
int UninstallService();
+
+
+/** int QueryService():
+ * Checks if service is running.
+ * Return 1 on success (running) or 0 if not.
+ */
+int CheckServiceRunning();
+
+
+/* os_start_service: Starts ossec service */
+int os_start_service();
+
+
+/* os_stop_service: Stops ossec service */
+int os_stop_service();
/** int os_WinMain(int argc, char **argv)
Index: ossec-installer.nsi
===================================================================
RCS file: /usr/cvsroot/ossec-hids/src/win32/ossec-installer.nsi,v
diff -u -r1.27 -r1.28
--- ossec-installer.nsi 9 May 2007 16:46:49 -0000 1.27
+++ ossec-installer.nsi 11 Jul 2007 04:26:59 -0000 1.28
@@ -8,7 +8,7 @@
!define VERSION "1.2"
!define NAME "Ossec HIDS"
-!define /date CDATE "%H:%M:%S %d %b, %Y"
+!define /date CDATE "%b %d %Y at %H:%M:%S"
Name "${NAME} Windows Agent v${VERSION}"
@@ -79,7 +79,7 @@
FileOpen $0 $INSTDIR\VERSION.txt w
IfErrors done
FileWrite $0 "${NAME} v${VERSION} - "
-FileWrite $0 "Installed at: ${CDATE}"
+FileWrite $0 "Installed on ${CDATE}"
FileClose $0
done:
Index: win-files.txt
===================================================================
RCS file: /usr/cvsroot/ossec-hids/src/win32/win-files.txt,v
diff -u -r1.24 -r1.25
--- win-files.txt 30 Jun 2007 21:48:14 -0000 1.24
+++ win-files.txt 11 Jul 2007 04:26:59 -0000 1.25
@@ -52,3 +52,4 @@
win32/LICENSE.txt LICENSE.txt
win32/favicon.ico favicon.ico
win32/icofile.rc icofile.rc
+win32/ui ui
Index: win_service.c
===================================================================
RCS file: /usr/cvsroot/ossec-hids/src/win32/win_service.c,v
diff -u -r1.8 -r1.9
--- win_service.c 18 Apr 2007 02:04:59 -0000 1.8
+++ win_service.c 11 Jul 2007 04:26:59 -0000 1.9
@@ -31,6 +31,112 @@
void WINAPI OssecServiceStart (DWORD argc, LPTSTR *argv);
+
+/* os_start_service: Starts ossec service */
+int os_start_service()
+{
+ int rc = 0;
+ SC_HANDLE schSCManager, schService;
+
+
+ /* Removing from the services database */
+ schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
+ if (schSCManager)
+ {
+ schService = OpenService(schSCManager,g_lpszServiceName,
+ SC_MANAGER_ALL_ACCESS);
+ if(schService)
+ {
+
+ if(StartService(schService, 0, NULL))
+ {
+ rc = 1;
+ }
+ else
+ {
+ if(GetLastError() == ERROR_SERVICE_ALREADY_RUNNING)
+ {
+ rc = -1;
+ }
+ }
+
+ CloseServiceHandle(schService);
+ }
+
+ CloseServiceHandle(schSCManager);
+ }
+
+ return(rc);
+}
+
+
+/* os_start_service: Starts ossec service */
+int os_stop_service()
+{
+ int rc = 0;
+ SC_HANDLE schSCManager, schService;
+
+
+ /* Removing from the services database */
+ schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
+ if (schSCManager)
+ {
+ schService = OpenService(schSCManager,g_lpszServiceName,
+ SC_MANAGER_ALL_ACCESS);
+ if(schService)
+ {
+ SERVICE_STATUS lpServiceStatus;
+
+ if(ControlService(schService,
+ SERVICE_CONTROL_STOP, &lpServiceStatus))
+ {
+ rc = 1;
+ }
+
+ CloseServiceHandle(schService);
+ }
+
+ CloseServiceHandle(schSCManager);
+ }
+
+ return(rc);
+}
+
+
+/* int QueryService(): Checks if service is running. */
+int CheckServiceRunning()
+{
+ int rc = 0;
+ SC_HANDLE schSCManager, schService;
+
+
+ /* Removing from the services database */
+ schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
+ if (schSCManager)
+ {
+ schService = OpenService(schSCManager,g_lpszServiceName,
+ SC_MANAGER_ALL_ACCESS);
+ if(schService)
+ {
+ /* Checking status */
+ SERVICE_STATUS lpServiceStatus;
+
+ if(QueryServiceStatus(schService, &lpServiceStatus))
+ {
+ if(lpServiceStatus.dwCurrentState == SERVICE_RUNNING)
+ {
+ rc = 1;
+ }
+ }
+ CloseServiceHandle(schService);
+ }
+
+ CloseServiceHandle(schSCManager);
+ }
+
+ return(rc);
+}
+
/* int InstallService()
* Install the OSSEC HIDS agent service.
@@ -67,7 +173,7 @@
g_lpszServiceDisplayName,
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS,
- SERVICE_DEMAND_START,
+ SERVICE_AUTO_START,
SERVICE_ERROR_NORMAL,
lpszBinaryPathName,
NULL, NULL, NULL, NULL, NULL);
OSSEC home |
Main Index |
Thread Index
OSSEC project: www.ossec.net.
Mailling list information: http://www.ossec.net/en/mailing_lists.html.