From a40373e197387a40993d696ccb25cd27a243605e Mon Sep 17 00:00:00 2001 From: calve Date: Fri, 11 Dec 2015 12:13:25 +0100 Subject: [PATCH 1/2] Basic custom ``Reply-To`` mail header implementation --- etc/ossec.conf | 1 + src/config/global-config.c | 10 +++++++++- src/config/mail-config.h | 1 + src/os_maild/config.c | 1 + src/os_maild/sendcustomemail.c | 9 ++++++++- src/os_maild/sendmail.c | 8 ++++++++ 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/etc/ossec.conf b/etc/ossec.conf index 5f7125661..621cde434 100755 --- a/etc/ossec.conf +++ b/etc/ossec.conf @@ -6,6 +6,7 @@ daniel.cid@example.com smtp.example.com. ossecm@ossec.example.com. + no diff --git a/src/config/global-config.c b/src/config/global-config.c index 4357f159a..e97e06674 100644 --- a/src/config/global-config.c +++ b/src/config/global-config.c @@ -114,6 +114,7 @@ int Read_Global(XML_NODE node, void *configp, void *mailp) const char *xml_emailto = "email_to"; const char *xml_emailfrom = "email_from"; + const char *xml_emailreplyto = "email_reply_to"; const char *xml_emailidsname = "email_idsname"; const char *xml_smtpserver = "smtp_server"; const char *xml_heloserver = "helo_server"; @@ -403,7 +404,7 @@ int Read_Global(XML_NODE node, void *configp, void *mailp) } /* For the email now - * email_to, email_from, idsname, smtp_Server and maxperhour. + * email_to, email_from, email_replyto, idsname, smtp_Server and maxperhour. * We will use a separate structure for that. */ else if (strcmp(node[i]->element, xml_emailto) == 0) { @@ -431,6 +432,13 @@ int Read_Global(XML_NODE node, void *configp, void *mailp) } os_strdup(node[i]->content, Mail->from); } + } else if (strcmp(node[i]->element, xml_emailreplyto) == 0) { + if (Mail) { + if (Mail->reply_to) { + free(Mail->reply_to); + } + os_strdup(node[i]->content, Mail->reply_to); + } } else if (strcmp(node[i]->element, xml_emailidsname) == 0) { if (Mail) { if (Mail->idsname) { diff --git a/src/config/mail-config.h b/src/config/mail-config.h index 5696a74cb..f6864dc2e 100644 --- a/src/config/mail-config.h +++ b/src/config/mail-config.h @@ -21,6 +21,7 @@ typedef struct _MailConfig { int subject_full; int priority; char **to; + char *reply_to; char *from; char *idsname; char *smtpserver; diff --git a/src/os_maild/config.c b/src/os_maild/config.c index 514a869e2..13f2f2f6f 100644 --- a/src/os_maild/config.c +++ b/src/os_maild/config.c @@ -20,6 +20,7 @@ int MailConf(int test_config, const char *cfgfile, MailConfig *Mail) modules |= CMAIL; Mail->to = NULL; + Mail->reply_to = NULL; Mail->from = NULL; Mail->idsname = NULL; Mail->smtpserver = NULL; diff --git a/src/os_maild/sendcustomemail.c b/src/os_maild/sendcustomemail.c index d0dc798cf..270d3f78d 100644 --- a/src/os_maild/sendcustomemail.c +++ b/src/os_maild/sendcustomemail.c @@ -24,6 +24,7 @@ #define RCPTTO "Rcpt To: <%s>\r\n" #define DATAMSG "DATA\r\n" #define FROM "From: OSSEC HIDS <%s>\r\n" +#define REPLYTO "Reply-To: OSSEC HIDS <%s>\r\n" #define TO "To: <%s>\r\n" #define CC "Cc: <%s>\r\n" #define SUBJECT "Subject: %s\r\n" @@ -45,7 +46,7 @@ #define MAIL_DEBUG(x,y,z) if(MAIL_DEBUG_FLAG) merror(x,y,z) -int OS_SendCustomEmail(char **to, char *subject, char *smtpserver, char *from, char *idsname, FILE *fp, const struct tm *p) +int OS_SendCustomEmail(char **to, char *subject, char *smtpserver, char *from, char *replyto, char *idsname, FILE *fp, const struct tm *p) { FILE *sendmail = NULL; int socket = -1, i = 0; @@ -187,6 +188,12 @@ int OS_SendCustomEmail(char **to, char *subject, char *smtpserver, char *from, c OS_SendTCP(socket, snd_msg); } + if (replyto) { + memset(snd_msg, '\0', 128); + snprintf(snd_msg, 127, REPLYTO, replyto); + OS_SendTCP(socket, snd_msg); + } + /* Add CCs */ if (to[1]) { i = 1; diff --git a/src/os_maild/sendmail.c b/src/os_maild/sendmail.c index 72107203a..c3bec7179 100644 --- a/src/os_maild/sendmail.c +++ b/src/os_maild/sendmail.c @@ -26,6 +26,7 @@ #define DATAMSG "DATA\r\n" #define FROM "From: OSSEC HIDS <%s>\r\n" #define TO "To: <%s>\r\n" +#define REPLYTO "Reply-To: OSSEC HIDS <%s>\r\n" /*#define CC "Cc: <%s>\r\n"*/ #define SUBJECT "Subject: %s\r\n" #define ENDHEADER "\r\n" @@ -204,6 +205,13 @@ int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg) OS_SendTCP(socket, snd_msg); } + /* Send reply-to if set */ + if (mail->reply_to){ + memset(snd_msg, '\0', 128); + snprintf(snd_msg, 127, REPLYTO, mail->reply_to); + OS_SendTCP(socket, snd_msg); + } + /* Send date */ memset(snd_msg, '\0', 128); From b9f3000ccb0bbc75ce86b6fae34b7a2570eae030 Mon Sep 17 00:00:00 2001 From: calve Date: Wed, 6 Jan 2016 00:37:14 +0000 Subject: [PATCH 2/2] Implements Reply-To for OS_Sendmail() --- src/os_maild/sendmail.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/os_maild/sendmail.c b/src/os_maild/sendmail.c index c3bec7179..3028a43c4 100644 --- a/src/os_maild/sendmail.c +++ b/src/os_maild/sendmail.c @@ -470,6 +470,17 @@ int OS_Sendmail(MailConfig *mail, struct tm *p) OS_SendTCP(socket, snd_msg); } + /* Send reply-to if set */ + if (mail->reply_to){ + memset(snd_msg, '\0', 128); + snprintf(snd_msg, 127, REPLYTO, mail->reply_to); + if (sendmail) { + fprintf(sendmail, snd_msg); + } else { + OS_SendTCP(socket, snd_msg); + } + } + /* Add CCs */ if (mail->to[1]) { i = 1;