Cleanups for mailwrapper(8):
- K&R -> ANSI prototype [O] - Do not bother to do free right before exit() or execve() [O] - Remove some dead code in addarg() - Make additional parameters specified in mailer.conf(5) actually work and document the fact. [N] - Avoid using __progname but instead use getprogname() and setprogname() to provide more sensible messages. [O, N] - Update $OpenBSD$ and $NetBSD$ to reflect the fact that we have sync'ed with their code. - WARNS=6 Obtained from/Inspired by: OpenBSD [O], NetBSD [N] (partially)
This commit is contained in:
parent
ed48a217f6
commit
8fe1b8c03e
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=159326
@ -31,7 +31,7 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd December 16, 1998
|
.Dd May 31, 2006
|
||||||
.Dt MAILER.CONF 5
|
.Dt MAILER.CONF 5
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -41,29 +41,59 @@
|
|||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The file
|
The file
|
||||||
.Pa /etc/mail/mailer.conf
|
.Pa /etc/mail/mailer.conf
|
||||||
contains a series of pairs.
|
contains a series of lines of the form
|
||||||
The first member of each pair is the name
|
.Pp
|
||||||
|
.Pa name
|
||||||
|
.Pa program
|
||||||
|
.Op Ar arguments ...
|
||||||
|
.Pp
|
||||||
|
The first word of each line is the
|
||||||
|
.Pa name
|
||||||
of a program invoking
|
of a program invoking
|
||||||
.Xr mailwrapper 8
|
.Xr mailwrapper 8 .
|
||||||
which is typically a symbolic link to
|
(For example, on a typical system
|
||||||
.Pa /usr/sbin/sendmail .
|
.Pa /usr/sbin/sendmail
|
||||||
(On a typical system,
|
would be a symbolic link to
|
||||||
|
.Xr mailwrapper 8 ,
|
||||||
|
as would
|
||||||
.Xr newaliases 1
|
.Xr newaliases 1
|
||||||
and
|
and
|
||||||
.Xr mailq 1
|
.Xr mailq 1 .
|
||||||
would be set up this way.)
|
Thus,
|
||||||
The second member of each pair is the name of the program to
|
.Pa name
|
||||||
actually execute when the first name is invoked.
|
might be
|
||||||
The file may also
|
.Dq sendmail
|
||||||
contain comments, denoted by a # mark in the first column of any line.
|
or
|
||||||
|
.Dq newaliases
|
||||||
|
etc.)
|
||||||
|
.Pp
|
||||||
|
The second word of each line is the name of the
|
||||||
|
.Pa program
|
||||||
|
to actually execute when the first name is invoked.
|
||||||
|
.Pp
|
||||||
|
The further
|
||||||
|
.Ar arguments ,
|
||||||
|
if any, are passed to the
|
||||||
|
.Pa program ,
|
||||||
|
followed by the arguments
|
||||||
|
.Xr mailwrapper 8
|
||||||
|
was called with.
|
||||||
|
.Pp
|
||||||
|
The file may also contain comment lines, denoted by a
|
||||||
|
.Sq #
|
||||||
|
mark in the first column of any line.
|
||||||
|
first column of any line.
|
||||||
.Sh FILES
|
.Sh FILES
|
||||||
/etc/mail/mailer.conf
|
/etc/mail/mailer.conf
|
||||||
.Sh EXAMPLES
|
.Sh EXAMPLES
|
||||||
The following is an example of how to set up an
|
This example shows how to set up
|
||||||
.Nm
|
.Nm
|
||||||
for traditional sendmail invocation behavior.
|
to invoke the traditional
|
||||||
.Bd -literal
|
.Xr sendmail 8
|
||||||
# Execute the "real" sendmail program, named /usr/libexec/sendmail/sendmail
|
program:
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
# Execute the "real" sendmail program located in
|
||||||
|
# /usr/libexec/sendmail/sendmail
|
||||||
sendmail /usr/libexec/sendmail/sendmail
|
sendmail /usr/libexec/sendmail/sendmail
|
||||||
send-mail /usr/libexec/sendmail/sendmail
|
send-mail /usr/libexec/sendmail/sendmail
|
||||||
mailq /usr/libexec/sendmail/sendmail
|
mailq /usr/libexec/sendmail/sendmail
|
||||||
@ -71,20 +101,35 @@ newaliases /usr/libexec/sendmail/sendmail
|
|||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
This example shows how to invoke a sendmail-workalike like Postfix in
|
This example shows how to invoke a sendmail-workalike like Postfix in
|
||||||
place of sendmail.
|
place of
|
||||||
.Bd -literal
|
.Xr sendmail 8 :
|
||||||
|
.Bd -literal -offset indent
|
||||||
# Emulate sendmail using postfix
|
# Emulate sendmail using postfix
|
||||||
sendmail /usr/local/sbin/sendmail
|
sendmail /usr/local/sbin/sendmail
|
||||||
send-mail /usr/local/sbin/sendmail
|
send-mail /usr/local/sbin/sendmail
|
||||||
mailq /usr/local/sbin/sendmail
|
mailq /usr/local/sbin/sendmail
|
||||||
newaliases /usr/local/sbin/sendmail
|
newaliases /usr/local/sbin/sendmail
|
||||||
.Ed
|
.Ed
|
||||||
|
.Pp
|
||||||
|
This example shows the use of the mini_sendmail package from ports
|
||||||
|
in place of
|
||||||
|
.Xr sendmail 8 :
|
||||||
|
Note the use of additional arguments.
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
# Send outgoing mail to a smart relay using mini_sendmail
|
||||||
|
sendmail /usr/local/bin/mini_sendmail -srelayhost
|
||||||
|
send-mail /usr/local/bin/mini_sendmail -srelayhost
|
||||||
|
.Ed
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr mail 1 ,
|
.Xr mail 1 ,
|
||||||
.Xr mailq 1 ,
|
.Xr mailq 1 ,
|
||||||
.Xr newaliases 1 ,
|
.Xr newaliases 1 ,
|
||||||
.Xr mailwrapper 8 ,
|
.Xr mailwrapper 8 ,
|
||||||
.Xr sendmail 8
|
.Xr sendmail 8
|
||||||
|
.Pp
|
||||||
|
.Xr postfix 1
|
||||||
|
.Pq Pa ports/mail/postfix ,
|
||||||
|
.Xr mini_sendmail 8 Pq Pa ports/mail/mini_sendmail
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
.Nm
|
.Nm
|
||||||
appeared in
|
appeared in
|
||||||
|
@ -8,6 +8,7 @@ MAN= mailwrapper.8
|
|||||||
|
|
||||||
DPADD= ${LIBUTIL}
|
DPADD= ${LIBUTIL}
|
||||||
LDADD= -lutil
|
LDADD= -lutil
|
||||||
|
WARNS?= 6
|
||||||
.endif
|
.endif
|
||||||
|
|
||||||
.if ${MK_MAILWRAPPER} != "no" || ${MK_SENDMAIL} != "no"
|
.if ${MK_MAILWRAPPER} != "no" || ${MK_SENDMAIL} != "no"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* $OpenBSD: mailwrapper.c,v 1.6 1999/12/17 05:06:28 mickey Exp $ */
|
/* $OpenBSD: mailwrapper.c,v 1.15 2003/03/09 01:24:26 millert Exp $ */
|
||||||
/* $NetBSD: mailwrapper.c,v 1.3 1999/05/29 18:18:15 christos Exp $ */
|
/* $NetBSD: mailwrapper.c,v 1.7 2003/02/17 21:18:46 is Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1998
|
* Copyright (c) 1998
|
||||||
@ -38,11 +38,11 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <libutil.h>
|
#include <libutil.h>
|
||||||
|
#include <sysexits.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
#include "pathnames.h"
|
#include "pathnames.h"
|
||||||
|
|
||||||
@ -54,93 +54,66 @@ struct arglist {
|
|||||||
int main(int, char *[], char *[]);
|
int main(int, char *[], char *[]);
|
||||||
|
|
||||||
static void initarg(struct arglist *);
|
static void initarg(struct arglist *);
|
||||||
static void addarg(struct arglist *, const char *, int);
|
static void addarg(struct arglist *, const char *);
|
||||||
static void freearg(struct arglist *, int);
|
|
||||||
|
|
||||||
extern const char *__progname; /* from crt0.o */
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
initarg(al)
|
initarg(struct arglist *al)
|
||||||
struct arglist *al;
|
|
||||||
{
|
{
|
||||||
al->argc = 0;
|
al->argc = 0;
|
||||||
al->maxc = 10;
|
al->maxc = 10;
|
||||||
if ((al->argv = malloc(al->maxc * sizeof(char *))) == NULL)
|
if ((al->argv = malloc(al->maxc * sizeof(char *))) == NULL)
|
||||||
err(1, NULL);
|
err(EX_TEMPFAIL, "malloc");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
addarg(al, arg, copy)
|
addarg(struct arglist *al, const char *arg)
|
||||||
struct arglist *al;
|
|
||||||
const char *arg;
|
|
||||||
int copy;
|
|
||||||
{
|
{
|
||||||
char **argv2;
|
|
||||||
|
|
||||||
if (al->argc == al->maxc) {
|
if (al->argc == al->maxc) {
|
||||||
al->maxc <<= 1;
|
al->maxc <<= 1;
|
||||||
|
al->argv = realloc(al->argv, al->maxc * sizeof(char *));
|
||||||
if ((argv2 = realloc(al->argv,
|
if (al->argv == NULL)
|
||||||
al->maxc * sizeof(char *))) == NULL) {
|
err(EX_TEMPFAIL, "realloc");
|
||||||
if (al->argv)
|
|
||||||
free(al->argv);
|
|
||||||
al->argv = NULL;
|
|
||||||
err(1, NULL);
|
|
||||||
} else {
|
|
||||||
al->argv = argv2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (copy) {
|
if (arg == NULL)
|
||||||
if ((al->argv[al->argc++] = strdup(arg)) == NULL)
|
al->argv[al->argc++] = NULL;
|
||||||
err(1, NULL);
|
else if ((al->argv[al->argc++] = strdup(arg)) == NULL)
|
||||||
} else
|
err(EX_TEMPFAIL, "strdup");
|
||||||
al->argv[al->argc++] = (char *)arg;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
freearg(al, copy)
|
|
||||||
struct arglist *al;
|
|
||||||
int copy;
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
if (copy)
|
|
||||||
for (i = 0; i < al->argc; i++)
|
|
||||||
free(al->argv[i]);
|
|
||||||
free(al->argv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(argc, argv, envp)
|
main(int argc, char *argv[], char *envp[])
|
||||||
int argc;
|
|
||||||
char *argv[];
|
|
||||||
char *envp[];
|
|
||||||
{
|
{
|
||||||
FILE *config;
|
FILE *config;
|
||||||
char *line, *cp, *from, *to, *ap;
|
char *line, *cp, *from, *to, *ap;
|
||||||
|
const char *progname;
|
||||||
size_t len, lineno = 0;
|
size_t len, lineno = 0;
|
||||||
|
int i;
|
||||||
struct arglist al;
|
struct arglist al;
|
||||||
|
|
||||||
|
/* change __progname to mailwrapper so we get sensible error messages */
|
||||||
|
progname = getprogname();
|
||||||
|
setprogname("mailwrapper");
|
||||||
|
|
||||||
initarg(&al);
|
initarg(&al);
|
||||||
for (len = 0; len < argc; len++)
|
addarg(&al, argv[0]);
|
||||||
addarg(&al, argv[len], 0);
|
|
||||||
|
|
||||||
if ((config = fopen(_PATH_MAILERCONF, "r")) == NULL) {
|
if ((config = fopen(_PATH_MAILERCONF, "r")) == NULL) {
|
||||||
addarg(&al, NULL, 0);
|
addarg(&al, NULL);
|
||||||
openlog("mailwrapper", LOG_PID, LOG_MAIL);
|
openlog(getprogname(), LOG_PID, LOG_MAIL);
|
||||||
syslog(LOG_INFO, "can't open %s, using %s as default MTA",
|
syslog(LOG_INFO, "cannot open %s, using %s as default MTA",
|
||||||
_PATH_MAILERCONF, _PATH_DEFAULTMTA);
|
_PATH_MAILERCONF, _PATH_DEFAULTMTA);
|
||||||
closelog();
|
closelog();
|
||||||
execve(_PATH_DEFAULTMTA, al.argv, envp);
|
execve(_PATH_DEFAULTMTA, al.argv, envp);
|
||||||
freearg(&al, 0);
|
err(EX_OSERR, "cannot exec %s", _PATH_DEFAULTMTA);
|
||||||
err(1, "execing %s", _PATH_DEFAULTMTA);
|
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if ((line = fparseln(config, &len, &lineno, NULL, 0)) == NULL) {
|
if ((line = fparseln(config, &len, &lineno, NULL, 0)) == NULL) {
|
||||||
if (feof(config))
|
if (feof(config))
|
||||||
errx(1, "no mapping in %s", _PATH_MAILERCONF);
|
errx(EX_CONFIG, "no mapping in %s", _PATH_MAILERCONF);
|
||||||
err(1, "can't parse line %lu", (u_long)lineno);
|
err(EX_CONFIG, "cannot parse line %lu", (u_long)lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define WS " \t\n"
|
#define WS " \t\n"
|
||||||
@ -161,11 +134,12 @@ main(argc, argv, envp)
|
|||||||
if ((to = strsep(&cp, WS)) == NULL)
|
if ((to = strsep(&cp, WS)) == NULL)
|
||||||
goto parse_error;
|
goto parse_error;
|
||||||
|
|
||||||
if (strcmp(from, __progname) == 0) {
|
if (strcmp(from, progname) == 0) {
|
||||||
for (ap = strsep(&cp, WS); ap != NULL;
|
for (ap = strsep(&cp, WS); ap != NULL;
|
||||||
ap = strsep(&cp, WS))
|
ap = strsep(&cp, WS)) {
|
||||||
if (*ap)
|
if (*ap)
|
||||||
addarg(&al, ap, 0);
|
addarg(&al, ap);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,17 +148,15 @@ main(argc, argv, envp)
|
|||||||
|
|
||||||
(void)fclose(config);
|
(void)fclose(config);
|
||||||
|
|
||||||
addarg(&al, NULL, 0);
|
for (i = 1; i < argc; i++)
|
||||||
|
addarg(&al, argv[i]);
|
||||||
|
|
||||||
|
addarg(&al, NULL);
|
||||||
execve(to, al.argv, envp);
|
execve(to, al.argv, envp);
|
||||||
freearg(&al, 0);
|
err(EX_OSERR, "cannot exec %s", to);
|
||||||
warn("execing %s", to);
|
|
||||||
free(line);
|
|
||||||
exit(1);
|
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
parse_error:
|
parse_error:
|
||||||
freearg(&al, 0);
|
errx(EX_CONFIG, "parse error in %s at line %lu",
|
||||||
free(line);
|
|
||||||
errx(1, "parse error in %s at line %lu",
|
|
||||||
_PATH_MAILERCONF, (u_long)lineno);
|
_PATH_MAILERCONF, (u_long)lineno);
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user