#include <time.h>
#include <unistd.h>
#include <sys/types.h>
+#include <stdint.h>
#include <zlib.h>
#include <fnmatch.h>
/*
- We assume the syslog files belong to one host, i.e. we do not
+ We assume the syslog files belong to one host, i.e. we do not
consider the hostname at all
*/
#define EPOOL_BLOCK_SIZE 2048
#define EPOOL_MAX_SIZE 128
#define MAX_LOGFILES 32
-//#define EPOOL_DEBUG
+//#define EPOOL_DEBUG
//#define DEBUG
typedef struct _SList SList;
LogEntry *log;
LogEntry *logs_last; // pointer to last log (speedup add log)
};
-
+
// SEntry: Store SMTPD related logs
struct _SEntry {
};
// FEntry: Store filter (proxprox) related logs
-
+
struct _FEntry {
EPool ep;
int sentry_ref_del (SEntry *sentry, QEntry *qentry);
void sentry_ref_finalize (LParser *parser, SEntry *sentry);
int sentry_ref_rem_unneeded (LParser *parser, SEntry *sentry);
-void sentry_nqlist_add (SEntry *sentry, time_t ltime, const char *from, int from_len,
+void sentry_nqlist_add (SEntry *sentry, time_t ltime, const char *from, int from_len,
const char *to, int to_len, char dstatus);
void sentry_print (LParser *parser, SEntry *sentry);
void sentry_set_connect (SEntry *sentry, const char *connect, int len);
QEntry *qentry_new (const char *qid);
-QEntry *qentry_get (LParser *parser, const char *qid);
-void qentry_tolist_add (QEntry *qentry, time_t ltime, char dstatus, const char *to,
+QEntry *qentry_get (LParser *parser, const char *qid);
+void qentry_tolist_add (QEntry *qentry, time_t ltime, char dstatus, const char *to,
int to_len, const char *relay, int relay_len);
void qentry_set_from (QEntry *qentry, const char *from, int len);
void qentry_set_msgid (QEntry *qentry, const char *msgid, int len);
void qentry_set_client (QEntry *qentry, const char *client, int len);
void qentry_print (LParser *parser, QEntry *qentry);
void qentry_finalize (LParser *parser, QEntry *qentry);
-void qentry_free_noremove (LParser *parser, QEntry *qentry);
+void qentry_free_noremove (QEntry *qentry);
void qentry_free (LParser *parser, QEntry *qentry);
void qentry_cleanup_hash (gpointer key, gpointer value, gpointer user_data);
FEntry *fentry_get (LParser *parser, const char *logid);
void fentry_tolist_add (FEntry *fentry, char dstatus, const char *to,
int to_len, const char *qid, int qid_len);
-void fentry_free_noremove (LParser *parser, FEntry *fentry);
+void fentry_free_noremove (FEntry *fentry);
void fentry_free (LParser *parser, FEntry *fentry);
void fentry_cleanup_hash (gpointer key, gpointer value, gpointer user_data);
// Implementations
+// Checksum Macros
+#define PROXPROX 0xE0E4DEF0
+#define PMG_SMTP_FILTER 0x0A85A6B7
+#define POSTFIX_POSTSCREEN 0xD17E2019
+#define POSTFIX_QMGR 0x48465316
+#define POSTFIX_SMTP 0x4A466014
+#define POSTFIX_LMTP 0x43466014
+#define POSTFIX_LOCAL 0x484F05AF
+#define POSTFIX_ERROR 0x4B5E13AE
+#define POSTFIX_SMTPD 0x466014AE
+#define POSTFIX_CLEANUP 0x05A8BAC1
+
//#define LOGPATH "./log/"
#define LOGPATH "/var/log/"
//#define LOGPATH "/root/testlog/"
debug_error (char *msg, const char *line)
{
#ifdef DEBUG
- fprintf (stderr, "ERROR: %s\n", msg);
- if (line) fprintf (stderr, "LINE: %s\n", line);
+ fprintf (stderr, "ERROR: %s\n", msg);
+ if (line) fprintf (stderr, "LINE: %s\n", line);
G_BREAKPOINT();
}
void
-epool_free (EPool *ep)
+epool_free (EPool *ep)
{
SList *l;
gpointer data;
#ifdef DEBUG
return;
#endif
-
+
l = ep->mblocks;
while (l) {
data = l->data;
if (size > EPOOL_MAX_SIZE) {
SList *blocks;
if (space >= sizeof (SList)) {
- blocks = ep->blocks->data + ep->cpos;
+ blocks = (SList *)((char *)ep->blocks->data + ep->cpos);
ep->cpos += sizeof (SList);
} else {
blocks = (SList *)epool_alloc (ep, sizeof (SList));
blocks->next = ep->mblocks;
ep->mblocks = blocks;
-
+
return data;
} else if (space >= rs) {
- data = ep->blocks->data + ep->cpos;
+ data = (char *)ep->blocks->data + ep->cpos;
ep->cpos += rs;
return data;
} else {
- SList *blocks = ep->blocks->data + ep->cpos;
+ SList *blocks = (SList *)((char *)ep->blocks->data + ep->cpos);
data = g_slice_alloc0 (EPOOL_BLOCK_SIZE);
blocks->data = data;
#endif
return data;
- }
+ }
}
char *
-epool_strndup (EPool *ep, const char *s, int len)
+epool_strndup (EPool *ep, const char *s, int len)
{
int l = len + 1;
char *res = epool_alloc (ep, l);
}
char *
-epool_strndup0 (EPool *ep, const char *s, int len)
+epool_strndup0 (EPool *ep, const char *s, int len)
{
char *res = epool_alloc (ep, len + 1);
strncpy (res, s, len);
}
char *
-epool_strdup (EPool *ep, const char *s)
+epool_strdup (EPool *ep, const char *s)
{
int l = strlen (s) + 1;
char *res = epool_alloc (ep, l);
{
LogEntry *log = loglist->log;
while (log) {
- printf ("L%08X %s", log->linenr, log->text);
+ printf ("L%08lX %s", log->linenr, log->text);
log = log->next;
}
}
#ifdef DEBUG
if (len != strlen (text)) {
- debug_error ("string with wrong len", NULL);
+ debug_error ("string with wrong len", NULL);
}
#endif
if (text[len] != 0) {
- debug_error ("string is not null terminated", NULL);
+ debug_error ("string is not null terminated", NULL);
return;
}
blocks = (SList *)((char *)sentry + cpos);
cpos += sizeof (SList);
-
+
blocks->data = sentry;
blocks->next = NULL;
}
void
-sentry_ref_add (SEntry *sentry, QEntry *qentry)
+sentry_ref_add (SEntry *sentry, QEntry *qentry)
{
SList *l;
if (qentry->smtpd) {
if (qentry->smtpd != sentry) {
- debug_error ("qentry ref already set", NULL);
+ debug_error ("qentry ref already set", NULL);
}
return;
}
}
int
-sentry_ref_del (SEntry *sentry, QEntry *qentry)
+sentry_ref_del (SEntry *sentry, QEntry *qentry)
{
SList *l = sentry->refs;
int count = 0;
if (!qentry->smtpd) {
- debug_error ("qentry does not hav a qentry ref", NULL);
+ debug_error ("qentry does not hav a qentry ref", NULL);
return 0;
}
}
void
-sentry_ref_finalize (LParser *parser, SEntry *sentry)
+sentry_ref_finalize (LParser *parser, SEntry *sentry)
{
SList *l = sentry->refs;
qe->smtpd = NULL;
qentry_free (parser, qe);
-
+
if (fe) fentry_free (parser, fe);
-
+
}
if (!count) sentry_free_noremove (sentry);
}
int
-sentry_ref_rem_unneeded (LParser *parser, SEntry *sentry)
+sentry_ref_rem_unneeded (LParser *parser, SEntry *sentry)
{
SList *l = sentry->refs;
int count = 0;
}
void
-sentry_nqlist_add (SEntry *sentry, time_t ltime, const char *from, int from_len,
+sentry_nqlist_add (SEntry *sentry, time_t ltime, const char *from, int from_len,
const char *to, int to_len, char dstatus)
{
NQList *nq = (NQList *)epool_alloc (&sentry->ep, sizeof (NQList));
if (!found) return;
}
- if (parser->from || parser->to ||
+ if (parser->from || parser->to ||
parser->exclude_greylist || parser->exclude_ndrs) {
nq = sentry->nqlist;
int found = 0;
printf ("CTIME: %08lX\n", parser->ctime);
- if (sentry->connect) { printf ("CONNECT: %s\n", sentry->connect); }
+ if (sentry->connect) { printf ("CLIENT: %s\n", sentry->connect); }
//printf ("EXTERNAL: %d\n", sentry->external);
}
}
void
-sentry_free_noremove (SEntry *sentry)
+sentry_free_noremove (SEntry *sentry)
{
SList *l;
gpointer data;
-
+
#ifdef EPOOL_DEBUG
ep_allocated -= sentry->ep.allocated;
printf ("MEM: %d\n", ep_allocated);
#endif
-
+
#ifdef DEBUG
{
SEntry *se;
}
void
-sentry_free (LParser *parser, SEntry *sentry)
+sentry_free (LParser *parser, SEntry *sentry)
{
g_hash_table_remove (parser->smtpd_h, &sentry->pid);
printf ("FOUND ALLOCATED SENTRY:\n");
sentry_print (parser, se);
-
+
exit (-1);
}
#endif
blocks = (SList *)((char *)qentry + cpos);
cpos += sizeof (SList);
-
+
blocks->data = qentry;
blocks->next = NULL;
tl->dstatus = dstatus;
tl->ltime = ltime;
tl->next = qentry->tolist;
-
+
qentry->tolist = tl;
}
}
void
-qentry_print (LParser *parser, QEntry *qentry)
+qentry_print (LParser *parser, QEntry *qentry)
{
TOList *tl, *fl;
SEntry *se = qentry->smtpd;
if (se && se->connect && strcasestr (se->connect, parser->server)) found = 1;
if (qentry->client && strcasestr (qentry->client, parser->server)) found = 1;
- if (!found) return;
+ if (!found) return;
}
if (parser->from) {
}
tl = tl->next;
}
- if (!found) return;
+ if (!found) return;
}
- if (parser->strmatch &&
+ if (parser->strmatch &&
!(qentry->strmatch || (se && se->strmatch) || (fe && fe->strmatch)))
return;
if (parser->verbose) {
printf ("QENTRY: %s\n", qentry->qid);
-
+
printf ("CTIME: %08lX\n", parser->ctime);
printf ("SIZE: %u\n", qentry->size);
- if (se && se->connect) { printf ("CONNECT: %s\n", se->connect); }
-
- if (qentry->client) { printf ("CLIENT: %s\n", qentry->client); }
+ if (qentry->client) {
+ printf ("CLIENT: %s\n", qentry->client);
+ } else if (se && se->connect) {
+ printf ("CLIENT: %s\n", se->connect);
+ }
if (qentry->msgid) { printf ("MSGID: %s\n", qentry->msgid); }
char *to;
char dstatus;
char *relay;
-
+
if (fl) {
to = fl->to;
dstatus = fl->dstatus;
}
QEntry *
-qentry_get (LParser *parser, const char *qid)
+qentry_get (LParser *parser, const char *qid)
{
QEntry *qentry;
}
void
-qentry_free_noremove (LParser *parser, QEntry *qentry)
+qentry_free_noremove (QEntry *qentry)
{
SList *l;
gpointer data;
if ((se = qentry->smtpd)) {
if (sentry_ref_del (se, qentry) == 0) {
- if (se->disconnect) {
+ if (se->disconnect) {
sentry_free_noremove (se);
}
}
}
return;
#endif
-
+
l = qentry->ep.mblocks;
while (l) {
data = l->data;
}
void
-qentry_free (LParser *parser, QEntry *qentry)
+qentry_free (LParser *parser, QEntry *qentry)
{
g_hash_table_remove (parser->qmgr_h, qentry->qid);
- qentry_free_noremove (parser, qentry);
+ qentry_free_noremove (qentry);
}
void
LParser *parser = (LParser *)user_data;
qentry_print (parser, qe);
- qentry_free_noremove (parser, qe);
+ qentry_free_noremove (qe);
}
void
blocks = (SList *)((char *)fentry + cpos);
cpos += sizeof (SList);
-
+
blocks->data = fentry;
blocks->next = NULL;
fentry->logid = logid_cp = (char *)fentry + cpos;
- while ((*logid_cp++ = *logid++)) cpos++;
+ while ((*logid_cp++ = *logid++)) cpos++;
cpos = (cpos + 4) & ~3;
fentry->ep.blocks = blocks;
}
FEntry *
-fentry_get (LParser *parser, const char *logid)
+fentry_get (LParser *parser, const char *logid)
{
FEntry *fentry;
}
tl->dstatus = dstatus;
tl->next = fentry->tolist;
-
+
fentry->tolist = tl;
}
void
-fentry_free_noremove (LParser *parser, FEntry *fentry)
+fentry_free_noremove (FEntry *fentry)
{
SList *l;
gpointer data;
}
return;
#endif
-
+
l = fentry->ep.mblocks;
while (l) {
data = l->data;
}
void
-fentry_free (LParser *parser, FEntry *fentry)
+fentry_free (LParser *parser, FEntry *fentry)
{
g_hash_table_remove (parser->filter_h, fentry->logid);
- fentry_free_noremove (parser, fentry);
+ fentry_free_noremove (fentry);
}
void
gpointer user_data)
{
FEntry *fe = value;
- LParser *parser = (LParser *)user_data;
- fentry_free_noremove (parser, fe);
+ fentry_free_noremove (fe);
}
// Parser
#if 0
char *
-parser_track (LParser *parser, const char *qid, gboolean insert)
+parser_track (LParser *parser, const char *qid, gboolean insert)
{
char *res;
}
#endif
-static const int linebufsize = 8192;
+#define LINEBUFSIZE 8192
static int cur_year;
static int cur_month = 0;
static int cal_mtod[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
return res;
}
+#define JAN (('J'<<16)|('a'<<8)|'n')
+#define FEB (('F'<<16)|('e'<<8)|'b')
+#define MAR (('M'<<16)|('a'<<8)|'r')
+#define APR (('A'<<16)|('p'<<8)|'r')
+#define MAY (('M'<<16)|('a'<<8)|'y')
+#define JUN (('J'<<16)|('u'<<8)|'n')
+#define JUL (('J'<<16)|('u'<<8)|'l')
+#define AUG (('A'<<16)|('u'<<8)|'g')
+#define SEP (('S'<<16)|('e'<<8)|'p')
+#define OCT (('O'<<16)|('c'<<8)|'t')
+#define NOV (('N'<<16)|('o'<<8)|'v')
+#define DEC (('D'<<16)|('e'<<8)|'c')
+
time_t
parse_time (const char **text, int len)
{
const char *line = *text;
- if (len == (linebufsize - 1)) {
+ if (len == (LINEBUFSIZE - 1)) {
debug_error ("skipping long line data", line);
return 0;
}
-
+
if (len < 15) {
debug_error ("skipping short line data", line);
return 0;
int csum = (line[0]<<16) + (line[1]<<8) + line[2];
switch (csum) {
- case 4874606: mon = 0; break;
- case 4613474: mon = 1; break;
- case 5071218: mon = 2; break;
- case 4288626: mon = 3; break;
- case 5071225: mon = 4; break;
- case 4879726: mon = 5; break;
- case 4879724: mon = 6; break;
- case 4289895: mon = 7; break;
- case 5465456: mon = 8; break;
- case 5202804: mon = 9; break;
- case 5140342: mon = 10; break;
- case 4482403: mon = 11; break;
- default:
+ case JAN: mon = 0; break;
+ case FEB: mon = 1; break;
+ case MAR: mon = 2; break;
+ case APR: mon = 3; break;
+ case MAY: mon = 4; break;
+ case JUN: mon = 5; break;
+ case JUL: mon = 6; break;
+ case AUG: mon = 7; break;
+ case SEP: mon = 8; break;
+ case OCT: mon = 9; break;
+ case NOV: mon = 10; break;
+ case DEC: mon = 11; break;
+ default:
debug_error ("unable to parse month", line);
- return 0;
+ return 0;
}
// year change heuristik
- if (cur_month == 11 && mon == 0) {
+ if (cur_month == 11 && mon == 0) {
year++;
}
if (mon > cur_month) cur_month = mon;
return 0;
}
- found = 0; while (isdigit (*cpos)) { mday = mday*10 + *cpos - 48; cpos++; found++; }
+ found = 0; while (isdigit (*cpos)) { mday = mday*10 + *cpos - '0'; cpos++; found++; }
if (found < 1 || found > 2) {
debug_error ("unable to parse day of month", line);
return 0;
return 0;
}
- found = 0; while (isdigit (*cpos)) { hour = hour*10 + *cpos - 48; cpos++; found++; }
+ found = 0; while (isdigit (*cpos)) { hour = hour*10 + *cpos - '0'; cpos++; found++; }
if (found < 1 || found > 2) {
debug_error ("unable to parse hour", line);
return 0;
}
cpos++;
- found = 0; while (isdigit (*cpos)) { min = min*10 + *cpos - 48; cpos++; found++; }
+ found = 0; while (isdigit (*cpos)) { min = min*10 + *cpos - '0'; cpos++; found++; }
if (found < 1 || found > 2) {
debug_error ("unable to parse minute", line);
return 0;
}
cpos++;
- found = 0; while (isdigit (*cpos)) { sec = sec*10 + *cpos - 48; cpos++; found++; }
+ found = 0; while (isdigit (*cpos)) { sec = sec*10 + *cpos - '0'; cpos++; found++; }
if (found < 1 || found > 2) {
debug_error ("unable to parse second", line);
return 0;
int
-parser_count_files (LParser *parser)
+parser_count_files (LParser *parser)
{
int i;
time_t start = parser->start;
- char linebuf[linebufsize];
+ char linebuf[LINEBUFSIZE];
const char *line;
gzFile stream;
cur_month = 0;
if ((stream = gzopen (logfiles[i], "r"))) {
- if ((line = gzgets (stream, linebuf, linebufsize))) {
+ if ((line = gzgets (stream, linebuf, LINEBUFSIZE))) {
if (parse_time (&line, strlen (line)) < start) {
break;
}
return i;
}
}
-
+
return i + 1;
}
static char *
-parse_qid (const char **text, char *out, char delim, int maxlen)
+parse_qid (const char **text, char *out, char delim, int maxlen)
{
const char *idx;
char *copy = out;
idx = *text;
while (isxdigit (*idx)) { *copy++ = *idx++; found++; if (found > maxlen) break; }
- if (found > 1 && found < maxlen &&
+ if (found > 1 && found < maxlen &&
((delim && (*idx == delim)) || (!delim && isspace (*idx)))) {
*copy = 0;
idx++;
// gzgets is ways too slow, so we do it our own way
-static int
+static char
mygzgetc (gzFile stream)
{
int br;
static char *
mygzgets (gzFile stream, char *line, int bufsize)
{
- int c=0;
+ char c=0;
char *cpos;
cpos = line;
extern char *optarg;
extern int optind, opterr, optopt;
-int
+int
main (int argc, char * const argv[])
{
- char linebuf[linebufsize];
+ char linebuf[LINEBUFSIZE];
char *line;
- char *uniqueid = NULL;
+ char *inputfile = NULL;
const char *text;
const char *idx1;
const char *idx2;
const char *cpos;
int found = 0;
- int csum_prog;
+ uint32_t csum_prog;
unsigned long lines = 0;
unsigned long rel_line_nr = 0;
char qidbuf[30];
exit (-1);
}
- while ((opt = getopt (argc, argv, "f:t:s:e:h:m:q:x:l:I:vgn")) != -1) {
+ while ((opt = getopt (argc, argv, "f:t:s:e:h:m:q:x:i:l:vgn")) != -1) {
if (opt == 'f') {
parser->from = epool_strdup (&parser->ep, optarg);
} else if (opt == 't') {
parser->exclude_greylist = 1;
} else if (opt == 'n') {
parser->exclude_ndrs = 1;
- } else if (opt == 'I') {
- uniqueid = optarg;
} else if (opt == 'h') {
parser->server = epool_strdup (&parser->ep, optarg);
} else if (opt == 'm') {
}
} else if (opt == 'x') {
parser->strmatch = epool_strdup (&parser->ep, optarg);
+ } else if (opt == 'i') {
+ inputfile = optarg;
} else if (opt == 'l') {
char *l;
parser->limit = strtoul (optarg, &l, 0);
}
int filecount;
- if ((filecount = parser_count_files (parser)) <= 0) {
+ if (inputfile) {
+ filecount = 1;
+ } else if ((filecount = parser_count_files (parser)) <= 0) {
fprintf (stderr, "unable to access log files\n");
exit (-1);
}
- if (uniqueid) {
- printf ("# LogReader: %d %s\n", getpid(), uniqueid);
- } else {
- printf ("# LogReader: %d\n", getpid());
- }
+ printf ("# LogReader: %d\n", getpid());
printf ("# Query options\n");
if (parser->from) printf ("# Sender: %s\n", parser->from);
if (parser->strmatch) printf ("# Match: %s\n", parser->strmatch);
strftime (linebuf, 256, "%F %T", gmtime (&parser->start));
- printf ("# Start: %s (%lu)\n", linebuf, parser->start);
+ printf ("# Start: %s (%lu)\n", linebuf, parser->start);
strftime (linebuf, 256, "%F %T", gmtime (&parser->end));
- printf ("# END: %s (%lu)\n", linebuf, parser->end);
+ printf ("# END: %s (%lu)\n", linebuf, parser->end);
printf ("# End Query Options\n\n");
fflush (stdout);
cur_year = parser->year[i];
if (i <= 1) {
- if (!(stream = (gpointer) fopen (logfiles[i], "r"))) continue;
+ if (inputfile && strlen(inputfile) == 1 && *inputfile == '-') {
+ stream = (gpointer) stdin;
+ } else if (inputfile) {
+ if (!(stream = (gpointer) fopen (inputfile, "r"))) {
+ fprintf(stderr, "unable to open log file\n");
+ exit (-1);
+ }
+ } else if (!(stream = (gpointer) fopen (logfiles[i], "r"))) continue;
} else {
if (!(stream = (gpointer) gzopen (logfiles[i], "r"))) continue;
}
}
if (i <= 1) {
- line = fgets (linebuf, linebufsize, (FILE *)stream);
+ line = fgets (linebuf, LINEBUFSIZE, (FILE *)stream);
} else {
- line = mygzgets ((gzFile)stream, linebuf, linebufsize);
+ line = mygzgets ((gzFile)stream, linebuf, LINEBUFSIZE);
}
if (!line) break;
//const char *prog = cpos;
csum_prog = 0;
- found = 0; while (*cpos && (*cpos != ':') && (*cpos != '[')) {
- csum_prog = (csum_prog <<8) + *cpos;
- cpos++;
- found++;
+ found = 0; while (*cpos && (*cpos != ':') && (*cpos != '[')) {
+ csum_prog = ((csum_prog << 8)|(csum_prog >> 24)) + *cpos;
+ cpos++;
+ found++;
}
//idx1 = g_strndup (prog, found);
if (*cpos == '[') {
cpos++;
- found = 0; while (isdigit (*cpos)) {
- pid = pid*10 + *cpos - 48;
- cpos++;
- found++;
+ found = 0; while (isdigit (*cpos)) {
+ pid = pid*10 + *cpos - '0';
+ cpos++;
+ found++;
}
if (found < 1 || found > 15 || *cpos != ']') {
debug_error ("unable to parse pid", line);
}
cpos++;
}
-
+
if (*cpos++ != ':') {
debug_error ("missing collon", line);
continue;
strmatch = 1;
}
- if ((csum_prog == 0x70726F78) ||// proxprox
- (csum_prog == 0x6C746572)) { // pmg-smtp-filter
+ if ((csum_prog == PROXPROX) ||
+ (csum_prog == PMG_SMTP_FILTER)) {
if ((idx1 = parse_qid (&cpos, qidbuf, ':', 25))) {
//fixme: parse spam score
if ((*cpos == 'a') && !strncmp (cpos, "accept mail to <", 16)) {
-
+
const char *to_s, *to_e;
to_s = cpos = cpos + 16;
-
+
while (*cpos && (*cpos != '>')) { cpos++; }
-
+
if (*cpos != '>') continue;
to_e = cpos;
cpos++;
if ((*cpos++ != ' ') || (*cpos++ != '(')) continue;
-
+
if (!(idx1 = parse_qid (&cpos, qidbuf, ')', 15))) continue;
// parser_track (parser, idx1, 1);
const char *to_s, *to_e;
to_s = cpos = cpos + 16;
-
+
while (*cpos && (*cpos != '>')) { cpos++; }
-
+
to_e = cpos;
if (strncmp (cpos, "> to ", 5)) continue;
cpos += 14;
if (!(idx1 = parse_qid (&cpos, qidbuf, 0, 25))) continue;
-
+
fentry_tolist_add (fe, 'Q', to_s, to_e - to_s, idx1, strlen (idx1));
} else if ((*cpos == 'b') && !strncmp (cpos, "block mail to <", 15)) {
-
+
const char *to_s;
to_s = cpos = cpos + 15;
-
+
while (*cpos && (*cpos != '>')) { cpos++; }
-
+
if (*cpos != '>') continue;
fentry_tolist_add (fe, 'B', to_s, cpos - to_s, NULL, 0);
}
- } else if (csum_prog == 0x7265656E) { // postfix/postscreen
+ } else if (csum_prog == POSTFIX_POSTSCREEN) {
SEntry *se;
const char *to = cpos = cpos + 7;
while (*cpos && (*cpos != '>')) { cpos++; }
-
+
if (*cpos != '>') continue;
if (!(se = sentry_get (parser, pid, ctime, rel_line_nr))) {
sentry_print (parser, se);
sentry_free (parser, se);
}
-
- } else if (csum_prog == 0x716D6772) { // postfix/qmgr
+
+ } else if (csum_prog == POSTFIX_QMGR) {
if ((idx2 = text) && (idx1 = parse_qid (&idx2, qidbuf, ':', 15))) {
if (strmatch) qe->strmatch = 1;
- qe->cleanup = 1;
+ qe->cleanup = 1;
loglist_add (&qe->ep, &qe->loglist, line, len, lines);
-
+
if ((*idx2 == 'f') && !strncmp (idx2, "from=<", 6)) {
cpos = idx2 = idx2 + 6;
int size = 0;
cpos += 7;
- while (isdigit (*cpos)) { size = size*10 + *cpos++ - 48; }
+ while (isdigit (*cpos)) { size = size*10 + *cpos++ - '0'; }
qe->size = size;
}
-
+
} else if ((*idx2 == 'r') && !strncmp (idx2, "removed\n", 8)) {
qe->removed = 1;
}
}
- } else if ((csum_prog == 0x736D7470) || //postfix/smtp
- (csum_prog == 0x6C6D7470) || //postfix/lmtp
- (csum_prog == 0x6F63616C) || //postfix/local
- (csum_prog == 0x72726F72)) { //postfix/error
+ } else if ((csum_prog == POSTFIX_SMTP) ||
+ (csum_prog == POSTFIX_LMTP) ||
+ (csum_prog == POSTFIX_LOCAL) ||
+ (csum_prog == POSTFIX_ERROR)) {
- int lmtp = (csum_prog == 0x6C6D7470);
+ int lmtp = (csum_prog == POSTFIX_LMTP);
if ((cpos = text) && (idx1 = parse_qid (&cpos, qidbuf, ':', 15))) {
if (strmatch) qe->strmatch = 1;
- qe->cleanup = 1;
+ qe->cleanup = 1;
loglist_add (&qe->ep, &qe->loglist, line, len, lines);
const char *to_s, *to_e;
to_s = cpos;
-
+
while (*cpos && (*cpos != '>')) { cpos++; }
-
+
if (*cpos != '>') continue;
to_e = cpos;
cpos ++;
-
+
if (!(cpos = strstr (cpos, ", relay="))) continue;
cpos += 8;
relay_s = cpos;
while (*cpos && (*cpos != ',')) { cpos++; }
-
+
if (*cpos != ',') continue;
relay_e = cpos;
char dstatus = *cpos;
- qentry_tolist_add (qe, ctime, dstatus, to_s, to_e - to_s,
+ qentry_tolist_add (qe, ctime, dstatus, to_s, to_e - to_s,
relay_s, relay_e - relay_s);
if (!lmtp) continue; // filter always uses lmtp
} else {
continue;
}
-
+
if (!(idx1 = parse_qid (&cpos, qidbuf, ')', 25)))
continue;
qe->filtered = 1;
if ((fe = g_hash_table_lookup (parser->filter_h, idx1))) {
- qe->filter = fe;
+ qe->filter = fe;
}
}
- } else if (csum_prog == 0x6D747064) { // postfix/smtpd
+ } else if (csum_prog == POSTFIX_SMTPD) {
SEntry *se;
if (!pid) {
loglist_add (&se->ep, &se->loglist, line, len, lines);
if ((*text == 'c') && !strncmp (text, "connect from ", 13)) {
-
+
cpos = idx1 = text + 13;
while (*idx1 && !isspace (*idx1)) { idx1++; }
} else {
sentry_ref_finalize (parser, se);
}
-
+
} else if ((*text == 'N') && !strncmp (text, "NOQUEUE:", 8)) {
cpos = text + 8;
const char *to = cpos = cpos + 6;
while (*cpos && (*cpos != '>')) { cpos++; }
-
+
if (*cpos != '>') continue;
sentry_nqlist_add (se, ctime, from, idx1 - from, to, cpos - to, dstatus);
}
}
-
- } else if (csum_prog == 0x616E7570) { // postfix/cleanup
+
+ } else if (csum_prog == POSTFIX_CLEANUP) { // postfix/cleanup
QEntry *qe;
qe->cleanup = 1;
}
- }
+ }
}
}
}
printf ("MEM QMGR entries: %d\n", g_hash_table_size (parser->qmgr_h));
printf ("MEM FILTER entries: %d\n", g_hash_table_size (parser->filter_h));
- printf ("MEMDEB SMTPD entries: %d %d\n",
+ printf ("MEMDEB SMTPD entries: %d %d\n",
g_hash_table_size (smtpd_debug_alloc),
g_hash_table_size (smtpd_debug_free));
- printf ("MEMDEB QMGR entries: %d %d\n",
+ printf ("MEMDEB QMGR entries: %d %d\n",
g_hash_table_size (qmgr_debug_alloc),
g_hash_table_size (qmgr_debug_free));
- printf ("MEMDEB FILTER entries: %d %d\n",
+ printf ("MEMDEB FILTER entries: %d %d\n",
g_hash_table_size (filter_debug_alloc),
g_hash_table_size (filter_debug_free));
#endif
- g_hash_table_foreach (parser->qmgr_h, qentry_cleanup_hash, parser);
- g_hash_table_foreach (parser->smtpd_h, sentry_cleanup_hash, parser);
- g_hash_table_foreach (parser->filter_h, fentry_cleanup_hash, parser);
+ g_hash_table_foreach (parser->qmgr_h, qentry_cleanup_hash, parser);
+ g_hash_table_foreach (parser->smtpd_h, sentry_cleanup_hash, parser);
+ g_hash_table_foreach (parser->filter_h, fentry_cleanup_hash, parser);
#ifdef DEBUG
- printf ("MEMDEB SMTPD entries: %d %d\n",
+ printf ("MEMDEB SMTPD entries: %d %d\n",
g_hash_table_size (smtpd_debug_alloc),
g_hash_table_size (smtpd_debug_free));
- printf ("MEMDEB QMGR entries: %d %d\n",
+ printf ("MEMDEB QMGR entries: %d %d\n",
g_hash_table_size (qmgr_debug_alloc),
g_hash_table_size (qmgr_debug_free));
- printf ("MEMDEB FILTER entries: %d %d\n",
+ printf ("MEMDEB FILTER entries: %d %d\n",
g_hash_table_size (filter_debug_alloc),
g_hash_table_size (filter_debug_free));
- g_hash_table_foreach (smtpd_debug_alloc, sentry_debug_alloc, parser);
+ g_hash_table_foreach (smtpd_debug_alloc, sentry_debug_alloc, parser);
#endif
#ifdef EPOOL_DEBUG
- printf ("MEMMAX %d\n", ep_maxalloc);
+ printf ("MEMMAX %d\n", ep_maxalloc);
#endif
parser_free (parser);
-
+
fclose (stdout);
exit (0);