suricata
output-eve-syslog.c
Go to the documentation of this file.
1/* Copyright (C) 2021 Open Information Security Foundation
2 *
3 * You can copy, redistribute or modify this Program under the terms of
4 * the GNU General Public License version 2 as published by the Free
5 * Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18/**
19 * \file
20 *
21 * \author Mike Pomraning <mpomraning@qualys.com>
22 * \author Jeff Lucovsky <jeff@lucovsky.org>
23 *
24 * File-like output for logging: syslog
25 */
26
27#include "suricata-common.h" /* errno.h, string.h, etc. */
28#include "output.h" /* DEFAULT_LOG_* */
29#include "output-eve.h"
30#include "output-eve-syslog.h"
31#include "util-syslog.h"
32
33#ifdef OS_WIN32
34void SyslogInitialize(void)
35{
36}
37#else /* !OS_WIN32 */
38#define OUTPUT_NAME "syslog"
39
43
44static int SyslogInit(const SCConfNode *conf, const bool threaded, void **init_data)
45{
46 Context *context = SCCalloc(1, sizeof(Context));
47 if (context == NULL) {
48 SCLogError("Unable to allocate context for %s", OUTPUT_NAME);
49 return -1;
50 }
51 const char *facility_s = SCConfNodeLookupChildValue(conf, "facility");
52 if (facility_s == NULL) {
54 }
55
56 int facility = SCMapEnumNameToValue(facility_s, SCSyslogGetFacilityMap());
57 if (facility == -1) {
58 SCLogWarning("Invalid syslog facility: \"%s\","
59 " now using \"%s\" as syslog facility",
62 }
63
64 const char *level_s = SCConfNodeLookupChildValue(conf, "level");
65 if (level_s != NULL) {
66 int level = SCMapEnumNameToValue(level_s, SCSyslogGetLogLevelMap());
67 if (level != -1) {
68 context->alert_syslog_level = level;
69 }
70 }
71
72 const char *ident = SCConfNodeLookupChildValue(conf, "identity");
73 /* if null we just pass that to openlog, which will then
74 * figure it out by itself. */
75
76 openlog(ident, LOG_PID | LOG_NDELAY, facility);
77 SCLogNotice("Syslog: facility %s, level %s, ident %s", facility_s, level_s, ident);
78 *init_data = context;
79 return 0;
80}
81
82static int SyslogWrite(
83 const char *buffer, const int buffer_len, const void *init_data, void *thread_data)
84{
85 const Context *context = init_data;
86 syslog(context->alert_syslog_level, "%s", (const char *)buffer);
87
88 return 0;
89}
90
91static void SyslogDeInit(void *init_data)
92{
93 if (init_data) {
94 closelog();
95 SCFree(init_data);
96 }
97}
98
100{
101 SCEveFileType *file_type = SCCalloc(1, sizeof(SCEveFileType));
102
103 if (file_type == NULL) {
104 FatalError("Unable to allocate memory for eve file type %s", OUTPUT_NAME);
105 }
106
107 file_type->name = OUTPUT_NAME;
108 file_type->Init = SyslogInit;
109 file_type->Deinit = SyslogDeInit;
110 file_type->Write = SyslogWrite;
111 if (!SCRegisterEveFileType(file_type)) {
112 FatalError("Failed to register EVE file type: %s", OUTPUT_NAME);
113 }
114}
115#endif /* !OS_WIN32 */
const char * SCConfNodeLookupChildValue(const SCConfNode *node, const char *name)
Lookup the value of a child configuration node by name.
Definition conf.c:824
#define OUTPUT_NAME
struct Context_ Context
void SyslogInitialize(void)
bool SCRegisterEveFileType(SCEveFileType *plugin)
Register an Eve file type.
Definition output-eve.c:100
EVE logging subsystem.
Structure used to define an EVE output file type plugin.
Definition output-eve.h:74
void(* Deinit)(void *init_data)
Final call to deinitialize this filetype.
Definition output-eve.h:167
int(* Init)(const SCConfNode *conf, const bool threaded, void **init_data)
Function to initialize this filetype.
Definition output-eve.h:104
int(* Write)(const char *buffer, const int buffer_len, const void *init_data, void *thread_data)
Called for each EVE log record.
Definition output-eve.h:144
const char * name
The name of the output, used in the configuration.
Definition output-eve.h:89
#define FatalError(...)
Definition util-debug.h:510
#define SCLogNotice(...)
Macro used to log NOTICE messages.
Definition util-debug.h:243
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition util-debug.h:255
#define SCLogError(...)
Macro used to log ERROR messages.
Definition util-debug.h:267
int SCMapEnumNameToValue(const char *enum_name, SCEnumCharMap *table)
Maps a string name to an enum value from the supplied table. Please specify the last element of any m...
Definition util-enum.c:40
#define SCFree(p)
Definition util-mem.h:61
#define SCCalloc(nm, sz)
Definition util-mem.h:53
SCEnumCharMap * SCSyslogGetLogLevelMap(void)
returns the syslog facility enum map
Definition util-syslog.c:75
SCEnumCharMap * SCSyslogGetFacilityMap(void)
returns the syslog facility enum map
Definition util-syslog.c:57
#define DEFAULT_ALERT_SYSLOG_FACILITY_STR
Definition util-syslog.h:34
#define DEFAULT_ALERT_SYSLOG_FACILITY
Definition util-syslog.h:35
#define closelog()
#define syslog(__pri, __fmt, __param)
#define openlog(__ident, __option, __facility)