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