aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGilles Chehade <gilles@poolp.org>2018-11-25 20:38:19 +0100
committerGilles Chehade <gilles@poolp.org>2018-11-25 20:38:19 +0100
commitf58bad395d8dc16f012e99f7ab56b6991b4a9176 (patch)
tree69dc316b6ae1754f277a3974746d9fb855e4520b
parentsync with OpenBSD (diff)
downloadOpenSMTPD-f58bad395d8dc16f012e99f7ab56b6991b4a9176.tar.xz
OpenSMTPD-f58bad395d8dc16f012e99f7ab56b6991b4a9176.zip
fix mail.lmtp.c and mail.mda.c to properly handle temporary failures
-rw-r--r--smtpd/mail.lmtp.c5
-rw-r--r--smtpd/mail.mda.c15
2 files changed, 17 insertions, 3 deletions
diff --git a/smtpd/mail.lmtp.c b/smtpd/mail.lmtp.c
index 8d4b57cc..d831ca2f 100644
--- a/smtpd/mail.lmtp.c
+++ b/smtpd/mail.lmtp.c
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sysexits.h>
#include <unistd.h>
enum phase {
@@ -167,7 +168,7 @@ lmtp_connect_inet(const char *destination)
freeaddrinfo(res0);
if (s == -1)
- errx(1, "%s", cause);
+ errx(EX_TEMPFAIL, "%s", cause);
return fdopen(s, "r+");
}
@@ -191,7 +192,7 @@ lmtp_connect_unix(const char *destination)
errx(1, "unix: socket path is too long");
if (connect(s, (struct sockaddr *)&addr, sizeof addr) == -1)
- err(1, "connect");
+ err(EX_TEMPFAIL, "connect");
return fdopen(s, "r+");
}
diff --git a/smtpd/mail.mda.c b/smtpd/mail.mda.c
index 64398c84..f9fb3236 100644
--- a/smtpd/mail.mda.c
+++ b/smtpd/mail.mda.c
@@ -16,6 +16,7 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/wait.h>
#include <ctype.h>
#include <err.h>
@@ -26,12 +27,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sysexits.h>
#include <unistd.h>
int
main(int argc, char *argv[])
{
int ch;
+ int ret;
if (! geteuid())
errx(1, "mail.mda: may not be executed as root");
@@ -51,5 +54,15 @@ main(int argc, char *argv[])
if (argc > 1)
errx(1, "mail.mda: only one command is supported");
- return system(argv[0]) == 0 ? 0 : 1;
+ /* could not obtain a shell or could not obtain wait status,
+ * tempfail */
+ if ((ret = system(argv[0])) == -1)
+ errx(EX_TEMPFAIL, "%s", strerror(errno));
+
+ /* not exited properly but we have no details,
+ * tempfail */
+ if (! WIFEXITED(ret))
+ exit(EX_TEMPFAIL);
+
+ exit(WEXITSTATUS(ret));
}