ze-filter  (ze-filter-0.8.0-develop-180218)
mlfi_close.c
Go to the documentation of this file.
1 
2 /*
3  *
4  * ze-filter - Mail Server Filter for sendmail
5  *
6  * Copyright (c) 2001-2018 - Jose-Marcio Martins da Cruz
7  *
8  * Auteur : Jose Marcio Martins da Cruz
9  * jose.marcio.mc@gmail.org
10  *
11  * Historique :
12  * Creation : janvier 2002
13  *
14  * This program is free software, but with restricted license :
15  *
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20  *
21  * More details about ze-filter license can be found at ze-filter
22  * web site : http://foss.jose-marcio.org
23  */
24 
25 
26 /* ****************************************************************************
27  * *
28  * *
29  ******************************************************************************/
30 sfsistat
32  SMFICTX *ctx;
33 
34 {
35  CTXPRIV_T *priv = MLFIPRIV(ctx);
36  time_t now;
37  int result = SMFIS_CONTINUE;
38 
41  (void) count_connections(-1);
43  if (priv == NULL)
44  goto fin;
45  sm_macro_update(ctx, priv->sm);
46 #if HAVE_GETHRTIME
47  priv->t_close = gethrtime();
48 #else
49  priv->t_close = zeTime_ms();
50 #endif
51  now = time(NULL);
52 #if _FFR_MODULES
53  /*
54  ** ze-filter modules
55  **
56  */
57  if (do_module_callback(ctx, 0, &result))
58  goto fin;
59  if (result != SMFIS_CONTINUE)
60  goto fin;
61 #endif /* _FFR_MODULES */
62  if ((priv->peer_addr != NULL) && (strlen(priv->peer_addr) > 0)
63  && !STRCASEEQUAL(priv->peer_addr, "unknown")) {
64 #if HAVE_GETHRTIME
65  long dtms =
66  (long) ((priv->t_close - priv->t_open) / 1000000);
67 #else
68  long dtms = (long) (priv->t_close - priv->t_open);
69 #endif
70  if (dtms > tlongconn * 1000)
71  (void) livehistory_add_entry(priv->peer_addr, now, 1, LH_LONGCONN);
72  (void) raw_history_add_entry(ctx);
73  /*
74  * Let's update open connections for this address
75  */
76  (void) connopen_check_host(priv->peer_addr, priv->peer_name, -1);
77  /*
78  ** If this is an empty connection, update records
79  */
80  if (priv->nb_spams > 0)
81  (void) livehistory_add_entry(priv->peer_addr, now, priv->nb_spams,
82  LH_HI_SCORE);
83  if ((priv->nb_rcpt > 0) && (priv->nb_msgs == 0))
84  (void) livehistory_add_entry(priv->peer_addr, now, 1, LH_EMPTYCONN);
85  if (priv->nb_cbadrcpt > 0)
86  (void) livehistory_add_entry(priv->peer_addr, now, priv->nb_cbadrcpt,
87  LH_BADRCPT);
88  }
89 
91  sm_macro_free(priv->sm);
92  mlfi_cleanup(ctx, TRUE);
93 fin:
94  return result;
95 }
void stats_inc(int, long)
Definition: ze-stats.c:401
void sm_macro_free(sm_mac_T *)
Definition: ze-smmacros.c:132
sfsistat mlfi_cleanup(SMFICTX *ctx, bool ok)
Definition: mlfi_cleanup.c:31
char * peer_addr
uint64_t zeTime_ms()
Definition: zeTime.c:34
sfsistat mlfi_close(SMFICTX *ctx)
Definition: mlfi_close.c:31
bool raw_history_add_entry(SMFICTX *)
Definition: ze-history.c:309
#define SMFIS_CONTINUE
time_t tlongconn
Definition: ze-filter.c:93
#define MLFIPRIV(ctx)
#define STAT_CLOSE
Definition: ze-stats.h:31
#define INIT_CALLBACK(p, which)
Definition: ze-filter.c:125
#define LH_LONGCONN
#define LH_EMPTYCONN
void sm_macro_update(SMFICTX *, sm_mac_T *)
Definition: ze-smmacros.c:150
int count_connections(int)
Definition: ze-filter.c:300
#define LH_BADRCPT
#define INIT_CALLBACK_DELAY()
Definition: ze-filter.c:135
time_t t_open
#define TRUE
Definition: macros.h:157
#define CALLBACK_CLOSE
Definition: ze-callback.h:38
char * peer_name
int connopen_check_host(char *, char *, int)
Definition: ze-connopen.c:151
bool do_module_callback(SMFICTX *ctx, int step, int *result)
Definition: ze-mod-tools.c:84
sm_mac_T * sm
#define CHECK_CALLBACK_DELAY()
Definition: ze-filter.c:146
#define STRCASEEQUAL(a, b)
Definition: macros.h:72
int livehistory_add_entry(char *, time_t, int, int)
#define LH_HI_SCORE
time_t t_close