-/* @(#) $Id$ */
+/* @(#) $Id: ./src/analysisd/decoders/hostinfo.c, 2011/09/08 dcid Exp $
+ */
/* Copyright (C) 2009 Trend Micro Inc.
* All right reserved.
/* Opening HOSTINFO_FILE */
snprintf(_hi_buf,OS_SIZE_1024, "%s", HOSTINFO_FILE);
-
+
/* r+ to read and write. Do not truncate */
_hi_fp = fopen(_hi_buf,"r+");
return;
}
-
+
/* clearing the buffer */
memset(_hi_buf, '\0', OS_MAXSTR +1);
{
int changed = 0;
int bf_size;
-
+
char *ip;
char *portss;
char *tmpstr;
char opened[OS_MAXSTR + 1];
FILE *fp;
-
+
/* Checking maximum number of errors */
if(hi_err > 30)
{
"Ignoring it.", ARGV0);
return(0);
}
-
+
/* Zeroing buffers */
buffer[OS_MAXSTR] = '\0';
/* Copying log to buffer */
strncpy(buffer,lf->log, OS_MAXSTR);
-
-
+
+
/* Getting ip */
tmpstr = __go_after(buffer, HOST_HOST);
if(!tmpstr)
return(0);
}
-
+
/* Setting ip */
ip = tmpstr;
tmpstr = strchr(tmpstr, ',');
*tmpstr = '\0';
}
bf_size = strlen(ip);
-
-
+
+
/* Reads the file and search for a possible
* entry
*/
/* Removing new line */
tmpstr = strchr(_hi_buf, '\n');
if(tmpstr)
- *tmpstr = '\0';
+ *tmpstr = '\0';
/* Checking for ip */
if(strncmp(ip, _hi_buf, bf_size) == 0)
{
- /* Cannot use strncmp to avoid errors with crafted files */
+ /* Cannot use strncmp to avoid errors with crafted files */
if(strcmp(portss, _hi_buf + bf_size) == 0)
{
return(0);
changed = 1;
}
}
- }
+ }
+
-
/* Adding the new entry at the end of the file */
fseek(fp, 0, SEEK_END);
fprintf(fp,"%s%s\n", ip, portss);
/* Setting decoder */
lf->decoder_info = hostinfo_dec;
-
+
/* Setting comment */
if(changed == 1)
{
{
hostinfo_dec->id = id_new;
}
-
+
return(1);
}