@ -799,31 +799,10 @@ static int SMTPProcessCommandBDAT(SMTPState *state, Flow *f,
SCReturnInt ( 0 ) ;
}
static int SMTPProcessCommandDATA ( SMTPState * state , Flow * f ,
AppLayerParserState * pstate )
static void SetMimeEvents ( SMTPState * state )
{
SCEnter ( ) ;
if ( ! ( state - > parser_state & SMTP_PARSER_STATE_COMMAND_DATA_MODE ) ) {
/* looks like are still waiting for a confirmination from the server */
return 0 ;
}
if ( state - > current_line_len = = 1 & & state - > current_line [ 0 ] = = ' . ' ) {
state - > parser_state & = ~ SMTP_PARSER_STATE_COMMAND_DATA_MODE ;
/* kinda like a hack. The mail sent in DATA mode, would be
* acknowledged with a reply . We insert a dummy command to
* the command buffer to be used by the reply handler to match
* the reply received */
SMTPInsertCommandIntoCommandBuffer ( SMTP_COMMAND_DATA_MODE , state , f ) ;
if ( smtp_config . decode_mime & & state - > curr_tx - > mime_state ! = NULL ) {
/* Complete parsing task */
int ret = MimeDecParseComplete ( state - > curr_tx - > mime_state ) ;
if ( ret ! = MIME_DEC_OK ) {
SMTPSetEvent ( state , SMTP_DECODER_EVENT_MIME_PARSE_FAILED ) ;
SCLogDebug ( " MimeDecParseComplete() function failed " ) ;
if ( state - > curr_tx - > mime_state - > msg = = NULL ) {
return ;
}
/* Generate decoder events */
@ -852,6 +831,40 @@ static int SMTPProcessCommandDATA(SMTPState *state, Flow *f,
if ( msg - > anomaly_flags & ANOM_LONG_BOUNDARY ) {
SMTPSetEvent ( state , SMTP_DECODER_EVENT_MIME_BOUNDARY_TOO_LONG ) ;
}
}
/**
* \ retval 0 ok
* \ retval - 1 error
*/
static int SMTPProcessCommandDATA ( SMTPState * state , Flow * f ,
AppLayerParserState * pstate )
{
SCEnter ( ) ;
if ( ! ( state - > parser_state & SMTP_PARSER_STATE_COMMAND_DATA_MODE ) ) {
/* looks like are still waiting for a confirmination from the server */
return 0 ;
}
if ( state - > current_line_len = = 1 & & state - > current_line [ 0 ] = = ' . ' ) {
state - > parser_state & = ~ SMTP_PARSER_STATE_COMMAND_DATA_MODE ;
/* kinda like a hack. The mail sent in DATA mode, would be
* acknowledged with a reply . We insert a dummy command to
* the command buffer to be used by the reply handler to match
* the reply received */
SMTPInsertCommandIntoCommandBuffer ( SMTP_COMMAND_DATA_MODE , state , f ) ;
if ( smtp_config . decode_mime & & state - > curr_tx - > mime_state ! = NULL ) {
/* Complete parsing task */
int ret = MimeDecParseComplete ( state - > curr_tx - > mime_state ) ;
if ( ret ! = MIME_DEC_OK ) {
SMTPSetEvent ( state , SMTP_DECODER_EVENT_MIME_PARSE_FAILED ) ;
SCLogDebug ( " MimeDecParseComplete() function failed " ) ;
}
/* Generate decoder events */
SetMimeEvents ( state ) ;
}
state - > curr_tx - > done = 1 ;
SCLogDebug ( " marked tx as done " ) ;
@ -861,12 +874,20 @@ static int SMTPProcessCommandDATA(SMTPState *state, Flow *f,
if ( state - > current_command = = SMTP_COMMAND_DATA & &
( state - > parser_state & SMTP_PARSER_STATE_COMMAND_DATA_MODE ) ) {
if ( smtp_config . decode_mime & & state - > curr_tx - > mime_state ) {
if ( smtp_config . decode_mime & & state - > curr_tx - > mime_state ! = NULL ) {
int ret = MimeDecParseLine ( ( const uint8_t * ) state - > current_line ,
state - > current_line_len , state - > current_line_delimiter_len ,
state - > curr_tx - > mime_state ) ;
if ( ret ! = MIME_DEC_OK ) {
if ( ret ! = MIME_DEC_ERR_STATE ) {
/* Generate decoder events */
SetMimeEvents ( state ) ;
SCLogDebug ( " MimeDecParseLine() function returned an error code: %d " , ret ) ;
SMTPSetEvent ( state , SMTP_DECODER_EVENT_MIME_PARSE_FAILED ) ;
}
/* keep the parser in its error state so we can log that,
* the parser will reject new data */
}
}
}