1 /* @(#) $Id: ./src/monitord/report.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2010 Trend Micro Inc.
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
18 /* ossec-reportd - Runs manual reports. */
21 printf("\nOSSEC HIDS %s: Generate reports (via stdin).\n", ARGV0);
22 printf("Available options:\n");
23 printf("\t-h This help message.\n");
24 printf("\t-f <filter> <value> Filter the results.\n");
25 printf("\t-r <filter> <value> Show related entries.\n");
26 printf("\t-n Creates a description for the report.\n");
27 printf("\t-s Show the alert dump.\n");
29 printf("\tFilters allowed: group, rule, level, location,\n");
30 printf("\t user, srcip, filename\n");
32 printf("Examples:\n");
33 printf("\t-f group authentication_success (to filter on login success).\n");
34 printf("\t-f level 10 (to filter on level >= 10).\n");
35 printf("\t-f group authentication -r user srcip (to show the srcip for all users).\n");
41 int main(int argc, char **argv)
43 int c, test_config = 0;
45 char *dir = DEFAULTDIR;
47 char *group = GROUPGLOBAL;
48 // TODO: delete or implement
49 char *cfg __attribute__((unused)) = DEFAULTCPATH;
51 char *filter_by = NULL;
52 char *filter_value = NULL;
54 char *related_of = NULL;
55 char *related_values = NULL;
56 report_filter r_filter;
59 /* Setting the name */
62 r_filter.group = NULL;
64 r_filter.level = NULL;
65 r_filter.location = NULL;
66 r_filter.srcip = NULL;
68 r_filter.files = NULL;
69 r_filter.show_alerts = 0;
71 r_filter.related_group = 0;
72 r_filter.related_rule = 0;
73 r_filter.related_level = 0;
74 r_filter.related_location = 0;
75 r_filter.related_srcip = 0;
76 r_filter.related_user = 0;
77 r_filter.related_file = 0;
79 r_filter.report_name = NULL;
81 while((c = getopt(argc, argv, "Vdhstu:g:D:c:f:v:n:r:")) != -1)
95 ErrorExit("%s: -n needs an argument",ARGV0);
96 r_filter.report_name = optarg;
99 if(!optarg || !argv[optind])
100 ErrorExit("%s: -r needs two argument",ARGV0);
102 related_values = argv[optind];
104 if(os_report_configfilter(related_of, related_values,
105 &r_filter, REPORT_RELATED) < 0)
107 ErrorExit(CONFIG_ERROR, ARGV0, "user argument");
113 ErrorExit("%s: -f needs two argument",ARGV0);
115 filter_value = argv[optind];
117 if(os_report_configfilter(filter_by, filter_value,
118 &r_filter, REPORT_FILTER) < 0)
120 ErrorExit(CONFIG_ERROR, ARGV0, "user argument");
126 ErrorExit("%s: -u needs an argument",ARGV0);
131 ErrorExit("%s: -g needs an argument",ARGV0);
136 ErrorExit("%s: -D needs an argument",ARGV0);
141 ErrorExit("%s: -c needs an argument",ARGV0);
148 r_filter.show_alerts = 1;
157 /* Starting daemon */
158 debug1(STARTED_MSG,ARGV0);
160 /* Check if the user/group given are valid */
161 uid = Privsep_GetUser(user);
162 gid = Privsep_GetGroup(group);
163 if((uid < 0)||(gid < 0))
164 ErrorExit(USER_ERROR,ARGV0,user,group);
168 /* Exit here if test config is set */
173 /* Privilege separation */
174 if(Privsep_SetGroup(gid) < 0)
175 ErrorExit(SETGID_ERROR,ARGV0,group);
179 if(Privsep_Chroot(dir) < 0)
180 ErrorExit(CHROOT_ERROR,ARGV0,dir);
187 if(Privsep_SetUser(uid) < 0)
188 ErrorExit(SETUID_ERROR,ARGV0,user);
191 debug1(PRIVSEP_MSG,ARGV0,dir,user);
195 /* Signal manipulation */
200 /* Creating PID files */
201 if(CreatePID(ARGV0, getpid()) < 0)
202 ErrorExit(PID_ERROR,ARGV0);
205 /* Start up message */
206 verbose(STARTUP_MSG, ARGV0, (int)getpid());
208 /* the real stuff now */
209 os_ReportdStart(&r_filter);