summaryrefslogtreecommitdiffstats
path: root/usr.sbin/mailwrapper
diff options
context:
space:
mode:
authorimp <imp@FreeBSD.org>2000-01-10 03:20:13 +0000
committerimp <imp@FreeBSD.org>2000-01-10 03:20:13 +0000
commit249e15bd17f3386bc261cc4e9cfe8c78f5f809ce (patch)
treec9a1414d19c20c50791b9284054dc1cd20d5ffc6 /usr.sbin/mailwrapper
parentc96b473b05c3469627e5c3a0325fc35be815b1eb (diff)
downloadFreeBSD-src-249e15bd17f3386bc261cc4e9cfe8c78f5f809ce.zip
FreeBSD-src-249e15bd17f3386bc261cc4e9cfe8c78f5f809ce.tar.gz
Merge from OpenBSD:
o Realloc memory leak fixed which won't matter but would trigger purify o Default to sendmail when no mailer.conf exists. Fixed bugs in OpenBSD version: o Add NULL termination in the right place. Also put back the err. free shouldn't touch errno. Pointed out by: theo de raadt (except the NULL bug :-)
Diffstat (limited to 'usr.sbin/mailwrapper')
-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