-/* @(#) $Id: read_nmapg.c,v 1.11 2009/06/24 17:06:27 dcid Exp $ */
+/* @(#) $Id: ./src/logcollector/read_nmapg.c, 2011/09/08 dcid Exp $
+ */
/* Copyright (C) 2009 Trend Micro Inc.
* All right 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
*/
-/* Get port and protocol.
+/* Get port and protocol.
*/
static char *__get_port(char *str, char *proto, char *port, int msize)
{
str++;
}
-
+
/* Getting port */
p = strchr(str, '/');
if(!p)
*p = '\0';
p++;
-
+
/* Getting port */
strncpy(port, str, msize);
port[msize -1] = '\0';
-
-
+
+
/* Checking if the port is open */
q = __go_after(p, NMAPG_OPEN);
if(!q)
p = strchr(q, '/');
if(!p)
return(NULL);
- p++;
+ p++;
}
else
{
p = q;
}
-
-
+
+
/* Getting protocol */
str = p;
*p = '\0';
p++;
-
+
strncpy(proto, str, msize);
proto[msize -1] = '\0';
-
-
+
+
/* Setting proto to null if port is not open */
if(filtered)
- proto[0] = '\0';
-
-
+ proto[0] = '\0';
+
+
/* Removing slashes */
if(*p == '/')
{
return(q);
}
-
+
return(NULL);
}
/* X and Y must be not null */
if(!x || !y)
return(NULL);
-
+
x_s = strlen(x);
y_s = strlen(y);
{
int final_msg_s;
int need_clear = 0;
-
+
char str[OS_MAXSTR + 1];
char final_msg[OS_MAXSTR + 1];
char buffer[OS_MAXSTR + 1];
char *ip = NULL;
char *p;
char *q;
-
+
*rc = 0;
str[OS_MAXSTR] = '\0';
final_msg[OS_MAXSTR] = '\0';
}
continue;
}
-
+
/* Removing \n at the end of the string */
if ((q = strchr(str, '\n')) != NULL)
{
need_clear = 1;
}
-
+
/* Do not get commented lines */
if((str[0] == '#') || (str[0] == '\0'))
{
continue;
}
-
+
/* Getting host */
q = __go_after(str, NMAPG_HOST);
if(!q)
{
goto file_error;
}
-
-
+
+
/* Getting ip/hostname */
p = strchr(q, ')');
if(!p)
goto file_error;
}
-
+
/* Setting the valid ip */
ip = q;
-
+
/* Getting the ports */
/* Now fixing p, to have the closing parenthesis */
p++;
*p = '\0';
-
-
+
+
/* q now should point to the ports */
p = __go_after(q, NMAPG_PORT);
if(!p)
snprintf(final_msg, OS_MAXSTR, "Host: %s, open ports:",
ip);
final_msg_s = OS_MAXSTR - ((strlen(final_msg) +3));
-
+
/* Getting port and protocol */
do
{
break;
}
-
+
p = __get_port(p, proto, port, 9);
if(!p)
{
break;
}
-
+
/* Port not open */
if(proto[0] == '\0')
{
continue;
}
-
+
/* Adding ports */
snprintf(buffer, OS_MAXSTR, " %s(%s)", port, proto);
strncat(final_msg, buffer, final_msg_s);
final_msg_s-=(strlen(buffer) +2);
-
+
}while(*p == ',' && (p++));
-
+
if(drop_it == 0)
- {
+ {
/* Sending message to queue */
- if(SendMSG(logr_queue, final_msg, logff[pos].file,
+ if(SendMSG(logr_queue, final_msg, logff[pos].file,
HOSTINFO_MQ) < 0)
{
merror(QUEUE_SEND, ARGV0);
}
}
-
+
/* Getting next */
continue;
-
+
/* Handling errors */
file_error:
-
+
merror("%s: Bad formated nmap grepable file.", ARGV0);
*rc = -1;
return(NULL);
-
+
}
-
+
return(NULL);
}