X-Git-Url: http://ftp.carnet.hr/pub/carnet-debian/scm?a=blobdiff_plain;ds=sidebyside;f=src%2Fos_maild%2Fsendmail.c;h=d937a15a6f1c92d8fc0d6516e64725f3ac0a66a4;hb=e81e4e82e5115bf99b6fbd9ebd486de325d67ed6;hp=92157a7cf34e9abd9dcf0a515058f7d3b234d4c5;hpb=301048b51990573e58a30dc4a5bb4ec285cad554;p=ossec-hids.git diff --git a/src/os_maild/sendmail.c b/src/os_maild/sendmail.c index 92157a7..d937a15 100755 --- 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 - * License (version 2) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -35,8 +36,10 @@ #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 XHEADER "X-IDS-OSSEC: %s\r\n" /* Error messages - Can be translated */ @@ -63,8 +66,8 @@ int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg) 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); @@ -79,7 +82,7 @@ int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg) if(msg) free(msg); close(socket); - return(OS_INVALID); + return(OS_INVALID); } 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); - return(OS_INVALID); + return(OS_INVALID); } } 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); - free(msg); + free(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); - return(OS_INVALID); + return(OS_INVALID); } 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; - + 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; - + i++; continue; } @@ -201,7 +204,7 @@ int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg) if(msg) free(msg); close(socket); - return(OS_INVALID); + return(OS_INVALID); } 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); - + /* 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 - + 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); + OS_SendTCP(socket,ENDHEADER); /* 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 */ - 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)))) { @@ -250,7 +254,7 @@ int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg) if(msg) free(msg); close(socket); - return(OS_INVALID); + return(OS_INVALID); } /* 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); - memset(snd_msg,'\0',128); + memset(snd_msg,'\0',128); /* 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]; - char additional_to[512]; 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(); @@ -297,10 +298,10 @@ int OS_Sendmail(MailConfig *mail, struct tm *p) { 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); @@ -315,7 +316,7 @@ int OS_Sendmail(MailConfig *mail, struct tm *p) if(msg) free(msg); close(socket); - return(OS_INVALID); + return(OS_INVALID); } 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); - return(OS_INVALID); + return(OS_INVALID); } } else @@ -365,7 +366,7 @@ int OS_Sendmail(MailConfig *mail, struct tm *p) } MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", HELOMSG, msg); - free(msg); + free(msg); /* Building "Mail from" msg */ @@ -379,10 +380,10 @@ int OS_Sendmail(MailConfig *mail, struct tm *p) if(msg) free(msg); close(socket); - return(OS_INVALID); + return(OS_INVALID); } MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", snd_msg, msg); - free(msg); + free(msg); /* Building "RCPT TO" msg */ @@ -408,7 +409,7 @@ int OS_Sendmail(MailConfig *mail, struct tm *p) if(msg) free(msg); close(socket); - return(OS_INVALID); + return(OS_INVALID); } 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++; - continue; + continue; } - + 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); - return(OS_INVALID); + return(OS_INVALID); } MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", DATAMSG, msg); free(msg); @@ -484,7 +485,7 @@ int OS_Sendmail(MailConfig *mail, struct tm *p) { break; } - + 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 - + 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); @@ -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')) { - snprintf(snd_msg, 127, SUBJECT, _g_subject); + snprintf(snd_msg, 127, SUBJECT, _g_subject); /* 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,ENDHEADER); /* Sending body */ @@ -561,7 +570,7 @@ int OS_Sendmail(MailConfig *mail, struct tm *p) /* 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)))) { @@ -569,7 +578,7 @@ int OS_Sendmail(MailConfig *mail, struct tm *p) if(msg) free(msg); close(socket); - return(OS_INVALID); + return(OS_INVALID); } /* 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); - memset(snd_msg,'\0',128); + memset(snd_msg,'\0',128); /* Returning 0 (success) */