summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/mailwrapper/mailwrapper.c39
-rw-r--r--usr.sbin/mailwrapper/pathnames.h1
2 files changed, 31 insertions, 9 deletions
diff --git a/usr.sbin/mailwrapper/mailwrapper.c b/usr.sbin/mailwrapper/mailwrapper.c
index 536ec71..0fc1d24 100644
--- a/usr.sbin/mailwrapper/mailwrapper.c
+++ b/usr.sbin/mailwrapper/mailwrapper.c
@@ -1,3 +1,4 @@
+/* $OpenBSD: mailwrapper.c,v 1.6 1999/12/17 05:06:28 mickey Exp $ */
/* $NetBSD: mailwrapper.c,v 1.3 1999/05/29 18:18:15 christos Exp $ */
/* $FreeBSD$ */
@@ -38,6 +39,8 @@
#include <stdlib.h>
#include <unistd.h>
#include <libutil.h>
+#include <syslog.h>
+#include <stdarg.h>
#include "pathnames.h"
@@ -70,11 +73,20 @@ addarg(al, arg, copy)
const char *arg;
int copy;
{
+ char **argv2;
+
if (al->argc == al->maxc) {
- al->maxc <<= 1;
- if ((al->argv = realloc(al->argv,
- al->maxc * sizeof(char *))) == NULL)
- err(1, "mailwrapper");
+ al->maxc <<= 1;
+
+ if ((argv2 = realloc(al->argv,
+ al->maxc * sizeof(char *))) == NULL) {
+ if (al->argv)
+ free(al->argv);
+ al->argv = NULL;
+ err(1, "mailwrapper");
+ } else {
+ al->argv = argv2;
+ }
}
if (copy) {
if ((al->argv[al->argc++] = strdup(arg)) == NULL)
@@ -110,8 +122,18 @@ main(argc, argv, envp)
for (len = 0; len < argc; len++)
addarg(&al, argv[len], 0);
- if ((config = fopen(_PATH_MAILERCONF, "r")) == NULL)
- err(1, "mailwrapper: can't open %s", _PATH_MAILERCONF);
+ if ((config = fopen(_PATH_MAILERCONF, "r")) == NULL) {
+ addarg(&al, NULL, 0);
+ openlog("mailwrapper", LOG_PID, LOG_MAIL);
+ syslog(LOG_INFO, "can't open %s, using %s as default MTA",
+ _PATH_MAILERCONF, _PATH_DEFAULTMTA);
+ closelog();
+ execve(_PATH_DEFAULTMTA, al.argv, envp);
+ freearg(&al, 0);
+ free(line);
+ err(1, "mailwrapper: execing %s", _PATH_DEFAULTMTA);
+ /*NOTREACHED*/
+ }
for (;;) {
if ((line = fparseln(config, &len, &lineno, NULL, 0)) == NULL) {
@@ -152,12 +174,11 @@ main(argc, argv, envp)
(void)fclose(config);
- al.argv[al.argc] = NULL;
+ addarg(&al, NULL, 0);
execve(to, al.argv, envp);
- warn("mailwrapper: execing %s", to);
freearg(&al, 0);
free(line);
- exit(1);
+ err(1, "mailwrapper: execing %s", to);
/*NOTREACHED*/
parse_error:
freearg(&al, 0);
diff --git a/usr.sbin/mailwrapper/pathnames.h b/usr.sbin/mailwrapper/pathnames.h
index 250cb1b..d8ae498 100644
--- a/usr.sbin/mailwrapper/pathnames.h
+++ b/usr.sbin/mailwrapper/pathnames.h
@@ -32,3 +32,4 @@
*/
#define _PATH_MAILERCONF "/etc/mail/mailer.conf"
+#define _PATH_DEFAULTMTA "/usr/libexec/sendmail/sendmail"
OpenPOWER on IntegriCloud