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)
+++ /dev/null
-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)
.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
.certfile = NULL,
.features = 0,
.mailname = NULL,
- .mailnamefile = NULL,
};
# 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
const char *certfile;
int features;
const char *mailname;
- const char *mailnamefile;
/* XXX does not belong into config */
SSL *ssl;
#include <sys/param.h>
#include <sys/file.h>
+#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
{
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