1 /*
2 ** Copyright (C) 2014-2021 Cisco and/or its affiliates. All rights reserved.
3 ** Copyright (C) 2012-2013 Sourcefire, Inc.
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License Version 2 as
7 ** published by the Free Software Foundation. You may not use, modify or
8 ** distribute this program under any other version of the GNU General
9 ** Public License.
10 **
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
15 **
16 ** You should have received a copy of the GNU General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 **
20 ** Date: 01-27-2012
21 ** Author: Hui Cao <hcao@sourcefire.com>
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include "sf_types.h"
29
30 #include "output_api.h"
31 #include "output_lib.h"
32
33
34 extern char *file_name;
35 extern int file_line;
36
37 DynamicOutputData _dod;
38
39
initOutputPlugins(void * dod)40 OUTPUT_SO_PUBLIC int initOutputPlugins(void *dod)
41 {
42 DynamicOutputData* outputData = (DynamicOutputData*)dod;
43 /*Check the version*/
44 if (!dod)
45 return OUTPUT_ERROR;
46
47 if (outputData->majorVersion != OUTPUT_DATA_MAJOR_VERSION)
48 {
49 printf("ERROR major version %d != %d\n", outputData->majorVersion,
50 OUTPUT_DATA_MAJOR_VERSION);
51 return OUTPUT_ERROR;
52 }
53
54 if (outputData->minorVersion < OUTPUT_DATA_MINOR_VERSION)
55 {
56 printf("ERROR minor version %d < %d\n", outputData->minorVersion,
57 OUTPUT_DATA_MINOR_VERSION);
58 return OUTPUT_ERROR;
59 }
60
61 if (outputData->size < sizeof(DynamicOutputData))
62 {
63 printf("ERROR size %d != %u\n", outputData->size, (unsigned)sizeof(*outputData));
64 return OUTPUT_ERROR;
65 }
66
67 _dod = *((DynamicOutputData*)dod);
68 return OUTPUT_SUCCESS;
69
70 }
71
init_output_module(struct _SnortConfig * sc,Output_Module_t * om,char * args)72 void init_output_module(struct _SnortConfig *sc, Output_Module_t *om, char *args)
73 {
74 void *config;
75
76 if (!om)
77 return;
78
79 printf("Initializing module %s \n", om->name);
80 om->parse_args(&config, args, om->default_file);
81 if (om->alert_output)
82 {
83 _dod.addOutputModule(sc, om->alert_output, DYNAMIC_OUTPUT_TYPE_FLAG__ALERT, config);
84 }
85 if (om->log_output)
86 {
87 _dod.addOutputModule(sc, om->log_output, DYNAMIC_OUTPUT_TYPE_FLAG__LOG, config);
88 }
89 #ifdef SNORT_RELOAD
90 if (om->rotate)
91 {
92 _dod.addReload(om->rotate, config);
93 }
94 #endif
95 if (om->postconfig)
96 {
97 _dod.addPostconfig(sc, om->postconfig, config);
98 }
99 if (om->shutdown)
100 {
101 _dod.addCleanExit(om->shutdown, config);
102 }
103 }
104