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
17 /* ossec-reportd - Runs manual reports. */
20 printf("\nOSSEC HIDS %s: Generate reports (via stdin).\n", ARGV0);
21 printf("Available options:\n");
22 printf("\t-h This help message.\n");
23 printf("\t-f <filter> <value> Filter the results.\n");
24 printf("\t-r <filter> <value> Show related entries.\n");
25 printf("\t-n Creates a description for the report.\n");
26 printf("Examples:\n");
27 printf("\t-f group authentication success (to filter on login success).\n");
28 printf("\t-f level 10 (to filter on level >= 10).\n");
29 printf("\t-f group authentication -r user srcip (to show the srcip for all users).\n");
35 int main(int argc, char **argv)
37 int c, test_config = 0;
39 char *dir = DEFAULTDIR;
41 char *group = GROUPGLOBAL;
42 char *cfg = DEFAULTCPATH;
44 char *filter_by = NULL;
45 char *filter_value = NULL;
47 char *related_of = NULL;
48 char *related_values = NULL;
49 report_filter r_filter;
52 /* Setting the name */
55 r_filter.group = NULL;
57 r_filter.level = NULL;
58 r_filter.location = NULL;
59 r_filter.srcip = NULL;
62 r_filter.related_group = 0;
63 r_filter.related_rule = 0;
64 r_filter.related_level = 0;
65 r_filter.related_location = 0;
66 r_filter.related_srcip = 0;
67 r_filter.related_user = 0;
69 r_filter.report_name = NULL;
71 while((c = getopt(argc, argv, "Vdhtu:g:D:c:f:v:n:r:")) != -1)
85 ErrorExit("%s: -n needs an argument",ARGV0);
86 r_filter.report_name = optarg;
89 if(!optarg || !argv[optind])
90 ErrorExit("%s: -r needs two argument",ARGV0);
92 related_values = argv[optind];
94 if(os_report_configfilter(related_of, related_values,
95 &r_filter, REPORT_RELATED) < 0)
97 ErrorExit(CONFIG_ERROR, ARGV0, "user argument");
103 ErrorExit("%s: -f needs two argument",ARGV0);
105 filter_value = argv[optind];
107 if(os_report_configfilter(filter_by, filter_value,
108 &r_filter, REPORT_FILTER) < 0)
110 ErrorExit(CONFIG_ERROR, ARGV0, "user argument");
116 ErrorExit("%s: -u needs an argument",ARGV0);
121 ErrorExit("%s: -g needs an argument",ARGV0);
126 ErrorExit("%s: -D needs an argument",ARGV0);
130 ErrorExit("%s: -c needs an argument",ARGV0);
143 /* Starting daemon */
144 debug1(STARTED_MSG,ARGV0);
146 /* Check if the user/group given are valid */
147 uid = Privsep_GetUser(user);
148 gid = Privsep_GetGroup(group);
149 if((uid < 0)||(gid < 0))
150 ErrorExit(USER_ERROR,ARGV0,user,group);
154 /* Exit here if test config is set */
159 /* Privilege separation */
160 if(Privsep_SetGroup(gid) < 0)
161 ErrorExit(SETGID_ERROR,ARGV0,group);
165 if(Privsep_Chroot(dir) < 0)
166 ErrorExit(CHROOT_ERROR,ARGV0,dir);
173 if(Privsep_SetUser(uid) < 0)
174 ErrorExit(SETUID_ERROR,ARGV0,user);
177 debug1(PRIVSEP_MSG,ARGV0,dir,user);
181 /* Signal manipulation */
186 /* Creating PID files */
187 if(CreatePID(ARGV0, getpid()) < 0)
188 ErrorExit(PID_ERROR,ARGV0);
191 /* Start up message */
192 verbose(STARTUP_MSG, ARGV0, (int)getpid());
195 /* the real stuff now */
196 os_ReportdStart(&r_filter);