1 /* $Id$ */
2 /*
3  ** Copyright (C) 2014-2021 Cisco and/or its affiliates. All rights reserved.
4  ** Copyright (C) 2005-2013 Sourcefire, Inc.
5  **
6  ** This program is free software; you can redistribute it and/or modify
7  ** it under the terms of the GNU General Public License Version 2 as
8  ** published by the Free Software Foundation.  You may not use, modify or
9  ** distribute this program under any other version of the GNU General
10  ** Public License.
11  **
12  ** This program is distributed in the hope that it will be useful,
13  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  ** GNU General Public License for more details.
16  **
17  ** You should have received a copy of the GNU General Public License
18  ** along with this program; if not, write to the Free Software
19  ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20  */
21 
22 #include <stdio.h>
23 #include <string.h>
24 #include <ctype.h>
25 #include <stdarg.h>
26 #include <stdlib.h>
27 
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31 
32 #include "sf_types.h"
33 #include "sf_dynamic_define.h"
34 #include "sf_preproc_info.h"
35 #include "sf_snort_packet.h"
36 #include "sf_dynamic_preproc_lib.h"
37 #include "sf_dynamic_meta.h"
38 #include "sf_dynamic_preprocessor.h"
39 #include "sf_dynamic_common.h"
40 
41 DynamicPreprocessorData _dpd;
42 
DynamicPreprocessorFatalMessage(const char * format,...)43 NORETURN void DynamicPreprocessorFatalMessage(const char *format, ...)
44 {
45     char buf[STD_BUF];
46     va_list ap;
47 
48     va_start(ap, format);
49     vsnprintf(buf, STD_BUF, format, ap);
50     va_end(ap);
51 
52     buf[STD_BUF - 1] = '\0';
53 
54     _dpd.fatalMsg("%s", buf);
55 
56     exit(1);
57 }
58 
59 
InitializePreprocessor(DynamicPreprocessorData * dpd)60 PREPROC_LINKAGE int InitializePreprocessor(DynamicPreprocessorData *dpd)
61 {
62     if (dpd->version < PREPROCESSOR_DATA_VERSION)
63     {
64         printf("ERROR version %d < %d\n", dpd->version,
65             PREPROCESSOR_DATA_VERSION);
66         return -1;
67     }
68 
69     if (dpd->size != sizeof(DynamicPreprocessorData))
70     {
71         printf("ERROR size %d != %u\n", dpd->size, (unsigned)sizeof(*dpd));
72         return -2;
73     }
74 
75     _dpd = *dpd;
76     DYNAMIC_PREPROC_SETUP();
77     return 0;
78 }
79 
LibVersion(DynamicPluginMeta * dpm)80 PREPROC_LINKAGE int LibVersion(DynamicPluginMeta *dpm)
81 {
82 
83     dpm->type  = TYPE_PREPROCESSOR;
84     dpm->major = MAJOR_VERSION;
85     dpm->minor = MINOR_VERSION;
86     dpm->build = BUILD_VERSION;
87     strncpy(dpm->uniqueName, PREPROC_NAME, MAX_NAME_LEN-1);
88     dpm->uniqueName[MAX_NAME_LEN-1] = '\0';
89     return 0;
90 }
91 
92