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 :-)
This commit is contained in:
parent
b2508fe3ad
commit
ff4d7851f0
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=55705
@ -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)
|
||||
|
||||
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);
|
||||
|
@ -32,3 +32,4 @@
|
||||
*/
|
||||
|
||||
#define _PATH_MAILERCONF "/etc/mail/mailer.conf"
|
||||
#define _PATH_DEFAULTMTA "/usr/libexec/sendmail/sendmail"
|
||||
|
Loading…
Reference in New Issue
Block a user