Imported Upstream version 2.7
[ossec-hids.git] / src / syscheckd / syscheck-baseline.c
1 /* @(#) $Id: ./src/syscheckd/syscheck-baseline.c, 2011/09/08 dcid Exp $
2  */
3
4 /* Copyright (C) 2009 Trend Micro Inc.
5  * All rights 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  * License details at the LICENSE file included with OSSEC or
13  * online at: http://www.ossec.net/en/licensing.html
14  */
15
16
17 #include "shared.h"
18 #include "syscheck.h"
19
20
21 /* Help information for syscheck-baseline.
22  */
23 void sb_help(char *argv0)
24 {
25     /* -s  sleep between files.
26      * -c config
27      * -D workdir (where ossec is installed to read internal_options.conf)
28      * -o output_file
29      * -i input_file (only used with compare)
30      * -v (compare)
31      */
32 }
33
34
35 /* void read_internal()
36  * Reads syscheck internal options.
37  */
38 void read_internal(no_stop)
39 {
40     if(no_stop)
41     {
42         syscheck.tsleep = 0;
43         syscheck.sleep_after = 9999;
44     }
45     else
46     {
47         syscheck.tsleep = getDefine_Int("syscheck","sleep",1,64);
48         syscheck.sleep_after = getDefine_Int("syscheck","sleep_after",1,128);
49     }
50     return;
51 }
52
53
54
55
56 /* Unix main.
57  */
58 int main(int argc, char **argv)
59 {
60     int c,r,no_stop = 1;
61     int test_config = 0;
62
63     char *cfg = DEFAULTCPATH;
64     char *input_f = NULL;
65     char *output_f = NULL;
66
67
68     /* Zeroing the structure */
69     syscheck.workdir = NULL;
70
71
72     /* Setting the name */
73     OS_SetName(ARGV0);
74
75
76     while((c = getopt(argc, argv, "VtdshD:c:i:o:")) != -1)
77     {
78         switch(c)
79         {
80             case 'V':
81                 print_version();
82                 break;
83             case 'h':
84                 sb_help(ARGV0);
85                 break;
86             case 's':
87                 no_stop = 0;
88                 break;
89             case 'd':
90                 nowDebug();
91                 break;
92             case 'i':
93                 if(!optarg)
94                     ErrorExit("%s: -i needs an argument",ARGV0);
95                 input_f = optarg;
96                 break;
97             case 'o':
98                 if(!optarg)
99                     ErrorExit("%s: -o needs an argument",ARGV0);
100                 output_f = optarg;
101                 break;
102             case 'D':
103                 if(!optarg)
104                     ErrorExit("%s: -D needs an argument",ARGV0);
105                 syscheck.workdir = optarg;
106                 break;
107             case 'c':
108                 if(!optarg)
109                     ErrorExit("%s: -c needs an argument",ARGV0);
110                 cfg = optarg;
111                 break;
112             case 't':
113                 test_config = 1;
114                 break;
115             default:
116                 help(ARGV0);
117                 break;
118         }
119     }
120
121
122     /* Checking if the configuration is present */
123     if(File_DateofChange(cfg) < 0)
124         ErrorExit(NO_CONFIG, ARGV0, cfg);
125
126
127     /* Read syscheck config */
128     if((r = Read_Syscheck_Config(cfg)) < 0)
129     {
130         ErrorExit(CONFIG_ERROR, ARGV0, cfg);
131     }
132     else if((r == 1) || (syscheck.disabled == 1))
133     {
134         syscheck.dir[0] = NULL;
135         if(!test_config)
136         {
137             merror("%s: WARN: Syscheck disabled.", ARGV0);
138         }
139     }
140
141
142     /* Reading internal options */
143     read_internal(no_stop);
144
145
146     /* Exit if testing config */
147     if(test_config)
148         exit(0);
149
150
151     /* Setting default values */
152     if(syscheck.workdir == NULL)
153         syscheck.workdir = DEFAULTDIR;
154
155
156     /* Creating a temporary fp */
157     syscheck.db = (char *)calloc(1024,sizeof(char));
158     if(syscheck.db == NULL)
159         ErrorExit(MEM_ERROR,ARGV0);
160
161     snprintf(syscheck.db,1023, output_f);
162
163
164     /* Printing options */
165     #ifdef WIN32
166     r = 0;
167     while(syscheck.registry[r] != NULL)
168     {
169         verbose("%s: INFO: Monitoring registry entry: '%s'.",
170                 ARGV0, syscheck.registry[r]);
171         r++;
172     }
173     #endif
174
175     r = 0;
176     while(syscheck.dir[r] != NULL)
177     {
178         verbose("%s: INFO: Monitoring directory: '%s'.",
179                 ARGV0, syscheck.dir[r]);
180         r++;
181     }
182
183     /* Start the signal handling */
184     StartSIG(ARGV0);
185
186
187     /* Start up message */
188     verbose(STARTUP_MSG, ARGV0, getpid());
189
190
191     /* Create local database */
192     create_db(0);
193
194
195     fflush(syscheck.fp);
196
197
198     return(0);
199 }
200
201
202 /* EOF */