27 #include "libmilter/mfapi.h" 40 static long HISTORY_ENTRIES = 0x8000L;
195 #define HISTORY_T_INIT {0, JBT_INITIALIZER} 217 static RawData_T hfile = { -1, 0, PTHREAD_MUTEX_INITIALIZER };
219 #define HISTORY_LOCK() MUTEX_LOCK(&hfile.st_mutex) 220 #define HISTORY_UNLOCK() MUTEX_UNLOCK(&hfile.st_mutex) 236 ZE_MessageInfo(15,
"HISTORY_ENTRIES = %6ld; cf = %6ld\n", HISTORY_ENTRIES,
237 (
long) history_entries);
239 if (history_entries > 0)
240 HISTORY_ENTRIES = history_entries * 1024;
242 ZE_MessageInfo(15,
"HISTORY_ENTRIES = %6ld; cf = %6ld\n", HISTORY_ENTRIES,
243 (
long) history_entries);
245 if (work_dir == NULL)
247 snprintf(fname,
sizeof (fname),
"%s/%s", work_dir,
"ze-history");
259 mode = (S_IRUSR | S_IRGRP | S_IROTH);
264 oflag = (O_RDWR | O_CREAT);
267 hfile.
fd = open(fname, oflag, mode);
276 while ((r = read(hfile.
fd, &h, sizeof (h))) ==
sizeof (h)) {
328 ctx2histraw(&history, priv);
330 if (lseek(hfile.
fd, hfile.
ptr * sizeof (history), SEEK_SET) == (
off_t) - 1)
334 if (write(hfile.
fd, &history, sizeof (history)) < 0)
339 hfile.
ptr = (hfile.
ptr % HISTORY_ENTRIES);
353 ctx2histraw(dst, src)
357 if ((dst == NULL) || (src == NULL))
360 memset(dst, 0,
sizeof (*dst));
368 dst->t_length = (long) ((src->
t_close - src->
t_open) / 1000000);
372 dst->t_open = src->
t_open;
403 dst->t_open = src->
t_open;
406 dst->result = src->
result;
411 dst->nb_spamtrap = src->nb_spamtrap;
435 histraw2histres(dst, src)
440 if ((dst == NULL) || (src == NULL))
443 if (strlen(dst->ip) == 0) {
446 strlcpy(dst->ip, src->
ip, sizeof (dst->ip));
452 if ((dst->ti == 0) || (src->
conn_id < dst->ti))
454 if ((dst->tf == 0) || (src->
conn_id > dst->tf))
456 if ((dst->throttle_max == 0) || (src->
conn_rate > dst->throttle_max))
458 if ((dst->serv_rate_max == 0) || (src->
serv_rate > dst->serv_rate_max))
504 dst->rej_resolve_failed++;
507 dst->rej_resolve_forged++;
547 if ((dst->t_length_min == 0) || (src->
t_length < dst->t_length_min))
549 if ((dst->t_length_max == 0) || (src->
t_length > dst->t_length_max))
553 if ((dst->t_work_min == 0) || (src->
t_work < dst->t_work_min))
554 dst->t_work_min = src->
t_work;
555 if ((dst->t_work_max == 0) || (src->
t_work > dst->t_work_max))
556 dst->t_work_max = src->
t_work;
571 memset(&c->
glob, 0, sizeof (c->
glob));
581 res_history_add_noeud(c, h, verbose)
588 memset(&buf, 0,
sizeof (buf));
594 histraw2histres(ptr, h);
598 memset(&buf, 0,
sizeof (buf));
599 histraw2histres(&buf, h);
607 histraw2histres(&c->
glob, h);
650 verbose = verbose || (
ip != NULL);
657 if (tf <= (time_t) 0)
660 ZE_LogMsgDebug(15,
" ti tf dt : %ld %ld %ld\n", (
long) ti, (
long) tf,
666 ptr = p *
sizeof (buf);
669 if (pread(fd, &buf,
sizeof (buf), ptr) !=
sizeof (buf))
672 if (lseek(fd, ptr, SEEK_SET) == (
off_t) - 1) {
676 if (read(fd, &buf,
sizeof (buf)) !=
sizeof (buf))
685 if ((
ip != NULL) && (strcmp(
ip, buf.
ip) != 0))
688 if (strlen(buf.
ip) == 0 || strstr(buf.
ip,
"unknown") != NULL)
691 res_history_add_noeud(hst, &buf, verbose);
712 static bool log_hostnames =
FALSE;
714 static int log_count = 0;
717 print_noeud_summary(
void *rec,
void *arg)
719 char sout[256], *s =
"", nodename[128];
733 printf(
"*** %-20s : %s\n", p->
ip, s);
737 strlcpy(sout, ctime(&p->
ti), sizeof (sout));
738 if ((s =
strchr(sout,
'\n')) != NULL)
740 printf(
" First Connection : %s \n", sout);
742 strlcpy(sout, ctime(&p->
tf), sizeof (sout));
743 if ((s =
strchr(sout,
'\n')) != NULL)
745 printf(
" Last Connection : %s \n", sout);
746 printf(
" Connections : %7d\n", p->
nb_conn);
747 printf(
" Throttle Max : %7d / 10 min\n", p->
throttle_max);
749 (
" Duration (sec) : %7.3f %7.3f %8.3f %7.3f (min mean max std-dev)\n",
753 (
" Work (sec) : %7.3f %7.3f %8.3f %7.3f (min mean max std-dev)\n",
757 printf(
" Mean Throuput : %7.3f KBytes/sec\n",
761 printf(
" Messages : %7d\n", p->
nb_msgs);
762 printf(
" Empty Connections : %7d\n", p->
nb_empty);
764 printf(
" Volume : %7lu KBytes\n",
765 ((
unsigned long) p->
nb_bytes) / 1024);
766 printf(
" Mean Volume : %7.2f KBytes/msg\n",
768 printf(
" Recipients : %7d\n", p->
nb_rcpt);
776 printf(
" Yield : %7.2f rcpt/connection\n",
778 printf(
" Files : %7d\n", p->
nb_files);
779 printf(
" X-Files : %7d\n", p->
nb_xfiles);
780 printf(
" Virus : %7d\n", p->
nb_virus);
781 printf(
" User Filter : %7d\n", p->
nb_policy);
786 printf(
" Open Connections : %7d\n", p->
rej_open);
787 printf(
" Empty Connections : %7d\n", p->
rej_empty);
788 printf(
" Sender has bad MX : %7d\n", p->
rej_badmx);
793 printf(
" Content reject : %7d\n", p->
rej_regex);
794 printf(
" Oracle reject : %7d\n", p->
rej_oracle);
795 printf(
" Rcpt reject : %7d\n", p->
rej_rcpt);
796 printf(
" Intranet User : %7d\n", p->
rej_luser);
803 print_global_summary(data, arg)
819 printf(
"*** TOTAL\n");
821 strlcpy(sout, ctime(&p->
ti), sizeof (sout));
822 if ((s =
strchr(sout,
'\n')) != NULL)
824 printf(
" First Connection : %s \n", sout);
826 strlcpy(sout, ctime(&p->
tf), sizeof (sout));
827 if ((s =
strchr(sout,
'\n')) != NULL)
829 printf(
" Last Connection : %s \n", sout);
830 printf(
" Connections : %7d\n", p->
nb_conn);
831 printf(
" Gateways : %7ld\n", (
long int ) hst->
nb);
832 printf(
" Throttle Max : %7d / 10 min (for the server)\n",
834 printf(
" Throttle Max : %7d / 10 min (for a single gateway)\n",
837 (
" Duration (sec) : %7.3f %7.3f %8.3f %7.3f (min mean max std-dev)\n",
841 (
" Work (sec) : %7.3f %7.3f %8.3f %7.3f (min mean max std-dev)\n",
845 printf(
" Mean Throuput : %7.3f KBytes/sec\n",
849 printf(
" Messages : %7d\n", p->
nb_msgs);
850 printf(
" Empty Connections : %7d\n", p->
nb_empty);
852 printf(
" Volume : %7lu KBytes\n",
853 ((
unsigned long) p->
nb_bytes) / 1000);
854 printf(
" Mean Volume : %7.2f KBytes/msg\n",
856 printf(
" Recipients : %7d\n", p->
nb_rcpt);
864 printf(
" Yield : %7.2f msgs/connection\n",
866 printf(
" Yield : %7.2f rcpt/connection\n",
868 printf(
" Files : %7d\n", p->
nb_files);
869 printf(
" X-Files : %7d\n", p->
nb_xfiles);
870 printf(
" Virus : %7d\n", p->
nb_virus);
871 printf(
" User Filter : %7d\n", p->
nb_policy);
878 printf(
" Open Connections : %7d\n", p->
rej_open);
879 printf(
" Empty Connections : %7d\n", p->
rej_empty);
880 printf(
" Sender has bad MX : %7d\n", p->
rej_badmx);
885 printf(
" Content : %7d\n", p->
rej_regex);
887 printf(
" Rcpt reject : %7d\n", p->
rej_rcpt);
888 printf(
" Intranet User : %7d\n", p->
rej_luser);
895 print_noeud_data(
void *rec,
void *arg)
897 char *s =
"", nodename[128];
981 printf(
". %-20s | ", p->
ip);
990 printf(
". %-20s : %7d %7d %7d : %s\n",
995 printf(
". %-20s : %7d %7d %7d %7d : %s\n",
1001 printf(
". %-20s : %7d %7d %7d %7d : %s\n",
1007 printf(
". %-20s : %7d %7d %7d %7d %7d %7d : %s\n", p->
ip, p->
nb_conn,
1013 printf(
". %-20s : %7d %7d %7d : %s\n", p->
ip, p->
nb_conn,
1061 verbose = verbose || (
ip != NULL);
1063 log_hostnames = hostnames || (
ip != NULL) || verbose;
1068 memset(&log, 0,
sizeof (log));
1069 log.
hostnames = hostnames || (
ip != NULL) || verbose;
1076 name = (
ip != NULL ?
ip :
"HOSTNAME");
1080 printf(
"*** Summary\n\n");
1083 printf(
"*** Clients doing empty connections\n\n");
1085 (
". IP ADDRESS | CONNECT | EMPTY BADRCPT | EMPTY BADRCPT OPEN | %s\n",
1089 printf(
"*** Rejected connections (clients doing empty connections)\n\n");
1091 (
". IP ADDRESS | CONNECT | EMPTY BADRCPT | EMPTY BADRCPT OPEN | %s\n",
1095 printf(
"*** Rejected connections (clients harvesting addresses)\n\n");
1097 (
". IP ADDRESS | CONNECT | EMPTY BADRCPT | EMPTY BADRCPT OPEN | %s\n",
1101 printf(
"*** Rejected connections (clients harvesting addresses)\n\n");
1103 (
". IP ADDRESS | CONNECT | EMPTY BADRCPT | EMPTY BADRCPT OPEN | %s\n",
1107 printf(
"*** Clients doing too many open connections\n\n");
1109 (
". IP ADDRESS | CONNECT | EMPTY BADRCPT | EMPTY BADRCPT OPEN | %s\n",
1113 printf(
"*** Connection rate\n\n");
1116 printf(
"*** Rejected connections (throttle too high)\n\n");
1117 printf(
". IP ADDRESS : CONNECT THROTTLE REJECT : %s\n", name);
1120 printf(
"*** Clients with bad DNS resolution\n\n");
1121 printf(
". IP ADDRESS : CONNECT MSGS FAIL FORGED : %s\n",
1125 printf(
"*** Clients being rejected (bad DNS resolution)\n\n");
1126 printf(
". IP ADDRESS : CONNECT MSGS FAIL FORGED : %s\n",
1130 printf(
"*** Connections marked by content checking\n\n");
1132 (
". IP ADDRESS : CONNECT MSGS CONTENT ORACLE SPAMS HAMS : %s\n",
1136 printf(
"*** Gateways sending X-Files or Virus\n");
1137 printf(
". IP ADDRESS : CONNECT XFILES VIRUS : %s\n",
1141 printf(
"*** Gateways sending messages to Spam traps\n\n");
1142 printf(
". IP ADDRESS : CONNECT SPAMTRAP : %s\n", name);
1145 printf(
"*** Sender MX is doubious\n\n");
1146 printf(
". IP ADDRESS : CONNECT MSGS BADMX : %s\n", name);
1149 printf(
"*** Greylisted\n\n");
1150 printf(
". IP ADDRESS : CONNECT ...MSGS R-MSGS R-RCPTS : %s\n",
1157 if (verbose || (
ip != NULL))
1161 print_global_summary(hst, &log);
1165 log_hostnames =
TRUE;
1171 printf(
"\n*** Records found : %d\n\n", nb);
1190 time_t ti = 0, tr = 0;
1206 if (tf <= (time_t) 0)
1213 ZE_LogMsgDebug(15,
" ti tf dt : %ld %ld %ld\n", (
long) ti, (
long) tf,
1219 ptr = p *
sizeof (buf);
1222 if (pread(fd, &buf,
sizeof (buf), ptr) !=
sizeof (buf))
1225 if (lseek(fd, ptr, SEEK_SET) == (
off_t) - 1) {
1229 if (read(fd, &buf,
sizeof (buf)) !=
sizeof (buf))
1237 if ((tr < ti) || (tr > tf))
1240 if (strlen(buf.
ip) == 0 || strstr(buf.
ip,
"unknown") != NULL)
bool zeBTree_Set_BTree_Size(ZEBT_T *, bool, int)
int jinet_pton(int, char *, void *)
#define CACHE_GETHOSTNAMEBYADDR(ip, name, size, query)
void * zeBTree_Get(ZEBT_T *, void *)
bool zeBTree_Init(ZEBT_T *, size_t, ZEBT_CMP_F)
HistRes_T * res_history_lookup(History_T *, char *)
#define ZE_LogMsgInfo(level,...)
bool zeBTree_Add(ZEBT_T *, void *)
int ip_strcmp(char *, char *)
int32_t rej_resolve_forged
int32_t rej_resolve_failed
bool raw_history_open(bool ronly)
#define ZE_LogMsgDebug(level,...)
void zeKStatsUpdate(kstats_T *, double)
bool zeBTree_Clear(ZEBT_T *)
void res_history_summary(History_T *hst, char *ip, time_t tf, time_t dt, bool verbose, bool hostnames, int type, int nbrecs)
bool res_history_update(History_T *hst, char *ip, time_t tf, time_t dt, bool verbose)
#define ZE_MessageInfo(level,...)
bool load_live_history(History_T *hst, time_t tf, time_t dt)
#define ZE_LogSysError(...)
int32_t dbrcpt_bad_network
char * cf_get_str(int id)
#define ZE_LogMsgWarning(level,...)
#define STRCASEEQUAL(a, b)
double zeKMean(kstats_T *s)
int livehistory_add_entry(char *, time_t, int, int)
double zeKStdDev(kstats_T *s)
#define NET_CLASS_LABEL(class)
struct log_history_T log_history_T
#define CF_HISTORY_ENTRIES
int zeBTree_Browse(ZEBT_T *, ZEBT_BROWSE_F, void *)
bool raw_history_add_entry(SMFICTX *ctx)
void res_history_clear(History_T *)