ze-filter
(ze-filter-0.8.0-develop-180218)
ze-null-milter.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
#if 0
25
#include <ze-sys.h>
26
#else
27
#include <stdlib.h>
28
#include <stdio.h>
29
#include <sysexits.h>
30
#include <unistd.h>
31
#endif
32
#include "libmilter/mfapi.h"
33
34
#ifndef HAVE_XXFI_UNKNOWN
35
#define HAVE_XXFI_UNKNOWN 1
36
#endif
37
#ifndef HAVE_XXFI_DATA
38
#define HAVE_XXFI_DATA 1
39
#endif
40
#ifndef HAVE_XXFI_NEGOTIATE
41
#define HAVE_XXFI_NEGOTIATE 1
42
#endif
43
#ifndef HAVE_XXFI_SIGNAL
44
#define HAVE_XXFI_SIGNAL 0
45
#endif
46
47
/* ****************************************************************************
48
* *
49
* *
50
******************************************************************************/
51
static
sfsistat
mlfi_connect
(SMFICTX *,
char
*, _SOCK_ADDR *);
52
static
sfsistat
mlfi_helo
(SMFICTX *,
char
*);
53
static
sfsistat
mlfi_envfrom
(SMFICTX *,
char
**);
54
static
sfsistat
mlfi_envto
(SMFICTX *,
char
**);
55
static
sfsistat
mlfi_header
(SMFICTX *,
char
*,
char
*);
56
static
sfsistat
mlfi_eoh
(SMFICTX *);
57
static
sfsistat
mlfi_body
(SMFICTX *,
unsigned
char
*,
size_t
);
58
static
sfsistat
mlfi_eom
(SMFICTX *);
59
static
sfsistat
mlfi_close
(SMFICTX *);
60
static
sfsistat
mlfi_abort
(SMFICTX *);
61
static
sfsistat
mlfi_cleanup
(SMFICTX *,
bool
);
62
63
#define MLFIPRIV(ctx) (ctx != NULL ? (CTXPRIV_T *) smfi_getpriv(ctx) : NULL)
64
65
typedef
struct
mlfiPfiv
{
66
int
dummy
;
67
68
unsigned
long
pf0
;
69
unsigned
long
pf1
;
70
unsigned
long
pf2
;
71
unsigned
long
pf3
;
72
}
CTXPRIV_T
;
73
74
75
#define FREE(x) \
76
do { \
77
if (x != NULL) \
78
free(x); \
79
x = NULL; \
80
} while (0)
81
82
/* ****************************************************************************
83
* *
84
* *
85
******************************************************************************/
86
static
sfsistat
87
mlfi_connect
(ctx, hostname, hostaddr)
88
SMFICTX *ctx;
89
char
*hostname;
90
_SOCK_ADDR *hostaddr;
91
{
92
CTXPRIV_T
*priv =
MLFIPRIV
(ctx);
93
94
if
(hostname == NULL)
95
hostname =
"HOST_UNKNOWN"
;
96
97
if
(priv == NULL) {
98
printf(
"mlfi_connect : priv is NULL\n"
);
99
}
100
FREE
(priv);
101
102
smfi_setpriv(ctx, NULL);
103
104
return
SMFIS_CONTINUE
;
105
}
106
107
/* ****************************************************************************
108
* *
109
* *
110
******************************************************************************/
111
static
sfsistat
112
mlfi_helo
(ctx, name)
113
SMFICTX *ctx;
114
char
*name;
115
{
116
CTXPRIV_T
*priv =
MLFIPRIV
(ctx);
117
118
printf(
"smfi_hello -> OK !\n"
);
119
return
SMFIS_CONTINUE
;
120
}
121
122
/* ****************************************************************************
123
* *
124
* *
125
******************************************************************************/
126
static
sfsistat
127
mlfi_envfrom
(SMFICTX * ctx,
char
**from)
128
{
129
CTXPRIV_T
*priv =
MLFIPRIV
(ctx);
130
131
return
SMFIS_CONTINUE
;
132
}
133
134
/* ****************************************************************************
135
* *
136
* *
137
******************************************************************************/
138
static
sfsistat
139
mlfi_envto
(SMFICTX * ctx,
char
**to)
140
{
141
CTXPRIV_T
*priv =
MLFIPRIV
(ctx);
142
143
return
SMFIS_CONTINUE
;
144
}
145
146
/* ****************************************************************************
147
* *
148
* *
149
******************************************************************************/
150
static
sfsistat
151
mlfi_header
(SMFICTX * ctx,
char
*headerf,
char
*headerv)
152
{
153
CTXPRIV_T
*priv =
MLFIPRIV
(ctx);
154
155
return
SMFIS_CONTINUE
;
156
}
157
158
/* ****************************************************************************
159
* *
160
* *
161
******************************************************************************/
162
static
sfsistat
163
mlfi_eoh
(SMFICTX * ctx)
164
{
165
CTXPRIV_T
*priv =
MLFIPRIV
(ctx);
166
167
return
SMFIS_CONTINUE
;
168
}
169
170
/* ****************************************************************************
171
* *
172
* *
173
******************************************************************************/
174
static
sfsistat
175
mlfi_body
(SMFICTX * ctx,
unsigned
char
*buf,
size_t
size)
176
{
177
CTXPRIV_T
*priv =
MLFIPRIV
(ctx);
178
179
return
SMFIS_CONTINUE
;
180
}
181
182
/* ****************************************************************************
183
* *
184
* *
185
******************************************************************************/
186
static
sfsistat
187
mlfi_eom
(SMFICTX * ctx)
188
{
189
CTXPRIV_T
*priv =
MLFIPRIV
(ctx);
190
191
return
SMFIS_CONTINUE
;
192
}
193
194
/* ****************************************************************************
195
* *
196
* *
197
******************************************************************************/
198
static
sfsistat
199
mlfi_close
(SMFICTX * ctx)
200
{
201
CTXPRIV_T
*priv =
MLFIPRIV
(ctx);
202
203
return
SMFIS_CONTINUE
;
204
}
205
206
/* ****************************************************************************
207
* *
208
* *
209
******************************************************************************/
210
static
sfsistat
211
mlfi_abort
(SMFICTX * ctx)
212
{
213
CTXPRIV_T
*priv =
MLFIPRIV
(ctx);
214
215
return
SMFIS_CONTINUE
;
216
}
217
218
/* ****************************************************************************
219
* *
220
* *
221
******************************************************************************/
222
static
sfsistat
223
mlfi_cleanup
(SMFICTX * ctx,
bool
ok
)
224
{
225
CTXPRIV_T
*priv =
MLFIPRIV
(ctx);
226
227
return
SMFIS_CONTINUE
;
228
}
229
230
/* ****************************************************************************
231
* *
232
* *
233
**************************************************************************** */
234
static
sfsistat
235
mlfi_unknown(ctx, cmd)
236
SMFICTX *ctx;
237
const
char
*cmd;
238
{
239
CTXPRIV_T
*priv =
MLFIPRIV
(ctx);
240
241
return
SMFIS_CONTINUE
;
242
}
243
244
245
/* ****************************************************************************
246
* *
247
* *
248
**************************************************************************** */
249
static
sfsistat
250
mlfi_data(ctx)
251
SMFICTX *ctx;
252
{
253
CTXPRIV_T
*priv =
MLFIPRIV
(ctx);
254
255
return
SMFIS_CONTINUE
;
256
}
257
258
/* ****************************************************************************
259
* *
260
* *
261
******************************************************************************/
262
static
sfsistat
263
mlfi_negotiate(SMFICTX * ctx,
264
unsigned
long
f0,
unsigned
long
f1,
265
unsigned
long
f2,
unsigned
long
f3,
266
unsigned
long
*
pf0
,
unsigned
long
*
pf1
,
267
unsigned
long
*
pf2
,
unsigned
long
*
pf3
)
268
{
269
CTXPRIV_T
*priv = NULL;
270
sfsistat result = SMFIS_ALL_OPTS;
271
272
*
pf0
= f0;
273
*
pf1
= f1;
274
*
pf2
= f2;
275
*pf3 = f3;
276
277
printf(
"malloc inside mlfi_negotiate\n"
);
278
priv = malloc(
sizeof
(
CTXPRIV_T
));
279
if
(priv != NULL) {
280
printf(
"malloc priv OK\n"
);
281
if
(smfi_setpriv(ctx, priv) != MI_SUCCESS) {
282
FREE
(priv);
283
printf(
"smfi_setpriv(priv) error\n"
);
284
285
result =
SMFIS_TEMPFAIL
;
286
287
goto
fin;
288
}
289
}
290
291
if
(priv != NULL) {
292
}
293
294
fin:
295
return
result;
296
}
297
298
/* ****************************************************************************
299
* *
300
* *
301
******************************************************************************/
302
struct
smfiDesc
smfilter
= {
303
"SampleFilter"
,
/* filter name */
304
SMFI_VERSION,
/* version code -- do not change */
305
SMFIF_ADDHDRS,
/* flags */
306
mlfi_connect
,
/* connection info filter */
307
mlfi_helo
,
/* SMTP HELO command filter */
308
mlfi_envfrom
,
/* envelope sender filter */
309
mlfi_envto
,
/* envelope recipient filter */
310
mlfi_header
,
/* header filter */
311
mlfi_eoh
,
/* end of header */
312
mlfi_body
,
/* body block filter */
313
mlfi_eom
,
/* end of message */
314
mlfi_abort
,
/* message aborted */
315
mlfi_close
/* connection cleanup */
316
#if HAVE_XXFI_UNKNOWN
317
, mlfi_unknown
/* unknown command */
318
#endif
319
#if HAVE_XXFI_DATA && HAVE_XXFI_UNKNOWN
320
, mlfi_data
/* data */
321
#endif
322
#if HAVE_XXFI_NEGOTIATE && HAVE_XXFI_DATA && HAVE_XXFI_UNKNOWN
323
, mlfi_negotiate
/* negotiate */
324
#endif
325
#if HAVE_XXFI_SIGNAL
326
, NULL
/* signale */
327
#endif
328
};
329
330
int
331
main
(argc, argv)
332
int
argc;
333
char
*argv[];
334
{
335
int
res;
336
337
#if 0
338
(void) smfi_setconn(
"local:/tmp/null-milter.sock"
);
339
#else
340
(void) smfi_setconn(
"inet:2040@127.0.0.1"
);
341
#endif
342
343
if
(smfi_register(
smfilter
) == MI_FAILURE) {
344
fprintf(stderr,
"smfi_register failed\n"
);
345
exit(EX_UNAVAILABLE);
346
}
347
348
res = smfi_main();
349
printf(
"smfi_mail returned %d\n"
, res);
350
return
res;
351
}
352
353
/* eof */
mlfiPfiv
Definition:
ze-null-milter.c:65
SMFIS_TEMPFAIL
#define SMFIS_TEMPFAIL
Definition:
ze-smtp-divers.c:232
mlfiPfiv::pf3
unsigned long pf3
Definition:
ze-null-milter.c:71
mlfi_envfrom
sfsistat mlfi_envfrom(SMFICTX *ctx, char **envfrom)
Definition:
mlfi_envfrom.c:32
mlfi_cleanup
sfsistat mlfi_cleanup(SMFICTX *ctx, bool ok)
Definition:
mlfi_cleanup.c:31
mlfiPfiv::dummy
int dummy
Definition:
ze-null-milter.c:66
mlfi_close
sfsistat mlfi_close(SMFICTX *ctx)
Definition:
mlfi_close.c:31
ok
bool ok
Definition:
ze-connopen.c:59
SMFIS_CONTINUE
#define SMFIS_CONTINUE
Definition:
ze-smtp-divers.c:228
mlfiPfiv::pf1
unsigned long pf1
Definition:
ze-null-milter.c:69
mlfi_body
sfsistat mlfi_body(SMFICTX *ctx, unsigned char *bodyp, size_t bodylen)
Definition:
mlfi_body.c:31
mlfi_connect
sfsistat mlfi_connect(SMFICTX *ctx, char *hostname, _SOCK_ADDR *hostaddr)
Definition:
mlfi_connect.c:45
mlfi_abort
sfsistat mlfi_abort(SMFICTX *ctx)
Definition:
mlfi_abort.c:31
CTXPRIV_T
struct mlfiPfiv CTXPRIV_T
MLFIPRIV
#define MLFIPRIV(ctx)
Definition:
ze-null-milter.c:63
mlfiPfiv::pf2
unsigned long pf2
Definition:
ze-null-milter.c:70
mlfi_eom
sfsistat mlfi_eom(SMFICTX *ctx)
Definition:
mlfi_eom.c:107
mlfi_header
sfsistat mlfi_header(SMFICTX *ctx, char *headerf, char *headerv)
Definition:
mlfi_header.c:30
mlfi_helo
sfsistat mlfi_helo(SMFICTX *ctx, char *helohost)
Definition:
mlfi_helo.c:30
FREE
#define FREE(x)
Definition:
ze-null-milter.c:75
main
int main(int argc, argv)
Definition:
ze-null-milter.c:331
smfilter
struct smfiDesc smfilter
Definition:
ze-null-milter.c:302
mlfi_eoh
sfsistat mlfi_eoh(SMFICTX *ctx)
Definition:
mlfi_eoh.c:31
mlfi_envto
sfsistat mlfi_envto(SMFICTX *ctx, char **envto)
Definition:
mlfi_envto.c:31
CTXPRIV_T
Definition:
ze-filter-data.h:76
mlfiPfiv::pf0
unsigned long pf0
Definition:
ze-null-milter.c:68
src
ze-null-milter.c
Generated by
1.8.13