ze-filter  (ze-filter-0.8.0-develop-180218)
mlfi_unknown.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 #define MAX_UNKNOWN_CMD 2
30 
31 static sfsistat
32 mlfi_unknown(ctx, cmd)
33  SMFICTX *ctx;
34  const char *cmd;
35 
36 {
37  CTXPRIV_T *priv = MLFIPRIV(ctx);
38  int result = SMFIS_CONTINUE;
39  int ip_class;
40 
42  if (priv == NULL) {
43  result = SMFIS_TEMPFAIL;
44  return result;
45  }
46 
48 
49  ip_class = priv->netclass.class;
50  sm_macro_update(ctx, priv->sm);
51  ZE_MessageInfo(9, "%s : %s Unknown command : %s", CONNID_STR(priv->id),
52  priv->peer_addr, STRNULL(cmd, "NULL"));
53 
54  priv->nb_unknown_cmd++;
55  if (IS_UNKNOWN(ip_class) && priv->nb_unknown_cmd > MAX_UNKNOWN_CMD) {
56  char buf[256];
57 
58  (void) jsmfi_setreply(ctx, "421", "4.5.1", "Too many errors");
59  snprintf(buf, sizeof (buf), "Too many unknown SMTP commands : %d (%s)",
60  priv->nb_unknown_cmd, CTX_NETCLASS_LABEL(priv));
61  log_msg_context(ctx, buf);
62 
63  result = SMFIS_TEMPFAIL;
64  priv->result = result;
65  }
66  if (result != SMFIS_CONTINUE)
67  goto fin;
68 
69  /*
70  **
71  **
72  **
73  */
74 #if _FFR_MODULES
75  /*
76  ** ze-filter modules
77  **
78  */
79  if (do_module_callback(ctx, 0, &result))
80  goto fin;
81  if (result != SMFIS_CONTINUE)
82  goto fin;
83 #endif /* _FFR_MODULES */
84 fin:
86  return result;
87 }
#define SMFIS_TEMPFAIL
int jsmfi_setreply(SMFICTX *, char *, char *, char *)
Definition: ze-libmilter.c:99
char * peer_addr
#define STRNULL(x, r)
Definition: macros.h:81
#define CALLBACK_UNKNOWN
Definition: ze-callback.h:39
#define SMFIS_CONTINUE
#define MLFIPRIV(ctx)
#define INIT_CALLBACK(p, which)
Definition: ze-filter.c:125
void sm_macro_update(SMFICTX *, sm_mac_T *)
Definition: ze-smmacros.c:150
CONNID_T id
#define INIT_CALLBACK_DELAY()
Definition: ze-filter.c:135
#define IS_UNKNOWN(class)
Definition: ze-netclass.h:51
#define ZE_MessageInfo(level,...)
Definition: zeSyslog.h:90
#define MAX_UNKNOWN_CMD
Definition: mlfi_unknown.c:29
#define CTX_NETCLASS_LABEL(priv)
bool do_module_callback(SMFICTX *ctx, int step, int *result)
Definition: ze-mod-tools.c:84
sm_mac_T * sm
#define CONNID_STR(connid)
Definition: ze-filter.h:113
#define CHECK_CALLBACK_DELAY()
Definition: ze-filter.c:146
netclass_T netclass
int nb_unknown_cmd
void log_msg_context(SMFICTX *ctx, char *why)