Skip to content

Commit

Permalink
Implement new DELIVERY config parameter.
Browse files Browse the repository at this point in the history
This allows dma to support three modes of delivery: local-only,
remote-only, and local + remote (the default). It supersedes the
NULLCLIENT directive, which is equivalent to the remote-only mode.

Fixes: corecode#121
  • Loading branch information
iskunk committed Apr 23, 2023
1 parent 43fff9a commit a01d05e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 23 deletions.
27 changes: 21 additions & 6 deletions conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,23 @@ parse_conf(const char *config_path)
user = NULL;
config.masquerade_host = host;
config.masquerade_user = user;
} else if (strcmp(word, "DELIVERY") == 0 && data != NULL) {
if (strcmp(data, "LOCALANDREMOTE") == 0)
config.features |= (DELIVERY_LOCAL | DELIVERY_REMOTE);
else if (strcmp(data, "LOCALONLY") == 0) {
config.features |= DELIVERY_LOCAL;
config.features &= ~DELIVERY_REMOTE;
} else if (strcmp(data, "REMOTEONLY") == 0) {
config.features &= ~DELIVERY_LOCAL;
config.features |= DELIVERY_REMOTE;
} else {
errlogx(EX_CONFIG, "invalid DELIVERY value in %s:%d", config_path, lineno);
/* NOTREACHED */
}
free(data);
} else if (strcmp(word, "STARTTLS") == 0 && data == NULL)
config.features |= STARTTLS;
else if (strcmp(word, "FINGERPRINT") == 0) {
else if (strcmp(word, "FINGERPRINT") == 0 && data != NULL) {
if (strlen(data) != SHA256_DIGEST_LENGTH * 2) {
errlogx(EX_CONFIG, "invalid sha256 fingerprint length");
}
Expand All @@ -244,16 +258,17 @@ parse_conf(const char *config_path)
config.features |= INSECURE;
else if (strcmp(word, "FULLBOUNCE") == 0 && data == NULL)
config.features |= FULLBOUNCE;
else if (strcmp(word, "NULLCLIENT") == 0 && data == NULL)
config.features |= NULLCLIENT;
else {
else if (strcmp(word, "NULLCLIENT") == 0 && data == NULL) {
config.features &= ~DELIVERY_LOCAL;
config.features |= DELIVERY_REMOTE;
} else {
errlogx(EX_CONFIG, "syntax error in %s:%d", config_path, lineno);
/* NOTREACHED */
}
}

if ((config.features & NULLCLIENT) && config.smarthost == NULL) {
errlogx(EX_CONFIG, "%s: NULLCLIENT requires SMARTHOST", config_path);
if (!(config.features & DELIVERY_LOCAL) && config.smarthost == NULL) {
errlogx(EX_CONFIG, "%s: remote-only delivery requires SMARTHOST", config_path);
/* NOTREACHED */
}

Expand Down
22 changes: 13 additions & 9 deletions dma.8
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,20 @@ setting it to
will send all mails as
.Ql Sm off Va username @percolator .
.Sm on
.It Ic NULLCLIENT Xo
(boolean, default=commented)
.It Ic DELIVERY Xo
(string, default=LOCALANDREMOTE)
.Xc
Bypass aliases and local delivery, and instead forward all mails to
the defined
.Sq SMARTHOST .
.Sq NULLCLIENT
requires
.Sq SMARTHOST
to be set.
Type(s) of delivery that
.Nm
should perform.
Set this to
.Sq LOCALONLY
to allow only deliveries to local recipients.
Set it to
.Sq REMOTEONLY
to forward all messages to the defined
.Sq SMARTHOST ,
bypassing local aliases.
.El
.Ss Environment variables
The behavior of
Expand Down
11 changes: 6 additions & 5 deletions dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct config config = {
.spooldir = "/var/spool/dma",
.authpath = NULL,
.certfile = NULL,
.features = 0,
.features = DELIVERY_LOCAL | DELIVERY_REMOTE,
.mailname = NULL,
.masquerade_host = NULL,
.masquerade_user = NULL,
Expand Down Expand Up @@ -233,10 +233,9 @@ add_recp(struct queue *queue, const char *str, int expand)
LIST_INSERT_HEAD(&queue->queue, it, next);

/**
* Do local delivery if there is no @.
* Do not do local delivery when NULLCLIENT is set.
* Do local delivery if there is no @ and DELIVERY_LOCAL is set.
*/
if (strrchr(it->addr, '@') == NULL && (config.features & NULLCLIENT) == 0) {
if (strrchr(it->addr, '@') == NULL && (config.features & DELIVERY_LOCAL)) {
it->remote = 0;
if (expand) {
aliased = do_alias(queue, it->addr);
Expand All @@ -255,8 +254,10 @@ add_recp(struct queue *queue, const char *str, int expand)
endpwent();
}
}
} else {
} else if (config.features & DELIVERY_REMOTE) {
it->remote = 1;
} else {
return (-1);
}

return (0);
Expand Down
6 changes: 4 additions & 2 deletions dma.conf
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,7 @@
# MASQUERADE percolator will send mails as $username@percolator, e.g. fish@percolator
# MASQUERADE herb@ert will send all mails as herb@ert

# Directly forward the mail to the SMARTHOST bypassing aliases and local delivery
#NULLCLIENT
# Uncomment and set to LOCALONLY or REMOTEONLY if you want local-only or
# remote-only delivery. Note that remote-only mode requires SMARTHOST to
# be specified, and ignores local aliases.
#DELIVERY LOCALANDREMOTE
3 changes: 2 additions & 1 deletion dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
#define INSECURE 0x020 /* Allow plain login w/o encryption */
#define FULLBOUNCE 0x040 /* Bounce the full message */
#define TLS_OPP 0x080 /* Opportunistic STARTTLS */
#define NULLCLIENT 0x100 /* Nullclient support */
#define DELIVERY_LOCAL 0x100 /* Do local delivery */
#define DELIVERY_REMOTE 0x200 /* Do remote delivery */

#ifndef CONF_PATH
#error Please define CONF_PATH
Expand Down

0 comments on commit a01d05e

Please sign in to comment.