Skip to content

Commit

Permalink
afsmtp: New destination driver, to send mails via SMTP
Browse files Browse the repository at this point in the history
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
bazsi committed Mar 9, 2012
1 parent 7104231 commit 404ceb9
Show file tree
Hide file tree
Showing 8 changed files with 1,034 additions and 1 deletion.
40 changes: 40 additions & 0 deletions configure.in
Expand Up @@ -174,6 +174,10 @@ AC_ARG_WITH(json,
Use the JSON implementation specified]
,,with_json="auto")

AC_ARG_WITH(libesmtp,
AC_HELP_STRING([--with-libesmtp=DIR],
[use libesmtp library from (prefix) directory DIR]),,)

AC_ARG_ENABLE(systemd,
[ --enable-systemd Enable systemd support (default: auto)]
,,enable_systemd="auto")
Expand Down Expand Up @@ -792,6 +796,37 @@ if test "x$with_libmongo_client" = "xno"; then
enable_mongodb="no"
fi

dnl ***************************************************************************
dnl libesmtp headers/libraries
dnl ***************************************************************************
if test "x$enable_smtp" != "xno" && test "x$with_libesmtp" != "no"; then
libesmtp="yes"
if test "x$with_libesmtp" != "yes" && test "x$with_libesmtp" != "x"; then
CPPFLAGS_SAVE="$CPPFLAGS"
LDFLAGS_SAVE="$LDFLAGS"
CPPFLAGS="$CPPFLAGS -I$with_libesmtp/include"
LDFLAGS="$LDFLAGS -L$with_libesmtp/lib"
AC_CHECK_HEADER(libesmtp.h, [LIBESMTP_CFLAGS="-I$with_libesmtp/include"
LIBESMTP_LIBS="-L$with_libesmtp/lib"], [libesmtp=no])
CPPFLAGS="$CPPFLAGS_SAVE"
LDFLAGS="$LDFLAGS_SAVE"
else
AC_MSG_CHECKING(for libESMTP)
if libesmtp-config --version >/dev/null 2>&1; then
AC_MSG_RESULT(yes)
LIBESMTP_CFLAGS="`libesmtp-config --cflags`"
LIBESMTP_LIBS="`libesmtp-config --libs`"
else
AC_MSG_RESULT(no)
libesmtp=no
fi
fi
if test "x$enable_smtp" = "xyes" && test "x$libesmtp" = "xno"; then
AC_MSG_ERROR(libESMTP not found)
fi
enable_smtp=$libesmtp
fi

dnl ***************************************************************************
dnl misc features to be enabled
dnl ***************************************************************************
Expand Down Expand Up @@ -1068,6 +1103,7 @@ AM_CONDITIONAL(ENABLE_SQL, [test "$enable_sql" = "yes"])
AM_CONDITIONAL(ENABLE_SUN_STREAMS, [test "$enable_sun_streams" = "yes"])
AM_CONDITIONAL(ENABLE_PACCT, [test "$enable_pacct" = "yes"])
AM_CONDITIONAL(ENABLE_MONGODB, [test "$enable_mongodb" = "yes"])
AM_CONDITIONAL(ENABLE_SMTP, [test "$enable_smtp" = "yes"])
AM_CONDITIONAL(ENABLE_JSON_FORMAT, [test "$enable_json_format" = "yes"])
AM_CONDITIONAL(ENABLE_JSON_PARSE, [test "$enable_json_parse" = "yes"])
AM_CONDITIONAL(WITH_LIBSYSTEMD, [test "$with_libsystemd" = "yes"])
Expand Down Expand Up @@ -1101,6 +1137,8 @@ AC_SUBST(LIBDBI_CFLAGS)
AC_SUBST(LIBMONGO_LIBS)
AC_SUBST(LIBMONGO_CFLAGS)
AC_SUBST(LIBMONGO_SUBDIRS)
AC_SUBST(LIBESMTP_CFLAGS)
AC_SUBST(LIBESMTP_LIBS)
AC_SUBST(JSON_LIBS)
AC_SUBST(JSON_CFLAGS)
AC_SUBST(IVYKIS_SUBDIRS)
Expand Down Expand Up @@ -1130,6 +1168,7 @@ AC_OUTPUT(dist.conf
modules/afprog/Makefile
modules/afuser/Makefile
modules/afmongodb/Makefile
modules/afsmtp/Makefile
modules/dbparser/Makefile
modules/dbparser/tests/Makefile
modules/csvparser/Makefile
Expand Down Expand Up @@ -1184,4 +1223,5 @@ echo " SQL support (module) : ${enable_sql:=no}"
echo " PACCT module (EXPERIMENTAL) : ${enable_pacct:=no}"
echo " MongoDB destination (module): ${enable_mongodb:=no}"
echo " JSON support (module) : parser=${enable_json_parse:=no}, formatter=${enable_json_format:=no} (using ${with_json})"
echo " SMTP support (module) : ${enable_smtp:=no}"

2 changes: 1 addition & 1 deletion modules/Makefile.am
@@ -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
19 changes: 19 additions & 0 deletions modules/afsmtp/Makefile.am
@@ -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
101 changes: 101 additions & 0 deletions modules/afsmtp/afsmtp-grammar.ym
@@ -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 */

%%
58 changes: 58 additions & 0 deletions modules/afsmtp/afsmtp-parser.c
@@ -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 **)
35 changes: 35 additions & 0 deletions modules/afsmtp/afsmtp-parser.h
@@ -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

0 comments on commit 404ceb9

Please sign in to comment.