55534711e3c7e53a130c0f164bf5823f7f822141
[ossec-hids.git] / src / rootcheck / rootcheck-config.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 #ifndef OSSECHIDS
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <unistd.h>
18
19 #include "shared.h"
20
21 #include "os_xml/os_xml.h"
22
23 #include "rootcheck.h"
24
25
26 /* Read_Rootcheck_Config: Reads the rootcheck config
27  */
28 int Read_Rootcheck_Config(char * cfgfile)
29 {
30     OS_XML xml;
31
32     char *str = NULL;
33
34
35     /* XML Definitions */
36     char *(xml_daemon[])={xml_rootcheck,"daemon", NULL};
37     char *(xml_notify[])={xml_rootcheck, "notify", NULL};
38     char *(xml_base_dir[])={xml_rootcheck, "base_directory", NULL};
39     char *(xml_workdir[])={xml_rootcheck, "work_directory", NULL};
40     char *(xml_rootkit_files[])={xml_rootcheck, "rootkit_files", NULL};
41     char *(xml_rootkit_trojans[])={xml_rootcheck, "rootkit_trojans", NULL};
42     char *(xml_rootkit_unixaudit[])={xml_rootcheck, "system_audit", NULL};
43     char *(xml_rootkit_winaudit[])={xml_rootcheck, "windows_audit", NULL};
44     char *(xml_rootkit_winapps[])={xml_rootcheck, "windows_apps", NULL};
45     char *(xml_rootkit_winmalware[])={xml_rootcheck, "windows_malware", NULL};
46     char *(xml_scanall[])={xml_rootcheck, "scanall", NULL};
47     char *(xml_readall[])={xml_rootcheck, "readall", NULL};
48     char *(xml_time[])={xml_rootcheck, "frequency", NULL};
49
50     /* :) */
51     xml_time[2] = NULL;
52     
53     if(OS_ReadXML(cfgfile,&xml) < 0)
54     {
55         merror("config_op: XML error: %s",xml.err);
56         return(OS_INVALID);
57     }
58
59     if(!OS_RootElementExist(&xml,xml_rootcheck))
60     {
61         OS_ClearXML(&xml);
62         merror("%s: Rootcheck configuration not found. ",ARGV0);
63         return(-1);
64     }
65
66
67     /* run as a daemon */
68     str = OS_GetOneContentforElement(&xml,xml_daemon);
69     if(str)
70     {
71         if(str[0] == 'n')
72             rootcheck.daemon = 0;
73         free(str);
74         str = NULL;    
75     }
76
77     /* time  */
78     #ifdef OSSECHIDS
79     str = OS_GetOneContentforElement(&xml,xml_time);
80     if(str)
81     {
82         if(!OS_StrIsNum(str))
83         {
84             merror("Invalid frequency time '%s' for the rootkit "
85                     "detection (must be int).", str);
86             return(OS_INVALID);
87         }
88
89         rootcheck.time = atoi(str);
90
91         free(str);
92         str = NULL;
93     }
94     #endif
95                                                                                                             
96     
97     /* Scan all flag */
98     if(!rootcheck.scanall)
99     {
100         str = OS_GetOneContentforElement(&xml,xml_scanall);
101         if(str)
102         {
103             if(str[0] == 'y')
104                 rootcheck.scanall = 1;
105             free(str);
106             str = NULL;
107         }
108     }
109
110
111     /* read all flag */
112     if(!rootcheck.readall)
113     {
114         str = OS_GetOneContentforElement(&xml,xml_readall);
115         if(str)
116         {
117             if(str[0] == 'y')
118                 rootcheck.readall = 1;
119             free(str);
120             str = NULL;
121         }
122     }
123     
124     
125     /* Notifications type */
126     str  = OS_GetOneContentforElement(&xml,xml_notify);
127     if(str)
128     {
129         if(strcasecmp(str,"queue") == 0)
130             rootcheck.notify = QUEUE;
131         else if(strcasecmp(str,"syslog") == 0)
132             rootcheck.notify = SYSLOG;
133         else
134         {
135             merror("%s: Invalid notification option. Only "
136                       "'syslog' or 'queue' are allowed.",ARGV0);
137             return(-1);
138         }
139         
140         free(str);
141         str = NULL;           
142     }
143     else
144     {
145         /* Default to SYSLOG */
146         rootcheck.notify = SYSLOG;
147     }
148
149     /* Getting work directory */
150     if(!rootcheck.workdir)
151         rootcheck.workdir  = OS_GetOneContentforElement(&xml,xml_workdir);    
152     
153     
154     rootcheck.rootkit_files  = OS_GetOneContentforElement
155                                (&xml,xml_rootkit_files);
156     rootcheck.rootkit_trojans  = OS_GetOneContentforElement
157                                (&xml,xml_rootkit_trojans);
158     
159     rootcheck.unixaudit = OS_GetContents 
160                                 (&xml,xml_rootkit_unixaudit);
161
162     rootcheck.winaudit  = OS_GetOneContentforElement
163                                 (&xml,xml_rootkit_winaudit);
164
165     rootcheck.winapps  = OS_GetOneContentforElement
166                                 (&xml,xml_rootkit_winapps);
167
168     rootcheck.winmalware  = OS_GetOneContentforElement
169                                 (&xml,xml_rootkit_winmalware);
170                                 
171     rootcheck.basedir  = OS_GetOneContentforElement(&xml, xml_base_dir);
172
173
174     OS_ClearXML(&xml);
175  
176     debug1("%s: DEBUG: Daemon set to '%d'",ARGV0, rootcheck.daemon);
177     debug1("%s: DEBUG: alert set to '%d'",ARGV0, rootcheck.notify);
178        
179     return(0);
180 }
181
182 /* EOF */
183 #endif