1 /* @(#) $Id: report.c,v 1.4 2009/06/24 17:06:27 dcid Exp $ */
3 /* Copyright (C) 2009 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 3) 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;
60 r_filter.related_group = 0;
61 r_filter.related_rule = 0;
62 r_filter.related_level = 0;
63 r_filter.related_location = 0;
64 r_filter.related_srcip = 0;
65 r_filter.related_user = 0;
67 r_filter.report_name = NULL;
69 while((c = getopt(argc, argv, "Vdhtu:g:D:c:f:v:n:r:")) != -1)
83 ErrorExit("%s: -n needs an argument",ARGV0);
84 r_filter.report_name = optarg;
87 if(!optarg || !argv[optind])
88 ErrorExit("%s: -r needs two argument",ARGV0);
90 related_values = argv[optind];
92 if(os_report_configfilter(related_of, related_values,
93 &r_filter, REPORT_RELATED) < 0)
95 ErrorExit(CONFIG_ERROR, ARGV0, "user argument");
101 ErrorExit("%s: -f needs two argument",ARGV0);
103 filter_value = argv[optind];
105 if(os_report_configfilter(filter_by, filter_value,
106 &r_filter, REPORT_FILTER) < 0)
108 ErrorExit(CONFIG_ERROR, ARGV0, "user argument");
114 ErrorExit("%s: -u needs an argument",ARGV0);
119 ErrorExit("%s: -g needs an argument",ARGV0);
124 ErrorExit("%s: -D needs an argument",ARGV0);
128 ErrorExit("%s: -c needs an argument",ARGV0);
141 /* Starting daemon */
142 debug1(STARTED_MSG,ARGV0);
144 /* Check if the user/group given are valid */
145 uid = Privsep_GetUser(user);
146 gid = Privsep_GetGroup(group);
147 if((uid < 0)||(gid < 0))
148 ErrorExit(USER_ERROR,ARGV0,user,group);
152 /* Exit here if test config is set */
157 /* Privilege separation */
158 if(Privsep_SetGroup(gid) < 0)
159 ErrorExit(SETGID_ERROR,ARGV0,group);
163 if(Privsep_Chroot(dir) < 0)
164 ErrorExit(CHROOT_ERROR,ARGV0,dir);
171 if(Privsep_SetUser(uid) < 0)
172 ErrorExit(SETUID_ERROR,ARGV0,user);
175 debug1(PRIVSEP_MSG,ARGV0,dir,user);
179 /* Signal manipulation */
184 /* Creating PID files */
185 if(CreatePID(ARGV0, getpid()) < 0)
186 ErrorExit(PID_ERROR,ARGV0);
189 /* Start up message */
190 verbose(STARTUP_MSG, ARGV0, (int)getpid());
193 /* the real stuff now */
194 os_ReportdStart(&r_filter);