Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
afsmtp: New destination driver, to send mails via SMTP
This introduces the afsmtp destination driver, updated to the latest 3.4 conventions, and with all the threading bugs that were also present in afmongodb too, fixed. The driver itself uses libESMTP to send mail, and has the following config syntax: destination d_smtp { smtp( host("localhost") port(25) subject("ALERT! IMPORTANT EVENT FROM ${HOST}") header("X-Severity", "${SEVERITY}") from("no-reply@${HOST}.dummy") to("syslog-alerts@my.example.domain") bcc("big-brother@my.example.domain") cc("it@my.example.domain") reply-to("admin@my.example.domain") ); }; Signed-off-by: Gergely Nagy <algernon@balabit.hu> Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
- Loading branch information
Showing
8 changed files
with
1,034 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
SUBDIRS = afsocket afsql afstreams affile afprog afuser afmongodb csvparser confgen syslogformat pacctformat basicfuncs dbparser tfjson tfuuid jsonparser dummy | ||
SUBDIRS = afsocket afsql afstreams affile afprog afuser afmongodb afsmtp csvparser confgen syslogformat pacctformat basicfuncs dbparser tfjson tfuuid jsonparser dummy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
moduledir = @moduledir@ | ||
AM_CPPFLAGS = -I$(top_srcdir)/lib -I../../lib | ||
module_LTLIBRARIES = libafsmtp.la | ||
|
||
export top_srcdir | ||
|
||
if ENABLE_SMTP | ||
|
||
libafsmtp_la_CFLAGS = $(LIBESMTP_CFLAGS) $(IVYKIS_CFLAGS) $(EVENTLOG_CFLAGS) $(SYSLOG_NG_CFLAGS) | ||
libafsmtp_la_SOURCES = afsmtp-grammar.y afsmtp.c afsmtp.h afsmtp-parser.c afsmtp-parser.h | ||
libafsmtp_la_LIBADD = $(LIBESMTP_LIBS) $(IVYKIS_LIBS) $(EVENTLOG_LIBS) $(SYSLOG_NG_LIBS) | ||
libafsmtp_la_LDFLAGS = -avoid-version | ||
|
||
endif | ||
|
||
BUILT_SOURCES = afsmtp-grammar.y afsmtp-grammar.c afsmtp-grammar.h | ||
EXTRA_DIST = $(BUILT_SOURCES) afsmtp-grammar.ym | ||
|
||
include $(top_srcdir)/build/lex-rules.am |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (c) 2011-2012 BalaBit IT Ltd, Budapest, Hungary | ||
* Copyright (c) 2011-2012 Gergely Nagy <algernon@balabit.hu> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 as published | ||
* by the Free Software Foundation, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* As an additional exemption you are allowed to compile & link against the | ||
* OpenSSL libraries as published by the OpenSSL project. See the file | ||
* COPYING for details. | ||
* | ||
*/ | ||
|
||
%code requires { | ||
|
||
#include "afsmtp-parser.h" | ||
|
||
} | ||
|
||
%code { | ||
|
||
#include "cfg-parser.h" | ||
#include "afsmtp-grammar.h" | ||
#include "plugin.h" | ||
|
||
extern LogDriver *last_driver; | ||
|
||
} | ||
|
||
%name-prefix "afsmtp_" | ||
%lex-param {CfgLexer *lexer} | ||
%parse-param {CfgLexer *lexer} | ||
%parse-param {LogDriver **instance} | ||
%parse-param {gpointer arg} | ||
|
||
/* INCLUDE_DECLS */ | ||
|
||
%token KW_SMTP | ||
%token KW_SUBJECT | ||
%token KW_FROM | ||
%token KW_TO | ||
%token KW_BODY | ||
%token KW_HEADER | ||
%token KW_CC | ||
%token KW_BCC | ||
%token KW_SENDER | ||
%token KW_REPLY_TO | ||
|
||
%% | ||
|
||
start | ||
: LL_CONTEXT_DESTINATION KW_SMTP | ||
{ | ||
last_driver = *instance = afsmtp_dd_new(); | ||
} | ||
'(' afsmtp_options ')' { YYACCEPT; } | ||
; | ||
|
||
afsmtp_options | ||
: afsmtp_option afsmtp_options | ||
| | ||
; | ||
|
||
afsmtp_option | ||
: KW_HOST '(' string ')' { afsmtp_dd_set_host(last_driver, $3); free($3); } | ||
| KW_PORT '(' LL_NUMBER ')' { afsmtp_dd_set_port(last_driver, $3); } | ||
| KW_SUBJECT '(' string ')' { afsmtp_dd_set_subject(last_driver, $3); free($3); } | ||
| KW_BODY '(' string ')' { afsmtp_dd_set_body(last_driver, $3); free($3); } | ||
| KW_HEADER '(' string string ')' { | ||
afsmtp_dd_add_header(last_driver, $3, $4); | ||
free($3); free($4); | ||
} | ||
|
||
| KW_FROM '(' string ')' { afsmtp_dd_set_from(last_driver, $3, $3); free($3); } | ||
| KW_FROM '(' string string ')' { afsmtp_dd_set_from(last_driver, $3, $4); free($3); free($4); } | ||
| KW_SENDER '(' string ')' { afsmtp_dd_set_from(last_driver, $3, $3); free($3); } | ||
| KW_SENDER '(' string string ')' { afsmtp_dd_set_from(last_driver, $3, $4); free($3); free($4); } | ||
| KW_TO '(' string ')' { afsmtp_dd_add_rcpt(last_driver, AFSMTP_RCPT_TYPE_TO, $3, $3); free($3); } | ||
| KW_TO '(' string string ')' { afsmtp_dd_add_rcpt(last_driver, AFSMTP_RCPT_TYPE_TO, $3, $4); free($3); free($4); } | ||
| KW_CC '(' string ')' { afsmtp_dd_add_rcpt(last_driver, AFSMTP_RCPT_TYPE_CC, $3, $3); free($3); } | ||
| KW_CC '(' string string ')' { afsmtp_dd_add_rcpt(last_driver, AFSMTP_RCPT_TYPE_CC, $3, $4); free($3); free($4); } | ||
| KW_BCC '(' string ')' { afsmtp_dd_add_rcpt(last_driver, AFSMTP_RCPT_TYPE_BCC, $3, $3); free($3); } | ||
| KW_BCC '(' string string ')' { afsmtp_dd_add_rcpt(last_driver, AFSMTP_RCPT_TYPE_BCC, $3, $4); free($3); free($4); } | ||
| KW_REPLY_TO '(' string ')' { afsmtp_dd_add_rcpt(last_driver, AFSMTP_RCPT_TYPE_REPLY_TO, $3, $3); free($3); } | ||
| KW_REPLY_TO '(' string string ')' { afsmtp_dd_add_rcpt(last_driver, AFSMTP_RCPT_TYPE_REPLY_TO, $3, $4); free($3); free($4); } | ||
| dest_driver_option | ||
; | ||
|
||
/* INCLUDE_RULES */ | ||
|
||
%% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2011-2012 BalaBit IT Ltd, Budapest, Hungary | ||
* Copyright (c) 2011-2012 Gergely Nagy <algernon@balabit.hu> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 as published | ||
* by the Free Software Foundation, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* As an additional exemption you are allowed to compile & link against the | ||
* OpenSSL libraries as published by the OpenSSL project. See the file | ||
* COPYING for details. | ||
* | ||
*/ | ||
|
||
#include "afsmtp.h" | ||
#include "cfg-parser.h" | ||
#include "afsmtp-grammar.h" | ||
|
||
extern int afsmtp_debug; | ||
int afsmtp_parse(CfgLexer *lexer, LogDriver **instance); | ||
|
||
static CfgLexerKeyword afsmtp_keywords[] = { | ||
{ "smtp", KW_SMTP }, | ||
{ "host", KW_HOST }, | ||
{ "port", KW_PORT }, | ||
{ "subject", KW_SUBJECT }, | ||
{ "from", KW_FROM }, | ||
{ "to", KW_TO }, | ||
{ "cc", KW_CC }, | ||
{ "bcc", KW_BCC }, | ||
{ "reply_to", KW_REPLY_TO }, | ||
{ "sender", KW_SENDER }, | ||
{ "body", KW_BODY }, | ||
{ "header", KW_HEADER }, | ||
{ NULL } | ||
}; | ||
|
||
CfgParser afsmtp_parser = | ||
{ | ||
#if ENABLE_DEBUG | ||
.debug_flag = &afsmtp_debug, | ||
#endif | ||
.name = "afsmtp", | ||
.keywords = afsmtp_keywords, | ||
.parse = (int (*)(CfgLexer *lexer, gpointer *instance, gpointer)) afsmtp_parse, | ||
.cleanup = (void (*)(gpointer)) log_pipe_unref, | ||
}; | ||
|
||
CFG_PARSER_IMPLEMENT_LEXER_BINDING(afsmtp_, LogDriver **) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2011-2012 BalaBit IT Ltd, Budapest, Hungary | ||
* Copyright (c) 2011-2012 Gergely Nagy <algernon@balabit.hu> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 as published | ||
* by the Free Software Foundation, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* As an additional exemption you are allowed to compile & link against the | ||
* OpenSSL libraries as published by the OpenSSL project. See the file | ||
* COPYING for details. | ||
* | ||
*/ | ||
|
||
#ifndef AFSMTP_PARSER_H_INCLUDED | ||
#define AFSMTP_PARSER_H_INCLUDED | ||
|
||
#include "cfg-parser.h" | ||
#include "cfg-lexer.h" | ||
#include "afsmtp.h" | ||
|
||
extern CfgParser afsmtp_parser; | ||
|
||
CFG_PARSER_DECLARE_LEXER_BINDING(afsmtp_, LogDriver **) | ||
|
||
#endif |
Oops, something went wrong.