ze-filter  (ze-filter-0.8.0-develop-180218)
ze-libmilter.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 : Wed Nov 17 22:29:20 CET 2004
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-libmilter.h>
30 
31 
32 /* ****************************************************************************
33  * *
34  * *
35  ******************************************************************************/
36 int
38  SMFICTX *ctx;
39  char *msg;
40 {
41  CTXPRIV_T *priv = MLFIPRIV(ctx);
42  int res;
43  char *sout, buf[1024];
44  char *url = cf_get_str(CF_POLICY_URL);
45 
46  char *rcode, *xcode, *rmsg, *tag;
47  char *s, *p = NULL;
48 
49  tag = rcode = xcode = rmsg = NULL;
50  {
51  if ((s = strdup(msg)) != NULL) {
52  p = tag = s;
53 
54  p = strchr(p, ':');
55  if (p != NULL) {
56  *p++ = '\0';
57  rcode = p;
58 
59  p = strchr(p, ':');
60  if (p != NULL) {
61  *p++ = '\0';
62  xcode = p;
63 
64  p = strchr(p, ':');
65  if (p != NULL) {
66  *p++ = '\0';
67  rmsg = p;
68  }
69  }
70  }
71  }
72  }
73 
74  rmsg = STRNULL(rmsg, "Access denied");
75  rcode = STRNULL(rcode, "421");
76  xcode = STRNULL(xcode, "4.5.0");
77 
78  sout = rmsg;
79  if ((url != NULL) && (strlen(url) > 0)) {
80  snprintf(buf, sizeof (buf), "%s - See %s", rmsg, url);
81  sout = buf;
82  }
83 
84  if ((res = smfi_setreply(ctx, rcode, xcode, sout)) != MI_SUCCESS)
85  ZE_MessageWarning(9, "%s smfi_setreply returned MI_FAILURE",
86  CONNID_STR(priv->id));
87 
88  FREE(s);
89 
90  return res;
91 }
92 
93 
94 /* ****************************************************************************
95  * *
96  * *
97  ******************************************************************************/
98 int
99 jsmfi_setreply(ctx, ca, cb, msg)
100  SMFICTX *ctx;
101  char *ca;
102  char *cb;
103  char *msg;
104 {
105  CTXPRIV_T *priv = MLFIPRIV(ctx);
106  int res;
107  char *sout, buf[1024];
108  char *url = cf_get_str(CF_POLICY_URL);
109 
110  sout = msg;
111 
112  if ((url != NULL) && (strlen(url) > 0)) {
113  snprintf(buf, sizeof (buf), "%s - See %s", msg, url);
114  sout = buf;
115  }
116 
117  if ((res = smfi_setreply(ctx, ca, cb, sout)) != MI_SUCCESS)
118  ZE_MessageWarning(9, "%s smfi_setreply returned MI_FAILURE",
119  CONNID_STR(priv->id));
120 
121  {
122  size_t sz;
123 
124  FREE(priv->reply_code);
125 #if 1
126  sz = strlen(ca) + strlen(cb) + strlen(sout) + 4;
127  ;
128  if ((priv->reply_code = malloc(sz)) != NULL)
129  snprintf(priv->reply_code, sz, "%s %s %s", ca, cb, sout);
130 #else
131  sz = strlen(ca) + strlen(cb) + 2;
132 
133  if ((priv->reply_code = malloc(sz)) != NULL)
134  snprintf(priv->reply_code, sz, "%s %s", ca, cb);
135 #endif
136  }
137 
138  if (priv->reply_code == NULL)
139  ZE_LogSysError("strdup error");
140 
141  return res;
142 }
143 
144 /* ****************************************************************************
145  * *
146  * *
147  ******************************************************************************/
148 int
149 jsmfi_vsetreply(SMFICTX * ctx, char *ca, char *cb, char *format, ...)
150 #if 0
151  SMFICTX *ctx;
152  char *ca;
153  char *cb;
154  char *format;
155 #endif
156 {
157  va_list arg;
158  char s[1024];
159 
160  va_start(arg, format);
161  vsnprintf(s, sizeof (s), format, arg);
162  va_end(arg);
163 
164  return jsmfi_setreply(ctx, ca, cb, s);
165 }
166 
167 /* ****************************************************************************
168  * *
169  * *
170  ******************************************************************************/
171 int
172 Smfi_ChgFrom(ctx, mail, args)
173  SMFICTX *ctx;
174  char *mail;
175  char *args;
176 {
177  CTXPRIV_T *priv = MLFIPRIV(ctx);
178 
179 #if HAVE_SMFI_CHGFROM
180  if ((priv->mta_caps.f0 & SMFIF_CHGFROM) != 0)
181  return smfi_chgfrom(ctx, mail, args);
182 #endif
183 
184  return SMFIS_CONTINUE;
185 }
int Smfi_ChgFrom(SMFICTX *ctx, char *mail, char *args)
Definition: ze-libmilter.c:172
#define FREE(x)
Definition: macros.h:37
MTA_caps_T mta_caps
unsigned long f0
#define STRNULL(x, r)
Definition: macros.h:81
char * reply_code
#define SMFIS_CONTINUE
#define CF_POLICY_URL
Definition: cfh-defs.h:35
int jsmfi_vsetreply(SMFICTX *ctx, char *ca, char *cb, char *format,...)
Definition: ze-libmilter.c:149
#define MLFIPRIV(ctx)
#define strchr
Definition: ze-sys.h:218
CONNID_T id
#define ZE_MessageWarning(level,...)
Definition: zeSyslog.h:92
#define ZE_LogSysError(...)
Definition: zeSyslog.h:129
char * cf_get_str(int id)
Definition: ze-cf.c:854
#define CONNID_STR(connid)
Definition: ze-filter.h:113
int jsmfi_setreply_from_access(SMFICTX *ctx, char *msg)
Definition: ze-libmilter.c:37
int jsmfi_setreply(SMFICTX *ctx, char *ca, char *cb, char *msg)
Definition: ze-libmilter.c:99
int msg[MAX_SCORE+2]
Definition: ze-stats.c:41