commit - 76e3b8e2062bd83badd8e162307739afa8094e19
commit + 03a6f52ae9e64345f1b1571c9cab24de5fa869a2
blob - c0f2f0b1c7fc7046f28a70dc68e14fdef013417d
blob + 3f8c0c98f6f645d86408130fc996f5915263d38e
--- main.c
+++ main.c
void usage(void);
void dnsbl_connect(char *, int, struct timespec *, char *, char *, uint64_t,
- uint64_t, struct smtp_filter_connect *);
+ uint64_t, char *, struct inx_addr *);
void dnsbl_resolve(struct asr_result *, void *);
void dnsbl_timeout(int, short, void *);
void dnsbl_session_free(struct dnsbl_session *);
void
dnsbl_connect(char *type, int version, struct timespec *tm, char *direction,
- char *phase, uint64_t reqid, uint64_t token,
- struct smtp_filter_connect *params)
+ char *phase, uint64_t reqid, uint64_t token, char *hostname,
+ struct inx_addr *xaddr)
{
struct dnsbl_session *session;
struct timeval timeout = {1, 0};
session->reqid = reqid;
session->token = token;
- addr = (u_char *)&(params->addr);
+ if (xaddr->af == AF_INET)
+ addr = (u_char *)&(xaddr->addr);
+ else
+ addr = (u_char *)&(xaddr->addr6);
for (i = 0; i < nblacklists; i++) {
- if (params->af == AF_INET) {
+ if (xaddr->af == AF_INET) {
if (snprintf(query, sizeof(query), "%u.%u.%u.%u.%s",
addr[3], addr[2], addr[1], addr[0],
blacklists[i]) >= sizeof(query))
errx(1, "Can't create query, domain too long");
- } else if (params->af == AF_INET6) {
+ } else if (xaddr->af == AF_INET6) {
if (snprintf(query, sizeof(query), "%hhx.%hhx.%hhx.%hhx"
".%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx"
".%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx.%hhx"
blob - 96d943ce505fbd9c14b4c290260c7d42ca4db6ac
blob + c85df01c0873425f605da34a290d4fb520a94f6b
--- smtp_proc.c
+++ smtp_proc.c
#define NITEMS(x) (sizeof(x) / sizeof(*x))
-typedef int (*smtp_cb)(char *, int, struct timespec *, char *, char *, uint64_t,
- uint64_t, void *);
-
struct smtp_callback;
struct smtp_request;
-static int smtp_register(char *, char *, char *, smtp_cb);
+static int smtp_register(char *, char *, char *, void *);
static void smtp_newline(int, short, void *);
static void smtp_connect(struct smtp_callback *, int, struct timespec *,
uint64_t, uint64_t, char *);
-static void smtp_handle_filter(struct smtp_callback *, int, struct timespec *,
- uint64_t, uint64_t, void *);
struct smtp_callback {
char *type;
char *direction;
void (*smtp_parse)(struct smtp_callback *, int, struct timespec *,
uint64_t, uint64_t, char *);
- smtp_cb cb;
+ void *cb;
} smtp_callbacks[] = {
{"filter", "connect", "smtp-in", smtp_connect, NULL}
};
int
smtp_register_filter_connect(void (*cb)(char *, int, struct timespec *, char *,
- char *, uint64_t, uint64_t, struct smtp_filter_connect *))
+ char *, uint64_t, uint64_t, char *, struct inx_addr *))
{
- return smtp_register("filter", "connect", "smtp-in", (smtp_cb) cb);
+ return smtp_register("filter", "connect", "smtp-in", (void *)cb);
}
void
smtp_connect(struct smtp_callback *cb, int version, struct timespec *tm,
uint64_t reqid, uint64_t token, char *params)
{
- struct smtp_filter_connect sfconnect;
+ struct inx_addr addrx;
+ char *hostname;
char *address;
int ret;
+ void (*f)(char *, int, struct timespec *,char *, char *, uint64_t,
+ uint64_t, char *, struct inx_addr *);
- sfconnect.hostname = params;
+ hostname = params;
if ((address = strchr(params, '|')) == NULL)
errx(1, "Invalid line received: missing address");
address++[0] = '\0';
- sfconnect.af = AF_INET;
+ addrx.af = AF_INET;
if (strncasecmp(address, "ipv6:", 5) == 0) {
- sfconnect.af = AF_INET6;
+ addrx.af = AF_INET6;
address += 5;
}
- ret = inet_pton(sfconnect.af, address, sfconnect.af == AF_INET ?
- (void *)&(sfconnect.addr) : (void *)&(sfconnect.addr6));
+ ret = inet_pton(addrx.af, address, addrx.af == AF_INET ?
+ (void *)&(addrx.addr) : (void *)&(addrx.addr6));
if (ret == 0)
errx(1, "Invalid line received: Couldn't parse address");
if (ret == -1)
err(1, "Couldn't convert address");
- smtp_handle_filter(cb, version, tm, reqid, token, (void *)(&sfconnect));
+ f = cb->cb;
+ f(cb->type, version, tm, cb->direction, cb->phase, reqid, token,
+ hostname, &addrx);
}
-static void
-smtp_handle_filter(struct smtp_callback *cb, int version, struct timespec *tm,
- uint64_t reqid, uint64_t token, void *params)
-{
- enum filter_decision fdes;
-
- fdes = cb->cb(cb->type, version, tm, cb->direction, cb->phase, reqid,
- token, params);
- switch (fdes) {
- case FILTER_PROCEED:
- smtp_filter_proceed(reqid, token);
- break;
- case FILTER_REJECT:
- smtp_filter_reject(reqid, token, 451,
- "Rejected by filter");
- break;
- case FILTER_DISCONNECT:
- smtp_filter_disconnect(reqid, token,
- "Rejected by filter");
- break;
- case FILTER_REWRITE:
- errx(1, "Not sure what is intended here yet");
- }
-}
-
void
smtp_filter_proceed(uint64_t reqid, uint64_t token)
{
}
static int
-smtp_register(char *type, char *phase, char *direction, smtp_cb cb)
+smtp_register(char *type, char *phase, char *direction, void *cb)
{
int i;
blob - fa683bd047374ac2553016d10a3e68943857d0b8
blob + eb1d00f093efc93ba2f5c600652e21aa9a983230
--- smtp_proc.h
+++ smtp_proc.h
#include <netinet/in.h>
-struct smtp_filter_connect {
- char *hostname;
+#include <netinet/in.h>
+
+struct inx_addr {
int af;
union {
struct in_addr addr;
};
};
-enum filter_decision {
- FILTER_PROCEED = 0,
- FILTER_REJECT,
- FILTER_DISCONNECT,
- FILTER_REWRITE
-};
-
int smtp_register_filter_connect(void (*cb)(char *, int, struct timespec *,
- char *, char *, uint64_t, uint64_t, struct smtp_filter_connect *));
+ char *, char *, uint64_t, uint64_t, char *, struct inx_addr *));
void smtp_filter_proceed(uint64_t, uint64_t);
void smtp_filter_reject(uint64_t, uint64_t, int, const char *, ...)
__attribute__((__format__ (printf, 4, 5)));