summaryrefslogtreecommitdiffstats
path: root/contrib/sendmail/rmail
diff options
context:
space:
mode:
authorgshapiro <gshapiro@FreeBSD.org>2000-08-12 22:19:16 +0000
committergshapiro <gshapiro@FreeBSD.org>2000-08-12 22:19:16 +0000
commit74c280481f7b3087059573dc63b94ac093b17466 (patch)
tree7f1b2dddabe7373f19a658433a351ef5464ef883 /contrib/sendmail/rmail
parentc3cd75415d60bc002b20182ffd3383ea9e901a80 (diff)
downloadFreeBSD-src-74c280481f7b3087059573dc63b94ac093b17466.zip
FreeBSD-src-74c280481f7b3087059573dc63b94ac093b17466.tar.gz
Fix conflicts from merge of sendmail 8.11.0.
PR: bin/11552 misc/18512 bin/15088
Diffstat (limited to 'contrib/sendmail/rmail')
-rw-r--r--contrib/sendmail/rmail/rmail.c334
1 files changed, 185 insertions, 149 deletions
diff --git a/contrib/sendmail/rmail/rmail.c b/contrib/sendmail/rmail/rmail.c
index 3c268ab..bd21b7c 100644
--- a/contrib/sendmail/rmail/rmail.c
+++ b/contrib/sendmail/rmail/rmail.c
@@ -1,5 +1,6 @@
/*
- * Copyright (c) 1998 Sendmail, Inc. All rights reserved.
+ * Copyright (c) 1998-2000 Sendmail, Inc. and its suppliers.
+ * All rights reserved.
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
@@ -11,20 +12,24 @@
#ifndef lint
static char copyright[] =
-"@(#) Copyright (c) 1988, 1993\n\
+"@(#) Copyright (c) 1998-2000 Sendmail, Inc. and its suppliers.\n\
+ All rights reserved.\n\
+ Copyright (c) 1988, 1993\n\
The Regents of the University of California. All rights reserved.\n";
-#endif /* not lint */
+#endif /* ! lint */
#ifndef lint
-static char sccsid[] = "@(#)rmail.c 8.18 (Berkeley) 10/23/1998";
-#endif /* not lint */
+static char id[] = "@(#)$Id: rmail.c,v 8.39.4.5 2000/07/18 05:55:29 gshapiro Exp $";
+#endif /* ! lint */
+
+/* $FreeBSD$ */
/*
* RMAIL -- UUCP mail server.
*
* This program reads the >From ... remote from ... lines that UUCP is so
* fond of and turns them into something reasonable. It then execs sendmail
- * with various options built from these lines.
+ * with various options built from these lines.
*
* The expected syntax is:
*
@@ -43,6 +48,8 @@ static char sccsid[] = "@(#)rmail.c 8.18 (Berkeley) 10/23/1998";
* The err(3) routine is included here deliberately to make this code
* a bit more portable.
*/
+
+#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/wait.h>
@@ -52,66 +59,74 @@ static char sccsid[] = "@(#)rmail.c 8.18 (Berkeley) 10/23/1998";
#ifdef BSD4_4
# define FORK vfork
# include <paths.h>
-#else
+#else /* BSD4_4 */
# define FORK fork
# ifndef _PATH_SENDMAIL
# define _PATH_SENDMAIL "/usr/lib/sendmail"
-# endif
-#endif
+# endif /* ! _PATH_SENDMAIL */
+#endif /* BSD4_4 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef EX_OK
# undef EX_OK /* unistd.h may have another use for this */
-#endif
+#endif /* EX_OK */
#include <sysexits.h>
#ifndef MAX
# define MAX(a, b) ((a) < (b) ? (b) : (a))
-#endif
+#endif /* ! MAX */
#ifndef __P
# ifdef __STDC__
# define __P(protos) protos
-# else
+# else /* __STDC__ */
# define __P(protos) ()
# define const
-# endif
-#endif
+# endif /* __STDC__ */
+#endif /* ! __P */
-#if defined(BSD4_4) || defined(linux) || SOLARIS >= 20600 || (SOLARIS < 10000 && SOLARIS >= 206)
-# define HASSNPRINTF 1
-#endif
+#ifndef STDIN_FILENO
+# define STDIN_FILENO 0
+#endif /* ! STDIN_FILENO */
-#if defined(IRIX64) || defined(IRIX5) || defined(IRIX6) || \
- defined(BSD4_4) || defined(__osf__) || defined(__GNU_LIBRARY__)
-# ifndef HASSTRERROR
-# define HASSTRERROR 1 /* has strerror(3) */
-# endif
-#endif
-
-#if !HASSTRERROR
-extern char *strerror __P((int));
-#endif
+#if defined(BSD4_4) || defined(linux) || SOLARIS >= 20600 || (SOLARIS < 10000 && SOLARIS >= 206) || _AIX4 >= 40300
+# define HASSNPRINTF 1
+#endif /* defined(BSD4_4) || defined(linux) || SOLARIS >= 20600 || (SOLARIS < 10000 && SOLARIS >= 206) || _AIX4 >= 40300 */
#if defined(sun) && !defined(BSD) && !defined(SOLARIS) && !defined(__svr4__) && !defined(__SVR4)
-# define memmove(d, s, l) (bcopy((s), (d), (l)))
-#endif
+# define memmove(d, s, l) (bcopy((s), (d), (l)))
+#endif /* defined(sun) && !defined(BSD) && !defined(SOLARIS) && !defined(__svr4__) && !defined(__SVR4) */
#if !HASSNPRINTF
extern int snprintf __P((char *, size_t, const char *, ...));
#endif /* !HASSNPRINTF */
-u_char tTdvect[100];
+#if defined(BSD4_4) || defined(__osf__) || defined(__GNU_LIBRARY__) || defined(IRIX64) || defined(IRIX5) || defined(IRIX6)
+# ifndef HASSTRERROR
+# define HASSTRERROR 1
+# endif /* ! HASSTRERROR */
+#endif /* defined(BSD4_4) || defined(__osf__) || defined(__GNU_LIBRARY__) ||
+ defined(IRIX64) || defined(IRIX5) || defined(IRIX6) */
+
+#if defined(SUNOS403) || defined(NeXT) || (defined(MACH) && defined(i386) && !defined(__GNU__)) || defined(oldBSD43) || defined(MORE_BSD) || defined(umipsbsd) || defined(ALTOS_SYSTEM_V) || defined(RISCOS) || defined(_AUX_SOURCE) || defined(UMAXV) || defined(titan) || defined(UNIXWARE) || defined(sony_news) || defined(luna) || defined(nec_ews_svr4) || defined(_nec_ews_svr4) || defined(__MAXION__)
+# undef WIFEXITED
+# undef WEXITSTATUS
+# define WIFEXITED(st) (((st) & 0377) == 0)
+# define WEXITSTATUS(st) (((st) >> 8) & 0377)
+#endif /* defined(SUNOS403) || defined(NeXT) || (defined(MACH) && defined(i386) && !defined(__GNU__)) || defined(oldBSD43) || defined(MORE_BSD) || defined(umipsbsd) || defined(ALTOS_SYSTEM_V) || defined(RISCOS) || defined(_AUX_SOURCE) || defined(UMAXV) || defined(titan) || defined(UNIXWARE) || defined(sony_news) || defined(luna) || defined(nec_ews_svr4) || defined(_nec_ews_svr4) || defined(__MAXION__) */
+
-void err __P((int, const char *, ...));
-void usage __P((void));
-char *xalloc __P((int));
+#include "sendmail/errstring.h"
+
+static void err __P((int, const char *, ...));
+static void usage __P((void));
+static char *xalloc __P((int));
#define newstr(s) strcpy(xalloc(strlen(s) + 1), s)
-char *
+static char *
xalloc(sz)
register int sz;
{
@@ -132,45 +147,49 @@ main(argc, argv)
int argc;
char *argv[];
{
- extern char *optarg;
- extern int errno, optind;
- FILE *fp;
- struct stat sb;
+ int ch, debug, i, pdes[2], pid, status;
size_t fplen = 0, fptlen = 0, len;
off_t offset;
- int ch, debug, i, pdes[2], pid, status;
+ FILE *fp;
char *addrp = NULL, *domain, *p, *t;
char *from_path, *from_sys, *from_user;
char *args[100], buf[2048], lbuf[2048];
+ struct stat sb;
+ extern char *optarg;
+ extern int optind;
debug = 0;
domain = "UUCP"; /* Default "domain". */
while ((ch = getopt(argc, argv, "D:T")) != -1)
- switch (ch) {
- case 'T':
+ {
+ switch (ch)
+ {
+ case 'T':
debug = 1;
break;
- case 'D':
+
+ case 'D':
domain = optarg;
break;
- case '?':
- default:
+
+ case '?':
+ default:
usage();
}
+ }
+
argc -= optind;
argv += optind;
if (argc < 1)
usage();
- fplen = fptlen = 0;
- addrp = "";
from_path = from_sys = from_user = NULL;
- for (offset = 0;;) {
-
+ for (offset = 0; ; )
+ {
/* Get and nul-terminate the line. */
if (fgets(lbuf, sizeof(lbuf), stdin) == NULL)
- exit (EX_DATAERR);
+ exit(EX_DATAERR);
if ((p = strchr(lbuf, '\n')) == NULL)
err(EX_DATAERR, "line too long");
*p = '\0';
@@ -183,32 +202,40 @@ main(argc, argv)
else if (offset == 0)
err(EX_DATAERR,
"missing or empty From line: %s", lbuf);
- else {
+ else
+ {
*p = '\n';
break;
}
- if (*addrp == '\0')
+ if (addrp == NULL || *addrp == '\0')
err(EX_DATAERR, "corrupted From line: %s", lbuf);
/* Use the "remote from" if it exists. */
- for (p = addrp; (p = strchr(p + 1, 'r')) != NULL;)
- if (!strncmp(p, "remote from ", 12)) {
- for (t = p += 12;
- *t && !(isascii(*t) && isspace(*t)); ++t);
+ for (p = addrp; (p = strchr(p + 1, 'r')) != NULL; )
+ {
+ if (!strncmp(p, "remote from ", 12))
+ {
+ for (t = p += 12; *t != '\0'; ++t)
+ {
+ if (isascii(*t) && isspace(*t))
+ break;
+ }
*t = '\0';
if (debug)
- (void)fprintf(stderr,
- "remote from: %s\n", p);
+ fprintf(stderr, "remote from: %s\n", p);
break;
}
+ }
/* Else use the string up to the last bang. */
- if (p == NULL) {
+ if (p == NULL)
+ {
if (*addrp == '!')
- err(EX_DATAERR,
- "bang starts address: %s", addrp);
- else if ((t = strrchr(addrp, '!')) != NULL) {
+ err(EX_DATAERR, "bang starts address: %s",
+ addrp);
+ else if ((t = strrchr(addrp, '!')) != NULL)
+ {
*t = '\0';
p = addrp;
addrp = t + 1;
@@ -216,34 +243,43 @@ main(argc, argv)
err(EX_DATAERR,
"corrupted From line: %s", lbuf);
if (debug)
- (void)fprintf(stderr, "bang: %s\n", p);
+ fprintf(stderr, "bang: %s\n", p);
}
}
+
/* 'p' now points to any system string from this line. */
- if (p != NULL) {
+ if (p != NULL)
+ {
/* Nul terminate it as necessary. */
- for (t = p; *t && !(isascii(*t) && isspace(*t)); ++t);
+ for (t = p; *t != '\0'; ++t)
+ {
+ if (isascii(*t) && isspace(*t))
+ break;
+ }
*t = '\0';
/* If the first system, copy to the from_sys string. */
- if (from_sys == NULL) {
+ if (from_sys == NULL)
+ {
from_sys = newstr(p);
if (debug)
- (void)fprintf(stderr,
- "from_sys: %s\n", from_sys);
+ fprintf(stderr, "from_sys: %s\n",
+ from_sys);
}
/* Concatenate to the path string. */
len = t - p;
- if (from_path == NULL) {
+ if (from_path == NULL)
+ {
fplen = 0;
if ((from_path = malloc(fptlen = 256)) == NULL)
err(EX_TEMPFAIL, NULL);
}
- if (fplen + len + 2 > fptlen) {
+ if (fplen + len + 2 > fptlen)
+ {
fptlen += MAX(fplen + len + 2, 256);
- if ((from_path =
- realloc(from_path, fptlen)) == NULL)
+ if ((from_path = realloc(from_path,
+ fptlen)) == NULL)
err(EX_TEMPFAIL, NULL);
}
memmove(from_path + fplen, p, len);
@@ -253,7 +289,11 @@ main(argc, argv)
}
/* Save off from user's address; the last one wins. */
- for (p = addrp; *p && !(isascii(*p) && isspace(*p)); ++p);
+ for (p = addrp; *p != '\0'; ++p)
+ {
+ if (isascii(*p) && isspace(*p))
+ break;
+ }
*p = '\0';
if (*addrp == '\0')
addrp = "<>";
@@ -261,11 +301,11 @@ main(argc, argv)
free(from_user);
from_user = newstr(addrp);
- if (debug) {
+ if (debug)
+ {
if (from_path != NULL)
- (void)fprintf(stderr,
- "from_path: %s\n", from_path);
- (void)fprintf(stderr, "from_user: %s\n", from_user);
+ fprintf(stderr, "from_path: %s\n", from_path);
+ fprintf(stderr, "from_user: %s\n", from_user);
}
if (offset != -1)
@@ -284,86 +324,99 @@ main(argc, argv)
/* set from system and protocol used */
if (from_sys == NULL)
- (void)snprintf(buf, sizeof(buf), "-p%s", domain);
+ snprintf(buf, sizeof(buf), "-p%s", domain);
else if (strchr(from_sys, '.') == NULL)
- (void)snprintf(buf, sizeof(buf), "-p%s:%s.%s",
+ snprintf(buf, sizeof(buf), "-p%s:%s.%s",
domain, from_sys, domain);
else
- (void)snprintf(buf, sizeof(buf), "-p%s:%s", domain, from_sys);
+ snprintf(buf, sizeof(buf), "-p%s:%s", domain, from_sys);
args[i++] = newstr(buf);
- /* Set name of ``from'' person. */
- (void)snprintf(buf, sizeof(buf), "-f%s%s",
- from_path ? from_path : "", from_user);
+ /* Set name of ``from'' person. */
+ snprintf(buf, sizeof(buf), "-f%s%s",
+ from_path ? from_path : "", from_user);
args[i++] = newstr(buf);
/*
- * Don't copy arguments beginning with - as they will be
- * passed to sendmail and could be interpreted as flags.
- * To prevent confusion of sendmail wrap < and > around
- * the address (helps to pass addrs like @gw1,@gw2:aa@bb)
- */
- while (*argv) {
+ ** Don't copy arguments beginning with - as they will be
+ ** passed to sendmail and could be interpreted as flags.
+ ** To prevent confusion of sendmail wrap < and > around
+ ** the address (helps to pass addrs like @gw1,@gw2:aa@bb)
+ */
+
+ while (*argv)
+ {
if (**argv == '-')
err(EX_USAGE, "dash precedes argument: %s", *argv);
+
if (strchr(*argv, ',') == NULL || strchr(*argv, '<') != NULL)
args[i++] = *argv;
- else {
- if ((args[i] = malloc(strlen(*argv) + 3)) == NULL)
+ else
+ {
+ len = strlen(*argv) + 3;
+ if ((args[i] = malloc(len)) == NULL)
err(EX_TEMPFAIL, "Cannot malloc");
- sprintf (args [i++], "<%s>", *argv);
+ snprintf(args[i++], len, "<%s>", *argv);
}
argv++;
- }
+ }
args[i] = 0;
- if (debug) {
- (void)fprintf(stderr, "Sendmail arguments:\n");
+ if (debug)
+ {
+ fprintf(stderr, "Sendmail arguments:\n");
for (i = 0; args[i]; i++)
- (void)fprintf(stderr, "\t%s\n", args[i]);
+ fprintf(stderr, "\t%s\n", args[i]);
}
/*
- * If called with a regular file as standard input, seek to the right
- * position in the file and just exec sendmail. Could probably skip
- * skip the stat, but it's not unreasonable to believe that a failed
- * seek will cause future reads to fail.
- */
- if (!fstat(STDIN_FILENO, &sb) && S_ISREG(sb.st_mode)) {
+ ** If called with a regular file as standard input, seek to the right
+ ** position in the file and just exec sendmail. Could probably skip
+ ** skip the stat, but it's not unreasonable to believe that a failed
+ ** seek will cause future reads to fail.
+ */
+
+ if (!fstat(STDIN_FILENO, &sb) && S_ISREG(sb.st_mode))
+ {
if (lseek(STDIN_FILENO, offset, SEEK_SET) != offset)
err(EX_TEMPFAIL, "stdin seek");
- execv(_PATH_SENDMAIL, args);
+ (void) execv(_PATH_SENDMAIL, args);
err(EX_OSERR, "%s", _PATH_SENDMAIL);
}
if (pipe(pdes) < 0)
err(EX_OSERR, NULL);
- switch (pid = FORK()) {
- case -1: /* Err. */
+ switch (pid = FORK())
+ {
+ case -1: /* Err. */
err(EX_OSERR, NULL);
- case 0: /* Child. */
- if (pdes[0] != STDIN_FILENO) {
- (void)dup2(pdes[0], STDIN_FILENO);
- (void)close(pdes[0]);
+ /* NOTREACHED */
+
+ case 0: /* Child. */
+ if (pdes[0] != STDIN_FILENO)
+ {
+ (void) dup2(pdes[0], STDIN_FILENO);
+ (void) close(pdes[0]);
}
- (void)close(pdes[1]);
- execv(_PATH_SENDMAIL, args);
+ (void) close(pdes[1]);
+ (void) execv(_PATH_SENDMAIL, args);
_exit(127);
/* NOTREACHED */
}
if ((fp = fdopen(pdes[1], "w")) == NULL)
err(EX_OSERR, NULL);
- (void)close(pdes[0]);
+ (void) close(pdes[0]);
/* Copy the file down the pipe. */
- do {
- (void)fprintf(fp, "%s", lbuf);
+ do
+ {
+ (void) fprintf(fp, "%s", lbuf);
} while (fgets(lbuf, sizeof(lbuf), stdin) != NULL);
if (ferror(stdin))
- err(EX_TEMPFAIL, "stdin: %s", strerror(errno));
+ err(EX_TEMPFAIL, "stdin: %s", errstring(errno));
if (fclose(fp))
err(EX_OSERR, NULL);
@@ -372,65 +425,48 @@ main(argc, argv)
err(EX_OSERR, "%s", _PATH_SENDMAIL);
if (!WIFEXITED(status))
- err(EX_OSERR,
- "%s: did not terminate normally", _PATH_SENDMAIL);
+ err(EX_OSERR, "%s: did not terminate normally", _PATH_SENDMAIL);
if (WEXITSTATUS(status))
err(status, "%s: terminated with %d (non-zero) status",
_PATH_SENDMAIL, WEXITSTATUS(status));
exit(EX_OK);
+ /* NOTREACHED */
+ return EX_OK;
}
-void
+static void
usage()
{
- (void)fprintf(stderr, "usage: rmail [-T] [-D domain] user ...\n");
+ (void) fprintf(stderr, "usage: rmail [-T] [-D domain] user ...\n");
exit(EX_USAGE);
}
#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
+# include <stdarg.h>
+#else /* __STDC__ */
+# include <varargs.h>
+#endif /* __STDC__ */
-void
+static void
#ifdef __STDC__
err(int eval, const char *fmt, ...)
-#else
+#else /* __STDC__ */
err(eval, fmt, va_alist)
int eval;
const char *fmt;
va_dcl
-#endif
+#endif /* __STDC__ */
{
va_list ap;
-#if __STDC__
+#ifdef __STDC__
va_start(ap, fmt);
-#else
+#else /* __STDC__ */
va_start(ap);
-#endif
- (void)fprintf(stderr, "rmail: ");
- (void)vfprintf(stderr, fmt, ap);
+#endif /* __STDC__ */
+ (void) fprintf(stderr, "rmail: ");
+ (void) vfprintf(stderr, fmt, ap);
va_end(ap);
- (void)fprintf(stderr, "\n");
+ (void) fprintf(stderr, "\n");
exit(eval);
}
-
-#if !HASSTRERROR
-
-char *
-strerror(eno)
- int eno;
-{
- extern int sys_nerr;
- extern char *sys_errlist[];
- static char ebuf[60];
-
- if (eno >= 0 && eno < sys_nerr)
- return sys_errlist[eno];
- (void) sprintf(ebuf, "Error %d", eno);
- return ebuf;
-}
-
-#endif /* !HASSTRERROR */
OpenPOWER on IntegriCloud