new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / os_execd / config.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 "execd.h"
12
13
14 /* Read the config file */
15 int ExecdConfig(const char *cfgfile)
16 {
17 #ifdef WIN32
18     int is_disabled = 1;
19 #else
20     int is_disabled = 0;
21 #endif
22     const char *(xmlf[]) = {"ossec_config", "active-response", "disabled", NULL};
23     const char *(blocks[]) = {"ossec_config", "active-response", "repeated_offenders", NULL};
24     char *disable_entry;
25     char *repeated_t;
26     char **repeated_a;
27
28     OS_XML xml;
29
30     /* Read XML file */
31     if (OS_ReadXML(cfgfile, &xml) < 0) {
32         ErrorExit(XML_ERROR, ARGV0, cfgfile, xml.err, xml.err_line);
33     }
34
35     /* We do not validate the xml in here. It is done by other processes. */
36     disable_entry = OS_GetOneContentforElement(&xml, xmlf);
37     if (disable_entry) {
38         if (strcmp(disable_entry, "yes") == 0) {
39             is_disabled = 1;
40         } else if (strcmp(disable_entry, "no") == 0) {
41             is_disabled = 0;
42         } else {
43             merror(XML_VALUEERR, ARGV0,
44                    "disabled",
45                    disable_entry);
46             return (-1);
47         }
48     }
49
50     repeated_t = OS_GetOneContentforElement(&xml, blocks);
51     if (repeated_t) {
52         int i = 0;
53         int j = 0;
54         repeated_a = OS_StrBreak(',', repeated_t, 5);
55         if (!repeated_a) {
56             merror(XML_VALUEERR, ARGV0,
57                    "repeated_offenders",
58                    disable_entry);
59             return (-1);
60         }
61
62         while (repeated_a[i] != NULL) {
63             char *tmpt = repeated_a[i];
64             while (*tmpt != '\0') {
65                 if (*tmpt == ' ' || *tmpt == '\t') {
66                     tmpt++;
67                 } else {
68                     break;
69                 }
70             }
71
72             if (*tmpt == '\0') {
73                 i++;
74                 continue;
75             }
76
77             repeated_offenders_timeout[j] = atoi(tmpt);
78             verbose("%s: INFO: Adding offenders timeout: %d (for #%d)",
79                     ARGV0, repeated_offenders_timeout[j], j + 1);
80             j++;
81             repeated_offenders_timeout[j] = 0;
82             if (j >= 6) {
83                 break;
84             }
85             i++;
86         }
87     }
88
89     OS_ClearXML(&xml);
90
91     return (is_disabled);
92 }
93