-/* @(#) $Id: read_postgresql_log.c,v 1.5 2009/06/24 17:06:27 dcid Exp $ */
+/* @(#) $Id: ./src/logcollector/read_postgresql_log.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 3) as published by the FSF - Free Software
+ * License (version 2) as published by the FSF - Free Software
* Foundation.
*
* License details at the LICENSE file included with OSSEC or
-/* Send pgsql message and check the return code.
+/* Send pgsql message and check the return code.
*/
void __send_pgsql_msg(int pos, int drop_it, char *buffer)
{
/* Zeroing buffer and str */
buffer[0] = '\0';
- buffer[OS_MAXSTR] = '\0';
+ buffer[OS_MAXSTR] = '\0';
str[OS_MAXSTR]= '\0';
*rc = 0;
/* 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';
{
need_clear = 1;
}
-
-
+
+
#ifdef WIN32
if ((p = strrchr(str, '\r')) != NULL)
{
}
#endif
-
+
/* PostgreSQL messages have the following format:
* [2007-08-31 19:17:32.186 ADT] 192.168.2.99:db_name
*/
if((str_len > 32) &&
- (str[0] == '[') &&
- (str[5] == '-') &&
- (str[8] == '-') &&
- (str[11] == ' ') &&
- (str[14] == ':') &&
- (str[17] == ':') &&
+ (str[0] == '[') &&
+ (str[5] == '-') &&
+ (str[8] == '-') &&
+ (str[11] == ' ') &&
+ (str[14] == ':') &&
+ (str[17] == ':') &&
isdigit((int)str[1]) &&
isdigit((int)str[12]))
{
-
+
/* If the saved message is empty, set it and continue. */
if(buffer[0] == '\0')
{
strncpy(buffer, str, str_len + 2);
}
}
-
-
+
+
/* Query logs can be in multiple lines.
* They always start with a tab in the additional ones.
*/
{
/* Size of the buffer */
int buffer_len = strlen(buffer);
-
+
p = str +1;
-
+
/* 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)
{
strncat(buffer, str, str_len +3);
}
}
-
+
continue;
}
{
__send_pgsql_msg(pos, drop_it, buffer);
}
-
- return(NULL);
+
+ return(NULL);
}
/* EOF */