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