5c3d77998391e4611aa9568991f05848e2745c31
[ossec-hids.git] / src / analysisd / active-response.c
1 /* @(#) $Id$ */
2
3 /* Copyright (C) 2009 Trend Micro Inc.
4  * All right reserved.
5  *
6  * This program is a free software; you can redistribute it
7  * and/or modify it under the terms of the GNU General Public
8  * License (version 2) as published by the FSF - Free Software
9  * Foundation
10  */
11
12  
13 #include "shared.h"
14 #include "active-response.h"
15
16
17 /** void AR_Init()
18  * Initializing active response.
19  */
20 void AR_Init()
21 {
22     ar_commands = OSList_Create();
23     active_responses = OSList_Create();
24     ar_flag = 0;
25
26     if(!ar_commands || !active_responses)
27     {
28         ErrorExit(LIST_ERROR, ARGV0);
29     }
30 }
31
32
33 /** int AR_ReadConfig(int test_config, char *cfgfile)
34  * Reads active response configuration and write them
35  * to the appropriate lists.
36  */
37 int AR_ReadConfig(int test_config, char *cfgfile)
38 {
39     FILE *fp;
40     int modules = 0;
41
42     modules|= CAR;
43
44
45     /* Cleaning ar file */
46     fp = fopen(DEFAULTARPATH, "w");
47     if(!fp)
48     {
49         merror(FOPEN_ERROR, ARGV0, DEFAULTARPATH);
50         return(OS_INVALID);
51     }
52     fprintf(fp, "restart-ossec0 - restart-ossec.sh - 0\n");
53     fprintf(fp, "restart-ossec0 - restart-ossec.cmd - 0\n");
54     fclose(fp);
55
56
57     /* Setting right permission */
58     chmod(DEFAULTARPATH, 0444);
59
60
61     /* Reading configuration */
62     if(ReadConfig(modules, cfgfile, ar_commands, active_responses) < 0)
63     {
64         return(OS_INVALID);
65     }
66
67
68     return(0);
69 }
70
71 /* EOF */