]> git.ipfire.org Git - people/ms/dma.git/commitdiff
implement masquerading using the MASQUERADE config option
authorSimon Schubert <2@0x2c.org>
Wed, 16 Nov 2011 11:38:49 +0000 (12:38 +0100)
committerSimon Schubert <2@0x2c.org>
Wed, 16 Nov 2011 11:38:49 +0000 (12:38 +0100)
conf.c
dma.8
dma.c
dma.conf
dma.h

diff --git a/conf.c b/conf.c
index 060e0cd023adf4eec01e22021603bd05721db52d..29b6e1bdbdbc9755ac633988136b9d6da133b1b3 100644 (file)
--- 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 18b2c8c16db10f38278a0e13603634bf42f0bdac..d34b3d6df0f5ee3ce25c505f57797bc99c164468 100644 (file)
--- 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 5a287fa9da860c63dc503d1c9870ea889e85b81c..205e2bf90c4a2661c73069f25487576519861f93 100644 (file)
--- 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);
        }
 
index d9ae76b51170d0fe7e9e730714b708d0bc2f42b7..56fa1045e0ba87bb4d95c6ae60fb1d1187e5fc5e 100644 (file)
--- a/dma.conf
+++ b/dma.conf
 # 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 03139dc25677de083982e9af62090968581a0332..029f41c57b8b9101e23fb1a83e49e8b6c4a76146 100644 (file)
--- 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;