/* ** Modular Logfile Analyzer ** Copyright 2000 Jan Kneschke ** ** Homepage: http://www.modlogan.org ** This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version, and provided that the above copyright and permission notice is included with all distributed copies of this or derived software. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA ** ** $Id: parse.c,v 1.6 2004/08/27 20:07:39 ostborn Exp $ */ #include #include #include #include #include #include #include "mlocale.h" #include "mplugins.h" #include "mrecord.h" #include "mdatatypes.h" #include "misc.h" #include "plugin_config.h" #define DEBUG_PCRE int parse_record_pcre(mconfig *ext_conf, mlogrec *record, buffer *b) { #define N 20 + 1 const char **list; int ovector[3 * N], n; #ifdef DEBUG_PCRE int i; #endif config_input *conf = ext_conf->plugin_conf; mlogrec_web *recweb = NULL; if (record->ext_type != M_RECORD_TYPE_WEB) { if (record->ext_type != M_RECORD_TYPE_UNSET) { mrecord_free_ext(record); } record->ext_type = M_RECORD_TYPE_WEB; record->ext = mrecord_init_web(); } recweb = record->ext; if (recweb == NULL) return M_RECORD_HARD_ERROR; if ((n = pcre_exec(conf->match_squid, conf->match_squid_extra, b->ptr, b->used - 1, 0, 0, ovector, 3 * N)) < 0) { if (n == PCRE_ERROR_NOMATCH) { fprintf(stderr, "%s.%d: string doesn't match: %s\n", __FILE__, __LINE__, b->ptr); } else { fprintf(stderr, "%s.%d: execution error while matching: %d\n", __FILE__, __LINE__, n); } return -1; } if (n >= 12) { pcre_get_substring_list(b->ptr, ovector, n, &list); /* * the logfile format: * it differs from all other logfiles as one record consists of multiple lines. * * date -> #^Date:\s([0-9]{2}/[0-9]{2}/[0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2})$# * prot -> #^Method:\s([A-Z]+)$# * src -> #^From:\s(.+)$# * dest -> #^To:\s(.+)$# * file -> #^File:\s(.+)$# * actn -> #^Action:\s(.+)$# * virus-> #^Virus:\s(.*)$# Date: 04/06/2001 11:06:36 Method: SMTP From: xxx@xxx.com To: xxx@xxx.de File: MKCOMPAT.EXE Action: The file terscan/virus/virARC6XaWwB is moved to the configured virus directory. Virus: PE_MAGISTR.A ---------------------------------- */ #ifdef DEBUG_PCRE for (i = 0; i < n; i++) { printf("%d: %s\n", i, list[i]); } #endif free(list); } return 0; #undef N } int mplugins_input_viruswall_get_next_record(mconfig *ext_conf, mlogrec *record) { int ret = 0; config_input *conf = ext_conf->plugin_conf; if (record == NULL) return M_RECORD_HARD_ERROR; /* fill the line buffer */ if (NULL == mgets(&(conf->inputfile), conf->buf)) return M_RECORD_EOF; ret = parse_record_pcre (ext_conf, record, conf->buf); if (ret == M_RECORD_CORRUPT) { M_DEBUG1(ext_conf->debug_level, M_DEBUG_SECTION_PARSING, M_DEBUG_LEVEL_WARNINGS, "affected Record: %s\n", conf->buf->ptr ); } return ret; }