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