projects
/
ossec-hids.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
izmjene za lintian
[ossec-hids.git]
/
src
/
os_maild
/
sendmail.c
diff --git
a/src/os_maild/sendmail.c
b/src/os_maild/sendmail.c
index
92157a7
..
d937a15
100755
(executable)
--- a/
src/os_maild/sendmail.c
+++ b/
src/os_maild/sendmail.c
@@
-1,11
+1,12
@@
-/* @(#) $Id$ */
+/* @(#) $Id: ./src/os_maild/sendmail.c, 2011/09/08 dcid Exp $
+ */
/* Copyright (C) 2009 Trend Micro Inc.
* All rights reserved.
*
* This program is a free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public
/* Copyright (C) 2009 Trend Micro Inc.
* All rights reserved.
*
* This program is a 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 FSF - Free Software
+ * License (version 2) as published by the FSF - Free Software
* Foundation
*/
* Foundation
*/
@@
-35,8
+36,10
@@
#define TO "To: <%s>\r\n"
#define CC "Cc: <%s>\r\n"
#define SUBJECT "Subject: %s\r\n"
#define TO "To: <%s>\r\n"
#define CC "Cc: <%s>\r\n"
#define SUBJECT "Subject: %s\r\n"
+#define ENDHEADER "\r\n"
#define ENDDATA "\r\n.\r\n"
#define QUITMSG "QUIT\r\n"
#define ENDDATA "\r\n.\r\n"
#define QUITMSG "QUIT\r\n"
+#define XHEADER "X-IDS-OSSEC: %s\r\n"
/* Error messages - Can be translated */
/* Error messages - Can be translated */
@@
-63,8
+66,8
@@
int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg)
char final_to[512];
char final_to[512];
- /* Connecting to the smtp server */
- socket = OS_ConnectTCP(SMTP_DEFAULT_PORT, mail->smtpserver);
+ /* Connecting to the smtp server */
+ socket = OS_ConnectTCP(SMTP_DEFAULT_PORT, mail->smtpserver, 0);
if(socket < 0)
{
return(socket);
if(socket < 0)
{
return(socket);
@@
-79,7
+82,7
@@
int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg)
if(msg)
free(msg);
close(socket);
if(msg)
free(msg);
close(socket);
- return(OS_INVALID);
+ return(OS_INVALID);
}
MAIL_DEBUG("DEBUG: Received banner: '%s' %s", msg, "");
free(msg);
}
MAIL_DEBUG("DEBUG: Received banner: '%s' %s", msg, "");
free(msg);
@@
-109,7
+112,7
@@
int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg)
if(msg)
free(msg);
close(socket);
if(msg)
free(msg);
close(socket);
- return(OS_INVALID);
+ return(OS_INVALID);
}
}
else
}
}
else
@@
-129,7
+132,7
@@
int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg)
}
MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", HELOMSG, msg);
}
MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", HELOMSG, msg);
- free(msg);
+ free(msg);
/* Building "Mail from" msg */
/* Building "Mail from" msg */
@@
-143,16
+146,16
@@
int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg)
if(msg)
free(msg);
close(socket);
if(msg)
free(msg);
close(socket);
- return(OS_INVALID);
+ return(OS_INVALID);
}
MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", snd_msg, msg);
}
MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", snd_msg, msg);
- free(msg);
+ free(msg);
/* Additional RCPT to */
final_to[0] = '\0';
final_to_sz = sizeof(final_to) -2;
/* Additional RCPT to */
final_to[0] = '\0';
final_to_sz = sizeof(final_to) -2;
-
+
if(mail->gran_to)
{
i = 0;
if(mail->gran_to)
{
i = 0;
@@
-185,7
+188,7
@@
int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg)
snprintf(snd_msg,127, TO, mail->gran_to[i]);
strncat(final_to, snd_msg, final_to_sz);
final_to_sz -= strlen(snd_msg) +2;
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;
}
i++;
continue;
}
@@
-201,7
+204,7
@@
int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg)
if(msg)
free(msg);
close(socket);
if(msg)
free(msg);
close(socket);
- return(OS_INVALID);
+ return(OS_INVALID);
}
MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", DATAMSG, msg);
free(msg);
}
MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", DATAMSG, msg);
free(msg);
@@
-218,7
+221,7
@@
int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg)
/* Sending date */
memset(snd_msg,'\0',128);
/* Sending date */
memset(snd_msg,'\0',128);
-
+
/* Solaris doesn't have the "%z", so we set the timezone to 0. */
#ifdef SOLARIS
/* Solaris doesn't have the "%z", so we set the timezone to 0. */
#ifdef SOLARIS
@@
-226,7
+229,7
@@
int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg)
#else
strftime(snd_msg, 127, "Date: %a, %d %b %Y %T %z\r\n",p);
#endif
#else
strftime(snd_msg, 127, "Date: %a, %d %b %Y %T %z\r\n",p);
#endif
-
+
OS_SendTCP(socket,snd_msg);
OS_SendTCP(socket,snd_msg);
@@
-235,6
+238,7
@@
int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg)
snprintf(snd_msg, 127, SUBJECT, sms_msg->subject);
OS_SendTCP(socket,snd_msg);
snprintf(snd_msg, 127, SUBJECT, sms_msg->subject);
OS_SendTCP(socket,snd_msg);
+ OS_SendTCP(socket,ENDHEADER);
/* Sending body */
/* Sending body */
@@
-242,7
+246,7
@@
int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg)
/* Sending end of data \r\n.\r\n */
/* Sending end of data \r\n.\r\n */
- OS_SendTCP(socket,ENDDATA);
+ OS_SendTCP(socket,ENDDATA);
msg = OS_RecvTCP(socket, OS_SIZE_1024);
if(mail->strict_checking && ((msg == NULL)||(!OS_Match(VALIDMAIL, msg))))
{
msg = OS_RecvTCP(socket, OS_SIZE_1024);
if(mail->strict_checking && ((msg == NULL)||(!OS_Match(VALIDMAIL, msg))))
{
@@
-250,7
+254,7
@@
int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg)
if(msg)
free(msg);
close(socket);
if(msg)
free(msg);
close(socket);
- return(OS_INVALID);
+ return(OS_INVALID);
}
/* Checking msg in here, since it may be null */
if(msg)
}
/* Checking msg in here, since it may be null */
if(msg)
@@
-264,7
+268,7
@@
int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg)
if(msg)
free(msg);
if(msg)
free(msg);
- memset(snd_msg,'\0',128);
+ memset(snd_msg,'\0',128);
/* Returning 0 (success) */
/* Returning 0 (success) */
@@
-282,13
+286,10
@@
int OS_Sendmail(MailConfig *mail, struct tm *p)
int socket,i=0;
char *msg;
char snd_msg[128];
int socket,i=0;
char *msg;
char snd_msg[128];
- char additional_to[512];
MailNode *mailmsg;
MailNode *mailmsg;
- additional_to[0] = '\0';
-
- /* If there is no sms message, we attempt to get from the
+ /* If there is no sms message, we attempt to get from the
* email list.
*/
mailmsg = OS_PopLastMail();
* email list.
*/
mailmsg = OS_PopLastMail();
@@
-297,10
+298,10
@@
int OS_Sendmail(MailConfig *mail, struct tm *p)
{
merror("%s: No email to be sent. Inconsistent state.",ARGV0);
}
{
merror("%s: No email to be sent. Inconsistent state.",ARGV0);
}
-
- /* Connecting to the smtp server */
- socket = OS_ConnectTCP(SMTP_DEFAULT_PORT, mail->smtpserver);
+
+ /* Connecting to the smtp server */
+ socket = OS_ConnectTCP(SMTP_DEFAULT_PORT, mail->smtpserver, 0);
if(socket < 0)
{
return(socket);
if(socket < 0)
{
return(socket);
@@
-315,7
+316,7
@@
int OS_Sendmail(MailConfig *mail, struct tm *p)
if(msg)
free(msg);
close(socket);
if(msg)
free(msg);
close(socket);
- return(OS_INVALID);
+ return(OS_INVALID);
}
MAIL_DEBUG("DEBUG: Received banner: '%s' %s", msg, "");
free(msg);
}
MAIL_DEBUG("DEBUG: Received banner: '%s' %s", msg, "");
free(msg);
@@
-345,7
+346,7
@@
int OS_Sendmail(MailConfig *mail, struct tm *p)
if(msg)
free(msg);
close(socket);
if(msg)
free(msg);
close(socket);
- return(OS_INVALID);
+ return(OS_INVALID);
}
}
else
}
}
else
@@
-365,7
+366,7
@@
int OS_Sendmail(MailConfig *mail, struct tm *p)
}
MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", HELOMSG, msg);
}
MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", HELOMSG, msg);
- free(msg);
+ free(msg);
/* Building "Mail from" msg */
/* Building "Mail from" msg */
@@
-379,10
+380,10
@@
int OS_Sendmail(MailConfig *mail, struct tm *p)
if(msg)
free(msg);
close(socket);
if(msg)
free(msg);
close(socket);
- return(OS_INVALID);
+ return(OS_INVALID);
}
MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", snd_msg, msg);
}
MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", snd_msg, msg);
- free(msg);
+ free(msg);
/* Building "RCPT TO" msg */
/* Building "RCPT TO" msg */
@@
-408,7
+409,7
@@
int OS_Sendmail(MailConfig *mail, struct tm *p)
if(msg)
free(msg);
close(socket);
if(msg)
free(msg);
close(socket);
- return(OS_INVALID);
+ return(OS_INVALID);
}
MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", snd_msg, msg);
free(msg);
}
MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", snd_msg, msg);
free(msg);
@@
-438,9
+439,9
@@
int OS_Sendmail(MailConfig *mail, struct tm *p)
free(msg);
i++;
free(msg);
i++;
- continue;
+ continue;
}
}
-
+
MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", snd_msg, msg);
free(msg);
i++;
MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", snd_msg, msg);
free(msg);
i++;
@@
-458,7
+459,7
@@
int OS_Sendmail(MailConfig *mail, struct tm *p)
if(msg)
free(msg);
close(socket);
if(msg)
free(msg);
close(socket);
- return(OS_INVALID);
+ return(OS_INVALID);
}
MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", DATAMSG, msg);
free(msg);
}
MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", DATAMSG, msg);
free(msg);
@@
-484,7
+485,7
@@
int OS_Sendmail(MailConfig *mail, struct tm *p)
{
break;
}
{
break;
}
-
+
memset(snd_msg,'\0',128);
snprintf(snd_msg,127, TO, mail->to[i]);
OS_SendTCP(socket,snd_msg);
memset(snd_msg,'\0',128);
snprintf(snd_msg,127, TO, mail->to[i]);
OS_SendTCP(socket,snd_msg);
@@
-525,9
+526,16
@@
int OS_Sendmail(MailConfig *mail, struct tm *p)
#else
strftime(snd_msg, 127, "Date: %a, %d %b %Y %T %z\r\n",p);
#endif
#else
strftime(snd_msg, 127, "Date: %a, %d %b %Y %T %z\r\n",p);
#endif
-
+
OS_SendTCP(socket,snd_msg);
OS_SendTCP(socket,snd_msg);
+ if(mail->idsname)
+ {
+ /* Sending server name header */
+ memset(snd_msg,'\0',128);
+ snprintf(snd_msg,127, XHEADER, mail->idsname);
+ OS_SendTCP(socket, snd_msg);
+ }
/* Sending subject */
memset(snd_msg,'\0',128);
/* Sending subject */
memset(snd_msg,'\0',128);
@@
-536,7
+544,7
@@
int OS_Sendmail(MailConfig *mail, struct tm *p)
/* Checking if global subject is available */
if((_g_subject_level != 0) && (_g_subject[0] != '\0'))
{
/* Checking if global subject is available */
if((_g_subject_level != 0) && (_g_subject[0] != '\0'))
{
- snprintf(snd_msg, 127, SUBJECT, _g_subject);
+ snprintf(snd_msg, 127, SUBJECT, _g_subject);
/* Clearing global values */
_g_subject[0] = '\0';
/* Clearing global values */
_g_subject[0] = '\0';
@@
-548,6
+556,7
@@
int OS_Sendmail(MailConfig *mail, struct tm *p)
}
OS_SendTCP(socket,snd_msg);
}
OS_SendTCP(socket,snd_msg);
+ OS_SendTCP(socket,ENDHEADER);
/* Sending body */
/* Sending body */
@@
-561,7
+570,7
@@
int OS_Sendmail(MailConfig *mail, struct tm *p)
/* Sending end of data \r\n.\r\n */
/* Sending end of data \r\n.\r\n */
- OS_SendTCP(socket,ENDDATA);
+ OS_SendTCP(socket,ENDDATA);
msg = OS_RecvTCP(socket, OS_SIZE_1024);
if(mail->strict_checking && ((msg == NULL)||(!OS_Match(VALIDMAIL, msg))))
{
msg = OS_RecvTCP(socket, OS_SIZE_1024);
if(mail->strict_checking && ((msg == NULL)||(!OS_Match(VALIDMAIL, msg))))
{
@@
-569,7
+578,7
@@
int OS_Sendmail(MailConfig *mail, struct tm *p)
if(msg)
free(msg);
close(socket);
if(msg)
free(msg);
close(socket);
- return(OS_INVALID);
+ return(OS_INVALID);
}
/* Checking msg in here, since it may be null */
if(msg)
}
/* Checking msg in here, since it may be null */
if(msg)
@@
-583,7
+592,7
@@
int OS_Sendmail(MailConfig *mail, struct tm *p)
if(msg)
free(msg);
if(msg)
free(msg);
- memset(snd_msg,'\0',128);
+ memset(snd_msg,'\0',128);
/* Returning 0 (success) */
/* Returning 0 (success) */