1 /* Copyright (C) 2010 Trend Micro Inc.
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
12 #define ARGV0 "ossec-testrule"
16 #include "active-response.h"
20 #include "lists_make.h"
21 #include "eventinfo.h"
22 #include "analysisd.h"
24 /** Global definitions **/
33 OSDecoderInfo *NULL_Decoder;
35 /* print help statement */
36 __attribute__((noreturn))
37 static void help_makelists(void)
40 print_out(" %s: -[VhdtF] [-u user] [-g group] [-c config] [-D dir]", ARGV0);
41 print_out(" -V Version and license message");
42 print_out(" -h This help message");
43 print_out(" -d Execute in debug mode. This parameter");
44 print_out(" can be specified multiple times");
45 print_out(" to increase the debug level.");
46 print_out(" -t Test configuration");
47 print_out(" -F Force rebuild of all databases");
48 print_out(" -u <user> User to run as (default: %s)", USER);
49 print_out(" -g <group> Group to run as (default: %s)", GROUPGLOBAL);
50 print_out(" -c <config> Configuration file to use (default: %s)", DEFAULTCPATH);
51 print_out(" -D <dir> Directory to chroot into (default: %s)", DEFAULTDIR);
56 int main(int argc, char **argv)
60 const char *dir = DEFAULTDIR;
61 const char *user = USER;
62 const char *group = GROUPGLOBAL;
67 const char *cfg = DEFAULTCPATH;
75 memset(prev_month, '\0', 4);
77 while ((c = getopt(argc, argv, "VdhFtu:g:D:c:")) != -1) {
90 ErrorExit("%s: -u needs an argument", ARGV0);
96 ErrorExit("%s: -g needs an argument", ARGV0);
102 ErrorExit("%s: -D needs an argument", ARGV0);
108 ErrorExit("%s: -c needs an argument", ARGV0);
124 /* Check if the user/group given are valid */
125 uid = Privsep_GetUser(user);
126 gid = Privsep_GetGroup(group);
127 if (uid == (uid_t) - 1 || gid == (gid_t) - 1) {
128 ErrorExit(USER_ERROR, ARGV0, user, group);
132 debug1(FOUND_USER, ARGV0);
134 /* Read configuration file */
135 if (GlobalConf(cfg) < 0) {
136 ErrorExit(CONFIG_ERROR, ARGV0, cfg);
139 debug1(READ_CONFIG, ARGV0);
142 if (Privsep_SetGroup(gid) < 0) {
143 ErrorExit(SETGID_ERROR, ARGV0, group, errno, strerror(errno));
147 if (Privsep_Chroot(dir) < 0) {
148 ErrorExit(CHROOT_ERROR, ARGV0, dir, errno, strerror(errno));
153 if (test_config == 1) {
157 /* Create the lists for use in rules */
158 Lists_OP_CreateLists();
163 listfiles = Config.lists;
164 while (listfiles && *listfiles) {
165 if (Lists_OP_LoadList(*listfiles) < 0) {
166 ErrorExit(LISTS_ERROR, ARGV0, *listfiles);
175 Lists_OP_MakeAll(force);