new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / util / verify-agent-conf.c
1 /* Copyright (C) 2010 Trend Micro Inc.
2  * All right reserved.
3  *
4  * This program is a free software; you can redistribute it
5  * and/or modify it under the terms of the GNU General Public
6  * License (version 2) as published by the FSF - Free Software
7  * Foundation
8  */
9
10 #include "shared.h"
11 #include "config/localfile-config.h"
12 #include "config/config.h"
13 #include "logcollector/logcollector.h"
14
15 #undef ARGV0
16 #define ARGV0 "verify-agent-conf"
17
18 /* Prototypes */
19 static void helpmsg(void) __attribute__((noreturn));
20
21
22 static void helpmsg()
23 {
24     printf("\nOSSEC HIDS %s: Verify agent.conf syntax for errors.\n", ARGV0);
25     printf("Usage:  %s [-f <agent.conf file>]\n\n", ARGV0);
26     printf("Available options:\n");
27     printf("\t-h          This help message.\n");
28     printf("\t-f          Full file name and path to config file to be tested.\n");
29     printf("\t            If this option is not specified the following default\n");
30     printf("\t            will be used.\n");
31     printf(" ");
32     printf("\t            Validation is successful, if no errors are shown.\n");
33     exit(1);
34 }
35
36 int main(int argc, char **argv)
37 {
38     const char *ar = AGENTCONFIG;
39     int c = 0;
40     int modules = 0;
41     logreader_config log_config;
42
43     /* Set the name */
44     OS_SetName(ARGV0);
45
46     /* User arguments */
47     if (argc > 1) {
48         while ((c = getopt(argc, argv, "Vdhf:")) != -1) {
49             switch (c) {
50                 case 'V':
51                     print_version();
52                     break;
53                 case 'h':
54                     helpmsg();
55                     break;
56                 case 'd':
57                     nowDebug();
58                     break;
59                 case 'f':
60                     if (!optarg) {
61                         merror("%s: -f needs an argument", ARGV0);
62                         helpmsg();
63                     }
64                     ar = optarg;
65                     break;
66                 default:
67                     helpmsg();
68                     break;
69             }
70         }
71     }
72
73     printf("\n%s: Verifying [%s].\n\n", ARGV0, ar);
74
75     modules |= CLOCALFILE;
76     modules |= CAGENT_CONFIG;
77     log_config.config = NULL;
78     if (ReadConfig(modules, ar, &log_config, NULL) < 0) {
79         return (OS_INVALID);
80     }
81
82     return (0);
83 }
84