Imported Upstream version 2.7
[ossec-hids.git] / src / util / verify-agent-conf.c
1 /* @(#) $Id: ./src/util/verify-agent-conf.c, 2011/09/08 dcid Exp $
2  */
3
4 /* Copyright (C) 2010 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 "config/localfile-config.h"
16 #include "config/config.h"
17 #include "logcollector/logcollector.h"
18
19
20 #undef ARGV0
21 #define ARGV0 "verify-agent-conf"
22
23
24 /** help **/
25 void helpmsg()
26 {
27     printf("\nOSSEC HIDS %s: Verify agent.conf syntax for errors.\n", ARGV0);
28     printf("Usage:  %s [-f <agent.conf file>]\n\n", ARGV0);
29     printf("Available options:\n");
30     printf("\t-h          This help message.\n");
31     printf("\t-f          Full file name and path to config file to be tested.\n");
32     printf("\t            If this option is not specified the following default\n");
33     printf("\t            will be used.\n");
34     printf(" ");
35     printf("\t            Validation is successful, if no errors are shown.\n");
36     exit(1);
37 }
38
39
40 /* main: v0.3: 2005/04/04 */
41 int main(int argc, char **argv)
42 {
43     char* ar=AGENTCONFIG;
44     int c=0;
45     int modules = 0;
46     logreader_config log_config;
47
48
49     /* Setting the name */
50     OS_SetName(ARGV0);
51
52
53     /* printf ("Agrc [%d], Argv [%s]\n", argc, *argv); */
54
55     /* user arguments */
56     if(argc > 1)
57     {
58         while((c = getopt(argc, argv, "Vdhf:")) != -1)
59         {
60             switch(c){
61                 case 'V':
62                     print_version();
63                     break;
64                 case 'h':
65                     helpmsg();
66                     break;
67                 case 'd':
68                     nowDebug();
69                     break;
70                 case 'f':
71                     if(!optarg)
72                     {
73                         merror("%s: -f needs an argument",ARGV0);
74                         helpmsg();
75                     }
76                     ar = optarg;
77                     break;
78                 default:
79                     helpmsg();
80                     break;
81             }
82
83         }
84     }
85
86
87
88     printf("\n%s: Verifying [%s].\n\n", ARGV0, ar);
89
90     modules|= CLOCALFILE;
91     modules|= CAGENT_CONFIG;
92     log_config.config = NULL;
93     if(ReadConfig(modules, ar, &log_config, NULL) < 0)
94     {
95         return(OS_INVALID);
96     }
97
98     logff = log_config.config;
99
100     return(0);
101
102
103 }
104
105 /* EOF */