diff options
author | gilles <gilles@poolp.org> | 2016-06-25 17:36:44 +0200 |
---|---|---|
committer | gilles <gilles@poolp.org> | 2016-06-25 17:36:44 +0200 |
commit | 090f9a8bf330602558b5fcc4bfb6aee8649c4821 (patch) | |
tree | d811eda8302ae80f59aa6fdce09aa361150012e9 | |
parent | cosmethic change (diff) | |
download | OpenSMTPD-extras-090f9a8bf330602558b5fcc4bfb6aee8649c4821.tar.xz OpenSMTPD-extras-090f9a8bf330602558b5fcc4bfb6aee8649c4821.zip |
filter_rspamd.c should consider session / transaction as opaque structures
-rw-r--r-- | extras/filters/filter-rspamd/filter_rspamd.c | 25 | ||||
-rw-r--r-- | extras/filters/filter-rspamd/rspamd.c | 40 | ||||
-rw-r--r-- | extras/filters/filter-rspamd/rspamd.h | 35 |
3 files changed, 77 insertions, 23 deletions
diff --git a/extras/filters/filter-rspamd/filter_rspamd.c b/extras/filters/filter-rspamd/filter_rspamd.c index 43118df..616cf70 100644 --- a/extras/filters/filter-rspamd/filter_rspamd.c +++ b/extras/filters/filter-rspamd/filter_rspamd.c @@ -40,12 +40,15 @@ on_connect(uint64_t id, struct filter_connect *conn) struct session *rs = filter_api_session(id); const char *ip; - /* will fail on local enqueuer, fallback to "localhost" */ ip = filter_api_sockaddr_to_text((struct sockaddr *)&conn->local); - if (ip == NULL) - ip = "127.0.0.1"; - rs->ip = xstrdup(ip, "on_connect"); - rs->hostname = xstrdup(conn->hostname, "on_connect"); + + if (! session_set_ip(rs, ip ? ip : "127.0.0.1")) + return filter_api_reject_code(id, FILTER_FAIL, 421, + "temporary failure"); + + if (! session_set_hostname(rs, conn->hostname)) + return filter_api_reject_code(id, FILTER_FAIL, 421, + "temporary failure"); return filter_api_accept(id); } @@ -55,7 +58,9 @@ on_helo(uint64_t id, const char *helo) { struct session *rs = filter_api_session(id); - rs->helo = xstrdup(helo, "on_helo"); + if (! session_set_helo(rs, helo)) + return filter_api_reject_code(id, FILTER_FAIL, 421, + "temporary failure"); return filter_api_accept(id); } @@ -67,7 +72,9 @@ on_mail(uint64_t id, struct mailaddr *mail) const char *address; address = filter_api_mailaddr_to_text(mail); - tx->from = xstrdup(address, "on_mail"); + if (! transaction_set_from(tx, address)) + return filter_api_reject_code(id, FILTER_FAIL, 421, + "temporary failure"); return filter_api_accept(id); } @@ -79,7 +86,9 @@ on_rcpt(uint64_t id, struct mailaddr *rcpt) const char *address; address = filter_api_mailaddr_to_text(rcpt); - dict_set(&tx->rcpts, address, NULL); + if (! transaction_add_rcpt(tx, address)) + return filter_api_reject_code(id, FILTER_FAIL, 421, + "temporary failure"); return filter_api_accept(id); } diff --git a/extras/filters/filter-rspamd/rspamd.c b/extras/filters/filter-rspamd/rspamd.c index f58ee35..a238f0a 100644 --- a/extras/filters/filter-rspamd/rspamd.c +++ b/extras/filters/filter-rspamd/rspamd.c @@ -98,6 +98,46 @@ transaction_destructor(void *ctx) } +int +session_set_helo(struct session *s, const char *helo) +{ + if ((s->helo = strdup(helo)) == NULL) + return 0; + return 1; +} + +int +session_set_ip(struct session *s, const char *ip) +{ + if ((s->ip = strdup(ip)) == NULL) + return 0; + return 1; +} + +int +session_set_hostname(struct session *s, const char *hostname) +{ + if ((s->hostname = strdup(hostname)) == NULL) + return 0; + return 1; +} + +int +transaction_set_from(struct transaction *t, const char *from) +{ + if ((t->from = strdup(from)) == NULL) + return 0; + return 1; +} + +int +transaction_add_rcpt(struct transaction *t, const char *rcpt) +{ + /* XXX - not the best data structure */ + dict_set(&t->rcpts, rcpt, NULL); + return 1; +} + /* XXX * this needs to be handled differently, but lets focus on the filter for now diff --git a/extras/filters/filter-rspamd/rspamd.h b/extras/filters/filter-rspamd/rspamd.h index 631e2ea..5c37fae 100644 --- a/extras/filters/filter-rspamd/rspamd.h +++ b/extras/filters/filter-rspamd/rspamd.h @@ -58,21 +58,26 @@ struct transaction { char *line; }; -void *session_allocator(uint64_t); -void session_destructor(void *); - -void *transaction_allocator(uint64_t); -void transaction_destructor(void *); - -int rspamd_connect(struct transaction *); -void rspamd_connected(struct transaction *); -void rspamd_send_query(struct transaction *); -void rspamd_send_chunk(struct transaction *, const char *); -void rspamd_read_response(struct transaction *); -int rspamd_parse_response(struct transaction *); -void rspamd_error(struct transaction *); - -void rspamd_io(struct io *, int); +void *session_allocator(uint64_t); +void session_destructor(void *); +int session_set_helo(struct session *, const char *); +int session_set_ip(struct session *, const char *); +int session_set_hostname(struct session *, const char *); + +void *transaction_allocator(uint64_t); +void transaction_destructor(void *); +int transaction_set_from(struct transaction *, const char *); +int transaction_add_rcpt(struct transaction *, const char *); + +int rspamd_connect(struct transaction *); +void rspamd_connected(struct transaction *); +void rspamd_send_query(struct transaction *); +void rspamd_send_chunk(struct transaction *, const char *); +void rspamd_read_response(struct transaction *); +int rspamd_parse_response(struct transaction *); +void rspamd_error(struct transaction *); + +void rspamd_io(struct io *, int); |