X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?p=ossec-hids.git;a=blobdiff_plain;f=src%2Flogcollector%2Fread_mssql_log.c;h=ae685bb430fd858abdf22f07f829be67e658367e;hp=41ad273f59d204ea9d2cba9b3d11cf1b59fb143f;hb=6ef2f786c6c8ead94841b5f93baf9f43421f08c8;hpb=301048b51990573e58a30dc4a5bb4ec285cad554 diff --git a/src/logcollector/read_mssql_log.c b/src/logcollector/read_mssql_log.c index 41ad273..ae685bb 100755 --- a/src/logcollector/read_mssql_log.c +++ b/src/logcollector/read_mssql_log.c @@ -1,4 +1,5 @@ -/* @(#) $Id$ */ +/* @(#) $Id: ./src/logcollector/read_mssql_log.c, 2011/09/08 dcid Exp $ + */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. @@ -20,7 +21,7 @@ -/* Send mssql message and check the return code. +/* Send mssql message and check the return code. */ void __send_mssql_msg(int pos, int drop_it, char *buffer) { @@ -52,7 +53,7 @@ void *read_mssql_log(int pos, int *rc, int drop_it) /* Zeroing buffer and str */ buffer[0] = '\0'; - buffer[OS_MAXSTR] = '\0'; + buffer[OS_MAXSTR] = '\0'; str[OS_MAXSTR]= '\0'; *rc = 0; @@ -60,20 +61,20 @@ void *read_mssql_log(int pos, int *rc, int drop_it) /* Getting new entry */ while(fgets(str, OS_MAXSTR - OS_LOG_HEADER, logff[pos].fp) != NULL) { - + /* Getting buffer size */ str_len = strlen(str); - + /* Checking str_len size. Very useless, but just to make sure.. */ if(str_len >= sizeof(buffer) -2) { str_len = sizeof(buffer) -10; } - + /* Getting the last occurence of \n */ - if ((p = strrchr(str, '\n')) != NULL) + if ((p = strrchr(str, '\n')) != NULL) { *p = '\0'; @@ -88,8 +89,8 @@ void *read_mssql_log(int pos, int *rc, int drop_it) { need_clear = 1; } - - + + #ifdef WIN32 if ((p = strrchr(str, '\r')) != NULL) { @@ -111,7 +112,7 @@ void *read_mssql_log(int pos, int *rc, int drop_it) } #endif - + /* MSSQL messages have the following formats: * 2009-03-25 04:47:30.01 Server @@ -119,17 +120,17 @@ void *read_mssql_log(int pos, int *rc, int drop_it) * 2009-02-06 11:48:59 Server */ if((str_len > 19) && - (str[4] == '-') && - (str[7] == '-') && - (str[10] == ' ') && - (str[13] == ':') && - (str[16] == ':') && + (str[4] == '-') && + (str[7] == '-') && + (str[10] == ' ') && + (str[13] == ':') && + (str[16] == ':') && isdigit((int)str[0]) && isdigit((int)str[1]) && isdigit((int)str[2]) && isdigit((int)str[3])) { - + /* If the saved message is empty, set it and continue. */ if(buffer[0] == '\0') { @@ -147,8 +148,8 @@ void *read_mssql_log(int pos, int *rc, int drop_it) strncpy(buffer, str, str_len + 2); } } - - + + /* Query logs can be in multiple lines. * They always start with a tab in the additional ones. */ @@ -156,16 +157,16 @@ void *read_mssql_log(int pos, int *rc, int drop_it) { /* Size of the buffer */ int buffer_len = strlen(buffer); - + p = str; - + /* Removing extra spaces and tabs */ while(*p == ' ' || *p == '\t') { p++; } - - + + /* Adding additional message to the saved buffer. */ if(sizeof(buffer) - buffer_len > str_len +256) { @@ -178,7 +179,7 @@ void *read_mssql_log(int pos, int *rc, int drop_it) strncat(buffer, str, str_len +3); } } - + continue; } @@ -188,8 +189,8 @@ void *read_mssql_log(int pos, int *rc, int drop_it) { __send_mssql_msg(pos, drop_it, buffer); } - - return(NULL); + + return(NULL); } /* EOF */