From 5754971ca3648ec7e7948adf228e8413187a2ea4 Mon Sep 17 00:00:00 2001 From: Simon Schubert Date: Thu, 9 Jul 2009 14:37:16 +0200 Subject: [PATCH] dma: add the MAILNAME and MAILNAMEFILE config options Submitted-by: Peter Pentchev --- etc/dma/dma.conf | 8 ++++++++ libexec/dma/conf.c | 8 ++++++++ libexec/dma/dma.8 | 14 ++++++++++++++ libexec/dma/dma.c | 30 +++++++++++++++++++++++++++++- libexec/dma/dma.h | 2 ++ 5 files changed, 61 insertions(+), 1 deletion(-) diff --git a/etc/dma/dma.conf b/etc/dma/dma.conf index 5251df98eb..6376a41b8a 100644 --- a/etc/dma/dma.conf +++ b/etc/dma/dma.conf @@ -44,3 +44,11 @@ AUTHPATH /etc/dma/auth.conf # Uncomment if you want the bounce message to include the complete original # message, not just the headers. #FULLBOUNCE + +# The name to be used when introducing this host, if different from +# the result of "hostname". If specified, this overrides MAILNAMEFILE. +#MAILNAME mail.example.net + +# The name of the file to read the MAILNAME from; if this file is not +# present, the result of "hostname" will be used. +#MAILNAMEFILE /etc/mailname diff --git a/libexec/dma/conf.c b/libexec/dma/conf.c index 161edcd08f..e587c3082a 100644 --- a/libexec/dma/conf.c +++ b/libexec/dma/conf.c @@ -236,6 +236,14 @@ parse_conf(const char *config_path, struct config *config) if (data != NULL) config->certfile = strdup(data); } + else if (strcmp(word, "MAILNAME") == 0) { + if (data != NULL) + config->mailname = strdup(data); + } + else if (strcmp(word, "MAILNAMEFILE") == 0) { + if (data != NULL) + config->mailnamefile = strdup(data); + } else if (strcmp(word, "VIRTUAL") == 0) config->features |= VIRTUAL; else if (strcmp(word, "STARTTLS") == 0) diff --git a/libexec/dma/dma.8 b/libexec/dma/dma.8 index 0a1330c162..bb178bcdc8 100644 --- a/libexec/dma/dma.8 +++ b/libexec/dma/dma.8 @@ -222,6 +222,20 @@ This option is handy if you are behind a dialup line. .Xc Uncomment if you want the bounce message to include the complete original message, not just the headers. +.It Ic MAILNAME Xo +(string, default=empty) +.Xc +The name to be used when introducing this host, if different from +the result of +.Xr hostname 1 . +If specified, this option overrides +.Sq MAILNAMEFILE . +.It Ic MAILNAMEFILE Xo +(string, default=empty) +.Xc +The name of the file to read the +.Sq MAILNAME +from. .El .Ss virtusertable The diff --git a/libexec/dma/dma.c b/libexec/dma/dma.c index 44a49c5cc4..6219faba0f 100644 --- a/libexec/dma/dma.c +++ b/libexec/dma/dma.c @@ -80,10 +80,38 @@ char * hostname(void) { static char name[MAXHOSTNAMELEN+1]; + int initialized = 0; + FILE *fp; + size_t len; + + if (initialized) + return (name); + if (config->mailname != NULL && config->mailname[0] != '\0') { + snprintf(name, sizeof(name), "%s", config->mailname); + initialized = 1; + return (name); + } + if (config->mailnamefile != NULL && config->mailnamefile[0] != '\0') { + fp = fopen(config->mailnamefile, "r"); + if (fp != NULL) { + if (fgets(name, sizeof(name), fp) != NULL) { + len = strlen(name); + while (len > 0 && + (name[len - 1] == '\r' || + name[len - 1] == '\n')) + name[--len] = '\0'; + if (name[0] != '\0') { + initialized = 1; + return (name); + } + } + fclose(fp); + } + } if (gethostname(name, sizeof(name)) != 0) strcpy(name, "(unknown hostname)"); - + initialized = 1; return name; } diff --git a/libexec/dma/dma.h b/libexec/dma/dma.h index ff47202850..49a2ae6b33 100644 --- a/libexec/dma/dma.h +++ b/libexec/dma/dma.h @@ -121,6 +121,8 @@ struct config { #ifdef HAVE_CRYPTO SSL *ssl; #endif /* HAVE_CRYPTO */ + char *mailname; + char *mailnamefile; }; -- 2.41.0