Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new DELIVERY config parameter. #125

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you made this check down in deliver() where deliver_remote is called you can use bounce on the email which might be better behavior if local delivery is allowed. Of course if both local and remote delivery are disabled we probably want to catch that at configuration time.

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