3 /* Copyright (C) 2010 Trend Micro Inc.
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
11 * License details at the LICENSE file included with OSSEC or
12 * online at: http://www.ossec.net/en/licensing.html
17 * Available at http://www.ossec.net
22 * Responsible for correlation and log decoding.
26 #define ARGV0 "ossec-testrule"
33 #include "active-response.h"
37 #include "lists_make.h"
39 #include "eventinfo.h"
40 #include "analysisd.h"
46 /** External functions prototypes (only called here) **/
49 int GlobalConf(char * cfgfile);
53 void Lists_OP_CreateLists();
55 void makelist_help(const char *prog)
58 print_out("%s %s - %s (%s)", __name, __version, __author, __contact);
59 print_out("%s", __site);
61 print_out(" %s: -[Vhdt] [-u user] [-g group] [-c config] [-D dir]", prog);
62 print_out(" -V Version and license message");
63 print_out(" -h This help message");
64 print_out(" -d Execute in debug mode");
65 print_out(" -f Force rebuild of all databases");
66 print_out(" -u <user> Run as 'user'");
67 print_out(" -g <group> Run as 'group'");
68 print_out(" -c <config> Read the 'config' file");
69 print_out(" -D <dir> Chroot to 'dir'");
74 /** int main(int argc, char **argv)
76 int main(int argc, char **argv)
79 char *dir = DEFAULTDIR;
81 char *group = GROUPGLOBAL;
85 char *cfg = DEFAULTCPATH;
87 /* Setting the name */
93 memset(prev_month, '\0', 4);
95 while((c = getopt(argc, argv, "Vdhfu:g:D:c:")) != -1){
101 makelist_help(ARGV0);
108 ErrorExit("%s: -u needs an argument",ARGV0);
113 ErrorExit("%s: -g needs an argument",ARGV0);
118 ErrorExit("%s: -D needs an argument",ARGV0);
122 ErrorExit("%s: -c needs an argument",ARGV0);
136 /*Check if the user/group given are valid */
137 uid = Privsep_GetUser(user);
138 gid = Privsep_GetGroup(group);
139 if((uid < 0)||(gid < 0))
140 ErrorExit(USER_ERROR,ARGV0,user,group);
144 debug1(FOUND_USER, ARGV0);
147 /* Reading configuration file */
148 if(GlobalConf(cfg) < 0)
150 ErrorExit(CONFIG_ERROR,ARGV0, cfg);
153 debug1(READ_CONFIG, ARGV0);
155 /* Setting the group */
156 if(Privsep_SetGroup(gid) < 0)
157 ErrorExit(SETGID_ERROR,ARGV0,group);
160 if(Privsep_Chroot(dir) < 0)
161 ErrorExit(CHROOT_ERROR,ARGV0,dir);
167 /* Createing the lists for use in rules */
168 Lists_OP_CreateLists();
170 /* Reading the lists */
173 listfiles = Config.lists;
174 while(listfiles && *listfiles)
176 if(Lists_OP_LoadList(*listfiles) < 0)
177 ErrorExit(LISTS_ERROR, ARGV0, *listfiles);
185 Lists_OP_MakeAll(force);