From 5bc72de8fe74424fbcd9f17aba92185473db00ca Mon Sep 17 00:00:00 2001 From: Simon Schubert <2@0x2c.org> Date: Wed, 16 Nov 2011 12:38:49 +0100 Subject: [PATCH] implement masquerading using the MASQUERADE config option --- conf.c | 18 +++++++++++++++++- dma.8 | 30 ++++++++++++++++++++++++++++++ dma.c | 11 ++++++++++- dma.conf | 10 ++++++++++ dma.h | 2 ++ 5 files changed, 69 insertions(+), 2 deletions(-) diff --git a/conf.c b/conf.c index 060e0cd..29b6e1b 100644 --- a/conf.c +++ b/conf.c @@ -203,7 +203,23 @@ parse_conf(const char *config_path) config.certfile = data; else if (strcmp(word, "MAILNAME") == 0 && data != NULL) config.mailname = data; - else if (strcmp(word, "STARTTLS") == 0 && data == NULL) + else if (strcmp(word, "MASQUERADE") == 0 && data != NULL) { + char *user = NULL, *host = NULL; + if (strrchr(data, '@')) { + host = strrchr(data, '@'); + host = 0; + host++; + user = data; + } else { + host = data; + } + if (host && *host == 0) + host = NULL; + if (user && *user == 0) + user = NULL; + config.masquerade_host = host; + config.masquerade_user = user; + } else if (strcmp(word, "STARTTLS") == 0 && data == NULL) config.features |= STARTTLS; else if (strcmp(word, "OPPORTUNISTIC_TLS") == 0 && data == NULL) config.features |= TLS_OPP; diff --git a/dma.8 b/dma.8 index 18b2c8c..d34b3d6 100644 --- a/dma.8 +++ b/dma.8 @@ -262,6 +262,36 @@ If .Sq MAILNAME is an absolute path to a file, the first line of this file will be used as the hostname. +.It Ic MASQUERADE Xo +(string, default=empty) +.Xc +Masquerade the envelope from addresses with this address/hostname. +Use this setting if mails are not accepted by destination mail servers +because your sender domain is invalid. +This setting is overridden by the +.Fl f +flag and the +.Ev EMAIL +environment variable. +.Pp +If +.Sq MASQUERADE +does not contain a +.Li @ +sign, the string is interpreted as a host name. +For example, setting +.Sq MASQUERADE +to +.Ql john@ +on host +.Ql hamlet +will send all mails as +.Ql john@hamlet ; +setting it to +.Ql percolator +will send all mails as +.Ql Sm off Va username @percolator . +.Sm on .El .Ss Environment variables The behavior of diff --git a/dma.c b/dma.c index 5a287fa..205e2bf 100644 --- a/dma.c +++ b/dma.c @@ -80,6 +80,8 @@ struct config config = { .certfile = NULL, .features = 0, .mailname = NULL, + .masquerade_host = NULL, + .masquerade_user = NULL, }; @@ -103,7 +105,14 @@ set_from(struct queue *queue, const char *osender) if (sender == NULL) return (NULL); } else { - if (asprintf(&sender, "%s@%s", username, hostname()) <= 0) + const char *from_user = username; + const char *from_host = hostname(); + + if (config.masquerade_user) + from_user = config.masquerade_user; + if (config.masquerade_host) + from_host = config.masquerade_host; + if (asprintf(&sender, "%s@%s", from_user, from_host) <= 0) return (NULL); } diff --git a/dma.conf b/dma.conf index d9ae76b..56fa104 100644 --- a/dma.conf +++ b/dma.conf @@ -51,3 +51,13 @@ # If MAILNAME is an absolute path to a file, the first line of this file # will be used as the hostname. #MAILNAME mail.example.net + +# Masquerade envelope from addresses with this address/hostname. +# Use this if mails are not accepted by destination mail servers because +# your sender domain is invalid. +# By default, MASQUERADE is not set. +# Format: MASQUERADE [user@][host] +# Examples: +# MASQUERADE john@ on host "hamlet" will send all mails as john@hamlet +# MASQUERADE percolator will send mails as $username@percolator, e.g. fish@percolator +# MASQUERADE herb@ert will send all mails as herb@ert diff --git a/dma.h b/dma.h index 03139dc..029f41c 100644 --- a/dma.h +++ b/dma.h @@ -121,6 +121,8 @@ struct config { const char *certfile; int features; const char *mailname; + const char *masquerade_host; + const char *masquerade_user; /* XXX does not belong into config */ SSL *ssl; -- 2.39.2