]> git.ipfire.org Git - people/ms/dma.git/commitdiff
merge mailname and mailnamefile; drop 17-mailname.patch
authorSimon Schubert <2@0x2c.org>
Thu, 28 Oct 2010 20:50:48 +0000 (22:50 +0200)
committerSimon Schubert <2@0x2c.org>
Thu, 28 Oct 2010 20:50:48 +0000 (22:50 +0200)
conf.c
debian/patches/17-mailname.patch [deleted file]
dma.8
dma.c
dma.conf
dma.h
util.c

diff --git a/conf.c b/conf.c
index 6c7bd1c57eed3e0319a807d36c7f96e1cc307264..060e0cd023adf4eec01e22021603bd05721db52d 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -203,8 +203,6 @@ parse_conf(const char *config_path)
                        config.certfile = data;
                else if (strcmp(word, "MAILNAME") == 0 && data != NULL)
                        config.mailname = data;
-               else if (strcmp(word, "MAILNAMEFILE") == 0 && data != NULL)
-                       config.mailnamefile = data;
                else if (strcmp(word, "STARTTLS") == 0 && data == NULL)
                        config.features |= STARTTLS;
                else if (strcmp(word, "OPPORTUNISTIC_TLS") == 0 && data == NULL)
diff --git a/debian/patches/17-mailname.patch b/debian/patches/17-mailname.patch
deleted file mode 100644 (file)
index 6326134..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-Description: Several fixes to the mail name file parsing.
- Fix a file descriptor leak in the MAILNAMEFILE code.
- Fix a mistake in my patch submitted to DFBSD - "initialized" should be static!
- For Debian, use /etc/mailname for the MAILNAMEFILE.
-Origin: other: http://svn.ringlet.net/svn/ringlet/mail/dma/
-Forwarded: yes
-Author: Peter Pentchev <roam@ringlet.net>
-Last-Update: 2010-06-21
-
---- a/dma.conf
-+++ b/dma.conf
-@@ -59,4 +59,4 @@
- # 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
-+MAILNAMEFILE /etc/mailname
---- a/util.c
-+++ b/util.c
-@@ -47,8 +47,9 @@
- hostname(void)
- {
-       static char name[MAXHOSTNAMELEN+1];
--      int initialized = 0;
-+      static int initialized = 0;
-       FILE *fp;
-+      char *res;
-       size_t len;
-       if (initialized)
-@@ -62,7 +63,9 @@
-       if (config.mailnamefile != NULL && config.mailnamefile[0] != '\0') {
-               fp = fopen(config.mailnamefile, "r");
-               if (fp != NULL) {
--                      if (fgets(name, sizeof(name), fp) != NULL) {
-+                      res = fgets(name, sizeof(name), fp);
-+                      fclose(fp);
-+                      if (res != NULL) {
-                               len = strlen(name);
-                               while (len > 0 &&
-                                   (name[len - 1] == '\r' ||
-@@ -73,7 +76,6 @@
-                                       return (name);
-                               }
-                       }
--                      fclose(fp);
-               }
-       }
-       if (gethostname(name, sizeof(name)) != 0)
diff --git a/dma.8 b/dma.8
index 9db2a3c5c3e575ed2865e978ae8c91599a7be505..774ee9a463b609a0f452ee7e30fae3b4303b0dd6 100644 (file)
--- a/dma.8
+++ b/dma.8
@@ -252,17 +252,16 @@ 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
+The internet hostname
+.Nm
+uses to identify the host.
+If not set or empty, the result of
+.Xr gethostname 2
+is used.
+If
 .Sq MAILNAME
-from.
+is an absolute path to a file, the first line of this file will be used
+as the hostname.
 .El
 .Ss Environment variables
 The behavior of
diff --git a/dma.c b/dma.c
index a3e2a70bb4941763626001f4eb62329db572861a..ca1afb01e20052393a2e9e9c1128774fe04d8999 100644 (file)
--- a/dma.c
+++ b/dma.c
@@ -79,7 +79,6 @@ struct config config = {
        .certfile       = NULL,
        .features       = 0,
        .mailname       = NULL,
-       .mailnamefile   = NULL,
 };
 
 
index a9cb57248291ea5a7d32d2f6f6dc5ec01068ee74..d9ae76b51170d0fe7e9e730714b708d0bc2f42b7 100644 (file)
--- a/dma.conf
+++ b/dma.conf
 # 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.
+# The internet hostname dma uses to identify the host.
+# If not set or empty, the result of gethostname(2) is used.
+# 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
-
-# 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/dma.h b/dma.h
index 60a83451ca38ada34f8cdecc07512650af0199ad..e2ff3ded87e904f91b50bdf6494578f3e2280c43 100644 (file)
--- a/dma.h
+++ b/dma.h
@@ -113,7 +113,6 @@ struct config {
        const char *certfile;
        int features;
        const char *mailname;
-       const char *mailnamefile;
 
        /* XXX does not belong into config */
        SSL *ssl;
diff --git a/util.c b/util.c
index ff6b123538ce462874c9e3b690e83dec9136f304..6381aaf256fc3052bf11514f7e7ec66562dca18c 100644 (file)
--- a/util.c
+++ b/util.c
@@ -35,6 +35,7 @@
 #include <sys/param.h>
 #include <sys/file.h>
 
+#include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <netdb.h>
@@ -52,40 +53,50 @@ hostname(void)
 {
        static char name[MAXHOSTNAMELEN+1];
        static int initialized = 0;
-       FILE *fp;
-       char *res;
-       size_t len;
 
        if (initialized)
                return (name);
 
-       if (config.mailname != NULL && config.mailname[0] != '\0') {
+       if (config.mailname == NULL || !*config.mailname)
+               goto local;
+
+       if (config.mailname[0] == '/') {
+               /*
+                * If the mailname looks like an absolute path,
+                * treat it as a file.
+                */
+               FILE *fp;
+               char *res;
+
+               fp = fopen(config.mailname, "r");
+               if (fp == NULL)
+                       goto local;
+
+               res = fgets(name, sizeof(name), fp);
+               fclose(fp);
+               if (res == NULL)
+                       goto local;
+
+               while (*res != 0 && !isspace(*res))
+                       ++res;
+               *res = 0;
+
+               if (!*name)
+                       goto local;
+
+               initialized = 1;
+               return (name);
+       } else {
                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) {
-                       res = fgets(name, sizeof(name), fp);
-                       fclose(fp);
-                       if (res != 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);
-                               }
-                       }
-               }
-       }
+
+local:
        if (gethostname(name, sizeof(name)) != 0)
                strcpy(name, "(unknown hostname)");
        initialized = 1;
-       return name;
+       return (name);
 }
 
 void