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

Remove SMS support. #1638

Merged
merged 1 commit into from
Jan 11, 2019
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
4 changes: 1 addition & 3 deletions src/config/email-alerts-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ int Read_EmailAlerts(XML_NODE node, __attribute__((unused)) void *configp, void
}

} else if (strcmp(node[i]->element, xml_email_format) == 0) {
if (strcmp(node[i]->content, "sms") == 0) {
Mail->gran_format[granto_size] = SMS_FORMAT;
} else if (strcmp(node[i]->content, "default") == 0) {
if (strcmp(node[i]->content, "default") == 0) {
/* Default is full format */
} else {
merror(XML_VALUEERR, __local_name, node[i]->element, node[i]->content);
Expand Down
25 changes: 0 additions & 25 deletions src/os_maild/maild.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,31 +237,6 @@ static void OS_Run(MailConfig *mail)
tm = time(NULL);
p = localtime(&tm);

/* SMS messages are sent without delay */
if (msg_sms) {
pid_t pid;

pid = fork();

if (pid < 0) {
merror(FORK_ERROR, ARGV0, errno, strerror(errno));
sleep(30);
continue;
} else if (pid == 0) {
if (OS_Sendsms(mail, p, msg_sms) < 0) {
merror(SNDMAIL_ERROR, ARGV0, mail->smtpserver);
}

exit(0);
}

/* Free SMS structure */
FreeMailMsg(msg_sms);
msg_sms = NULL;

/* Increase child count */
childcount++;
}

/* If mail_timeout == NEXTMAIL_TIMEOUT, we will try to get
* more messages, before sending anything
Expand Down
1 change: 0 additions & 1 deletion src/os_maild/maild.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ MailMsg *OS_RecvMailQ(file_queue *fileq, struct tm *p, MailConfig *mail,

/* Send an email */
int OS_Sendmail(MailConfig *mail, struct tm *p) __attribute__((nonnull));
int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg) __attribute__((nonnull));
int OS_SendCustomEmail(char **to, char *subject, char *smtpserver, char *from, char *idsname, char *fname, const struct tm *p);

/* Mail timeout used by the file-queue */
Expand Down
233 changes: 0 additions & 233 deletions src/os_maild/sendmail.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,239 +47,6 @@
#define MAIL_DEBUG(x,y,z) if(MAIL_DEBUG_FLAG) merror(x,y,z)


int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg)
{
FILE *sendmail = NULL;
int socket = -1;
size_t final_to_sz;
char *msg;
char snd_msg[128];
char final_to[512];

if (mail->smtpserver[0] == '/') {
sendmail = popen(mail->smtpserver, "w");
if (!sendmail) {
return (OS_INVALID);
}
} else {
/* Connect to the SMTP server */
socket = OS_ConnectTCP(SMTP_DEFAULT_PORT, mail->smtpserver);
if (socket < 0) {
return (socket);
}

/* Receive the banner */
msg = OS_RecvTCP(socket, OS_SIZE_1024);
if ((msg == NULL) || (!OS_Match(VALIDBANNER, msg))) {
merror(BANNER_ERROR);
if (msg) {
free(msg);
}
close(socket);
return (OS_INVALID);
}
MAIL_DEBUG("DEBUG: Received banner: '%s' %s", msg, "");
free(msg);

/* Send HELO message */
memset(snd_msg, '\0', 128);
if (mail->heloserver) {
snprintf(snd_msg, 127, "Helo %s\r\n", mail->heloserver);
} else {
snprintf(snd_msg, 127, "Helo %s\r\n", "notify.ossec.net");
}
OS_SendTCP(socket, snd_msg);
msg = OS_RecvTCP(socket, OS_SIZE_1024);
if ((msg == NULL) || (!OS_Match(VALIDMAIL, msg))) {
if (msg) {
/* In some cases (with virus scans in the middle)
* we may get two banners. Check for that in here.
*/
if (OS_Match(VALIDBANNER, msg)) {
free(msg);

/* Try again */
msg = OS_RecvTCP(socket, OS_SIZE_1024);
if ((msg == NULL) || (!OS_Match(VALIDMAIL, msg))) {
merror("%s:%s", HELO_ERROR, msg != NULL ? msg : "null");
if (msg) {
free(msg);
}
close(socket);
return (OS_INVALID);
}
} else {
merror("%s:%s", HELO_ERROR, msg);
free(msg);
close(socket);
return (OS_INVALID);
}
} else {
merror("%s:%s", HELO_ERROR, "null");
close(socket);
return (OS_INVALID);
}
}

MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", snd_msg, msg);
free(msg);

/* Build "Mail from" msg */
memset(snd_msg, '\0', 128);
snprintf(snd_msg, 127, MAILFROM, mail->from);
OS_SendTCP(socket, snd_msg);
msg = OS_RecvTCP(socket, OS_SIZE_1024);
if ((msg == NULL) || (!OS_Match(VALIDMAIL, msg))) {
merror(FROM_ERROR);
if (msg) {
free(msg);
}
close(socket);
return (OS_INVALID);
}
MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", snd_msg, msg);
free(msg);

/* Additional RCPT to */
final_to[0] = '\0';
final_to_sz = sizeof(final_to) - 2;

if (mail->gran_to) {
int i = 0;
while (mail->gran_to[i] != NULL) {
if (mail->gran_set[i] != SMS_FORMAT) {
i++;
continue;
}

memset(snd_msg, '\0', 128);
snprintf(snd_msg, 127, RCPTTO, mail->gran_to[i]);
OS_SendTCP(socket, snd_msg);
msg = OS_RecvTCP(socket, OS_SIZE_1024);
if ((msg == NULL) || (!OS_Match(VALIDMAIL, msg))) {
merror(TO_ERROR, mail->gran_to[i]);
if (msg) {
free(msg);
}
close(socket);
return (OS_INVALID);
}
MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", snd_msg, msg);
free(msg);

/* Create header for to */
memset(snd_msg, '\0', 128);
snprintf(snd_msg, 127, TO, mail->gran_to[i]);
strncat(final_to, snd_msg, final_to_sz);
final_to_sz -= strlen(snd_msg) + 2;

i++;
continue;
}
}

/* Send the "DATA" msg */
OS_SendTCP(socket, DATAMSG);
msg = OS_RecvTCP(socket, OS_SIZE_1024);
if ((msg == NULL) || (!OS_Match(VALIDDATA, msg))) {
merror(DATA_ERROR);
if (msg) {
free(msg);
}
close(socket);
return (OS_INVALID);
}
MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", DATAMSG, msg);
free(msg);

/* Build "From" and "To" in the e-mail header */
OS_SendTCP(socket, final_to);
}

memset(snd_msg, '\0', 128);
snprintf(snd_msg, 127, FROM, mail->from);

if (sendmail) {
fprintf(sendmail, "%s", snd_msg);
} else {
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 (socket > 0) {
OS_SendTCP(socket, snd_msg);
}
}

/* Send date */
memset(snd_msg, '\0', 128);

/* Solaris doesn't have the "%z", so we set the timezone to 0 */
#ifdef SOLARIS
strftime(snd_msg, 127, "Date: %a, %d %b %Y %T -0000\r\n", p);
#else
strftime(snd_msg, 127, "Date: %a, %d %b %Y %T %z\r\n", p);
#endif

if (sendmail) {
fprintf(sendmail, "%s", snd_msg);
} else {
OS_SendTCP(socket, snd_msg);
}

/* Send subject */
memset(snd_msg, '\0', 128);
snprintf(snd_msg, 127, SUBJECT, sms_msg->subject);

if (sendmail) {
fprintf(sendmail, "%s", snd_msg);
fprintf(sendmail, ENDHEADER);
fprintf(sendmail, "%s", sms_msg->body);

if (pclose(sendmail) == -1) {
merror(WAITPID_ERROR, ARGV0, errno, strerror(errno));
}
} else {
OS_SendTCP(socket, snd_msg);
OS_SendTCP(socket, ENDHEADER);

/* Send body */
OS_SendTCP(socket, sms_msg->body);

/* Send end of data \r\n.\r\n */
OS_SendTCP(socket, ENDDATA);
msg = OS_RecvTCP(socket, OS_SIZE_1024);
if (mail->strict_checking && ((msg == NULL) || (!OS_Match(VALIDMAIL, msg)))) {
merror(END_DATA_ERROR);
if (msg) {
free(msg);
}
close(socket);
return (OS_INVALID);
}
/* Check msg, since it may be null */
if (msg) {
free(msg);
}

/* Quit and close socket */
OS_SendTCP(socket, QUITMSG);
msg = OS_RecvTCP(socket, OS_SIZE_1024);

if (msg) {
free(msg);
}

close(socket);
}

memset_secure(snd_msg, '\0', 128);
return (0);
}

int OS_Sendmail(MailConfig *mail, struct tm *p)
{
FILE *sendmail = NULL;
Expand Down