ze-filter  (ze-filter-0.8.0-develop-180218)
ze-mod-tools.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 : Sun Jun 10 15:23:49 CEST 2007
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 #include <ze-sys.h>
27 #include <ze-filter.h>
28 #include "ze-filter-data.h"
29 #include <ze-spool.h>
30 #include <ze-mod-tools.h>
31 
32 
33 /* ****************************************************************************
34  * *
35  * *
36  ******************************************************************************/
37 void
38 ctx2mod_args(mod, ctx)
39  mod_ctx_T *mod;
40  SMFICTX *ctx;
41 {
42  CTXPRIV_T *priv = MLFIPRIV(ctx);
43 
44  ASSERT(priv != NULL);
45  memset(mod, 0, sizeof (*mod));
46  mod->callback = priv->callback_id;
47  mod->id = CONNID_STR(priv->id);
48  mod->claddr = priv->peer_addr;
49  mod->clname = priv->peer_name;
50  mod->helo = priv->helohost;
51  mod->from = priv->env_from;
52  mod->rcpt = priv->env_to;
53  mod->sfile = priv->fname;
54  mod->xfiles = FALSE; /* XXX */
55  mod->raw_scores = &priv->rawScores; /* XXX */
56  mod->net_scores = &priv->netScores; /* XXX */
57  mod->result = 0;
58 }
59 
60 /* ****************************************************************************
61  * *
62  * *
63  ******************************************************************************/
64 int
66  int r;
67 {
68  switch (r) {
69  case MODR_REJECT:
70  return SMFIS_REJECT;
71  break;
72  case MODR_TEMPFAIL:
73  return SMFIS_TEMPFAIL;
74  break;
75  }
76  return SMFIS_CONTINUE;
77 }
78 
79 /* ****************************************************************************
80  * *
81  * *
82  ******************************************************************************/
83 bool
84 do_module_callback(ctx, step, result)
85  SMFICTX *ctx;
86  int step;
87  int *result;
88 {
89  CTXPRIV_T *priv = MLFIPRIV(ctx);
90  mod_ctx_T mctx;
91  bool stop = FALSE;
92 
93  *result = SMFIS_CONTINUE;
94  memset(&mctx, 0, sizeof (mctx));
95  ctx2mod_args(&mctx, ctx);
96 
97  module_call(priv->callback_id, step, &mctx);
98 
99  *result = mod2ctx_result(mctx.result);
100 
101  if (MOD_QUARANTINE(mctx.flags))
103 
104  ZE_MessageInfo(12, "RESULT : %08x %08x", mctx.result, mctx.flags);
105 
106  if (*result != SMFIS_CONTINUE) {
107  char reason[128];
108 
109  /*
110  * set reply
111  */
112  if (strlen(mctx.code) > 0 && strlen(mctx.xcode) > 0
113  && strlen(mctx.reply) > 0) {
114  (void) jsmfi_setreply(ctx, mctx.code, mctx.xcode, mctx.reply);
115  }
116 
117  /*
118  * log context
119  */
120  snprintf(reason, sizeof (reason), "Message rejected by module %s",
121  mctx.modname);
122  log_msg_context(ctx, reason);
123  }
124 
125  stop = MOD_STOP_CHECKS(mctx.flags);
126 
127  return stop;
128 }
#define MOD_STOP_CHECKS(flag)
Definition: ze-modules.h:43
msg_scores_T rawScores
char * fname
#define ASSERT(a)
Definition: macros.h:27
#define SMFIS_TEMPFAIL
#define WHY_QUARANTINE
Definition: ze-spool.h:33
int jsmfi_setreply(SMFICTX *, char *, char *, char *)
Definition: ze-libmilter.c:99
#define SUFFIX_QUARANTINE
Definition: ze-spool.h:42
#define MOD_QUARANTINE(flag)
Definition: ze-modules.h:42
char * peer_addr
void ctx2mod_args(mod_ctx_T *mod, SMFICTX *ctx)
Definition: ze-mod-tools.c:38
char * clname
Definition: ze-modules.h:61
#define FALSE
Definition: macros.h:160
#define SMFIS_CONTINUE
#define SMFIS_REJECT
char * env_to
#define MLFIPRIV(ctx)
int mod2ctx_result(int r)
Definition: ze-mod-tools.c:65
#define DO_QUARANTINE_MESSAGE(priv, why, suffix)
char * helo
Definition: ze-modules.h:62
char * rcpt
Definition: ze-modules.h:64
CONNID_T id
#define MODR_REJECT
Definition: ze-modules.h:36
char * from
Definition: ze-modules.h:63
msg_scores_T * raw_scores
Definition: ze-modules.h:67
#define ZE_MessageInfo(level,...)
Definition: zeSyslog.h:90
char * id
Definition: ze-modules.h:59
int callback
Definition: ze-modules.h:58
char code[8]
Definition: ze-modules.h:71
#define MODR_TEMPFAIL
Definition: ze-modules.h:37
msg_scores_T * net_scores
Definition: ze-modules.h:68
char * peer_name
msg_scores_T netScores
char * env_from
bool module_call(int callback, int step, mod_ctx_T *arg)
Definition: ze-modules.c:421
char * helohost
bool xfiles
Definition: ze-modules.h:66
int result
Definition: ze-modules.h:69
#define CONNID_STR(connid)
Definition: ze-filter.h:113
char modname[32]
Definition: ze-modules.h:74
char xcode[8]
Definition: ze-modules.h:72
int flags
Definition: ze-modules.h:70
void log_msg_context(SMFICTX *ctx, char *why)
char * sfile
Definition: ze-modules.h:65
char * claddr
Definition: ze-modules.h:60
bool do_module_callback(SMFICTX *ctx, int step, int *result)
Definition: ze-mod-tools.c:84
char reply[64]
Definition: ze-modules.h:73