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