Skip to content

Commit

Permalink
Reverted revisions 496:HEAD. These changes were aimed at moving SMTP
Browse files Browse the repository at this point in the history
SIZE= handling into counters.  This is effectively impossible since it
needs to handle when a mail rule matches and sets the size, which short
cuts the counters out.
  • Loading branch information
bruceg committed Sep 2, 2006
1 parent db5b29a commit 522c616
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 121 deletions.
2 changes: 0 additions & 2 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ Changes in version 1.01
- Added a list of built-in plugins. The list currently contains the
three accept* plugins, which are extremely trivial.

- Some internal plugin API changes.

Development of this version has been sponsored by FutureQuest, Inc.
[email protected] http://www.FutureQuest.net/
-------------------------------------------------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
- Move message size checking from protocol-smtp to plugin-counters

- Fix SASL "Authentication failed" message to include EMSS code

- Write install document.
Expand Down
6 changes: 2 additions & 4 deletions backend-echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@ static const response* reset(void)
return 0;
}

static const response* sender(str* s, str* p)
static const response* sender(str* s)
{
str_copys(&tmp, "Sender='");
str_cat(&tmp, s);
str_cats(&tmp, "'.");
resp.message = tmp.s;
return &resp;
(void)p;
}

static const response* recipient(str* r, str* p)
static const response* recipient(str* r)
{
str_copys(&tmp, "Recipient='");
str_cat(&tmp, r);
str_cats(&tmp, "'.");
resp.message = tmp.s;
return &resp;
(void)p;
}

static const response* data_block(const char* bytes, unsigned long len)
Expand Down
6 changes: 2 additions & 4 deletions backend-qmail.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,20 @@ static const response* reset(void)
return 0;
}

static const response* do_sender(str* sender, str* params)
static const response* do_sender(str* sender)
{
if (!str_catc(&buffer, 'F') ||
!str_cat(&buffer, sender) ||
!str_catc(&buffer, 0)) return &resp_oom;
return 0;
(void)params;
}

static const response* do_recipient(str* recipient, str* params)
static const response* do_recipient(str* recipient)
{
if (!str_catc(&buffer, 'T') ||
!str_cat(&buffer, recipient) ||
!str_catc(&buffer, 0)) return &resp_oom;
return 0;
(void)params;
}

static const response* data_start(void)
Expand Down
3 changes: 1 addition & 2 deletions builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

static RESPONSE(accept,250,0);

static const response* accept(str* s, str* p)
static const response* accept(str* s)
{
return &resp_accept;
(void)s;
(void)p;
}

struct plugin builtin_plugins[] = {
Expand Down
53 changes: 13 additions & 40 deletions mailfront.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <systime.h>
#include <msg/msg.h>
#include <str/iter.h>
#include <str/str.h>

#include "mailfront.h"
Expand Down Expand Up @@ -51,10 +50,10 @@ const response* handle_init(void)
return 0;
}

const response* handle_helo(str* host, str* welcome)
const response* handle_helo(str* host)
{
const response* resp;
MODULE_CALL(helo, (host, welcome), 0);
MODULE_CALL(helo, (host), 0);
session_setstr("helo_domain", host->s);
return 0;
}
Expand All @@ -68,29 +67,29 @@ const response* handle_reset(void)
return resp;
}

const response* handle_sender(str* sender, str* params)
const response* handle_sender(str* sender)
{
const response* resp = 0;
const response* tmpresp = 0;
MODULE_CALL(sender, (sender, params), 1);
MODULE_CALL(sender, (sender), 1);
if (resp == 0)
return &resp_no_sender;
if (session.backend->sender != 0)
if (!response_ok(tmpresp = session.backend->sender(sender, params)))
if (!response_ok(tmpresp = session.backend->sender(sender)))
return tmpresp;
if (resp == 0 || resp->message == 0) resp = tmpresp;
return resp;
}

const response* handle_recipient(str* recip, str* params)
const response* handle_recipient(str* recip)
{
const response* resp = 0;
const response* hresp = 0;
MODULE_CALL(recipient, (recip, params), 1);
MODULE_CALL(recipient, (recip), 1);
if (resp == 0)
return &resp_no_rcpt;
if (session.backend->recipient != 0)
if (!response_ok(hresp = session.backend->recipient(recip, params)))
if (!response_ok(hresp = session.backend->recipient(recip)))
return hresp;
if (resp == 0 || resp->message == 0) resp = hresp;
return resp;
Expand Down Expand Up @@ -157,39 +156,13 @@ int respond_line(unsigned number, int final,
return 1;
}

int respond_part(unsigned number, int final,
const char* msg, unsigned long len)
{
const char* nl;
while ((nl = memchr(msg, '\n', len)) != 0) {
respond_line(number, 0, msg, nl - msg);
++nl;
len -= nl - msg;
msg = nl;
}
return respond_line(number, final, msg, len);
}

int respond(const response* resp)
{
return respond_part(resp->number, 1, resp->message, strlen(resp->message));
}

const char* find_param(const str* params, const char* name)
{
const long len = strlen(name);
striter i;
for (striter_start(&i, params, 0);
striter_valid(&i);
striter_advance(&i)) {
if (strncasecmp(i.startptr, name, len) == 0) {
if (i.startptr[len] == '0')
return i.startptr + len;
if (i.startptr[len] == '=')
return i.startptr + len + 1;
}
}
return 0;
const char* msg;
const char* nl;
for (msg = resp->message; (nl = strchr(msg, '\n')) != 0; msg = nl + 1)
respond_line(resp->number, 0, msg, nl-msg);
return respond_line(resp->number, 1, msg, strlen(msg));
}

int main(int argc, char* argv[])
Expand Down
15 changes: 6 additions & 9 deletions mailfront.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ struct plugin
struct plugin* next;
const char* name;
const response* (*init)(void);
const response* (*helo)(str*, str*);
const response* (*helo)(str*);
const response* (*reset)(void);
const response* (*sender)(str*, str*);
const response* (*recipient)(str*, str*);
const response* (*sender)(str*);
const response* (*recipient)(str*);
const response* (*data_start)(void);
const response* (*data_block)(const char* bytes, unsigned long len);
const response* (*data_end)(void);
Expand Down Expand Up @@ -49,20 +49,17 @@ extern struct plugin builtin_plugins[];

/* From mailfront.c */
extern const char UNKNOWN[];
extern const response* handle_helo(str* host, str* welcome);
extern const response* handle_helo(str* host);
extern const response* handle_init(void);
extern const response* handle_reset(void);
extern const response* handle_sender(str* sender, str* params);
extern const response* handle_recipient(str* recip, str* params);
extern const response* handle_sender(str* sender);
extern const response* handle_recipient(str* recip);
extern const response* handle_data_start(void);
extern void handle_data_bytes(const char* bytes, unsigned len);
extern const response* handle_data_end(void);
extern int respond(const response*);
extern int respond_part(unsigned number, int final,
const char* msg, unsigned long len);
extern int respond_line(unsigned number, int final,
const char* msg, unsigned long len);
extern const char* find_param(const str* params, const char* name);

/* From netstring.c */
int get_netstring_len(ibuf* in, unsigned long* i);
Expand Down
3 changes: 1 addition & 2 deletions plugin-check-fqdn.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
static RESPONSE(nodomain,554,"5.1.2 Address is missing a domain name");
static RESPONSE(nofqdn,554,"5.1.2 Address does not contain a fully qualified domain name");

static const response* either(str* s, str* p)
static const response* either(str* s)
{
int at;
int dot;
Expand All @@ -14,7 +14,6 @@ static const response* either(str* s, str* p)
return &resp_nofqdn;
}
return 0;
(void)p;
}

struct plugin plugin = {
Expand Down
20 changes: 7 additions & 13 deletions plugin-counters.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ static unsigned linepos; /* The number of bytes since the last LF */
static int in_rec; /* True if we might be seeing Received: */
static int in_dt; /* True if we might be seeing Delivered-To: */

static const response* helo(str* host, str* welcome)
static const response* init(void)
{
if (welcome != 0) {
if (welcome->len > 0)
if (!str_catc(welcome, '\n') != 0) return &resp_oom;
if (!str_cats(welcome, "SIZE ")) return &resp_oom;
if (!str_catu(welcome, session_getenvu("DATABYTES"))) return &resp_oom;
}
/* This MUST be done in the init section to make sure the SMTP
* greeting displays the current value. */
session_setnum("maxdatabytes", session_getenvu("DATABYTES"));
return 0;
(void)host;
}

static const response* reset(void)
Expand All @@ -45,18 +41,17 @@ static unsigned long minenv(const char* sname, const char* name)
return u;
}

static const response* sender(str* r, str* p)
static const response* sender(str* r)
{
/* This MUST be done as a sender match to make sure SMTP "MAIL FROM"
* commands with a SIZE parameter can be rejected properly. */
minenv("maxdatabytes", "DATABYTES");
minenv("maxrcpts", "MAXRCPTS");
(void)r;
(void)p;
return 0;
}

static const response* recipient(str* r, str* p)
static const response* recipient(str* r)
{
unsigned long maxrcpts = minenv("maxrcpts", "MAXRCPTS");
minenv("maxdatabytes", "DATABYTES");
Expand All @@ -65,7 +60,6 @@ static const response* recipient(str* r, str* p)
return &resp_manyrcpt;
return 0;
(void)r;
(void)p;
}

static const response* start(void)
Expand Down Expand Up @@ -131,7 +125,7 @@ static const response* block(const char* bytes, unsigned long len)
}

struct plugin plugin = {
.helo = helo,
.init = init,
.reset = reset,
.sender = sender,
.recipient = recipient,
Expand Down
3 changes: 1 addition & 2 deletions plugin-cvm-validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static const response* validate_init(void)
return 0;
}

static const response* validate_recipient(str* recipient, str* params)
static const response* validate_recipient(str* recipient)
{
struct cvm_credential creds[3];
unsigned i;
Expand All @@ -50,7 +50,6 @@ static const response* validate_recipient(str* recipient, str* params)
str_free(&creds[1].value);
str_free(&creds[2].value);
return r;
(void)params;
}

struct plugin plugin = {
Expand Down
6 changes: 2 additions & 4 deletions plugin-mailrules.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ static void copy_addr(const str* addr,
static str saved_sender;
static str sender_domain;

static const response* validate_sender(str* sender, str* params)
static const response* validate_sender(str* sender)
{
struct rule* rule;
const response* r;
Expand All @@ -402,13 +402,12 @@ static const response* validate_sender(str* sender, str* params)
return r;
}
return 0;
(void)params;
}

static str laddr;
static str rdomain;

static const response* validate_recipient(str* recipient, str* params)
static const response* validate_recipient(str* recipient)
{
struct rule* rule;
const response* r;
Expand All @@ -424,7 +423,6 @@ static const response* validate_recipient(str* recipient, str* params)
return r;
}
return 0;
(void)params;
}

struct plugin plugin = {
Expand Down
6 changes: 2 additions & 4 deletions plugin-qmail-validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static const response* validate_init(void)
return 0;
}

static const response* validate_sender(str* sender, str* params)
static const response* validate_sender(str* sender)
{
int at;
str_copy(&tmp, sender);
Expand All @@ -54,10 +54,9 @@ static const response* validate_sender(str* sender, str* params)
if (dict_get(&bmf, &tmp)) return &resp_badmailfrom;
}
return 0;
(void)params;
}

static const response* validate_recipient(str* recipient, str* params)
static const response* validate_recipient(str* recipient)
{
int at;

Expand Down Expand Up @@ -85,7 +84,6 @@ static const response* validate_recipient(str* recipient, str* params)
}
}
return 0;
(void)params;
}

struct plugin plugin = {
Expand Down
3 changes: 1 addition & 2 deletions plugin-reject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

static response resp;

static const response* sender(str* s, str* p)
static const response* sender(str* s)
{
const char* sr;
if ((sr = getenv("SMTPREJECT")) != 0
Expand All @@ -21,7 +21,6 @@ static const response* sender(str* s, str* p)
}
return 0;
(void)s;
(void)p;
}

struct plugin plugin = {
Expand Down
Loading

0 comments on commit 522c616

Please sign in to comment.