Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows an optionnal Reply-To mail header #727

Merged
merged 2 commits into from
Mar 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions etc/ossec.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<email_to>daniel.cid@example.com</email_to>
<smtp_server>smtp.example.com.</smtp_server>
<email_from>ossecm@ossec.example.com.</email_from>
<!-- <email_reply_to>replyto@ossec.example.com.</email_reply_to> -->
<picviz_output>no</picviz_output>
</global>

Expand Down
10 changes: 9 additions & 1 deletion src/config/global-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/config/mail-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ typedef struct _MailConfig {
int subject_full;
int priority;
char **to;
char *reply_to;
char *from;
char *idsname;
char *smtpserver;
Expand Down
1 change: 1 addition & 0 deletions src/os_maild/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion src/os_maild/sendcustomemail.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions src/os_maild/sendmail.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -462,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;
Expand Down