1N/A/*
1N/A * Copyright (c) 1998-2006, 2008, 2009, 2011 Sendmail, Inc. and its suppliers.
1N/A * All rights reserved.
1N/A * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
1N/A * Copyright (c) 1988, 1993
1N/A * The Regents of the University of California. All rights reserved.
1N/A *
1N/A * By using this file, you agree to the terms and conditions set
1N/A * forth in the LICENSE file which can be found at the top level of
1N/A * the sendmail distribution.
1N/A *
1N/A */
1N/A
1N/A/*
1N/A * Copyright 1996-2006 Sun Microsystems, Inc. All rights reserved.
1N/A * Use is subject to license terms.
1N/A */
1N/A
1N/A#define _DEFINE
1N/A#include <sendmail.h>
1N/A#include <sm/sendmail.h>
1N/A#include <sm/xtrap.h>
1N/A#include <sm/signal.h>
1N/A
1N/A#ifndef lint
1N/ASM_UNUSED(static char copyright[]) =
1N/A"@(#) Copyright (c) 1998-2003 Sendmail, Inc. and its suppliers.\n\
1N/A@(#) All rights reserved.\n\
1N/A@(#) Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.\n\
1N/A@(#) Copyright (c) 1988, 1993\n\
1N/A@(#) The Regents of the University of California. All rights reserved.\n\
1N/A@(#) Copyright 1996-2006 Sun Microsystems, Inc. All rights reserved.\n\
1N/A@(#) Use is subject to license terms.\n";
1N/A#endif /* ! lint */
1N/A
1N/ASM_RCSID("@(#)$Id: main.c,v 8.976 2011/03/15 23:14:36 ca Exp $")
1N/A
1N/A#if NETINET || NETINET6
1N/A# include <arpa/inet.h>
1N/A#endif /* NETINET || NETINET6 */
1N/A
1N/A/* for getcfname() */
1N/A#include <sendmail/pathnames.h>
1N/A
1N/Astatic SM_DEBUG_T
1N/ADebugNoPRestart = SM_DEBUG_INITIALIZER("no_persistent_restart",
1N/A "@(#)$Debug: no_persistent_restart - don't restart, log only $");
1N/A
1N/Astatic void dump_class __P((STAB *, int));
1N/Astatic void obsolete __P((char **));
1N/Astatic void testmodeline __P((char *, ENVELOPE *));
1N/Astatic char *getextenv __P((const char *));
1N/Astatic void sm_printoptions __P((char **));
1N/Astatic SIGFUNC_DECL intindebug __P((int));
1N/Astatic SIGFUNC_DECL sighup __P((int));
1N/Astatic SIGFUNC_DECL sigpipe __P((int));
1N/Astatic SIGFUNC_DECL sigterm __P((int));
1N/A#ifdef SIGUSR1
1N/Astatic SIGFUNC_DECL sigusr1 __P((int));
1N/A#endif /* SIGUSR1 */
1N/A
1N/A/*
1N/A** SENDMAIL -- Post mail to a set of destinations.
1N/A**
1N/A** This is the basic mail router. All user mail programs should
1N/A** call this routine to actually deliver mail. Sendmail in
1N/A** turn calls a bunch of mail servers that do the real work of
1N/A** delivering the mail.
1N/A**
1N/A** Sendmail is driven by settings read in from /etc/mail/sendmail.cf
1N/A** (read by readcf.c).
1N/A**
1N/A** Usage:
1N/A** /usr/lib/sendmail [flags] addr ...
1N/A**
1N/A** See the associated documentation for details.
1N/A**
1N/A** Authors:
1N/A** Eric Allman, UCB/INGRES (until 10/81).
1N/A** Britton-Lee, Inc., purveyors of fine
1N/A** database computers (11/81 - 10/88).
1N/A** International Computer Science Institute
1N/A** (11/88 - 9/89).
1N/A** UCB/Mammoth Project (10/89 - 7/95).
1N/A** InReference, Inc. (8/95 - 1/97).
1N/A** Sendmail, Inc. (1/98 - present).
1N/A** The support of my employers is gratefully acknowledged.
1N/A** Few of them (Britton-Lee in particular) have had
1N/A** anything to gain from my involvement in this project.
1N/A**
1N/A** Gregory Neil Shapiro,
1N/A** Worcester Polytechnic Institute (until 3/98).
1N/A** Sendmail, Inc. (3/98 - present).
1N/A**
1N/A** Claus Assmann,
1N/A** Sendmail, Inc. (12/98 - present).
1N/A*/
1N/A
1N/Achar *FullName; /* sender's full name */
1N/AENVELOPE BlankEnvelope; /* a "blank" envelope */
1N/Astatic ENVELOPE MainEnvelope; /* the envelope around the basic letter */
1N/AADDRESS NullAddress = /* a null address */
1N/A { "", "", NULL, "" };
1N/Achar *CommandLineArgs; /* command line args for pid file */
1N/Abool Warn_Q_option = false; /* warn about Q option use */
1N/Astatic int MissingFds = 0; /* bit map of fds missing on startup */
1N/Achar *Mbdb = "pw"; /* mailbox database defaults to /etc/passwd */
1N/A
1N/A#ifdef NGROUPS_MAX
1N/AGIDSET_T InitialGidSet[NGROUPS_MAX];
1N/A#endif /* NGROUPS_MAX */
1N/A
1N/A#define MAXCONFIGLEVEL 10 /* highest config version level known */
1N/A
1N/A#if SASL
1N/Astatic sasl_callback_t srvcallbacks[] =
1N/A{
1N/A { SASL_CB_VERIFYFILE, &safesaslfile, NULL },
1N/A { SASL_CB_PROXY_POLICY, &proxy_policy, NULL },
1N/A { SASL_CB_LIST_END, NULL, NULL }
1N/A};
1N/A#endif /* SASL */
1N/A
1N/Aunsigned int SubmitMode;
1N/Aint SyslogPrefixLen; /* estimated length of syslog prefix */
1N/A#define PIDLEN 6 /* pid length for computing SyslogPrefixLen */
1N/A#ifndef SL_FUDGE
1N/A# define SL_FUDGE 10 /* fudge offset for SyslogPrefixLen */
1N/A#endif /* ! SL_FUDGE */
1N/A#define SLDLL 8 /* est. length of default syslog label */
1N/A
1N/A
1N/A/* Some options are dangerous to allow users to use in non-submit mode */
1N/A#define CHECK_AGAINST_OPMODE(cmd) \
1N/A{ \
1N/A if (extraprivs && \
1N/A OpMode != MD_DELIVER && OpMode != MD_SMTP && \
1N/A OpMode != MD_ARPAFTP && OpMode != MD_CHECKCONFIG && \
1N/A OpMode != MD_VERIFY && OpMode != MD_TEST) \
1N/A { \
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, \
1N/A "WARNING: Ignoring submission mode -%c option (not in submission mode)\n", \
1N/A (cmd)); \
1N/A break; \
1N/A } \
1N/A if (extraprivs && queuerun) \
1N/A { \
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, \
1N/A "WARNING: Ignoring submission mode -%c option with -q\n", \
1N/A (cmd)); \
1N/A break; \
1N/A } \
1N/A}
1N/A
1N/Aint
1N/Amain(argc, argv, envp)
1N/A int argc;
1N/A char **argv;
1N/A char **envp;
1N/A{
1N/A register char *p;
1N/A char **av;
1N/A extern char Version[];
1N/A char *ep, *from;
1N/A STAB *st;
1N/A register int i;
1N/A int j;
1N/A int dp;
1N/A int fill_errno;
1N/A int qgrp = NOQGRP; /* queue group to process */
1N/A bool safecf = true;
1N/A BITMAP256 *p_flags = NULL; /* daemon flags */
1N/A bool warn_C_flag = false;
1N/A bool auth = true; /* whether to set e_auth_param */
1N/A char warn_f_flag = '\0';
1N/A bool run_in_foreground = false; /* -bD mode */
1N/A bool queuerun = false, debug = false;
1N/A struct passwd *pw;
1N/A struct hostent *hp;
1N/A char *nullserver = NULL;
1N/A char *authinfo = NULL;
1N/A char *sysloglabel = NULL; /* label for syslog */
1N/A char *conffile = NULL; /* name of .cf file */
1N/A char *queuegroup = NULL; /* queue group to process */
1N/A char *quarantining = NULL; /* quarantine queue items? */
1N/A bool extraprivs;
1N/A bool forged, negate;
1N/A bool queuepersistent = false; /* queue runner process runs forever */
1N/A bool foregroundqueue = false; /* queue run in foreground */
1N/A bool save_val; /* to save some bool var. */
1N/A int cftype; /* which cf file to use? */
1N/A SM_FILE_T *smdebug;
1N/A static time_t starttime = 0; /* when was process started */
1N/A struct stat traf_st; /* for TrafficLog FIFO check */
1N/A char buf[MAXLINE];
1N/A char jbuf[MAXHOSTNAMELEN]; /* holds MyHostName */
1N/A static char rnamebuf[MAXNAME]; /* holds RealUserName */
1N/A char *emptyenviron[1];
1N/A#if STARTTLS
1N/A bool tls_ok;
1N/A#endif /* STARTTLS */
1N/A QUEUE_CHAR *new;
1N/A ENVELOPE *e;
1N/A extern int DtableSize;
1N/A extern int optind;
1N/A extern int opterr;
1N/A extern char *optarg;
1N/A extern char **environ;
1N/A#if SASL
1N/A extern void sm_sasl_init __P((void));
1N/A#endif /* SASL */
1N/A
1N/A#if USE_ENVIRON
1N/A envp = environ;
1N/A#endif /* USE_ENVIRON */
1N/A
1N/A /* turn off profiling */
1N/A SM_PROF(0);
1N/A
1N/A /* install default exception handler */
1N/A sm_exc_newthread(fatal_error);
1N/A
1N/A /* set the default in/out channel so errors reported to screen */
1N/A InChannel = smioin;
1N/A OutChannel = smioout;
1N/A
1N/A /*
1N/A ** Check to see if we reentered.
1N/A ** This would normally happen if e_putheader or e_putbody
1N/A ** were NULL when invoked.
1N/A */
1N/A
1N/A if (starttime != 0)
1N/A {
1N/A syserr("main: reentered!");
1N/A abort();
1N/A }
1N/A starttime = curtime();
1N/A
1N/A /* avoid null pointer dereferences */
1N/A TermEscape.te_rv_on = TermEscape.te_under_on = TermEscape.te_normal = "";
1N/A
1N/A RealUid = getuid();
1N/A RealGid = getgid();
1N/A
1N/A /* Check if sendmail is running with extra privs */
1N/A extraprivs = (RealUid != 0 &&
1N/A (geteuid() != getuid() || getegid() != getgid()));
1N/A
1N/A CurrentPid = getpid();
1N/A
1N/A /* get whatever .cf file is right for the opmode */
1N/A cftype = SM_GET_RIGHT_CF;
1N/A
1N/A /* in 4.4BSD, the table can be huge; impose a reasonable limit */
1N/A DtableSize = getdtsize();
1N/A if (DtableSize > 256)
1N/A DtableSize = 256;
1N/A
1N/A /*
1N/A ** Be sure we have enough file descriptors.
1N/A ** But also be sure that 0, 1, & 2 are open.
1N/A */
1N/A
1N/A /* reset errno and fill_errno; the latter is used way down below */
1N/A errno = fill_errno = 0;
1N/A fill_fd(STDIN_FILENO, NULL);
1N/A if (errno != 0)
1N/A fill_errno = errno;
1N/A fill_fd(STDOUT_FILENO, NULL);
1N/A if (errno != 0)
1N/A fill_errno = errno;
1N/A fill_fd(STDERR_FILENO, NULL);
1N/A if (errno != 0)
1N/A fill_errno = errno;
1N/A
1N/A sm_closefrom(STDERR_FILENO + 1, DtableSize);
1N/A errno = 0;
1N/A smdebug = NULL;
1N/A
1N/A#if LOG
1N/A# ifndef SM_LOG_STR
1N/A# define SM_LOG_STR "sendmail"
1N/A# endif /* ! SM_LOG_STR */
1N/A# ifdef LOG_MAIL
1N/A openlog(SM_LOG_STR, LOG_PID, LOG_MAIL);
1N/A# else /* LOG_MAIL */
1N/A openlog(SM_LOG_STR, LOG_PID);
1N/A# endif /* LOG_MAIL */
1N/A#endif /* LOG */
1N/A
1N/A /*
1N/A ** Seed the random number generator.
1N/A ** Used for queue file names, picking a queue directory, and
1N/A ** MX randomization.
1N/A */
1N/A
1N/A seed_random();
1N/A
1N/A /* do machine-dependent initializations */
1N/A init_md(argc, argv);
1N/A
1N/A
1N/A SyslogPrefixLen = PIDLEN + (MAXQFNAME - 3) + SL_FUDGE + SLDLL;
1N/A
1N/A /* reset status from syserr() calls for missing file descriptors */
1N/A Errors = 0;
1N/A ExitStat = EX_OK;
1N/A
1N/A SubmitMode = SUBMIT_UNKNOWN;
1N/A#if _FFR_LOCAL_DAEMON
1N/A LocalDaemon = false;
1N/A# if NETINET6
1N/A V6LoopbackAddrFound = false;
1N/A# endif /* NETINET6 */
1N/A#endif /* _FFR_LOCAL_DAEMON */
1N/A#if XDEBUG
1N/A checkfd012("after openlog");
1N/A#endif /* XDEBUG */
1N/A
1N/A tTsetup(tTdvect, sizeof(tTdvect), "0-99.1,*_trace_*.1");
1N/A
1N/A#ifdef NGROUPS_MAX
1N/A /* save initial group set for future checks */
1N/A i = getgroups(NGROUPS_MAX, InitialGidSet);
1N/A if (i <= 0)
1N/A {
1N/A InitialGidSet[0] = (GID_T) -1;
1N/A i = 0;
1N/A }
1N/A while (i < NGROUPS_MAX)
1N/A InitialGidSet[i++] = InitialGidSet[0];
1N/A#endif /* NGROUPS_MAX */
1N/A
1N/A /* drop group id privileges (RunAsUser not yet set) */
1N/A dp = drop_privileges(false);
1N/A setstat(dp);
1N/A
1N/A#ifdef SIGUSR1
1N/A /* Only allow root (or non-set-*-ID binaries) to use SIGUSR1 */
1N/A if (!extraprivs)
1N/A {
1N/A /* arrange to dump state on user-1 signal */
1N/A (void) sm_signal(SIGUSR1, sigusr1);
1N/A }
1N/A else
1N/A {
1N/A /* ignore user-1 signal */
1N/A (void) sm_signal(SIGUSR1, SIG_IGN);
1N/A }
1N/A#endif /* SIGUSR1 */
1N/A
1N/A /* initialize for setproctitle */
1N/A initsetproctitle(argc, argv, envp);
1N/A
1N/A /* Handle any non-getoptable constructions. */
1N/A obsolete(argv);
1N/A
1N/A /*
1N/A ** Do a quick prescan of the argument list.
1N/A */
1N/A
1N/A
1N/A /* find initial opMode */
1N/A OpMode = MD_DELIVER;
1N/A av = argv;
1N/A p = strrchr(*av, '/');
1N/A if (p++ == NULL)
1N/A p = *av;
1N/A if (strcmp(p, "newaliases") == 0)
1N/A OpMode = MD_INITALIAS;
1N/A else if (strcmp(p, "mailq") == 0)
1N/A OpMode = MD_PRINT;
1N/A else if (strcmp(p, "smtpd") == 0)
1N/A OpMode = MD_DAEMON;
1N/A else if (strcmp(p, "hoststat") == 0)
1N/A OpMode = MD_HOSTSTAT;
1N/A else if (strcmp(p, "purgestat") == 0)
1N/A OpMode = MD_PURGESTAT;
1N/A
1N/A#if defined(__osf__) || defined(_AIX3)
1N/A# define OPTIONS "A:B:b:C:cD:d:e:F:f:Gh:IiL:M:mN:nO:o:p:Q:q:R:r:sTtV:vX:x"
1N/A#endif /* defined(__osf__) || defined(_AIX3) */
1N/A#if defined(sony_news)
1N/A# define OPTIONS "A:B:b:C:cD:d:E:e:F:f:Gh:IiJ:L:M:mN:nO:o:p:Q:q:R:r:sTtV:vX:"
1N/A#endif /* defined(sony_news) */
1N/A#ifndef OPTIONS
1N/A# define OPTIONS "A:B:b:C:cD:d:e:F:f:Gh:IiL:M:mN:nO:o:p:Q:q:R:r:sTtV:vX:"
1N/A#endif /* ! OPTIONS */
1N/A
1N/A /* Set to 0 to allow -b; need to check optarg before using it! */
1N/A opterr = 0;
1N/A while ((j = getopt(argc, argv, OPTIONS)) != -1)
1N/A {
1N/A switch (j)
1N/A {
1N/A case 'b': /* operations mode */
1N/A j = (optarg == NULL) ? ' ' : *optarg;
1N/A switch (j)
1N/A {
1N/A case MD_DAEMON:
1N/A case MD_FGDAEMON:
1N/A case MD_SMTP:
1N/A case MD_INITALIAS:
1N/A case MD_DELIVER:
1N/A case MD_VERIFY:
1N/A case MD_TEST:
1N/A case MD_PRINT:
1N/A case MD_PRINTNQE:
1N/A case MD_HOSTSTAT:
1N/A case MD_PURGESTAT:
1N/A case MD_ARPAFTP:
1N/A#if _FFR_CHECKCONFIG
1N/A case MD_CHECKCONFIG:
1N/A#endif /* _FFR_CHECKCONFIG */
1N/A OpMode = j;
1N/A break;
1N/A
1N/A#if _FFR_LOCAL_DAEMON
1N/A case MD_LOCAL:
1N/A OpMode = MD_DAEMON;
1N/A LocalDaemon = true;
1N/A break;
1N/A#endif /* _FFR_LOCAL_DAEMON */
1N/A
1N/A case MD_FREEZE:
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Frozen configurations unsupported\n");
1N/A return EX_USAGE;
1N/A
1N/A default:
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Invalid operation mode %c\n",
1N/A j);
1N/A return EX_USAGE;
1N/A }
1N/A break;
1N/A
1N/A case 'D':
1N/A if (debug)
1N/A {
1N/A errno = 0;
1N/A syserr("-D file must be before -d");
1N/A ExitStat = EX_USAGE;
1N/A break;
1N/A }
1N/A dp = drop_privileges(true);
1N/A setstat(dp);
1N/A smdebug = sm_io_open(SmFtStdio, SM_TIME_DEFAULT,
1N/A optarg, SM_IO_APPEND, NULL);
1N/A if (smdebug == NULL)
1N/A {
1N/A syserr("cannot open %s", optarg);
1N/A ExitStat = EX_CANTCREAT;
1N/A break;
1N/A }
1N/A sm_debug_setfile(smdebug);
1N/A break;
1N/A
1N/A case 'd':
1N/A debug = true;
1N/A tTflag(optarg);
1N/A (void) sm_io_setvbuf(sm_debug_file(), SM_TIME_DEFAULT,
1N/A (char *) NULL, SM_IO_NBF,
1N/A SM_IO_BUFSIZ);
1N/A break;
1N/A
1N/A case 'G': /* relay (gateway) submission */
1N/A SubmitMode = SUBMIT_MTA;
1N/A break;
1N/A
1N/A case 'L':
1N/A if (optarg == NULL)
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "option requires an argument -- '%c'",
1N/A (char) j);
1N/A return EX_USAGE;
1N/A }
1N/A j = SM_MIN(strlen(optarg), 32) + 1;
1N/A sysloglabel = xalloc(j);
1N/A (void) sm_strlcpy(sysloglabel, optarg, j);
1N/A SyslogPrefixLen = PIDLEN + (MAXQFNAME - 3) +
1N/A SL_FUDGE + j;
1N/A break;
1N/A
1N/A case 'Q':
1N/A case 'q':
1N/A /* just check if it is there */
1N/A queuerun = true;
1N/A break;
1N/A }
1N/A }
1N/A opterr = 1;
1N/A
1N/A /* Don't leak queue information via debug flags */
1N/A if (extraprivs && queuerun && debug)
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "WARNING: Can not use -d with -q. Disabling debugging.\n");
1N/A sm_debug_close();
1N/A sm_debug_setfile(NULL);
1N/A (void) memset(tTdvect, '\0', sizeof(tTdvect));
1N/A }
1N/A
1N/A#if LOG
1N/A if (sysloglabel != NULL)
1N/A {
1N/A /* Sanitize the string */
1N/A for (p = sysloglabel; *p != '\0'; p++)
1N/A {
1N/A if (!isascii(*p) || !isprint(*p) || *p == '%')
1N/A *p = '*';
1N/A }
1N/A closelog();
1N/A# ifdef LOG_MAIL
1N/A openlog(sysloglabel, LOG_PID, LOG_MAIL);
1N/A# else /* LOG_MAIL */
1N/A openlog(sysloglabel, LOG_PID);
1N/A# endif /* LOG_MAIL */
1N/A }
1N/A#endif /* LOG */
1N/A
1N/A /* set up the blank envelope */
1N/A BlankEnvelope.e_puthdr = putheader;
1N/A BlankEnvelope.e_putbody = putbody;
1N/A BlankEnvelope.e_xfp = NULL;
1N/A STRUCTCOPY(NullAddress, BlankEnvelope.e_from);
1N/A CurEnv = &BlankEnvelope;
1N/A STRUCTCOPY(NullAddress, MainEnvelope.e_from);
1N/A
1N/A /*
1N/A ** Set default values for variables.
1N/A ** These cannot be in initialized data space.
1N/A */
1N/A
1N/A setdefaults(&BlankEnvelope);
1N/A initmacros(&BlankEnvelope);
1N/A
1N/A /* reset macro */
1N/A set_op_mode(OpMode);
1N/A if (OpMode == MD_DAEMON)
1N/A DaemonPid = CurrentPid; /* needed for finis() to work */
1N/A
1N/A pw = sm_getpwuid(RealUid);
1N/A if (pw != NULL)
1N/A (void) sm_strlcpy(rnamebuf, pw->pw_name, sizeof(rnamebuf));
1N/A else
1N/A (void) sm_snprintf(rnamebuf, sizeof(rnamebuf), "Unknown UID %d",
1N/A (int) RealUid);
1N/A
1N/A RealUserName = rnamebuf;
1N/A
1N/A if (tTd(0, 101))
1N/A {
1N/A sm_dprintf("Version %s\n", Version);
1N/A finis(false, true, EX_OK);
1N/A /* NOTREACHED */
1N/A }
1N/A
1N/A /*
1N/A ** if running non-set-user-ID binary as non-root, pretend
1N/A ** we are the RunAsUid
1N/A */
1N/A
1N/A if (RealUid != 0 && geteuid() == RealUid)
1N/A {
1N/A if (tTd(47, 1))
1N/A sm_dprintf("Non-set-user-ID binary: RunAsUid = RealUid = %d\n",
1N/A (int) RealUid);
1N/A RunAsUid = RealUid;
1N/A }
1N/A else if (geteuid() != 0)
1N/A RunAsUid = geteuid();
1N/A
1N/A EffGid = getegid();
1N/A if (RealUid != 0 && EffGid == RealGid)
1N/A RunAsGid = RealGid;
1N/A
1N/A if (tTd(47, 5))
1N/A {
1N/A sm_dprintf("main: e/ruid = %d/%d e/rgid = %d/%d\n",
1N/A (int) geteuid(), (int) getuid(),
1N/A (int) getegid(), (int) getgid());
1N/A sm_dprintf("main: RunAsUser = %d:%d\n",
1N/A (int) RunAsUid, (int) RunAsGid);
1N/A }
1N/A
1N/A /* save command line arguments */
1N/A j = 0;
1N/A for (av = argv; *av != NULL; )
1N/A j += strlen(*av++) + 1;
1N/A SaveArgv = (char **) xalloc(sizeof(char *) * (argc + 1));
1N/A CommandLineArgs = xalloc(j);
1N/A p = CommandLineArgs;
1N/A for (av = argv, i = 0; *av != NULL; )
1N/A {
1N/A int h;
1N/A
1N/A SaveArgv[i++] = newstr(*av);
1N/A if (av != argv)
1N/A *p++ = ' ';
1N/A (void) sm_strlcpy(p, *av++, j);
1N/A h = strlen(p);
1N/A p += h;
1N/A j -= h + 1;
1N/A }
1N/A SaveArgv[i] = NULL;
1N/A
1N/A if (tTd(0, 1))
1N/A {
1N/A extern char *CompileOptions[];
1N/A
1N/A sm_dprintf("Version %s\n Compiled with:", Version);
1N/A sm_printoptions(CompileOptions);
1N/A }
1N/A if (tTd(0, 10))
1N/A {
1N/A extern char *OsCompileOptions[];
1N/A
1N/A sm_dprintf(" OS Defines:");
1N/A sm_printoptions(OsCompileOptions);
1N/A#ifdef _PATH_UNIX
1N/A sm_dprintf("Kernel symbols:\t%s\n", _PATH_UNIX);
1N/A#endif /* _PATH_UNIX */
1N/A
1N/A sm_dprintf(" Conf file:\t%s (default for MSP)\n",
1N/A getcfname(OpMode, SubmitMode, SM_GET_SUBMIT_CF,
1N/A conffile));
1N/A sm_dprintf(" Conf file:\t%s (default for MTA)\n",
1N/A getcfname(OpMode, SubmitMode, SM_GET_SENDMAIL_CF,
1N/A conffile));
1N/A sm_dprintf(" Pid file:\t%s (default)\n", PidFile);
1N/A }
1N/A
1N/A if (tTd(0, 12))
1N/A {
1N/A extern char *SmCompileOptions[];
1N/A
1N/A sm_dprintf(" libsm Defines:");
1N/A sm_printoptions(SmCompileOptions);
1N/A }
1N/A
1N/A if (tTd(0, 13))
1N/A {
1N/A extern char *FFRCompileOptions[];
1N/A
1N/A sm_dprintf(" FFR Defines:");
1N/A sm_printoptions(FFRCompileOptions);
1N/A }
1N/A
1N/A /* clear sendmail's environment */
1N/A ExternalEnviron = environ;
1N/A emptyenviron[0] = NULL;
1N/A environ = emptyenviron;
1N/A
1N/A /*
1N/A ** restore any original TZ setting until TimeZoneSpec has been
1N/A ** determined - or early log messages may get bogus time stamps
1N/A */
1N/A
1N/A if ((p = getextenv("TZ")) != NULL)
1N/A {
1N/A char *tz;
1N/A int tzlen;
1N/A
1N/A /* XXX check for reasonable length? */
1N/A tzlen = strlen(p) + 4;
1N/A tz = xalloc(tzlen);
1N/A (void) sm_strlcpyn(tz, tzlen, 2, "TZ=", p);
1N/A
1N/A /* XXX check return code? */
1N/A (void) putenv(tz);
1N/A }
1N/A
1N/A /* prime the child environment */
1N/A sm_setuserenv("AGENT", "sendmail");
1N/A
1N/A (void) sm_signal(SIGPIPE, SIG_IGN);
1N/A OldUmask = umask(022);
1N/A FullName = getextenv("NAME");
1N/A if (FullName != NULL)
1N/A FullName = newstr(FullName);
1N/A
1N/A /*
1N/A ** Initialize name server if it is going to be used.
1N/A */
1N/A
1N/A#if NAMED_BIND
1N/A if (!bitset(RES_INIT, _res.options))
1N/A (void) res_init();
1N/A if (tTd(8, 8))
1N/A _res.options |= RES_DEBUG;
1N/A else
1N/A _res.options &= ~RES_DEBUG;
1N/A# ifdef RES_NOALIASES
1N/A _res.options |= RES_NOALIASES;
1N/A# endif /* RES_NOALIASES */
1N/A TimeOuts.res_retry[RES_TO_DEFAULT] = _res.retry;
1N/A TimeOuts.res_retry[RES_TO_FIRST] = _res.retry;
1N/A TimeOuts.res_retry[RES_TO_NORMAL] = _res.retry;
1N/A TimeOuts.res_retrans[RES_TO_DEFAULT] = _res.retrans;
1N/A TimeOuts.res_retrans[RES_TO_FIRST] = _res.retrans;
1N/A TimeOuts.res_retrans[RES_TO_NORMAL] = _res.retrans;
1N/A#endif /* NAMED_BIND */
1N/A
1N/A errno = 0;
1N/A from = NULL;
1N/A
1N/A /* initialize some macros, etc. */
1N/A init_vendor_macros(&BlankEnvelope);
1N/A
1N/A /* version */
1N/A macdefine(&BlankEnvelope.e_macro, A_PERM, 'v', Version);
1N/A
1N/A /* hostname */
1N/A hp = myhostname(jbuf, sizeof(jbuf));
1N/A if (jbuf[0] != '\0')
1N/A {
1N/A struct utsname utsname;
1N/A
1N/A if (tTd(0, 4))
1N/A sm_dprintf("Canonical name: %s\n", jbuf);
1N/A macdefine(&BlankEnvelope.e_macro, A_TEMP, 'w', jbuf);
1N/A macdefine(&BlankEnvelope.e_macro, A_TEMP, 'j', jbuf);
1N/A setclass('w', jbuf);
1N/A
1N/A p = strchr(jbuf, '.');
1N/A if (p != NULL && p[1] != '\0')
1N/A macdefine(&BlankEnvelope.e_macro, A_TEMP, 'm', &p[1]);
1N/A
1N/A if (uname(&utsname) >= 0)
1N/A p = utsname.nodename;
1N/A else
1N/A {
1N/A if (tTd(0, 22))
1N/A sm_dprintf("uname failed (%s)\n",
1N/A sm_errstring(errno));
1N/A makelower(jbuf);
1N/A p = jbuf;
1N/A }
1N/A if (tTd(0, 4))
1N/A sm_dprintf(" UUCP nodename: %s\n", p);
1N/A macdefine(&BlankEnvelope.e_macro, A_TEMP, 'k', p);
1N/A setclass('k', p);
1N/A setclass('w', p);
1N/A }
1N/A if (hp != NULL)
1N/A {
1N/A for (av = hp->h_aliases; av != NULL && *av != NULL; av++)
1N/A {
1N/A if (tTd(0, 4))
1N/A sm_dprintf("\ta.k.a.: %s\n", *av);
1N/A setclass('w', *av);
1N/A }
1N/A#if NETINET || NETINET6
1N/A for (i = 0; i >= 0 && hp->h_addr_list[i] != NULL; i++)
1N/A {
1N/A# if NETINET6
1N/A char *addr;
1N/A char buf6[INET6_ADDRSTRLEN];
1N/A struct in6_addr ia6;
1N/A# endif /* NETINET6 */
1N/A# if NETINET
1N/A struct in_addr ia;
1N/A# endif /* NETINET */
1N/A char ipbuf[103];
1N/A
1N/A ipbuf[0] = '\0';
1N/A switch (hp->h_addrtype)
1N/A {
1N/A# if NETINET
1N/A case AF_INET:
1N/A if (hp->h_length != INADDRSZ)
1N/A break;
1N/A
1N/A memmove(&ia, hp->h_addr_list[i], INADDRSZ);
1N/A (void) sm_snprintf(ipbuf, sizeof(ipbuf),
1N/A "[%.100s]", inet_ntoa(ia));
1N/A break;
1N/A# endif /* NETINET */
1N/A
1N/A# if NETINET6
1N/A case AF_INET6:
1N/A if (hp->h_length != IN6ADDRSZ)
1N/A break;
1N/A
1N/A memmove(&ia6, hp->h_addr_list[i], IN6ADDRSZ);
1N/A addr = anynet_ntop(&ia6, buf6, sizeof(buf6));
1N/A if (addr != NULL)
1N/A (void) sm_snprintf(ipbuf, sizeof(ipbuf),
1N/A "[%.100s]", addr);
1N/A break;
1N/A# endif /* NETINET6 */
1N/A }
1N/A if (ipbuf[0] == '\0')
1N/A break;
1N/A
1N/A if (tTd(0, 4))
1N/A sm_dprintf("\ta.k.a.: %s\n", ipbuf);
1N/A setclass('w', ipbuf);
1N/A }
1N/A#endif /* NETINET || NETINET6 */
1N/A#if NETINET6
1N/A freehostent(hp);
1N/A hp = NULL;
1N/A#endif /* NETINET6 */
1N/A }
1N/A
1N/A /* current time */
1N/A macdefine(&BlankEnvelope.e_macro, A_TEMP, 'b', arpadate((char *) NULL));
1N/A
1N/A /* current load average */
1N/A sm_getla();
1N/A
1N/A QueueLimitRecipient = (QUEUE_CHAR *) NULL;
1N/A QueueLimitSender = (QUEUE_CHAR *) NULL;
1N/A QueueLimitId = (QUEUE_CHAR *) NULL;
1N/A QueueLimitQuarantine = (QUEUE_CHAR *) NULL;
1N/A
1N/A /*
1N/A ** Crack argv.
1N/A */
1N/A
1N/A optind = 1;
1N/A while ((j = getopt(argc, argv, OPTIONS)) != -1)
1N/A {
1N/A switch (j)
1N/A {
1N/A case 'b': /* operations mode */
1N/A /* already done */
1N/A break;
1N/A
1N/A case 'A': /* use Alternate sendmail/submit.cf */
1N/A cftype = optarg[0] == 'c' ? SM_GET_SUBMIT_CF
1N/A : SM_GET_SENDMAIL_CF;
1N/A break;
1N/A
1N/A case 'B': /* body type */
1N/A CHECK_AGAINST_OPMODE(j);
1N/A BlankEnvelope.e_bodytype = newstr(optarg);
1N/A break;
1N/A
1N/A case 'C': /* select configuration file (already done) */
1N/A if (RealUid != 0)
1N/A warn_C_flag = true;
1N/A conffile = newstr(optarg);
1N/A dp = drop_privileges(true);
1N/A setstat(dp);
1N/A safecf = false;
1N/A break;
1N/A
1N/A case 'D':
1N/A case 'd': /* debugging */
1N/A /* already done */
1N/A break;
1N/A
1N/A case 'f': /* from address */
1N/A case 'r': /* obsolete -f flag */
1N/A CHECK_AGAINST_OPMODE(j);
1N/A if (from != NULL)
1N/A {
1N/A usrerr("More than one \"from\" person");
1N/A ExitStat = EX_USAGE;
1N/A break;
1N/A }
1N/A if (optarg[0] == '\0')
1N/A from = newstr("<>");
1N/A else
1N/A from = newstr(denlstring(optarg, true, true));
1N/A if (strcmp(RealUserName, from) != 0)
1N/A warn_f_flag = j;
1N/A break;
1N/A
1N/A case 'F': /* set full name */
1N/A CHECK_AGAINST_OPMODE(j);
1N/A FullName = newstr(optarg);
1N/A break;
1N/A
1N/A case 'G': /* relay (gateway) submission */
1N/A /* already set */
1N/A CHECK_AGAINST_OPMODE(j);
1N/A break;
1N/A
1N/A case 'h': /* hop count */
1N/A CHECK_AGAINST_OPMODE(j);
1N/A BlankEnvelope.e_hopcount = (short) strtol(optarg, &ep,
1N/A 10);
1N/A (void) sm_snprintf(buf, sizeof(buf), "%d",
1N/A BlankEnvelope.e_hopcount);
1N/A macdefine(&BlankEnvelope.e_macro, A_TEMP, 'c', buf);
1N/A
1N/A if (*ep)
1N/A {
1N/A usrerr("Bad hop count (%s)", optarg);
1N/A ExitStat = EX_USAGE;
1N/A }
1N/A break;
1N/A
1N/A case 'L': /* program label */
1N/A /* already set */
1N/A break;
1N/A
1N/A case 'n': /* don't alias */
1N/A CHECK_AGAINST_OPMODE(j);
1N/A NoAlias = true;
1N/A break;
1N/A
1N/A case 'N': /* delivery status notifications */
1N/A CHECK_AGAINST_OPMODE(j);
1N/A DefaultNotify |= QHASNOTIFY;
1N/A macdefine(&BlankEnvelope.e_macro, A_TEMP,
1N/A macid("{dsn_notify}"), optarg);
1N/A if (sm_strcasecmp(optarg, "never") == 0)
1N/A break;
1N/A for (p = optarg; p != NULL; optarg = p)
1N/A {
1N/A p = strchr(p, ',');
1N/A if (p != NULL)
1N/A *p++ = '\0';
1N/A if (sm_strcasecmp(optarg, "success") == 0)
1N/A DefaultNotify |= QPINGONSUCCESS;
1N/A else if (sm_strcasecmp(optarg, "failure") == 0)
1N/A DefaultNotify |= QPINGONFAILURE;
1N/A else if (sm_strcasecmp(optarg, "delay") == 0)
1N/A DefaultNotify |= QPINGONDELAY;
1N/A else
1N/A {
1N/A usrerr("Invalid -N argument");
1N/A ExitStat = EX_USAGE;
1N/A }
1N/A }
1N/A break;
1N/A
1N/A case 'o': /* set option */
1N/A setoption(*optarg, optarg + 1, false, true,
1N/A &BlankEnvelope);
1N/A break;
1N/A
1N/A case 'O': /* set option (long form) */
1N/A setoption(' ', optarg, false, true, &BlankEnvelope);
1N/A break;
1N/A
1N/A case 'p': /* set protocol */
1N/A CHECK_AGAINST_OPMODE(j);
1N/A p = strchr(optarg, ':');
1N/A if (p != NULL)
1N/A {
1N/A *p++ = '\0';
1N/A if (*p != '\0')
1N/A {
1N/A i = strlen(p) + 1;
1N/A ep = sm_malloc_x(i);
1N/A cleanstrcpy(ep, p, i);
1N/A macdefine(&BlankEnvelope.e_macro,
1N/A A_HEAP, 's', ep);
1N/A }
1N/A }
1N/A if (*optarg != '\0')
1N/A {
1N/A i = strlen(optarg) + 1;
1N/A ep = sm_malloc_x(i);
1N/A cleanstrcpy(ep, optarg, i);
1N/A macdefine(&BlankEnvelope.e_macro, A_HEAP,
1N/A 'r', ep);
1N/A }
1N/A break;
1N/A
1N/A case 'Q': /* change quarantining on queued items */
1N/A /* sanity check */
1N/A if (OpMode != MD_DELIVER &&
1N/A OpMode != MD_QUEUERUN)
1N/A {
1N/A usrerr("Can not use -Q with -b%c", OpMode);
1N/A ExitStat = EX_USAGE;
1N/A break;
1N/A }
1N/A
1N/A if (OpMode == MD_DELIVER)
1N/A set_op_mode(MD_QUEUERUN);
1N/A
1N/A FullName = NULL;
1N/A
1N/A quarantining = newstr(optarg);
1N/A break;
1N/A
1N/A case 'q': /* run queue files at intervals */
1N/A /* sanity check */
1N/A if (OpMode != MD_DELIVER &&
1N/A OpMode != MD_DAEMON &&
1N/A OpMode != MD_FGDAEMON &&
1N/A OpMode != MD_PRINT &&
1N/A OpMode != MD_PRINTNQE &&
1N/A OpMode != MD_QUEUERUN)
1N/A {
1N/A usrerr("Can not use -q with -b%c", OpMode);
1N/A ExitStat = EX_USAGE;
1N/A break;
1N/A }
1N/A
1N/A /* don't override -bd, -bD or -bp */
1N/A if (OpMode == MD_DELIVER)
1N/A set_op_mode(MD_QUEUERUN);
1N/A
1N/A FullName = NULL;
1N/A negate = optarg[0] == '!';
1N/A if (negate)
1N/A {
1N/A /* negate meaning of pattern match */
1N/A optarg++; /* skip '!' for next switch */
1N/A }
1N/A
1N/A switch (optarg[0])
1N/A {
1N/A case 'G': /* Limit by queue group name */
1N/A if (negate)
1N/A {
1N/A usrerr("Can not use -q!G");
1N/A ExitStat = EX_USAGE;
1N/A break;
1N/A }
1N/A if (queuegroup != NULL)
1N/A {
1N/A usrerr("Can not use multiple -qG options");
1N/A ExitStat = EX_USAGE;
1N/A break;
1N/A }
1N/A queuegroup = newstr(&optarg[1]);
1N/A break;
1N/A
1N/A case 'I': /* Limit by ID */
1N/A new = (QUEUE_CHAR *) xalloc(sizeof(*new));
1N/A new->queue_match = newstr(&optarg[1]);
1N/A new->queue_negate = negate;
1N/A new->queue_next = QueueLimitId;
1N/A QueueLimitId = new;
1N/A break;
1N/A
1N/A case 'R': /* Limit by recipient */
1N/A new = (QUEUE_CHAR *) xalloc(sizeof(*new));
1N/A new->queue_match = newstr(&optarg[1]);
1N/A new->queue_negate = negate;
1N/A new->queue_next = QueueLimitRecipient;
1N/A QueueLimitRecipient = new;
1N/A break;
1N/A
1N/A case 'S': /* Limit by sender */
1N/A new = (QUEUE_CHAR *) xalloc(sizeof(*new));
1N/A new->queue_match = newstr(&optarg[1]);
1N/A new->queue_negate = negate;
1N/A new->queue_next = QueueLimitSender;
1N/A QueueLimitSender = new;
1N/A break;
1N/A
1N/A case 'f': /* foreground queue run */
1N/A foregroundqueue = true;
1N/A break;
1N/A
1N/A case 'Q': /* Limit by quarantine message */
1N/A if (optarg[1] != '\0')
1N/A {
1N/A new = (QUEUE_CHAR *) xalloc(sizeof(*new));
1N/A new->queue_match = newstr(&optarg[1]);
1N/A new->queue_negate = negate;
1N/A new->queue_next = QueueLimitQuarantine;
1N/A QueueLimitQuarantine = new;
1N/A }
1N/A QueueMode = QM_QUARANTINE;
1N/A break;
1N/A
1N/A case 'L': /* act on lost items */
1N/A QueueMode = QM_LOST;
1N/A break;
1N/A
1N/A case 'p': /* Persistent queue */
1N/A queuepersistent = true;
1N/A if (QueueIntvl == 0)
1N/A QueueIntvl = 1;
1N/A if (optarg[1] == '\0')
1N/A break;
1N/A ++optarg;
1N/A /* FALLTHROUGH */
1N/A
1N/A default:
1N/A i = Errors;
1N/A QueueIntvl = convtime(optarg, 'm');
1N/A if (QueueIntvl < 0)
1N/A {
1N/A usrerr("Invalid -q value");
1N/A ExitStat = EX_USAGE;
1N/A }
1N/A
1N/A /* check for bad conversion */
1N/A if (i < Errors)
1N/A ExitStat = EX_USAGE;
1N/A break;
1N/A }
1N/A break;
1N/A
1N/A case 'R': /* DSN RET: what to return */
1N/A CHECK_AGAINST_OPMODE(j);
1N/A if (bitset(EF_RET_PARAM, BlankEnvelope.e_flags))
1N/A {
1N/A usrerr("Duplicate -R flag");
1N/A ExitStat = EX_USAGE;
1N/A break;
1N/A }
1N/A BlankEnvelope.e_flags |= EF_RET_PARAM;
1N/A if (sm_strcasecmp(optarg, "hdrs") == 0)
1N/A BlankEnvelope.e_flags |= EF_NO_BODY_RETN;
1N/A else if (sm_strcasecmp(optarg, "full") != 0)
1N/A {
1N/A usrerr("Invalid -R value");
1N/A ExitStat = EX_USAGE;
1N/A }
1N/A macdefine(&BlankEnvelope.e_macro, A_TEMP,
1N/A macid("{dsn_ret}"), optarg);
1N/A break;
1N/A
1N/A case 't': /* read recipients from message */
1N/A CHECK_AGAINST_OPMODE(j);
1N/A GrabTo = true;
1N/A break;
1N/A
1N/A case 'V': /* DSN ENVID: set "original" envelope id */
1N/A CHECK_AGAINST_OPMODE(j);
1N/A if (!xtextok(optarg))
1N/A {
1N/A usrerr("Invalid syntax in -V flag");
1N/A ExitStat = EX_USAGE;
1N/A }
1N/A else
1N/A {
1N/A BlankEnvelope.e_envid = newstr(optarg);
1N/A macdefine(&BlankEnvelope.e_macro, A_TEMP,
1N/A macid("{dsn_envid}"), optarg);
1N/A }
1N/A break;
1N/A
1N/A case 'X': /* traffic log file */
1N/A dp = drop_privileges(true);
1N/A setstat(dp);
1N/A if (stat(optarg, &traf_st) == 0 &&
1N/A S_ISFIFO(traf_st.st_mode))
1N/A TrafficLogFile = sm_io_open(SmFtStdio,
1N/A SM_TIME_DEFAULT,
1N/A optarg,
1N/A SM_IO_WRONLY, NULL);
1N/A else
1N/A TrafficLogFile = sm_io_open(SmFtStdio,
1N/A SM_TIME_DEFAULT,
1N/A optarg,
1N/A SM_IO_APPEND, NULL);
1N/A if (TrafficLogFile == NULL)
1N/A {
1N/A syserr("cannot open %s", optarg);
1N/A ExitStat = EX_CANTCREAT;
1N/A break;
1N/A }
1N/A (void) sm_io_setvbuf(TrafficLogFile, SM_TIME_DEFAULT,
1N/A NULL, SM_IO_LBF, 0);
1N/A break;
1N/A
1N/A /* compatibility flags */
1N/A case 'c': /* connect to non-local mailers */
1N/A case 'i': /* don't let dot stop me */
1N/A case 'm': /* send to me too */
1N/A case 'T': /* set timeout interval */
1N/A case 'v': /* give blow-by-blow description */
1N/A setoption(j, "T", false, true, &BlankEnvelope);
1N/A break;
1N/A
1N/A case 'e': /* error message disposition */
1N/A case 'M': /* define macro */
1N/A setoption(j, optarg, false, true, &BlankEnvelope);
1N/A break;
1N/A
1N/A case 's': /* save From lines in headers */
1N/A setoption('f', "T", false, true, &BlankEnvelope);
1N/A break;
1N/A
1N/A#ifdef DBM
1N/A case 'I': /* initialize alias DBM file */
1N/A set_op_mode(MD_INITALIAS);
1N/A break;
1N/A#endif /* DBM */
1N/A
1N/A#if defined(__osf__) || defined(_AIX3)
1N/A case 'x': /* random flag that OSF/1 & AIX mailx passes */
1N/A break;
1N/A#endif /* defined(__osf__) || defined(_AIX3) */
1N/A#if defined(sony_news)
1N/A case 'E':
1N/A case 'J': /* ignore flags for Japanese code conversion
1N/A implemented on Sony NEWS */
1N/A break;
1N/A#endif /* defined(sony_news) */
1N/A
1N/A default:
1N/A finis(true, true, EX_USAGE);
1N/A /* NOTREACHED */
1N/A break;
1N/A }
1N/A }
1N/A
1N/A /* if we've had errors so far, exit now */
1N/A if ((ExitStat != EX_OK && OpMode != MD_TEST && OpMode != MD_CHECKCONFIG) ||
1N/A ExitStat == EX_OSERR)
1N/A {
1N/A finis(false, true, ExitStat);
1N/A /* NOTREACHED */
1N/A }
1N/A
1N/A if (bitset(SUBMIT_MTA, SubmitMode))
1N/A {
1N/A /* If set daemon_flags on command line, don't reset it */
1N/A if (macvalue(macid("{daemon_flags}"), &BlankEnvelope) == NULL)
1N/A macdefine(&BlankEnvelope.e_macro, A_PERM,
1N/A macid("{daemon_flags}"), "CC f");
1N/A }
1N/A else if (OpMode == MD_DELIVER || OpMode == MD_SMTP)
1N/A {
1N/A SubmitMode = SUBMIT_MSA;
1N/A
1N/A /* If set daemon_flags on command line, don't reset it */
1N/A if (macvalue(macid("{daemon_flags}"), &BlankEnvelope) == NULL)
1N/A macdefine(&BlankEnvelope.e_macro, A_PERM,
1N/A macid("{daemon_flags}"), "c u");
1N/A }
1N/A
1N/A /*
1N/A ** Do basic initialization.
1N/A ** Read system control file.
1N/A ** Extract special fields for local use.
1N/A */
1N/A
1N/A#if XDEBUG
1N/A checkfd012("before readcf");
1N/A#endif /* XDEBUG */
1N/A vendor_pre_defaults(&BlankEnvelope);
1N/A
1N/A readcf(getcfname(OpMode, SubmitMode, cftype, conffile),
1N/A safecf, &BlankEnvelope);
1N/A#if !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_)
1N/A ConfigFileRead = true;
1N/A#endif /* !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_) */
1N/A vendor_post_defaults(&BlankEnvelope);
1N/A
1N/A /* now we can complain about missing fds */
1N/A if (MissingFds != 0 && LogLevel > 8)
1N/A {
1N/A char mbuf[MAXLINE];
1N/A
1N/A mbuf[0] = '\0';
1N/A if (bitset(1 << STDIN_FILENO, MissingFds))
1N/A (void) sm_strlcat(mbuf, ", stdin", sizeof(mbuf));
1N/A if (bitset(1 << STDOUT_FILENO, MissingFds))
1N/A (void) sm_strlcat(mbuf, ", stdout", sizeof(mbuf));
1N/A if (bitset(1 << STDERR_FILENO, MissingFds))
1N/A (void) sm_strlcat(mbuf, ", stderr", sizeof(mbuf));
1N/A
1N/A /* Notice: fill_errno is from high above: fill_fd() */
1N/A sm_syslog(LOG_WARNING, NOQID,
1N/A "File descriptors missing on startup: %s; %s",
1N/A &mbuf[2], sm_errstring(fill_errno));
1N/A }
1N/A
1N/A /* Remove the ability for a normal user to send signals */
1N/A if (RealUid != 0 && RealUid != geteuid())
1N/A {
1N/A uid_t new_uid = geteuid();
1N/A
1N/A#if HASSETREUID
1N/A /*
1N/A ** Since we can differentiate between uid and euid,
1N/A ** make the uid a different user so the real user
1N/A ** can't send signals. However, it doesn't need to be
1N/A ** root (euid has root).
1N/A */
1N/A
1N/A if (new_uid == 0)
1N/A new_uid = DefUid;
1N/A if (tTd(47, 5))
1N/A sm_dprintf("Changing real uid to %d\n", (int) new_uid);
1N/A if (setreuid(new_uid, geteuid()) < 0)
1N/A {
1N/A syserr("main: setreuid(%d, %d) failed",
1N/A (int) new_uid, (int) geteuid());
1N/A finis(false, true, EX_OSERR);
1N/A /* NOTREACHED */
1N/A }
1N/A if (tTd(47, 10))
1N/A sm_dprintf("Now running as e/ruid %d:%d\n",
1N/A (int) geteuid(), (int) getuid());
1N/A#else /* HASSETREUID */
1N/A /*
1N/A ** Have to change both effective and real so need to
1N/A ** change them both to effective to keep privs.
1N/A */
1N/A
1N/A if (tTd(47, 5))
1N/A sm_dprintf("Changing uid to %d\n", (int) new_uid);
1N/A if (setuid(new_uid) < 0)
1N/A {
1N/A syserr("main: setuid(%d) failed", (int) new_uid);
1N/A finis(false, true, EX_OSERR);
1N/A /* NOTREACHED */
1N/A }
1N/A if (tTd(47, 10))
1N/A sm_dprintf("Now running as e/ruid %d:%d\n",
1N/A (int) geteuid(), (int) getuid());
1N/A#endif /* HASSETREUID */
1N/A }
1N/A
1N/A#if NAMED_BIND
1N/A if (FallbackMX != NULL)
1N/A (void) getfallbackmxrr(FallbackMX);
1N/A#endif /* NAMED_BIND */
1N/A
1N/A if (SuperSafe == SAFE_INTERACTIVE && !SM_IS_INTERACTIVE(CurEnv->e_sendmode))
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "WARNING: SuperSafe=interactive should only be used with\n DeliveryMode=interactive\n");
1N/A }
1N/A
1N/A if (UseMSP && (OpMode == MD_DAEMON || OpMode == MD_FGDAEMON))
1N/A {
1N/A usrerr("Mail submission program cannot be used as daemon");
1N/A finis(false, true, EX_USAGE);
1N/A }
1N/A
1N/A if (OpMode == MD_DELIVER || OpMode == MD_SMTP ||
1N/A OpMode == MD_QUEUERUN || OpMode == MD_ARPAFTP ||
1N/A OpMode == MD_DAEMON || OpMode == MD_FGDAEMON)
1N/A makeworkgroups();
1N/A
1N/A /* set up the basic signal handlers */
1N/A if (sm_signal(SIGINT, SIG_IGN) != SIG_IGN)
1N/A (void) sm_signal(SIGINT, intsig);
1N/A (void) sm_signal(SIGTERM, intsig);
1N/A
1N/A /* Enforce use of local time (null string overrides this) */
1N/A if (TimeZoneSpec == NULL)
1N/A unsetenv("TZ");
1N/A else if (TimeZoneSpec[0] != '\0')
1N/A sm_setuserenv("TZ", TimeZoneSpec);
1N/A else
1N/A sm_setuserenv("TZ", NULL);
1N/A tzset();
1N/A
1N/A /* initialize mailbox database */
1N/A i = sm_mbdb_initialize(Mbdb);
1N/A if (i != EX_OK)
1N/A {
1N/A usrerr("Can't initialize mailbox database \"%s\": %s",
1N/A Mbdb, sm_strexit(i));
1N/A ExitStat = i;
1N/A }
1N/A
1N/A /* avoid denial-of-service attacks */
1N/A resetlimits();
1N/A
1N/A if (OpMode == MD_TEST)
1N/A {
1N/A /* can't be done after readcf if RunAs* is used */
1N/A dp = drop_privileges(true);
1N/A if (dp != EX_OK)
1N/A {
1N/A finis(false, true, dp);
1N/A /* NOTREACHED */
1N/A }
1N/A }
1N/A else if (OpMode != MD_DAEMON && OpMode != MD_FGDAEMON)
1N/A {
1N/A /* drop privileges -- daemon mode done after socket/bind */
1N/A dp = drop_privileges(false);
1N/A setstat(dp);
1N/A if (dp == EX_OK && UseMSP && (geteuid() == 0 || getuid() == 0))
1N/A {
1N/A usrerr("Mail submission program must have RunAsUser set to non root user");
1N/A finis(false, true, EX_CONFIG);
1N/A /* NOTREACHED */
1N/A }
1N/A }
1N/A
1N/A#if NAMED_BIND
1N/A _res.retry = TimeOuts.res_retry[RES_TO_DEFAULT];
1N/A _res.retrans = TimeOuts.res_retrans[RES_TO_DEFAULT];
1N/A#endif /* NAMED_BIND */
1N/A
1N/A /*
1N/A ** Find our real host name for future logging.
1N/A */
1N/A
1N/A authinfo = getauthinfo(STDIN_FILENO, &forged);
1N/A macdefine(&BlankEnvelope.e_macro, A_TEMP, '_', authinfo);
1N/A
1N/A /* suppress error printing if errors mailed back or whatever */
1N/A if (BlankEnvelope.e_errormode != EM_PRINT)
1N/A HoldErrs = true;
1N/A
1N/A /* set up the $=m class now, after .cf has a chance to redefine $m */
1N/A expand("\201m", jbuf, sizeof(jbuf), &BlankEnvelope);
1N/A if (jbuf[0] != '\0')
1N/A setclass('m', jbuf);
1N/A
1N/A /* probe interfaces and locate any additional names */
1N/A if (DontProbeInterfaces != DPI_PROBENONE)
1N/A load_if_names();
1N/A
1N/A if (tTd(0, 10))
1N/A {
1N/A char pidpath[MAXPATHLEN];
1N/A
1N/A /* Now we know which .cf file we use */
1N/A sm_dprintf(" Conf file:\t%s (selected)\n",
1N/A getcfname(OpMode, SubmitMode, cftype, conffile));
1N/A expand(PidFile, pidpath, sizeof(pidpath), &BlankEnvelope);
1N/A sm_dprintf(" Pid file:\t%s (selected)\n", pidpath);
1N/A }
1N/A
1N/A if (tTd(0, 1))
1N/A {
1N/A sm_dprintf("\n============ SYSTEM IDENTITY (after readcf) ============");
1N/A sm_dprintf("\n (short domain name) $w = ");
1N/A xputs(sm_debug_file(), macvalue('w', &BlankEnvelope));
1N/A sm_dprintf("\n (canonical domain name) $j = ");
1N/A xputs(sm_debug_file(), macvalue('j', &BlankEnvelope));
1N/A sm_dprintf("\n (subdomain name) $m = ");
1N/A xputs(sm_debug_file(), macvalue('m', &BlankEnvelope));
1N/A sm_dprintf("\n (node name) $k = ");
1N/A xputs(sm_debug_file(), macvalue('k', &BlankEnvelope));
1N/A sm_dprintf("\n========================================================\n\n");
1N/A }
1N/A
1N/A /*
1N/A ** Do more command line checking -- these are things that
1N/A ** have to modify the results of reading the config file.
1N/A */
1N/A
1N/A /* process authorization warnings from command line */
1N/A if (warn_C_flag)
1N/A auth_warning(&BlankEnvelope, "Processed by %s with -C %s",
1N/A RealUserName, conffile);
1N/A if (Warn_Q_option && !wordinclass(RealUserName, 't'))
1N/A auth_warning(&BlankEnvelope, "Processed from queue %s",
1N/A QueueDir);
1N/A if (sysloglabel != NULL && !wordinclass(RealUserName, 't') &&
1N/A RealUid != 0 && RealUid != TrustedUid && LogLevel > 1)
1N/A sm_syslog(LOG_WARNING, NOQID, "user %d changed syslog label",
1N/A (int) RealUid);
1N/A
1N/A /* check body type for legality */
1N/A i = check_bodytype(BlankEnvelope.e_bodytype);
1N/A if (i == BODYTYPE_ILLEGAL)
1N/A {
1N/A usrerr("Illegal body type %s", BlankEnvelope.e_bodytype);
1N/A BlankEnvelope.e_bodytype = NULL;
1N/A }
1N/A else if (i != BODYTYPE_NONE)
1N/A SevenBitInput = (i == BODYTYPE_7BIT);
1N/A
1N/A /* tweak default DSN notifications */
1N/A if (DefaultNotify == 0)
1N/A DefaultNotify = QPINGONFAILURE|QPINGONDELAY;
1N/A
1N/A /* check for sane configuration level */
1N/A if (ConfigLevel > MAXCONFIGLEVEL)
1N/A {
1N/A syserr("Warning: .cf version level (%d) exceeds sendmail version %s functionality (%d)",
1N/A ConfigLevel, Version, MAXCONFIGLEVEL);
1N/A }
1N/A
1N/A /* need MCI cache to have persistence */
1N/A if (HostStatDir != NULL && MaxMciCache == 0)
1N/A {
1N/A HostStatDir = NULL;
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Warning: HostStatusDirectory disabled with ConnectionCacheSize = 0\n");
1N/A }
1N/A
1N/A /* need HostStatusDir in order to have SingleThreadDelivery */
1N/A if (SingleThreadDelivery && HostStatDir == NULL)
1N/A {
1N/A SingleThreadDelivery = false;
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Warning: HostStatusDirectory required for SingleThreadDelivery\n");
1N/A }
1N/A
1N/A#if _FFR_MEMSTAT
1N/A j = sm_memstat_open();
1N/A if (j < 0 && (RefuseLowMem > 0 || QueueLowMem > 0) && LogLevel > 4)
1N/A {
1N/A sm_syslog(LOG_WARNING, NOQID,
1N/A "cannot get memory statistics, settings ignored, error=%d"
1N/A , j);
1N/A }
1N/A#endif /* _FFR_MEMSTAT */
1N/A
1N/A /* check for permissions */
1N/A if (RealUid != 0 &&
1N/A RealUid != TrustedUid)
1N/A {
1N/A char *action = NULL;
1N/A
1N/A switch (OpMode)
1N/A {
1N/A case MD_QUEUERUN:
1N/A if (quarantining != NULL)
1N/A action = "quarantine jobs";
1N/A else
1N/A {
1N/A /* Normal users can do a single queue run */
1N/A if (QueueIntvl == 0)
1N/A break;
1N/A }
1N/A
1N/A /* but not persistent queue runners */
1N/A if (action == NULL)
1N/A action = "start a queue runner daemon";
1N/A /* FALLTHROUGH */
1N/A
1N/A case MD_PURGESTAT:
1N/A if (action == NULL)
1N/A action = "purge host status";
1N/A /* FALLTHROUGH */
1N/A
1N/A case MD_DAEMON:
1N/A case MD_FGDAEMON:
1N/A if (action == NULL)
1N/A action = "run daemon";
1N/A
1N/A if (tTd(65, 1))
1N/A sm_dprintf("Deny user %d attempt to %s\n",
1N/A (int) RealUid, action);
1N/A
1N/A if (LogLevel > 1)
1N/A sm_syslog(LOG_ALERT, NOQID,
1N/A "user %d attempted to %s",
1N/A (int) RealUid, action);
1N/A HoldErrs = false;
1N/A usrerr("Permission denied (real uid not trusted)");
1N/A finis(false, true, EX_USAGE);
1N/A /* NOTREACHED */
1N/A break;
1N/A
1N/A case MD_VERIFY:
1N/A if (bitset(PRIV_RESTRICTEXPAND, PrivacyFlags))
1N/A {
1N/A /*
1N/A ** If -bv and RestrictExpand,
1N/A ** drop privs to prevent normal
1N/A ** users from reading private
1N/A ** aliases/forwards/:include:s
1N/A */
1N/A
1N/A if (tTd(65, 1))
1N/A sm_dprintf("Drop privs for user %d attempt to expand (RestrictExpand)\n",
1N/A (int) RealUid);
1N/A
1N/A dp = drop_privileges(true);
1N/A
1N/A /* Fake address safety */
1N/A if (tTd(65, 1))
1N/A sm_dprintf("Faking DontBlameSendmail=NonRootSafeAddr\n");
1N/A setbitn(DBS_NONROOTSAFEADDR, DontBlameSendmail);
1N/A
1N/A if (dp != EX_OK)
1N/A {
1N/A if (tTd(65, 1))
1N/A sm_dprintf("Failed to drop privs for user %d attempt to expand, exiting\n",
1N/A (int) RealUid);
1N/A CurEnv->e_id = NULL;
1N/A finis(true, true, dp);
1N/A /* NOTREACHED */
1N/A }
1N/A }
1N/A break;
1N/A
1N/A case MD_TEST:
1N/A case MD_CHECKCONFIG:
1N/A case MD_PRINT:
1N/A case MD_PRINTNQE:
1N/A case MD_FREEZE:
1N/A case MD_HOSTSTAT:
1N/A /* Nothing special to check */
1N/A break;
1N/A
1N/A case MD_INITALIAS:
1N/A if (!wordinclass(RealUserName, 't'))
1N/A {
1N/A if (tTd(65, 1))
1N/A sm_dprintf("Deny user %d attempt to rebuild the alias map\n",
1N/A (int) RealUid);
1N/A if (LogLevel > 1)
1N/A sm_syslog(LOG_ALERT, NOQID,
1N/A "user %d attempted to rebuild the alias map",
1N/A (int) RealUid);
1N/A HoldErrs = false;
1N/A usrerr("Permission denied (real uid not trusted)");
1N/A finis(false, true, EX_USAGE);
1N/A /* NOTREACHED */
1N/A }
1N/A if (UseMSP)
1N/A {
1N/A HoldErrs = false;
1N/A usrerr("User %d cannot rebuild aliases in mail submission program",
1N/A (int) RealUid);
1N/A finis(false, true, EX_USAGE);
1N/A /* NOTREACHED */
1N/A }
1N/A /* FALLTHROUGH */
1N/A
1N/A default:
1N/A if (bitset(PRIV_RESTRICTEXPAND, PrivacyFlags) &&
1N/A Verbose != 0)
1N/A {
1N/A /*
1N/A ** If -v and RestrictExpand, reset
1N/A ** Verbose to prevent normal users
1N/A ** from seeing the expansion of
1N/A ** aliases/forwards/:include:s
1N/A */
1N/A
1N/A if (tTd(65, 1))
1N/A sm_dprintf("Dropping verbosity for user %d (RestrictExpand)\n",
1N/A (int) RealUid);
1N/A Verbose = 0;
1N/A }
1N/A break;
1N/A }
1N/A }
1N/A
1N/A if (MeToo)
1N/A BlankEnvelope.e_flags |= EF_METOO;
1N/A
1N/A switch (OpMode)
1N/A {
1N/A case MD_TEST:
1N/A /* don't have persistent host status in test mode */
1N/A HostStatDir = NULL;
1N/A /* FALLTHROUGH */
1N/A
1N/A case MD_CHECKCONFIG:
1N/A if (Verbose == 0)
1N/A Verbose = 2;
1N/A BlankEnvelope.e_errormode = EM_PRINT;
1N/A HoldErrs = false;
1N/A break;
1N/A
1N/A case MD_VERIFY:
1N/A BlankEnvelope.e_errormode = EM_PRINT;
1N/A HoldErrs = false;
1N/A /* arrange to exit cleanly on hangup signal */
1N/A if (sm_signal(SIGHUP, SIG_IGN) == (sigfunc_t) SIG_DFL)
1N/A (void) sm_signal(SIGHUP, intsig);
1N/A if (geteuid() != 0)
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Notice: -bv may give misleading output for non-privileged user\n");
1N/A break;
1N/A
1N/A case MD_FGDAEMON:
1N/A run_in_foreground = true;
1N/A set_op_mode(MD_DAEMON);
1N/A /* FALLTHROUGH */
1N/A
1N/A case MD_DAEMON:
1N/A vendor_daemon_setup(&BlankEnvelope);
1N/A
1N/A /* remove things that don't make sense in daemon mode */
1N/A FullName = NULL;
1N/A GrabTo = false;
1N/A
1N/A /* arrange to restart on hangup signal */
1N/A if (SaveArgv[0] == NULL || SaveArgv[0][0] != '/')
1N/A sm_syslog(LOG_WARNING, NOQID,
1N/A "daemon invoked without full pathname; kill -1 won't work");
1N/A break;
1N/A
1N/A case MD_INITALIAS:
1N/A Verbose = 2;
1N/A BlankEnvelope.e_errormode = EM_PRINT;
1N/A HoldErrs = false;
1N/A /* FALLTHROUGH */
1N/A
1N/A default:
1N/A /* arrange to exit cleanly on hangup signal */
1N/A if (sm_signal(SIGHUP, SIG_IGN) == (sigfunc_t) SIG_DFL)
1N/A (void) sm_signal(SIGHUP, intsig);
1N/A break;
1N/A }
1N/A
1N/A /* special considerations for FullName */
1N/A if (FullName != NULL)
1N/A {
1N/A char *full = NULL;
1N/A
1N/A /* full names can't have newlines */
1N/A if (strchr(FullName, '\n') != NULL)
1N/A {
1N/A full = newstr(denlstring(FullName, true, true));
1N/A FullName = full;
1N/A }
1N/A
1N/A /* check for characters that may have to be quoted */
1N/A if (!rfc822_string(FullName))
1N/A {
1N/A /*
1N/A ** Quote a full name with special characters
1N/A ** as a comment so crackaddr() doesn't destroy
1N/A ** the name portion of the address.
1N/A */
1N/A
1N/A FullName = addquotes(FullName, NULL);
1N/A if (full != NULL)
1N/A sm_free(full); /* XXX */
1N/A }
1N/A }
1N/A
1N/A /* do heuristic mode adjustment */
1N/A if (Verbose)
1N/A {
1N/A /* turn off noconnect option */
1N/A setoption('c', "F", true, false, &BlankEnvelope);
1N/A
1N/A /* turn on interactive delivery */
1N/A setoption('d', "", true, false, &BlankEnvelope);
1N/A }
1N/A
1N/A#ifdef VENDOR_CODE
1N/A /* check for vendor mismatch */
1N/A if (VendorCode != VENDOR_CODE)
1N/A {
1N/A message("Warning: .cf file vendor code mismatch: sendmail expects vendor %s, .cf file vendor is %s",
1N/A getvendor(VENDOR_CODE), getvendor(VendorCode));
1N/A }
1N/A#endif /* VENDOR_CODE */
1N/A
1N/A /* check for out of date configuration level */
1N/A if (ConfigLevel < MAXCONFIGLEVEL)
1N/A {
1N/A message("Warning: .cf file is out of date: sendmail %s supports version %d, .cf file is version %d",
1N/A Version, MAXCONFIGLEVEL, ConfigLevel);
1N/A }
1N/A
1N/A if (ConfigLevel < 3)
1N/A UseErrorsTo = true;
1N/A
1N/A /* set options that were previous macros */
1N/A if (SmtpGreeting == NULL)
1N/A {
1N/A if (ConfigLevel < 7 &&
1N/A (p = macvalue('e', &BlankEnvelope)) != NULL)
1N/A SmtpGreeting = newstr(p);
1N/A else
1N/A SmtpGreeting = "\201j Sendmail \201v ready at \201b";
1N/A }
1N/A if (UnixFromLine == NULL)
1N/A {
1N/A if (ConfigLevel < 7 &&
1N/A (p = macvalue('l', &BlankEnvelope)) != NULL)
1N/A UnixFromLine = newstr(p);
1N/A else
1N/A UnixFromLine = "From \201g \201d";
1N/A }
1N/A SmtpError[0] = '\0';
1N/A
1N/A /* our name for SMTP codes */
1N/A expand("\201j", jbuf, sizeof(jbuf), &BlankEnvelope);
1N/A if (jbuf[0] == '\0')
1N/A PSTRSET(MyHostName, "localhost");
1N/A else
1N/A PSTRSET(MyHostName, jbuf);
1N/A if (strchr(MyHostName, '.') == NULL)
1N/A message("WARNING: local host name (%s) is not qualified; see cf/README: WHO AM I?",
1N/A MyHostName);
1N/A
1N/A /* make certain that this name is part of the $=w class */
1N/A setclass('w', MyHostName);
1N/A
1N/A /* fill in the structure of the *default* queue */
1N/A st = stab("mqueue", ST_QUEUE, ST_FIND);
1N/A if (st == NULL)
1N/A syserr("No default queue (mqueue) defined");
1N/A else
1N/A set_def_queueval(st->s_quegrp, true);
1N/A
1N/A /* the indices of built-in mailers */
1N/A st = stab("local", ST_MAILER, ST_FIND);
1N/A if (st != NULL)
1N/A LocalMailer = st->s_mailer;
1N/A else if (OpMode != MD_TEST || !warn_C_flag)
1N/A syserr("No local mailer defined");
1N/A
1N/A st = stab("prog", ST_MAILER, ST_FIND);
1N/A if (st == NULL)
1N/A syserr("No prog mailer defined");
1N/A else
1N/A {
1N/A ProgMailer = st->s_mailer;
1N/A clrbitn(M_MUSER, ProgMailer->m_flags);
1N/A }
1N/A
1N/A st = stab("*file*", ST_MAILER, ST_FIND);
1N/A if (st == NULL)
1N/A syserr("No *file* mailer defined");
1N/A else
1N/A {
1N/A FileMailer = st->s_mailer;
1N/A clrbitn(M_MUSER, FileMailer->m_flags);
1N/A }
1N/A
1N/A st = stab("*include*", ST_MAILER, ST_FIND);
1N/A if (st == NULL)
1N/A syserr("No *include* mailer defined");
1N/A else
1N/A InclMailer = st->s_mailer;
1N/A
1N/A if (ConfigLevel < 6)
1N/A {
1N/A /* heuristic tweaking of local mailer for back compat */
1N/A if (LocalMailer != NULL)
1N/A {
1N/A setbitn(M_ALIASABLE, LocalMailer->m_flags);
1N/A setbitn(M_HASPWENT, LocalMailer->m_flags);
1N/A setbitn(M_TRYRULESET5, LocalMailer->m_flags);
1N/A setbitn(M_CHECKINCLUDE, LocalMailer->m_flags);
1N/A setbitn(M_CHECKPROG, LocalMailer->m_flags);
1N/A setbitn(M_CHECKFILE, LocalMailer->m_flags);
1N/A setbitn(M_CHECKUDB, LocalMailer->m_flags);
1N/A }
1N/A if (ProgMailer != NULL)
1N/A setbitn(M_RUNASRCPT, ProgMailer->m_flags);
1N/A if (FileMailer != NULL)
1N/A setbitn(M_RUNASRCPT, FileMailer->m_flags);
1N/A }
1N/A if (ConfigLevel < 7)
1N/A {
1N/A if (LocalMailer != NULL)
1N/A setbitn(M_VRFY250, LocalMailer->m_flags);
1N/A if (ProgMailer != NULL)
1N/A setbitn(M_VRFY250, ProgMailer->m_flags);
1N/A if (FileMailer != NULL)
1N/A setbitn(M_VRFY250, FileMailer->m_flags);
1N/A }
1N/A
1N/A /* MIME Content-Types that cannot be transfer encoded */
1N/A setclass('n', "multipart/signed");
1N/A
1N/A /* MIME message/xxx subtypes that can be treated as messages */
1N/A setclass('s', "rfc822");
1N/A
1N/A /* MIME Content-Transfer-Encodings that can be encoded */
1N/A setclass('e', "7bit");
1N/A setclass('e', "8bit");
1N/A setclass('e', "binary");
1N/A
1N/A#ifdef USE_B_CLASS
1N/A /* MIME Content-Types that should be treated as binary */
1N/A setclass('b', "image");
1N/A setclass('b', "audio");
1N/A setclass('b', "video");
1N/A setclass('b', "application/octet-stream");
1N/A#endif /* USE_B_CLASS */
1N/A
1N/A /* MIME headers which have fields to check for overflow */
1N/A setclass(macid("{checkMIMEFieldHeaders}"), "content-disposition");
1N/A setclass(macid("{checkMIMEFieldHeaders}"), "content-type");
1N/A
1N/A /* MIME headers to check for length overflow */
1N/A setclass(macid("{checkMIMETextHeaders}"), "content-description");
1N/A
1N/A /* MIME headers to check for overflow and rebalance */
1N/A setclass(macid("{checkMIMEHeaders}"), "content-disposition");
1N/A setclass(macid("{checkMIMEHeaders}"), "content-id");
1N/A setclass(macid("{checkMIMEHeaders}"), "content-transfer-encoding");
1N/A setclass(macid("{checkMIMEHeaders}"), "content-type");
1N/A setclass(macid("{checkMIMEHeaders}"), "mime-version");
1N/A
1N/A /* Macros to save in the queue file -- don't remove any */
1N/A setclass(macid("{persistentMacros}"), "r");
1N/A setclass(macid("{persistentMacros}"), "s");
1N/A setclass(macid("{persistentMacros}"), "_");
1N/A setclass(macid("{persistentMacros}"), "{if_addr}");
1N/A setclass(macid("{persistentMacros}"), "{daemon_flags}");
1N/A
1N/A /* operate in queue directory */
1N/A if (QueueDir == NULL || *QueueDir == '\0')
1N/A {
1N/A if (OpMode != MD_TEST)
1N/A {
1N/A syserr("QueueDirectory (Q) option must be set");
1N/A ExitStat = EX_CONFIG;
1N/A }
1N/A }
1N/A else
1N/A {
1N/A if (OpMode != MD_TEST)
1N/A setup_queues(OpMode == MD_DAEMON);
1N/A }
1N/A
1N/A /* check host status directory for validity */
1N/A if (HostStatDir != NULL && !path_is_dir(HostStatDir, false))
1N/A {
1N/A /* cannot use this value */
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Warning: Cannot use HostStatusDirectory = %s: %s\n",
1N/A HostStatDir, sm_errstring(errno));
1N/A HostStatDir = NULL;
1N/A }
1N/A
1N/A if (OpMode == MD_QUEUERUN &&
1N/A RealUid != 0 && bitset(PRIV_RESTRICTQRUN, PrivacyFlags))
1N/A {
1N/A struct stat stbuf;
1N/A
1N/A /* check to see if we own the queue directory */
1N/A if (stat(".", &stbuf) < 0)
1N/A syserr("main: cannot stat %s", QueueDir);
1N/A if (stbuf.st_uid != RealUid)
1N/A {
1N/A /* nope, really a botch */
1N/A HoldErrs = false;
1N/A usrerr("You do not have permission to process the queue");
1N/A finis(false, true, EX_NOPERM);
1N/A /* NOTREACHED */
1N/A }
1N/A }
1N/A
1N/A#if MILTER
1N/A /* sanity checks on milter filters */
1N/A if (OpMode == MD_DAEMON || OpMode == MD_SMTP)
1N/A {
1N/A milter_config(InputFilterList, InputFilters, MAXFILTERS);
1N/A setup_daemon_milters();
1N/A }
1N/A#endif /* MILTER */
1N/A
1N/A /* Convert queuegroup string to qgrp number */
1N/A if (queuegroup != NULL)
1N/A {
1N/A qgrp = name2qid(queuegroup);
1N/A if (qgrp == NOQGRP)
1N/A {
1N/A HoldErrs = false;
1N/A usrerr("Queue group %s unknown", queuegroup);
1N/A finis(false, true, ExitStat);
1N/A /* NOTREACHED */
1N/A }
1N/A }
1N/A
1N/A /* if checking config or have had errors so far, exit now */
1N/A if (OpMode == MD_CHECKCONFIG || (ExitStat != EX_OK && OpMode != MD_TEST))
1N/A {
1N/A finis(false, true, ExitStat);
1N/A /* NOTREACHED */
1N/A }
1N/A
1N/A#if SASL
1N/A /* sendmail specific SASL initialization */
1N/A sm_sasl_init();
1N/A#endif /* SASL */
1N/A
1N/A#if XDEBUG
1N/A checkfd012("before main() initmaps");
1N/A#endif /* XDEBUG */
1N/A
1N/A /*
1N/A ** Do operation-mode-dependent initialization.
1N/A */
1N/A
1N/A switch (OpMode)
1N/A {
1N/A case MD_PRINT:
1N/A /* print the queue */
1N/A HoldErrs = false;
1N/A (void) dropenvelope(&BlankEnvelope, true, false);
1N/A (void) sm_signal(SIGPIPE, sigpipe);
1N/A if (qgrp != NOQGRP)
1N/A {
1N/A int j;
1N/A
1N/A /* Selecting a particular queue group to run */
1N/A for (j = 0; j < Queue[qgrp]->qg_numqueues; j++)
1N/A {
1N/A if (StopRequest)
1N/A stop_sendmail();
1N/A (void) print_single_queue(qgrp, j);
1N/A }
1N/A finis(false, true, EX_OK);
1N/A /* NOTREACHED */
1N/A }
1N/A printqueue();
1N/A finis(false, true, EX_OK);
1N/A /* NOTREACHED */
1N/A break;
1N/A
1N/A case MD_PRINTNQE:
1N/A /* print number of entries in queue */
1N/A (void) dropenvelope(&BlankEnvelope, true, false);
1N/A (void) sm_signal(SIGPIPE, sigpipe);
1N/A printnqe(smioout, NULL);
1N/A finis(false, true, EX_OK);
1N/A /* NOTREACHED */
1N/A break;
1N/A
1N/A case MD_QUEUERUN:
1N/A /* only handle quarantining here */
1N/A if (quarantining == NULL)
1N/A break;
1N/A
1N/A if (QueueMode != QM_QUARANTINE &&
1N/A QueueMode != QM_NORMAL)
1N/A {
1N/A HoldErrs = false;
1N/A usrerr("Can not use -Q with -q%c", QueueMode);
1N/A ExitStat = EX_USAGE;
1N/A finis(false, true, ExitStat);
1N/A /* NOTREACHED */
1N/A }
1N/A quarantine_queue(quarantining, qgrp);
1N/A finis(false, true, EX_OK);
1N/A break;
1N/A
1N/A case MD_HOSTSTAT:
1N/A (void) sm_signal(SIGPIPE, sigpipe);
1N/A (void) mci_traverse_persistent(mci_print_persistent, NULL);
1N/A finis(false, true, EX_OK);
1N/A /* NOTREACHED */
1N/A break;
1N/A
1N/A case MD_PURGESTAT:
1N/A (void) mci_traverse_persistent(mci_purge_persistent, NULL);
1N/A finis(false, true, EX_OK);
1N/A /* NOTREACHED */
1N/A break;
1N/A
1N/A case MD_INITALIAS:
1N/A /* initialize maps */
1N/A initmaps();
1N/A finis(false, true, ExitStat);
1N/A /* NOTREACHED */
1N/A break;
1N/A
1N/A case MD_SMTP:
1N/A case MD_DAEMON:
1N/A /* reset DSN parameters */
1N/A DefaultNotify = QPINGONFAILURE|QPINGONDELAY;
1N/A macdefine(&BlankEnvelope.e_macro, A_PERM,
1N/A macid("{dsn_notify}"), NULL);
1N/A BlankEnvelope.e_envid = NULL;
1N/A macdefine(&BlankEnvelope.e_macro, A_PERM,
1N/A macid("{dsn_envid}"), NULL);
1N/A BlankEnvelope.e_flags &= ~(EF_RET_PARAM|EF_NO_BODY_RETN);
1N/A macdefine(&BlankEnvelope.e_macro, A_PERM,
1N/A macid("{dsn_ret}"), NULL);
1N/A
1N/A /* don't open maps for daemon -- done below in child */
1N/A break;
1N/A }
1N/A
1N/A if (tTd(0, 15))
1N/A {
1N/A /* print configuration table (or at least part of it) */
1N/A if (tTd(0, 90))
1N/A printrules();
1N/A for (i = 0; i < MAXMAILERS; i++)
1N/A {
1N/A if (Mailer[i] != NULL)
1N/A printmailer(sm_debug_file(), Mailer[i]);
1N/A }
1N/A }
1N/A
1N/A /*
1N/A ** Switch to the main envelope.
1N/A */
1N/A
1N/A CurEnv = newenvelope(&MainEnvelope, &BlankEnvelope,
1N/A sm_rpool_new_x(NULL));
1N/A MainEnvelope.e_flags = BlankEnvelope.e_flags;
1N/A
1N/A /*
1N/A ** If test mode, read addresses from stdin and process.
1N/A */
1N/A
1N/A if (OpMode == MD_TEST)
1N/A {
1N/A if (isatty(sm_io_getinfo(smioin, SM_IO_WHAT_FD, NULL)))
1N/A Verbose = 2;
1N/A
1N/A if (Verbose)
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)\n");
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Enter <ruleset> <address>\n");
1N/A }
1N/A macdefine(&(MainEnvelope.e_macro), A_PERM,
1N/A macid("{addr_type}"), "e r");
1N/A for (;;)
1N/A {
1N/A SM_TRY
1N/A {
1N/A (void) sm_signal(SIGINT, intindebug);
1N/A (void) sm_releasesignal(SIGINT);
1N/A if (Verbose == 2)
1N/A (void) sm_io_fprintf(smioout,
1N/A SM_TIME_DEFAULT,
1N/A "> ");
1N/A (void) sm_io_flush(smioout, SM_TIME_DEFAULT);
1N/A if (sm_io_fgets(smioin, SM_TIME_DEFAULT, buf,
1N/A sizeof(buf)) == NULL)
1N/A testmodeline("/quit", &MainEnvelope);
1N/A p = strchr(buf, '\n');
1N/A if (p != NULL)
1N/A *p = '\0';
1N/A if (Verbose < 2)
1N/A (void) sm_io_fprintf(smioout,
1N/A SM_TIME_DEFAULT,
1N/A "> %s\n", buf);
1N/A testmodeline(buf, &MainEnvelope);
1N/A }
1N/A SM_EXCEPT(exc, "[!F]*")
1N/A {
1N/A /*
1N/A ** 8.10 just prints \n on interrupt.
1N/A ** I'm printing the exception here in case
1N/A ** sendmail is extended to raise additional
1N/A ** exceptions in this context.
1N/A */
1N/A
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "\n");
1N/A sm_exc_print(exc, smioout);
1N/A }
1N/A SM_END_TRY
1N/A }
1N/A }
1N/A
1N/A#if STARTTLS
1N/A tls_ok = true;
1N/A if (OpMode == MD_QUEUERUN || OpMode == MD_DELIVER ||
1N/A OpMode == MD_ARPAFTP)
1N/A {
1N/A /* check whether STARTTLS is turned off for the client */
1N/A if (chkclientmodifiers(D_NOTLS))
1N/A tls_ok = false;
1N/A }
1N/A else if (OpMode == MD_DAEMON || OpMode == MD_FGDAEMON ||
1N/A OpMode == MD_SMTP)
1N/A {
1N/A /* check whether STARTTLS is turned off */
1N/A if (chkdaemonmodifiers(D_NOTLS) && chkclientmodifiers(D_NOTLS))
1N/A tls_ok = false;
1N/A }
1N/A else /* other modes don't need STARTTLS */
1N/A tls_ok = false;
1N/A
1N/A if (tls_ok)
1N/A {
1N/A /* basic TLS initialization */
1N/A tls_ok = init_tls_library();
1N/A }
1N/A
1N/A if (!tls_ok && (OpMode == MD_QUEUERUN || OpMode == MD_DELIVER))
1N/A {
1N/A /* disable TLS for client */
1N/A setclttls(false);
1N/A }
1N/A#endif /* STARTTLS */
1N/A
1N/A /*
1N/A ** If collecting stuff from the queue, go start doing that.
1N/A */
1N/A
1N/A if (OpMode == MD_QUEUERUN && QueueIntvl == 0)
1N/A {
1N/A pid_t pid = -1;
1N/A
1N/A#if STARTTLS
1N/A /* init TLS for client, ignore result for now */
1N/A (void) initclttls(tls_ok);
1N/A#endif /* STARTTLS */
1N/A
1N/A /*
1N/A ** The parent process of the caller of runqueue() needs
1N/A ** to stay around for a possible SIGTERM. The SIGTERM will
1N/A ** tell this process that all of the queue runners children
1N/A ** need to be sent SIGTERM as well. At the same time, we
1N/A ** want to return control to the command line. So we do an
1N/A ** extra fork().
1N/A */
1N/A
1N/A if (Verbose || foregroundqueue || (pid = fork()) <= 0)
1N/A {
1N/A /*
1N/A ** If the fork() failed we should still try to do
1N/A ** the queue run. If it succeeded then the child
1N/A ** is going to start the run and wait for all
1N/A ** of the children to finish.
1N/A */
1N/A
1N/A if (pid == 0)
1N/A {
1N/A /* Reset global flags */
1N/A RestartRequest = NULL;
1N/A ShutdownRequest = NULL;
1N/A PendingSignal = 0;
1N/A
1N/A /* disconnect from terminal */
1N/A disconnect(2, CurEnv);
1N/A }
1N/A
1N/A CurrentPid = getpid();
1N/A if (qgrp != NOQGRP)
1N/A {
1N/A int rwgflags = RWG_NONE;
1N/A
1N/A /*
1N/A ** To run a specific queue group mark it to
1N/A ** be run, select the work group it's in and
1N/A ** increment the work counter.
1N/A */
1N/A
1N/A for (i = 0; i < NumQueue && Queue[i] != NULL;
1N/A i++)
1N/A Queue[i]->qg_nextrun = (time_t) -1;
1N/A Queue[qgrp]->qg_nextrun = 0;
1N/A if (Verbose)
1N/A rwgflags |= RWG_VERBOSE;
1N/A if (queuepersistent)
1N/A rwgflags |= RWG_PERSISTENT;
1N/A rwgflags |= RWG_FORCE;
1N/A (void) run_work_group(Queue[qgrp]->qg_wgrp,
1N/A rwgflags);
1N/A }
1N/A else
1N/A (void) runqueue(false, Verbose,
1N/A queuepersistent, true);
1N/A
1N/A /* set the title to make it easier to find */
1N/A sm_setproctitle(true, CurEnv, "Queue control");
1N/A (void) sm_signal(SIGCHLD, SIG_DFL);
1N/A while (CurChildren > 0)
1N/A {
1N/A int status;
1N/A pid_t ret;
1N/A
1N/A errno = 0;
1N/A while ((ret = sm_wait(&status)) <= 0)
1N/A {
1N/A if (errno == ECHILD)
1N/A {
1N/A /*
1N/A ** Oops... something got messed
1N/A ** up really bad. Waiting for
1N/A ** non-existent children
1N/A ** shouldn't happen. Let's get
1N/A ** out of here.
1N/A */
1N/A
1N/A CurChildren = 0;
1N/A break;
1N/A }
1N/A continue;
1N/A }
1N/A
1N/A /* something is really really wrong */
1N/A if (errno == ECHILD)
1N/A {
1N/A sm_syslog(LOG_ERR, NOQID,
1N/A "queue control process: lost all children: wait returned ECHILD");
1N/A break;
1N/A }
1N/A
1N/A /* Only drop when a child gives status */
1N/A if (WIFSTOPPED(status))
1N/A continue;
1N/A
1N/A proc_list_drop(ret, status, NULL);
1N/A }
1N/A }
1N/A finis(true, true, ExitStat);
1N/A /* NOTREACHED */
1N/A }
1N/A
1N/A# if SASL
1N/A if (OpMode == MD_SMTP || OpMode == MD_DAEMON)
1N/A {
1N/A /* check whether AUTH is turned off for the server */
1N/A if (!chkdaemonmodifiers(D_NOAUTH) &&
1N/A (i = sasl_server_init(srvcallbacks, "Sendmail")) != SASL_OK)
1N/A syserr("!sasl_server_init failed! [%s]",
1N/A sasl_errstring(i, NULL, NULL));
1N/A }
1N/A# endif /* SASL */
1N/A
1N/A if (OpMode == MD_SMTP)
1N/A {
1N/A proc_list_add(CurrentPid, "Sendmail SMTP Agent",
1N/A PROC_DAEMON, 0, -1, NULL);
1N/A
1N/A /* clean up background delivery children */
1N/A (void) sm_signal(SIGCHLD, reapchild);
1N/A }
1N/A
1N/A /*
1N/A ** If a daemon, wait for a request.
1N/A ** getrequests will always return in a child.
1N/A ** If we should also be processing the queue, start
1N/A ** doing it in background.
1N/A ** We check for any errors that might have happened
1N/A ** during startup.
1N/A */
1N/A
1N/A if (OpMode == MD_DAEMON || QueueIntvl > 0)
1N/A {
1N/A char dtype[200];
1N/A
1N/A /* avoid cleanup in finis(), DaemonPid will be set below */
1N/A DaemonPid = 0;
1N/A if (!run_in_foreground && !tTd(99, 100))
1N/A {
1N/A /* put us in background */
1N/A i = fork();
1N/A if (i < 0)
1N/A syserr("daemon: cannot fork");
1N/A if (i != 0)
1N/A {
1N/A finis(false, true, EX_OK);
1N/A /* NOTREACHED */
1N/A }
1N/A
1N/A /*
1N/A ** Initialize exception stack and default exception
1N/A ** handler for child process.
1N/A */
1N/A
1N/A /* Reset global flags */
1N/A RestartRequest = NULL;
1N/A RestartWorkGroup = false;
1N/A ShutdownRequest = NULL;
1N/A PendingSignal = 0;
1N/A CurrentPid = getpid();
1N/A
1N/A sm_exc_newthread(fatal_error);
1N/A
1N/A /* disconnect from our controlling tty */
1N/A disconnect(2, &MainEnvelope);
1N/A }
1N/A
1N/A dtype[0] = '\0';
1N/A if (OpMode == MD_DAEMON)
1N/A {
1N/A (void) sm_strlcat(dtype, "+SMTP", sizeof(dtype));
1N/A DaemonPid = CurrentPid;
1N/A }
1N/A if (QueueIntvl > 0)
1N/A {
1N/A (void) sm_strlcat2(dtype,
1N/A queuepersistent
1N/A ? "+persistent-queueing@"
1N/A : "+queueing@",
1N/A pintvl(QueueIntvl, true),
1N/A sizeof(dtype));
1N/A }
1N/A if (tTd(0, 1))
1N/A (void) sm_strlcat(dtype, "+debugging", sizeof(dtype));
1N/A
1N/A sm_syslog(LOG_INFO, NOQID,
1N/A "starting daemon (%s): %s", Version, dtype + 1);
1N/A#if XLA
1N/A xla_create_file();
1N/A#endif /* XLA */
1N/A
1N/A /* save daemon type in a macro for possible PidFile use */
1N/A macdefine(&BlankEnvelope.e_macro, A_TEMP,
1N/A macid("{daemon_info}"), dtype + 1);
1N/A
1N/A /* save queue interval in a macro for possible PidFile use */
1N/A macdefine(&MainEnvelope.e_macro, A_TEMP,
1N/A macid("{queue_interval}"), pintvl(QueueIntvl, true));
1N/A
1N/A /* workaround: can't seem to release the signal in the parent */
1N/A (void) sm_signal(SIGHUP, sighup);
1N/A (void) sm_releasesignal(SIGHUP);
1N/A (void) sm_signal(SIGTERM, sigterm);
1N/A
1N/A if (QueueIntvl > 0)
1N/A {
1N/A#if _FFR_RUNPQG
1N/A if (qgrp != NOQGRP)
1N/A {
1N/A int rwgflags = RWG_NONE;
1N/A
1N/A /*
1N/A ** To run a specific queue group mark it to
1N/A ** be run, select the work group it's in and
1N/A ** increment the work counter.
1N/A */
1N/A
1N/A for (i = 0; i < NumQueue && Queue[i] != NULL;
1N/A i++)
1N/A Queue[i]->qg_nextrun = (time_t) -1;
1N/A Queue[qgrp]->qg_nextrun = 0;
1N/A if (Verbose)
1N/A rwgflags |= RWG_VERBOSE;
1N/A if (queuepersistent)
1N/A rwgflags |= RWG_PERSISTENT;
1N/A rwgflags |= RWG_FORCE;
1N/A (void) run_work_group(Queue[qgrp]->qg_wgrp,
1N/A rwgflags);
1N/A }
1N/A else
1N/A#endif /* _FFR_RUNPQG */
1N/A (void) runqueue(true, false, queuepersistent,
1N/A true);
1N/A
1N/A /*
1N/A ** If queuepersistent but not in daemon mode then
1N/A ** we're going to do the queue runner monitoring here.
1N/A ** If in daemon mode then the monitoring will happen
1N/A ** elsewhere.
1N/A */
1N/A
1N/A if (OpMode != MD_DAEMON && queuepersistent)
1N/A {
1N/A /*
1N/A ** Write the pid to file
1N/A ** XXX Overwrites sendmail.pid
1N/A */
1N/A
1N/A log_sendmail_pid(&MainEnvelope);
1N/A
1N/A /* set the title to make it easier to find */
1N/A sm_setproctitle(true, CurEnv, "Queue control");
1N/A (void) sm_signal(SIGCHLD, SIG_DFL);
1N/A while (CurChildren > 0)
1N/A {
1N/A int status;
1N/A pid_t ret;
1N/A int group;
1N/A
1N/A CHECK_RESTART;
1N/A errno = 0;
1N/A while ((ret = sm_wait(&status)) <= 0)
1N/A {
1N/A /*
1N/A ** Waiting for non-existent
1N/A ** children shouldn't happen.
1N/A ** Let's get out of here if
1N/A ** it occurs.
1N/A */
1N/A
1N/A if (errno == ECHILD)
1N/A {
1N/A CurChildren = 0;
1N/A break;
1N/A }
1N/A continue;
1N/A }
1N/A
1N/A /* something is really really wrong */
1N/A if (errno == ECHILD)
1N/A {
1N/A sm_syslog(LOG_ERR, NOQID,
1N/A "persistent queue runner control process: lost all children: wait returned ECHILD");
1N/A break;
1N/A }
1N/A
1N/A if (WIFSTOPPED(status))
1N/A continue;
1N/A
1N/A /* Probe only on a child status */
1N/A proc_list_drop(ret, status, &group);
1N/A
1N/A if (WIFSIGNALED(status))
1N/A {
1N/A if (WCOREDUMP(status))
1N/A {
1N/A sm_syslog(LOG_ERR, NOQID,
1N/A "persistent queue runner=%d core dumped, signal=%d",
1N/A group, WTERMSIG(status));
1N/A
1N/A /* don't restart this */
1N/A mark_work_group_restart(
1N/A group, -1);
1N/A continue;
1N/A }
1N/A
1N/A sm_syslog(LOG_ERR, NOQID,
1N/A "persistent queue runner=%d died, pid=%ld, signal=%d",
1N/A group, (long) ret,
1N/A WTERMSIG(status));
1N/A }
1N/A
1N/A /*
1N/A ** When debugging active, don't
1N/A ** restart the persistent queues.
1N/A ** But do log this as info.
1N/A */
1N/A
1N/A if (sm_debug_active(&DebugNoPRestart,
1N/A 1))
1N/A {
1N/A sm_syslog(LOG_DEBUG, NOQID,
1N/A "persistent queue runner=%d, exited",
1N/A group);
1N/A mark_work_group_restart(group,
1N/A -1);
1N/A }
1N/A CHECK_RESTART;
1N/A }
1N/A finis(true, true, ExitStat);
1N/A /* NOTREACHED */
1N/A }
1N/A
1N/A if (OpMode != MD_DAEMON)
1N/A {
1N/A char qtype[200];
1N/A
1N/A /*
1N/A ** Write the pid to file
1N/A ** XXX Overwrites sendmail.pid
1N/A */
1N/A
1N/A log_sendmail_pid(&MainEnvelope);
1N/A
1N/A /* set the title to make it easier to find */
1N/A qtype[0] = '\0';
1N/A (void) sm_strlcpyn(qtype, sizeof(qtype), 4,
1N/A "Queue runner@",
1N/A pintvl(QueueIntvl, true),
1N/A " for ",
1N/A QueueDir);
1N/A sm_setproctitle(true, CurEnv, qtype);
1N/A for (;;)
1N/A {
1N/A (void) pause();
1N/A
1N/A CHECK_RESTART;
1N/A
1N/A if (doqueuerun())
1N/A (void) runqueue(true, false,
1N/A false, false);
1N/A }
1N/A }
1N/A }
1N/A (void) dropenvelope(&MainEnvelope, true, false);
1N/A
1N/A#if STARTTLS
1N/A /* init TLS for server, ignore result for now */
1N/A (void) initsrvtls(tls_ok);
1N/A#endif /* STARTTLS */
1N/A
1N/A nextreq:
1N/A p_flags = getrequests(&MainEnvelope);
1N/A
1N/A /* drop privileges */
1N/A (void) drop_privileges(false);
1N/A
1N/A /*
1N/A ** Get authentication data
1N/A ** Set _ macro in BlankEnvelope before calling newenvelope().
1N/A */
1N/A
1N/A authinfo = getauthinfo(sm_io_getinfo(InChannel, SM_IO_WHAT_FD,
1N/A NULL), &forged);
1N/A macdefine(&BlankEnvelope.e_macro, A_TEMP, '_', authinfo);
1N/A
1N/A /* at this point we are in a child: reset state */
1N/A sm_rpool_free(MainEnvelope.e_rpool);
1N/A (void) newenvelope(&MainEnvelope, &MainEnvelope,
1N/A sm_rpool_new_x(NULL));
1N/A }
1N/A
1N/A if (LogLevel > 9)
1N/A {
1N/A /* log connection information */
1N/A sm_syslog(LOG_INFO, NULL, "connect from %s", authinfo);
1N/A }
1N/A
1N/A /*
1N/A ** If running SMTP protocol, start collecting and executing
1N/A ** commands. This will never return.
1N/A */
1N/A
1N/A if (OpMode == MD_SMTP || OpMode == MD_DAEMON)
1N/A {
1N/A char pbuf[20];
1N/A
1N/A /*
1N/A ** Save some macros for check_* rulesets.
1N/A */
1N/A
1N/A if (forged)
1N/A {
1N/A char ipbuf[103];
1N/A
1N/A (void) sm_snprintf(ipbuf, sizeof(ipbuf), "[%.100s]",
1N/A anynet_ntoa(&RealHostAddr));
1N/A macdefine(&BlankEnvelope.e_macro, A_TEMP,
1N/A macid("{client_name}"), ipbuf);
1N/A }
1N/A else
1N/A macdefine(&BlankEnvelope.e_macro, A_PERM,
1N/A macid("{client_name}"), RealHostName);
1N/A macdefine(&BlankEnvelope.e_macro, A_PERM,
1N/A macid("{client_ptr}"), RealHostName);
1N/A macdefine(&BlankEnvelope.e_macro, A_TEMP,
1N/A macid("{client_addr}"), anynet_ntoa(&RealHostAddr));
1N/A sm_getla();
1N/A
1N/A switch (RealHostAddr.sa.sa_family)
1N/A {
1N/A#if NETINET
1N/A case AF_INET:
1N/A (void) sm_snprintf(pbuf, sizeof(pbuf), "%d",
1N/A RealHostAddr.sin.sin_port);
1N/A break;
1N/A#endif /* NETINET */
1N/A#if NETINET6
1N/A case AF_INET6:
1N/A (void) sm_snprintf(pbuf, sizeof(pbuf), "%d",
1N/A RealHostAddr.sin6.sin6_port);
1N/A break;
1N/A#endif /* NETINET6 */
1N/A default:
1N/A (void) sm_snprintf(pbuf, sizeof(pbuf), "0");
1N/A break;
1N/A }
1N/A macdefine(&BlankEnvelope.e_macro, A_TEMP,
1N/A macid("{client_port}"), pbuf);
1N/A
1N/A if (OpMode == MD_DAEMON)
1N/A {
1N/A ENVELOPE *saved_env;
1N/A
1N/A /* validate the connection */
1N/A HoldErrs = true;
1N/A saved_env = CurEnv;
1N/A CurEnv = &BlankEnvelope;
1N/A nullserver = validate_connection(&RealHostAddr,
1N/A macvalue(macid("{client_name}"),
1N/A &BlankEnvelope),
1N/A &BlankEnvelope);
1N/A if (bitset(EF_DISCARD, BlankEnvelope.e_flags))
1N/A MainEnvelope.e_flags |= EF_DISCARD;
1N/A CurEnv = saved_env;
1N/A HoldErrs = false;
1N/A }
1N/A else if (p_flags == NULL)
1N/A {
1N/A p_flags = (BITMAP256 *) xalloc(sizeof(*p_flags));
1N/A clrbitmap(p_flags);
1N/A }
1N/A#if STARTTLS
1N/A if (OpMode == MD_SMTP)
1N/A (void) initsrvtls(tls_ok);
1N/A#endif /* STARTTLS */
1N/A
1N/A /* turn off profiling */
1N/A SM_PROF(1);
1N/A smtp(nullserver, *p_flags, &MainEnvelope);
1N/A
1N/A if (tTd(93, 100))
1N/A {
1N/A /* turn off profiling */
1N/A SM_PROF(0);
1N/A if (OpMode == MD_DAEMON)
1N/A goto nextreq;
1N/A }
1N/A }
1N/A
1N/A sm_rpool_free(MainEnvelope.e_rpool);
1N/A clearenvelope(&MainEnvelope, false, sm_rpool_new_x(NULL));
1N/A if (OpMode == MD_VERIFY)
1N/A {
1N/A set_delivery_mode(SM_VERIFY, &MainEnvelope);
1N/A PostMasterCopy = NULL;
1N/A }
1N/A else
1N/A {
1N/A /* interactive -- all errors are global */
1N/A MainEnvelope.e_flags |= EF_GLOBALERRS|EF_LOGSENDER;
1N/A }
1N/A
1N/A /*
1N/A ** Do basic system initialization and set the sender
1N/A */
1N/A
1N/A initsys(&MainEnvelope);
1N/A macdefine(&MainEnvelope.e_macro, A_PERM, macid("{ntries}"), "0");
1N/A macdefine(&MainEnvelope.e_macro, A_PERM, macid("{nrcpts}"), "0");
1N/A setsender(from, &MainEnvelope, NULL, '\0', false);
1N/A if (warn_f_flag != '\0' && !wordinclass(RealUserName, 't') &&
1N/A (!bitnset(M_LOCALMAILER, MainEnvelope.e_from.q_mailer->m_flags) ||
1N/A strcmp(MainEnvelope.e_from.q_user, RealUserName) != 0))
1N/A {
1N/A auth_warning(&MainEnvelope, "%s set sender to %s using -%c",
1N/A RealUserName, from, warn_f_flag);
1N/A#if SASL
1N/A auth = false;
1N/A#endif /* SASL */
1N/A }
1N/A if (auth)
1N/A {
1N/A char *fv;
1N/A
1N/A /* set the initial sender for AUTH= to $f@$j */
1N/A fv = macvalue('f', &MainEnvelope);
1N/A if (fv == NULL || *fv == '\0')
1N/A MainEnvelope.e_auth_param = NULL;
1N/A else
1N/A {
1N/A if (strchr(fv, '@') == NULL)
1N/A {
1N/A i = strlen(fv) + strlen(macvalue('j',
1N/A &MainEnvelope)) + 2;
1N/A p = sm_malloc_x(i);
1N/A (void) sm_strlcpyn(p, i, 3, fv, "@",
1N/A macvalue('j',
1N/A &MainEnvelope));
1N/A }
1N/A else
1N/A p = sm_strdup_x(fv);
1N/A MainEnvelope.e_auth_param = sm_rpool_strdup_x(MainEnvelope.e_rpool,
1N/A xtextify(p, "="));
1N/A sm_free(p); /* XXX */
1N/A }
1N/A }
1N/A if (macvalue('s', &MainEnvelope) == NULL)
1N/A macdefine(&MainEnvelope.e_macro, A_PERM, 's', RealHostName);
1N/A
1N/A av = argv + optind;
1N/A if (*av == NULL && !GrabTo)
1N/A {
1N/A MainEnvelope.e_to = NULL;
1N/A MainEnvelope.e_flags |= EF_GLOBALERRS;
1N/A HoldErrs = false;
1N/A SuperSafe = SAFE_NO;
1N/A usrerr("Recipient names must be specified");
1N/A
1N/A /* collect body for UUCP return */
1N/A if (OpMode != MD_VERIFY)
1N/A collect(InChannel, false, NULL, &MainEnvelope, true);
1N/A finis(true, true, EX_USAGE);
1N/A /* NOTREACHED */
1N/A }
1N/A
1N/A /*
1N/A ** Scan argv and deliver the message to everyone.
1N/A */
1N/A
1N/A save_val = LogUsrErrs;
1N/A LogUsrErrs = true;
1N/A sendtoargv(av, &MainEnvelope);
1N/A LogUsrErrs = save_val;
1N/A
1N/A /* if we have had errors sofar, arrange a meaningful exit stat */
1N/A if (Errors > 0 && ExitStat == EX_OK)
1N/A ExitStat = EX_USAGE;
1N/A
1N/A#if _FFR_FIX_DASHT
1N/A /*
1N/A ** If using -t, force not sending to argv recipients, even
1N/A ** if they are mentioned in the headers.
1N/A */
1N/A
1N/A if (GrabTo)
1N/A {
1N/A ADDRESS *q;
1N/A
1N/A for (q = MainEnvelope.e_sendqueue; q != NULL; q = q->q_next)
1N/A q->q_state = QS_REMOVED;
1N/A }
1N/A#endif /* _FFR_FIX_DASHT */
1N/A
1N/A /*
1N/A ** Read the input mail.
1N/A */
1N/A
1N/A MainEnvelope.e_to = NULL;
1N/A if (OpMode != MD_VERIFY || GrabTo)
1N/A {
1N/A int savederrors;
1N/A unsigned long savedflags;
1N/A
1N/A /*
1N/A ** workaround for compiler warning on Irix:
1N/A ** do not initialize variable in the definition, but
1N/A ** later on:
1N/A ** warning(1548): transfer of control bypasses
1N/A ** initialization of:
1N/A ** variable "savederrors" (declared at line 2570)
1N/A ** variable "savedflags" (declared at line 2571)
1N/A ** goto giveup;
1N/A */
1N/A
1N/A savederrors = Errors;
1N/A savedflags = MainEnvelope.e_flags & EF_FATALERRS;
1N/A MainEnvelope.e_flags |= EF_GLOBALERRS;
1N/A MainEnvelope.e_flags &= ~EF_FATALERRS;
1N/A Errors = 0;
1N/A buffer_errors();
1N/A collect(InChannel, false, NULL, &MainEnvelope, true);
1N/A
1N/A /* header checks failed */
1N/A if (Errors > 0)
1N/A {
1N/A giveup:
1N/A if (!GrabTo)
1N/A {
1N/A /* Log who the mail would have gone to */
1N/A logundelrcpts(&MainEnvelope,
1N/A MainEnvelope.e_message,
1N/A 8, false);
1N/A }
1N/A flush_errors(true);
1N/A finis(true, true, ExitStat);
1N/A /* NOTREACHED */
1N/A return -1;
1N/A }
1N/A
1N/A /* bail out if message too large */
1N/A if (bitset(EF_CLRQUEUE, MainEnvelope.e_flags))
1N/A {
1N/A finis(true, true, ExitStat != EX_OK ? ExitStat
1N/A : EX_DATAERR);
1N/A /* NOTREACHED */
1N/A return -1;
1N/A }
1N/A
1N/A /* set message size */
1N/A (void) sm_snprintf(buf, sizeof(buf), "%ld",
1N/A MainEnvelope.e_msgsize);
1N/A macdefine(&MainEnvelope.e_macro, A_TEMP,
1N/A macid("{msg_size}"), buf);
1N/A
1N/A Errors = savederrors;
1N/A MainEnvelope.e_flags |= savedflags;
1N/A }
1N/A errno = 0;
1N/A
1N/A if (tTd(1, 1))
1N/A sm_dprintf("From person = \"%s\"\n",
1N/A MainEnvelope.e_from.q_paddr);
1N/A
1N/A /* Check if quarantining stats should be updated */
1N/A if (MainEnvelope.e_quarmsg != NULL)
1N/A markstats(&MainEnvelope, NULL, STATS_QUARANTINE);
1N/A
1N/A /*
1N/A ** Actually send everything.
1N/A ** If verifying, just ack.
1N/A */
1N/A
1N/A if (Errors == 0)
1N/A {
1N/A if (!split_by_recipient(&MainEnvelope) &&
1N/A bitset(EF_FATALERRS, MainEnvelope.e_flags))
1N/A goto giveup;
1N/A }
1N/A
1N/A /* make sure we deliver at least the first envelope */
1N/A i = FastSplit > 0 ? 0 : -1;
1N/A for (e = &MainEnvelope; e != NULL; e = e->e_sibling, i++)
1N/A {
1N/A ENVELOPE *next;
1N/A
1N/A e->e_from.q_state = QS_SENDER;
1N/A if (tTd(1, 5))
1N/A {
1N/A sm_dprintf("main[%d]: QS_SENDER ", i);
1N/A printaddr(sm_debug_file(), &e->e_from, false);
1N/A }
1N/A e->e_to = NULL;
1N/A sm_getla();
1N/A GrabTo = false;
1N/A#if NAMED_BIND
1N/A _res.retry = TimeOuts.res_retry[RES_TO_FIRST];
1N/A _res.retrans = TimeOuts.res_retrans[RES_TO_FIRST];
1N/A#endif /* NAMED_BIND */
1N/A next = e->e_sibling;
1N/A e->e_sibling = NULL;
1N/A
1N/A /* after FastSplit envelopes: queue up */
1N/A sendall(e, i >= FastSplit ? SM_QUEUE : SM_DEFAULT);
1N/A e->e_sibling = next;
1N/A }
1N/A
1N/A /*
1N/A ** All done.
1N/A ** Don't send return error message if in VERIFY mode.
1N/A */
1N/A
1N/A finis(true, true, ExitStat);
1N/A /* NOTREACHED */
1N/A return ExitStat;
1N/A}
1N/A/*
1N/A** STOP_SENDMAIL -- Stop the running program
1N/A**
1N/A** Parameters:
1N/A** none.
1N/A**
1N/A** Returns:
1N/A** none.
1N/A**
1N/A** Side Effects:
1N/A** exits.
1N/A*/
1N/A
1N/Avoid
1N/Astop_sendmail()
1N/A{
1N/A /* reset uid for process accounting */
1N/A endpwent();
1N/A (void) setuid(RealUid);
1N/A exit(EX_OK);
1N/A}
1N/A/*
1N/A** FINIS -- Clean up and exit.
1N/A**
1N/A** Parameters:
1N/A** drop -- whether or not to drop CurEnv envelope
1N/A** cleanup -- call exit() or _exit()?
1N/A** exitstat -- exit status to use for exit() call
1N/A**
1N/A** Returns:
1N/A** never
1N/A**
1N/A** Side Effects:
1N/A** exits sendmail
1N/A*/
1N/A
1N/Avoid
1N/Afinis(drop, cleanup, exitstat)
1N/A bool drop;
1N/A bool cleanup;
1N/A volatile int exitstat;
1N/A{
1N/A char pidpath[MAXPATHLEN];
1N/A pid_t pid;
1N/A
1N/A /* Still want to process new timeouts added below */
1N/A sm_clear_events();
1N/A (void) sm_releasesignal(SIGALRM);
1N/A
1N/A if (tTd(2, 1))
1N/A {
1N/A sm_dprintf("\n====finis: stat %d e_id=%s e_flags=",
1N/A exitstat,
1N/A CurEnv->e_id == NULL ? "NOQUEUE" : CurEnv->e_id);
1N/A printenvflags(CurEnv);
1N/A }
1N/A if (tTd(2, 9))
1N/A printopenfds(false);
1N/A
1N/A SM_TRY
1N/A /*
1N/A ** Clean up. This might raise E:mta.quickabort
1N/A */
1N/A
1N/A /* clean up temp files */
1N/A CurEnv->e_to = NULL;
1N/A if (drop)
1N/A {
1N/A if (CurEnv->e_id != NULL)
1N/A {
1N/A int r;
1N/A
1N/A r = dropenvelope(CurEnv, true, false);
1N/A if (exitstat == EX_OK)
1N/A exitstat = r;
1N/A sm_rpool_free(CurEnv->e_rpool);
1N/A CurEnv->e_rpool = NULL;
1N/A
1N/A /* these may have pointed to the rpool */
1N/A CurEnv->e_to = NULL;
1N/A CurEnv->e_message = NULL;
1N/A CurEnv->e_statmsg = NULL;
1N/A CurEnv->e_quarmsg = NULL;
1N/A CurEnv->e_bodytype = NULL;
1N/A CurEnv->e_id = NULL;
1N/A CurEnv->e_envid = NULL;
1N/A CurEnv->e_auth_param = NULL;
1N/A }
1N/A else
1N/A poststats(StatFile);
1N/A }
1N/A
1N/A /* flush any cached connections */
1N/A mci_flush(true, NULL);
1N/A
1N/A /* close maps belonging to this pid */
1N/A closemaps(false);
1N/A
1N/A#if USERDB
1N/A /* close UserDatabase */
1N/A _udbx_close();
1N/A#endif /* USERDB */
1N/A
1N/A#if SASL
1N/A stop_sasl_client();
1N/A#endif /* SASL */
1N/A
1N/A#if XLA
1N/A /* clean up extended load average stuff */
1N/A xla_all_end();
1N/A#endif /* XLA */
1N/A
1N/A SM_FINALLY
1N/A /*
1N/A ** And exit.
1N/A */
1N/A
1N/A if (LogLevel > 78)
1N/A sm_syslog(LOG_DEBUG, CurEnv->e_id, "finis, pid=%d",
1N/A (int) CurrentPid);
1N/A if (exitstat == EX_TEMPFAIL ||
1N/A CurEnv->e_errormode == EM_BERKNET)
1N/A exitstat = EX_OK;
1N/A
1N/A /* XXX clean up queues and related data structures */
1N/A cleanup_queues();
1N/A pid = getpid();
1N/A#if SM_CONF_SHM
1N/A cleanup_shm(DaemonPid == pid);
1N/A#endif /* SM_CONF_SHM */
1N/A
1N/A /* close locked pid file */
1N/A close_sendmail_pid();
1N/A
1N/A if (DaemonPid == pid || PidFilePid == pid)
1N/A {
1N/A /* blow away the pid file */
1N/A expand(PidFile, pidpath, sizeof(pidpath), CurEnv);
1N/A (void) unlink(pidpath);
1N/A }
1N/A
1N/A /* reset uid for process accounting */
1N/A endpwent();
1N/A sm_mbdb_terminate();
1N/A#if _FFR_MEMSTAT
1N/A (void) sm_memstat_close();
1N/A#endif /* _FFR_MEMSTAT */
1N/A (void) setuid(RealUid);
1N/A#if SM_HEAP_CHECK
1N/A /* dump the heap, if we are checking for memory leaks */
1N/A if (sm_debug_active(&SmHeapCheck, 2))
1N/A sm_heap_report(smioout,
1N/A sm_debug_level(&SmHeapCheck) - 1);
1N/A#endif /* SM_HEAP_CHECK */
1N/A if (sm_debug_active(&SmXtrapReport, 1))
1N/A sm_dprintf("xtrap count = %d\n", SmXtrapCount);
1N/A if (cleanup)
1N/A exit(exitstat);
1N/A else
1N/A _exit(exitstat);
1N/A SM_END_TRY
1N/A}
1N/A/*
1N/A** INTINDEBUG -- signal handler for SIGINT in -bt mode
1N/A**
1N/A** Parameters:
1N/A** sig -- incoming signal.
1N/A**
1N/A** Returns:
1N/A** none.
1N/A**
1N/A** Side Effects:
1N/A** longjmps back to test mode loop.
1N/A**
1N/A** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
1N/A** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
1N/A** DOING.
1N/A*/
1N/A
1N/A/* Type of an exception generated on SIGINT during address test mode. */
1N/Astatic const SM_EXC_TYPE_T EtypeInterrupt =
1N/A{
1N/A SmExcTypeMagic,
1N/A "S:mta.interrupt",
1N/A "",
1N/A sm_etype_printf,
1N/A "interrupt",
1N/A};
1N/A
1N/A/* ARGSUSED */
1N/Astatic SIGFUNC_DECL
1N/Aintindebug(sig)
1N/A int sig;
1N/A{
1N/A int save_errno = errno;
1N/A
1N/A FIX_SYSV_SIGNAL(sig, intindebug);
1N/A errno = save_errno;
1N/A CHECK_CRITICAL(sig);
1N/A errno = save_errno;
1N/A sm_exc_raisenew_x(&EtypeInterrupt);
1N/A errno = save_errno;
1N/A return SIGFUNC_RETURN;
1N/A}
1N/A/*
1N/A** SIGTERM -- SIGTERM handler for the daemon
1N/A**
1N/A** Parameters:
1N/A** sig -- signal number.
1N/A**
1N/A** Returns:
1N/A** none.
1N/A**
1N/A** Side Effects:
1N/A** Sets ShutdownRequest which will hopefully trigger
1N/A** the daemon to exit.
1N/A**
1N/A** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
1N/A** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
1N/A** DOING.
1N/A*/
1N/A
1N/A/* ARGSUSED */
1N/Astatic SIGFUNC_DECL
1N/Asigterm(sig)
1N/A int sig;
1N/A{
1N/A int save_errno = errno;
1N/A
1N/A FIX_SYSV_SIGNAL(sig, sigterm);
1N/A ShutdownRequest = "signal";
1N/A errno = save_errno;
1N/A return SIGFUNC_RETURN;
1N/A}
1N/A/*
1N/A** SIGHUP -- handle a SIGHUP signal
1N/A**
1N/A** Parameters:
1N/A** sig -- incoming signal.
1N/A**
1N/A** Returns:
1N/A** none.
1N/A**
1N/A** Side Effects:
1N/A** Sets RestartRequest which should cause the daemon
1N/A** to restart.
1N/A**
1N/A** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
1N/A** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
1N/A** DOING.
1N/A*/
1N/A
1N/A/* ARGSUSED */
1N/Astatic SIGFUNC_DECL
1N/Asighup(sig)
1N/A int sig;
1N/A{
1N/A int save_errno = errno;
1N/A
1N/A FIX_SYSV_SIGNAL(sig, sighup);
1N/A RestartRequest = "signal";
1N/A errno = save_errno;
1N/A return SIGFUNC_RETURN;
1N/A}
1N/A/*
1N/A** SIGPIPE -- signal handler for SIGPIPE
1N/A**
1N/A** Parameters:
1N/A** sig -- incoming signal.
1N/A**
1N/A** Returns:
1N/A** none.
1N/A**
1N/A** Side Effects:
1N/A** Sets StopRequest which should cause the mailq/hoststatus
1N/A** display to stop.
1N/A**
1N/A** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
1N/A** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
1N/A** DOING.
1N/A*/
1N/A
1N/A/* ARGSUSED */
1N/Astatic SIGFUNC_DECL
1N/Asigpipe(sig)
1N/A int sig;
1N/A{
1N/A int save_errno = errno;
1N/A
1N/A FIX_SYSV_SIGNAL(sig, sigpipe);
1N/A StopRequest = true;
1N/A errno = save_errno;
1N/A return SIGFUNC_RETURN;
1N/A}
1N/A/*
1N/A** INTSIG -- clean up on interrupt
1N/A**
1N/A** This just arranges to exit. It pessimizes in that it
1N/A** may resend a message.
1N/A**
1N/A** Parameters:
1N/A** sig -- incoming signal.
1N/A**
1N/A** Returns:
1N/A** none.
1N/A**
1N/A** Side Effects:
1N/A** Unlocks the current job.
1N/A**
1N/A** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
1N/A** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
1N/A** DOING.
1N/A*/
1N/A
1N/A/* ARGSUSED */
1N/ASIGFUNC_DECL
1N/Aintsig(sig)
1N/A int sig;
1N/A{
1N/A bool drop = false;
1N/A int save_errno = errno;
1N/A
1N/A FIX_SYSV_SIGNAL(sig, intsig);
1N/A errno = save_errno;
1N/A CHECK_CRITICAL(sig);
1N/A sm_allsignals(true);
1N/A IntSig = true;
1N/A
1N/A FileName = NULL;
1N/A
1N/A /* Clean-up on aborted stdin message submission */
1N/A if (OpMode == MD_SMTP ||
1N/A OpMode == MD_DELIVER ||
1N/A OpMode == MD_ARPAFTP)
1N/A {
1N/A if (CurEnv->e_id != NULL)
1N/A {
1N/A char *fn;
1N/A
1N/A fn = queuename(CurEnv, DATAFL_LETTER);
1N/A if (fn != NULL)
1N/A (void) unlink(fn);
1N/A fn = queuename(CurEnv, ANYQFL_LETTER);
1N/A if (fn != NULL)
1N/A (void) unlink(fn);
1N/A }
1N/A _exit(EX_OK);
1N/A /* NOTREACHED */
1N/A }
1N/A
1N/A if (sig != 0 && LogLevel > 79)
1N/A sm_syslog(LOG_DEBUG, CurEnv->e_id, "interrupt");
1N/A if (OpMode != MD_TEST)
1N/A unlockqueue(CurEnv);
1N/A
1N/A finis(drop, false, EX_OK);
1N/A /* NOTREACHED */
1N/A}
1N/A/*
1N/A** DISCONNECT -- remove our connection with any foreground process
1N/A**
1N/A** Parameters:
1N/A** droplev -- how "deeply" we should drop the line.
1N/A** 0 -- ignore signals, mail back errors, make sure
1N/A** output goes to stdout.
1N/A** 1 -- also, make stdout go to /dev/null.
1N/A** 2 -- also, disconnect from controlling terminal
1N/A** (only for daemon mode).
1N/A** e -- the current envelope.
1N/A**
1N/A** Returns:
1N/A** none
1N/A**
1N/A** Side Effects:
1N/A** Trys to insure that we are immune to vagaries of
1N/A** the controlling tty.
1N/A*/
1N/A
1N/Avoid
1N/Adisconnect(droplev, e)
1N/A int droplev;
1N/A register ENVELOPE *e;
1N/A{
1N/A int fd;
1N/A
1N/A if (tTd(52, 1))
1N/A sm_dprintf("disconnect: In %d Out %d, e=%p\n",
1N/A sm_io_getinfo(InChannel, SM_IO_WHAT_FD, NULL),
1N/A sm_io_getinfo(OutChannel, SM_IO_WHAT_FD, NULL), e);
1N/A if (tTd(52, 100))
1N/A {
1N/A sm_dprintf("don't\n");
1N/A return;
1N/A }
1N/A if (LogLevel > 93)
1N/A sm_syslog(LOG_DEBUG, e->e_id,
1N/A "disconnect level %d",
1N/A droplev);
1N/A
1N/A /* be sure we don't get nasty signals */
1N/A (void) sm_signal(SIGINT, SIG_IGN);
1N/A (void) sm_signal(SIGQUIT, SIG_IGN);
1N/A
1N/A /* we can't communicate with our caller, so.... */
1N/A HoldErrs = true;
1N/A CurEnv->e_errormode = EM_MAIL;
1N/A Verbose = 0;
1N/A DisConnected = true;
1N/A
1N/A /* all input from /dev/null */
1N/A if (InChannel != smioin)
1N/A {
1N/A (void) sm_io_close(InChannel, SM_TIME_DEFAULT);
1N/A InChannel = smioin;
1N/A }
1N/A if (sm_io_reopen(SmFtStdio, SM_TIME_DEFAULT, SM_PATH_DEVNULL,
1N/A SM_IO_RDONLY, NULL, smioin) == NULL)
1N/A sm_syslog(LOG_ERR, e->e_id,
1N/A "disconnect: sm_io_reopen(\"%s\") failed: %s",
1N/A SM_PATH_DEVNULL, sm_errstring(errno));
1N/A
1N/A /*
1N/A ** output to the transcript
1N/A ** We also compare the fd numbers here since OutChannel
1N/A ** might be a layer on top of smioout due to encryption
1N/A ** (see sfsasl.c).
1N/A */
1N/A
1N/A if (OutChannel != smioout &&
1N/A sm_io_getinfo(OutChannel, SM_IO_WHAT_FD, NULL) !=
1N/A sm_io_getinfo(smioout, SM_IO_WHAT_FD, NULL))
1N/A {
1N/A (void) sm_io_close(OutChannel, SM_TIME_DEFAULT);
1N/A OutChannel = smioout;
1N/A
1N/A#if 0
1N/A /*
1N/A ** Has smioout been closed? Reopen it.
1N/A ** This shouldn't happen anymore, the code is here
1N/A ** just as a reminder.
1N/A */
1N/A
1N/A if (smioout->sm_magic == NULL &&
1N/A sm_io_reopen(SmFtStdio, SM_TIME_DEFAULT, SM_PATH_DEVNULL,
1N/A SM_IO_WRONLY, NULL, smioout) == NULL)
1N/A sm_syslog(LOG_ERR, e->e_id,
1N/A "disconnect: sm_io_reopen(\"%s\") failed: %s",
1N/A SM_PATH_DEVNULL, sm_errstring(errno));
1N/A#endif /* 0 */
1N/A }
1N/A if (droplev > 0)
1N/A {
1N/A fd = open(SM_PATH_DEVNULL, O_WRONLY, 0666);
1N/A if (fd == -1)
1N/A {
1N/A sm_syslog(LOG_ERR, e->e_id,
1N/A "disconnect: open(\"%s\") failed: %s",
1N/A SM_PATH_DEVNULL, sm_errstring(errno));
1N/A }
1N/A (void) sm_io_flush(smioout, SM_TIME_DEFAULT);
1N/A if (fd >= 0)
1N/A {
1N/A (void) dup2(fd, STDOUT_FILENO);
1N/A (void) dup2(fd, STDERR_FILENO);
1N/A (void) close(fd);
1N/A }
1N/A }
1N/A
1N/A /* drop our controlling TTY completely if possible */
1N/A if (droplev > 1)
1N/A {
1N/A (void) setsid();
1N/A errno = 0;
1N/A }
1N/A
1N/A#if XDEBUG
1N/A checkfd012("disconnect");
1N/A#endif /* XDEBUG */
1N/A
1N/A if (LogLevel > 71)
1N/A sm_syslog(LOG_DEBUG, e->e_id, "in background, pid=%d",
1N/A (int) CurrentPid);
1N/A
1N/A errno = 0;
1N/A}
1N/A
1N/Astatic void
1N/Aobsolete(argv)
1N/A char *argv[];
1N/A{
1N/A register char *ap;
1N/A register char *op;
1N/A
1N/A while ((ap = *++argv) != NULL)
1N/A {
1N/A /* Return if "--" or not an option of any form. */
1N/A if (ap[0] != '-' || ap[1] == '-')
1N/A return;
1N/A
1N/A /* Don't allow users to use "-Q." or "-Q ." */
1N/A if ((ap[1] == 'Q' && ap[2] == '.') ||
1N/A (ap[1] == 'Q' && argv[1] != NULL &&
1N/A argv[1][0] == '.' && argv[1][1] == '\0'))
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Can not use -Q.\n");
1N/A exit(EX_USAGE);
1N/A }
1N/A
1N/A /* skip over options that do have a value */
1N/A op = strchr(OPTIONS, ap[1]);
1N/A if (op != NULL && *++op == ':' && ap[2] == '\0' &&
1N/A ap[1] != 'd' &&
1N/A#if defined(sony_news)
1N/A ap[1] != 'E' && ap[1] != 'J' &&
1N/A#endif /* defined(sony_news) */
1N/A argv[1] != NULL && argv[1][0] != '-')
1N/A {
1N/A argv++;
1N/A continue;
1N/A }
1N/A
1N/A /* If -C doesn't have an argument, use sendmail.cf. */
1N/A#define __DEFPATH "sendmail.cf"
1N/A if (ap[1] == 'C' && ap[2] == '\0')
1N/A {
1N/A *argv = xalloc(sizeof(__DEFPATH) + 2);
1N/A (void) sm_strlcpyn(argv[0], sizeof(__DEFPATH) + 2, 2,
1N/A "-C", __DEFPATH);
1N/A }
1N/A
1N/A /* If -q doesn't have an argument, run it once. */
1N/A if (ap[1] == 'q' && ap[2] == '\0')
1N/A *argv = "-q0";
1N/A
1N/A /* If -Q doesn't have an argument, disable quarantining */
1N/A if (ap[1] == 'Q' && ap[2] == '\0')
1N/A *argv = "-Q.";
1N/A
1N/A /* if -d doesn't have an argument, use 0-99.1 */
1N/A if (ap[1] == 'd' && ap[2] == '\0')
1N/A *argv = "-d0-99.1";
1N/A
1N/A#if defined(sony_news)
1N/A /* if -E doesn't have an argument, use -EC */
1N/A if (ap[1] == 'E' && ap[2] == '\0')
1N/A *argv = "-EC";
1N/A
1N/A /* if -J doesn't have an argument, use -JJ */
1N/A if (ap[1] == 'J' && ap[2] == '\0')
1N/A *argv = "-JJ";
1N/A#endif /* defined(sony_news) */
1N/A }
1N/A}
1N/A/*
1N/A** AUTH_WARNING -- specify authorization warning
1N/A**
1N/A** Parameters:
1N/A** e -- the current envelope.
1N/A** msg -- the text of the message.
1N/A** args -- arguments to the message.
1N/A**
1N/A** Returns:
1N/A** none.
1N/A*/
1N/A
1N/Avoid
1N/A#ifdef __STDC__
1N/Aauth_warning(register ENVELOPE *e, const char *msg, ...)
1N/A#else /* __STDC__ */
1N/Aauth_warning(e, msg, va_alist)
1N/A register ENVELOPE *e;
1N/A const char *msg;
1N/A va_dcl
1N/A#endif /* __STDC__ */
1N/A{
1N/A char buf[MAXLINE];
1N/A SM_VA_LOCAL_DECL
1N/A
1N/A if (bitset(PRIV_AUTHWARNINGS, PrivacyFlags))
1N/A {
1N/A register char *p;
1N/A static char hostbuf[48];
1N/A
1N/A if (hostbuf[0] == '\0')
1N/A {
1N/A struct hostent *hp;
1N/A
1N/A hp = myhostname(hostbuf, sizeof(hostbuf));
1N/A#if NETINET6
1N/A if (hp != NULL)
1N/A {
1N/A freehostent(hp);
1N/A hp = NULL;
1N/A }
1N/A#endif /* NETINET6 */
1N/A }
1N/A
1N/A (void) sm_strlcpyn(buf, sizeof(buf), 2, hostbuf, ": ");
1N/A p = &buf[strlen(buf)];
1N/A SM_VA_START(ap, msg);
1N/A (void) sm_vsnprintf(p, SPACELEFT(buf, p), msg, ap);
1N/A SM_VA_END(ap);
1N/A addheader("X-Authentication-Warning", buf, 0, e, true);
1N/A if (LogLevel > 3)
1N/A sm_syslog(LOG_INFO, e->e_id,
1N/A "Authentication-Warning: %.400s",
1N/A buf);
1N/A }
1N/A}
1N/A/*
1N/A** GETEXTENV -- get from external environment
1N/A**
1N/A** Parameters:
1N/A** envar -- the name of the variable to retrieve
1N/A**
1N/A** Returns:
1N/A** The value, if any.
1N/A*/
1N/A
1N/Astatic char *
1N/Agetextenv(envar)
1N/A const char *envar;
1N/A{
1N/A char **envp;
1N/A int l;
1N/A
1N/A l = strlen(envar);
1N/A for (envp = ExternalEnviron; envp != NULL && *envp != NULL; envp++)
1N/A {
1N/A if (strncmp(*envp, envar, l) == 0 && (*envp)[l] == '=')
1N/A return &(*envp)[l + 1];
1N/A }
1N/A return NULL;
1N/A}
1N/A/*
1N/A** SM_SETUSERENV -- set an environment variable in the propagated environment
1N/A**
1N/A** Parameters:
1N/A** envar -- the name of the environment variable.
1N/A** value -- the value to which it should be set. If
1N/A** null, this is extracted from the incoming
1N/A** environment. If that is not set, the call
1N/A** to sm_setuserenv is ignored.
1N/A**
1N/A** Returns:
1N/A** none.
1N/A*/
1N/A
1N/Avoid
1N/Asm_setuserenv(envar, value)
1N/A const char *envar;
1N/A const char *value;
1N/A{
1N/A int i, l;
1N/A char **evp = UserEnviron;
1N/A char *p;
1N/A
1N/A if (value == NULL)
1N/A {
1N/A value = getextenv(envar);
1N/A if (value == NULL)
1N/A return;
1N/A }
1N/A
1N/A /* XXX enforce reasonable size? */
1N/A i = strlen(envar) + 1;
1N/A l = strlen(value) + i + 1;
1N/A p = (char *) xalloc(l);
1N/A (void) sm_strlcpyn(p, l, 3, envar, "=", value);
1N/A
1N/A while (*evp != NULL && strncmp(*evp, p, i) != 0)
1N/A evp++;
1N/A if (*evp != NULL)
1N/A {
1N/A *evp++ = p;
1N/A }
1N/A else if (evp < &UserEnviron[MAXUSERENVIRON])
1N/A {
1N/A *evp++ = p;
1N/A *evp = NULL;
1N/A }
1N/A
1N/A /* make sure it is in our environment as well */
1N/A if (putenv(p) < 0)
1N/A syserr("sm_setuserenv: putenv(%s) failed", p);
1N/A}
1N/A/*
1N/A** DUMPSTATE -- dump state
1N/A**
1N/A** For debugging.
1N/A*/
1N/A
1N/Avoid
1N/Adumpstate(when)
1N/A char *when;
1N/A{
1N/A register char *j = macvalue('j', CurEnv);
1N/A int rs;
1N/A extern int NextMacroId;
1N/A
1N/A sm_syslog(LOG_DEBUG, CurEnv->e_id,
1N/A "--- dumping state on %s: $j = %s ---",
1N/A when,
1N/A j == NULL ? "<NULL>" : j);
1N/A if (j != NULL)
1N/A {
1N/A if (!wordinclass(j, 'w'))
1N/A sm_syslog(LOG_DEBUG, CurEnv->e_id,
1N/A "*** $j not in $=w ***");
1N/A }
1N/A sm_syslog(LOG_DEBUG, CurEnv->e_id, "CurChildren = %d", CurChildren);
1N/A sm_syslog(LOG_DEBUG, CurEnv->e_id, "NextMacroId = %d (Max %d)",
1N/A NextMacroId, MAXMACROID);
1N/A sm_syslog(LOG_DEBUG, CurEnv->e_id, "--- open file descriptors: ---");
1N/A printopenfds(true);
1N/A sm_syslog(LOG_DEBUG, CurEnv->e_id, "--- connection cache: ---");
1N/A mci_dump_all(smioout, true);
1N/A rs = strtorwset("debug_dumpstate", NULL, ST_FIND);
1N/A if (rs > 0)
1N/A {
1N/A int status;
1N/A register char **pvp;
1N/A char *pv[MAXATOM + 1];
1N/A
1N/A pv[0] = NULL;
1N/A status = REWRITE(pv, rs, CurEnv);
1N/A sm_syslog(LOG_DEBUG, CurEnv->e_id,
1N/A "--- ruleset debug_dumpstate returns stat %d, pv: ---",
1N/A status);
1N/A for (pvp = pv; *pvp != NULL; pvp++)
1N/A sm_syslog(LOG_DEBUG, CurEnv->e_id, "%s", *pvp);
1N/A }
1N/A sm_syslog(LOG_DEBUG, CurEnv->e_id, "--- end of state dump ---");
1N/A}
1N/A
1N/A#ifdef SIGUSR1
1N/A/*
1N/A** SIGUSR1 -- Signal a request to dump state.
1N/A**
1N/A** Parameters:
1N/A** sig -- calling signal.
1N/A**
1N/A** Returns:
1N/A** none.
1N/A**
1N/A** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
1N/A** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
1N/A** DOING.
1N/A**
1N/A** XXX: More work is needed for this signal handler.
1N/A*/
1N/A
1N/A/* ARGSUSED */
1N/Astatic SIGFUNC_DECL
1N/Asigusr1(sig)
1N/A int sig;
1N/A{
1N/A int save_errno = errno;
1N/A
1N/A FIX_SYSV_SIGNAL(sig, sigusr1);
1N/A errno = save_errno;
1N/A CHECK_CRITICAL(sig);
1N/A dumpstate("user signal");
1N/A# if SM_HEAP_CHECK
1N/A dumpstab();
1N/A# endif /* SM_HEAP_CHECK */
1N/A errno = save_errno;
1N/A return SIGFUNC_RETURN;
1N/A}
1N/A#endif /* SIGUSR1 */
1N/A
1N/A/*
1N/A** DROP_PRIVILEGES -- reduce privileges to those of the RunAsUser option
1N/A**
1N/A** Parameters:
1N/A** to_real_uid -- if set, drop to the real uid instead
1N/A** of the RunAsUser.
1N/A**
1N/A** Returns:
1N/A** EX_OSERR if the setuid failed.
1N/A** EX_OK otherwise.
1N/A*/
1N/A
1N/Aint
1N/Adrop_privileges(to_real_uid)
1N/A bool to_real_uid;
1N/A{
1N/A int rval = EX_OK;
1N/A GIDSET_T emptygidset[1];
1N/A
1N/A if (tTd(47, 1))
1N/A sm_dprintf("drop_privileges(%d): Real[UG]id=%d:%d, get[ug]id=%d:%d, gete[ug]id=%d:%d, RunAs[UG]id=%d:%d\n",
1N/A (int) to_real_uid,
1N/A (int) RealUid, (int) RealGid,
1N/A (int) getuid(), (int) getgid(),
1N/A (int) geteuid(), (int) getegid(),
1N/A (int) RunAsUid, (int) RunAsGid);
1N/A
1N/A if (to_real_uid)
1N/A {
1N/A RunAsUserName = RealUserName;
1N/A RunAsUid = RealUid;
1N/A RunAsGid = RealGid;
1N/A EffGid = RunAsGid;
1N/A }
1N/A
1N/A /* make sure no one can grab open descriptors for secret files */
1N/A endpwent();
1N/A sm_mbdb_terminate();
1N/A
1N/A /* reset group permissions; these can be set later */
1N/A emptygidset[0] = (to_real_uid || RunAsGid != 0) ? RunAsGid : getegid();
1N/A
1N/A /*
1N/A ** Notice: on some OS (Linux...) the setgroups() call causes
1N/A ** a logfile entry if sendmail is not run by root.
1N/A ** However, it is unclear (no POSIX standard) whether
1N/A ** setgroups() can only succeed if executed by root.
1N/A ** So for now we keep it as it is; if you want to change it, use
1N/A ** if (geteuid() == 0 && setgroups(1, emptygidset) == -1)
1N/A */
1N/A
1N/A if (setgroups(1, emptygidset) == -1 && geteuid() == 0)
1N/A {
1N/A syserr("drop_privileges: setgroups(1, %d) failed",
1N/A (int) emptygidset[0]);
1N/A rval = EX_OSERR;
1N/A }
1N/A
1N/A /* reset primary group id */
1N/A if (to_real_uid)
1N/A {
1N/A /*
1N/A ** Drop gid to real gid.
1N/A ** On some OS we must reset the effective[/real[/saved]] gid,
1N/A ** and then use setgid() to finally drop all group privileges.
1N/A ** Later on we check whether we can get back the
1N/A ** effective gid.
1N/A */
1N/A
1N/A#if HASSETEGID
1N/A if (setegid(RunAsGid) < 0)
1N/A {
1N/A syserr("drop_privileges: setegid(%d) failed",
1N/A (int) RunAsGid);
1N/A rval = EX_OSERR;
1N/A }
1N/A#else /* HASSETEGID */
1N/A# if HASSETREGID
1N/A if (setregid(RunAsGid, RunAsGid) < 0)
1N/A {
1N/A syserr("drop_privileges: setregid(%d, %d) failed",
1N/A (int) RunAsGid, (int) RunAsGid);
1N/A rval = EX_OSERR;
1N/A }
1N/A# else /* HASSETREGID */
1N/A# if HASSETRESGID
1N/A if (setresgid(RunAsGid, RunAsGid, RunAsGid) < 0)
1N/A {
1N/A syserr("drop_privileges: setresgid(%d, %d, %d) failed",
1N/A (int) RunAsGid, (int) RunAsGid, (int) RunAsGid);
1N/A rval = EX_OSERR;
1N/A }
1N/A# endif /* HASSETRESGID */
1N/A# endif /* HASSETREGID */
1N/A#endif /* HASSETEGID */
1N/A }
1N/A if (rval == EX_OK && (to_real_uid || RunAsGid != 0))
1N/A {
1N/A if (setgid(RunAsGid) < 0 && (!UseMSP || getegid() != RunAsGid))
1N/A {
1N/A syserr("drop_privileges: setgid(%d) failed",
1N/A (int) RunAsGid);
1N/A rval = EX_OSERR;
1N/A }
1N/A errno = 0;
1N/A if (rval == EX_OK && getegid() != RunAsGid)
1N/A {
1N/A syserr("drop_privileges: Unable to set effective gid=%d to RunAsGid=%d",
1N/A (int) getegid(), (int) RunAsGid);
1N/A rval = EX_OSERR;
1N/A }
1N/A }
1N/A
1N/A /* fiddle with uid */
1N/A if (to_real_uid || RunAsUid != 0)
1N/A {
1N/A uid_t euid;
1N/A
1N/A /*
1N/A ** Try to setuid(RunAsUid).
1N/A ** euid must be RunAsUid,
1N/A ** ruid must be RunAsUid unless (e|r)uid wasn't 0
1N/A ** and we didn't have to drop privileges to the real uid.
1N/A */
1N/A
1N/A if (setuid(RunAsUid) < 0 ||
1N/A geteuid() != RunAsUid ||
1N/A (getuid() != RunAsUid &&
1N/A (to_real_uid || geteuid() == 0 || getuid() == 0)))
1N/A {
1N/A#if HASSETREUID
1N/A /*
1N/A ** if ruid != RunAsUid, euid == RunAsUid, then
1N/A ** try resetting just the real uid, then using
1N/A ** setuid() to drop the saved-uid as well.
1N/A */
1N/A
1N/A if (geteuid() == RunAsUid)
1N/A {
1N/A if (setreuid(RunAsUid, -1) < 0)
1N/A {
1N/A syserr("drop_privileges: setreuid(%d, -1) failed",
1N/A (int) RunAsUid);
1N/A rval = EX_OSERR;
1N/A }
1N/A if (setuid(RunAsUid) < 0)
1N/A {
1N/A syserr("drop_privileges: second setuid(%d) attempt failed",
1N/A (int) RunAsUid);
1N/A rval = EX_OSERR;
1N/A }
1N/A }
1N/A else
1N/A#endif /* HASSETREUID */
1N/A {
1N/A syserr("drop_privileges: setuid(%d) failed",
1N/A (int) RunAsUid);
1N/A rval = EX_OSERR;
1N/A }
1N/A }
1N/A euid = geteuid();
1N/A if (RunAsUid != 0 && setuid(0) == 0)
1N/A {
1N/A /*
1N/A ** Believe it or not, the Linux capability model
1N/A ** allows a non-root process to override setuid()
1N/A ** on a process running as root and prevent that
1N/A ** process from dropping privileges.
1N/A */
1N/A
1N/A syserr("drop_privileges: setuid(0) succeeded (when it should not)");
1N/A rval = EX_OSERR;
1N/A }
1N/A else if (RunAsUid != euid && setuid(euid) == 0)
1N/A {
1N/A /*
1N/A ** Some operating systems will keep the saved-uid
1N/A ** if a non-root effective-uid calls setuid(real-uid)
1N/A ** making it possible to set it back again later.
1N/A */
1N/A
1N/A syserr("drop_privileges: Unable to drop non-root set-user-ID privileges");
1N/A rval = EX_OSERR;
1N/A }
1N/A }
1N/A
1N/A if ((to_real_uid || RunAsGid != 0) &&
1N/A rval == EX_OK && RunAsGid != EffGid &&
1N/A getuid() != 0 && geteuid() != 0)
1N/A {
1N/A errno = 0;
1N/A if (setgid(EffGid) == 0)
1N/A {
1N/A syserr("drop_privileges: setgid(%d) succeeded (when it should not)",
1N/A (int) EffGid);
1N/A rval = EX_OSERR;
1N/A }
1N/A }
1N/A
1N/A if (tTd(47, 5))
1N/A {
1N/A sm_dprintf("drop_privileges: e/ruid = %d/%d e/rgid = %d/%d\n",
1N/A (int) geteuid(), (int) getuid(),
1N/A (int) getegid(), (int) getgid());
1N/A sm_dprintf("drop_privileges: RunAsUser = %d:%d\n",
1N/A (int) RunAsUid, (int) RunAsGid);
1N/A if (tTd(47, 10))
1N/A sm_dprintf("drop_privileges: rval = %d\n", rval);
1N/A }
1N/A return rval;
1N/A}
1N/A/*
1N/A** FILL_FD -- make sure a file descriptor has been properly allocated
1N/A**
1N/A** Used to make sure that stdin/out/err are allocated on startup
1N/A**
1N/A** Parameters:
1N/A** fd -- the file descriptor to be filled.
1N/A** where -- a string used for logging. If NULL, this is
1N/A** being called on startup, and logging should
1N/A** not be done.
1N/A**
1N/A** Returns:
1N/A** none
1N/A**
1N/A** Side Effects:
1N/A** possibly changes MissingFds
1N/A*/
1N/A
1N/Avoid
1N/Afill_fd(fd, where)
1N/A int fd;
1N/A char *where;
1N/A{
1N/A int i;
1N/A struct stat stbuf;
1N/A
1N/A if (fstat(fd, &stbuf) >= 0 || errno != EBADF)
1N/A return;
1N/A
1N/A if (where != NULL)
1N/A syserr("fill_fd: %s: fd %d not open", where, fd);
1N/A else
1N/A MissingFds |= 1 << fd;
1N/A i = open(SM_PATH_DEVNULL, fd == 0 ? O_RDONLY : O_WRONLY, 0666);
1N/A if (i < 0)
1N/A {
1N/A syserr("!fill_fd: %s: cannot open %s",
1N/A where == NULL ? "startup" : where, SM_PATH_DEVNULL);
1N/A }
1N/A if (fd != i)
1N/A {
1N/A (void) dup2(i, fd);
1N/A (void) close(i);
1N/A }
1N/A}
1N/A/*
1N/A** SM_PRINTOPTIONS -- print options
1N/A**
1N/A** Parameters:
1N/A** options -- array of options.
1N/A**
1N/A** Returns:
1N/A** none.
1N/A*/
1N/A
1N/Astatic void
1N/Asm_printoptions(options)
1N/A char **options;
1N/A{
1N/A int ll;
1N/A char **av;
1N/A
1N/A av = options;
1N/A ll = 7;
1N/A while (*av != NULL)
1N/A {
1N/A if (ll + strlen(*av) > 63)
1N/A {
1N/A sm_dprintf("\n");
1N/A ll = 0;
1N/A }
1N/A if (ll == 0)
1N/A sm_dprintf("\t\t");
1N/A else
1N/A sm_dprintf(" ");
1N/A sm_dprintf("%s", *av);
1N/A ll += strlen(*av++) + 1;
1N/A }
1N/A sm_dprintf("\n");
1N/A}
1N/A
1N/A/*
1N/A** TO8BIT -- convert \octal sequences in a test mode input line
1N/A**
1N/A** Parameters:
1N/A** str -- the input line.
1N/A**
1N/A** Returns:
1N/A** none.
1N/A**
1N/A** Side Effects:
1N/A** replaces \0octal in str with octal value.
1N/A*/
1N/A
1N/Astatic bool to8bit __P((char *));
1N/A
1N/Astatic bool
1N/Ato8bit(str)
1N/A char *str;
1N/A{
1N/A int c, len;
1N/A char *out, *in;
1N/A bool changed;
1N/A
1N/A if (str == NULL)
1N/A return false;
1N/A in = out = str;
1N/A changed = false;
1N/A len = 0;
1N/A while ((c = (*str++ & 0377)) != '\0')
1N/A {
1N/A int oct, nxtc;
1N/A
1N/A ++len;
1N/A if (c == '\\' &&
1N/A (nxtc = (*str & 0377)) == '0')
1N/A {
1N/A oct = 0;
1N/A while ((nxtc = (*str & 0377)) != '\0' &&
1N/A isascii(nxtc) && isdigit(nxtc))
1N/A {
1N/A oct <<= 3;
1N/A oct += nxtc - '0';
1N/A ++str;
1N/A ++len;
1N/A }
1N/A changed = true;
1N/A c = oct;
1N/A }
1N/A *out++ = c;
1N/A }
1N/A *out++ = c;
1N/A if (changed)
1N/A {
1N/A char *q;
1N/A
1N/A q = quote_internal_chars(in, in, &len);
1N/A if (q != in)
1N/A sm_strlcpy(in, q, len);
1N/A }
1N/A return changed;
1N/A}
1N/A
1N/A/*
1N/A** TESTMODELINE -- process a test mode input line
1N/A**
1N/A** Parameters:
1N/A** line -- the input line.
1N/A** e -- the current environment.
1N/A** Syntax:
1N/A** # a comment
1N/A** .X process X as a configuration line
1N/A** =X dump a configuration item (such as mailers)
1N/A** $X dump a macro or class
1N/A** /X try an activity
1N/A** X normal process through rule set X
1N/A*/
1N/A
1N/Astatic void
1N/Atestmodeline(line, e)
1N/A char *line;
1N/A ENVELOPE *e;
1N/A{
1N/A register char *p;
1N/A char *q;
1N/A auto char *delimptr;
1N/A int mid;
1N/A int i, rs;
1N/A STAB *map;
1N/A char **s;
1N/A struct rewrite *rw;
1N/A ADDRESS a;
1N/A char *lbp;
1N/A auto int lbs;
1N/A static int tryflags = RF_COPYNONE;
1N/A char exbuf[MAXLINE];
1N/A char lbuf[MAXLINE];
1N/A extern unsigned char TokTypeNoC[];
1N/A bool eightbit;
1N/A
1N/A /* skip leading spaces */
1N/A while (*line == ' ')
1N/A line++;
1N/A
1N/A lbp = NULL;
1N/A eightbit = false;
1N/A switch (line[0])
1N/A {
1N/A case '#':
1N/A case '\0':
1N/A return;
1N/A
1N/A case '?':
1N/A help("-bt", e);
1N/A return;
1N/A
1N/A case '.': /* config-style settings */
1N/A switch (line[1])
1N/A {
1N/A case 'D':
1N/A mid = macid_parse(&line[2], &delimptr);
1N/A if (mid == 0)
1N/A return;
1N/A lbs = sizeof(lbuf);
1N/A lbp = translate_dollars(delimptr, lbuf, &lbs);
1N/A macdefine(&e->e_macro, A_TEMP, mid, lbp);
1N/A if (lbp != lbuf)
1N/A SM_FREE(lbp);
1N/A break;
1N/A
1N/A case 'C':
1N/A if (line[2] == '\0') /* not to call syserr() */
1N/A return;
1N/A
1N/A mid = macid_parse(&line[2], &delimptr);
1N/A if (mid == 0)
1N/A return;
1N/A lbs = sizeof(lbuf);
1N/A lbp = translate_dollars(delimptr, lbuf, &lbs);
1N/A expand(lbp, exbuf, sizeof(exbuf), e);
1N/A if (lbp != lbuf)
1N/A SM_FREE(lbp);
1N/A p = exbuf;
1N/A while (*p != '\0')
1N/A {
1N/A register char *wd;
1N/A char delim;
1N/A
1N/A while (*p != '\0' && isascii(*p) && isspace(*p))
1N/A p++;
1N/A wd = p;
1N/A while (*p != '\0' && !(isascii(*p) && isspace(*p)))
1N/A p++;
1N/A delim = *p;
1N/A *p = '\0';
1N/A if (wd[0] != '\0')
1N/A setclass(mid, wd);
1N/A *p = delim;
1N/A }
1N/A break;
1N/A
1N/A case '\0':
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Usage: .[DC]macro value(s)\n");
1N/A break;
1N/A
1N/A default:
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Unknown \".\" command %s\n", line);
1N/A break;
1N/A }
1N/A return;
1N/A
1N/A case '=': /* config-style settings */
1N/A switch (line[1])
1N/A {
1N/A case 'S': /* dump rule set */
1N/A rs = strtorwset(&line[2], NULL, ST_FIND);
1N/A if (rs < 0)
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Undefined ruleset %s\n", &line[2]);
1N/A return;
1N/A }
1N/A rw = RewriteRules[rs];
1N/A if (rw == NULL)
1N/A return;
1N/A do
1N/A {
1N/A (void) sm_io_putc(smioout, SM_TIME_DEFAULT,
1N/A 'R');
1N/A s = rw->r_lhs;
1N/A while (*s != NULL)
1N/A {
1N/A xputs(smioout, *s++);
1N/A (void) sm_io_putc(smioout,
1N/A SM_TIME_DEFAULT, ' ');
1N/A }
1N/A (void) sm_io_putc(smioout, SM_TIME_DEFAULT,
1N/A '\t');
1N/A (void) sm_io_putc(smioout, SM_TIME_DEFAULT,
1N/A '\t');
1N/A s = rw->r_rhs;
1N/A while (*s != NULL)
1N/A {
1N/A xputs(smioout, *s++);
1N/A (void) sm_io_putc(smioout,
1N/A SM_TIME_DEFAULT, ' ');
1N/A }
1N/A (void) sm_io_putc(smioout, SM_TIME_DEFAULT,
1N/A '\n');
1N/A } while ((rw = rw->r_next) != NULL);
1N/A break;
1N/A
1N/A case 'M':
1N/A for (i = 0; i < MAXMAILERS; i++)
1N/A {
1N/A if (Mailer[i] != NULL)
1N/A printmailer(smioout, Mailer[i]);
1N/A }
1N/A break;
1N/A
1N/A case '\0':
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Usage: =Sruleset or =M\n");
1N/A break;
1N/A
1N/A default:
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Unknown \"=\" command %s\n", line);
1N/A break;
1N/A }
1N/A return;
1N/A
1N/A case '-': /* set command-line-like opts */
1N/A switch (line[1])
1N/A {
1N/A case 'd':
1N/A tTflag(&line[2]);
1N/A break;
1N/A
1N/A case '\0':
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Usage: -d{debug arguments}\n");
1N/A break;
1N/A
1N/A default:
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Unknown \"-\" command %s\n", line);
1N/A break;
1N/A }
1N/A return;
1N/A
1N/A case '$':
1N/A if (line[1] == '=')
1N/A {
1N/A mid = macid(&line[2]);
1N/A if (mid != 0)
1N/A stabapply(dump_class, mid);
1N/A return;
1N/A }
1N/A mid = macid(&line[1]);
1N/A if (mid == 0)
1N/A return;
1N/A p = macvalue(mid, e);
1N/A if (p == NULL)
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Undefined\n");
1N/A else
1N/A {
1N/A xputs(smioout, p);
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "\n");
1N/A }
1N/A return;
1N/A
1N/A case '/': /* miscellaneous commands */
1N/A p = &line[strlen(line)];
1N/A while (--p >= line && isascii(*p) && isspace(*p))
1N/A *p = '\0';
1N/A p = strpbrk(line, " \t");
1N/A if (p != NULL)
1N/A {
1N/A while (isascii(*p) && isspace(*p))
1N/A *p++ = '\0';
1N/A }
1N/A else
1N/A p = "";
1N/A if (line[1] == '\0')
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Usage: /[canon|map|mx|parse|try|tryflags]\n");
1N/A return;
1N/A }
1N/A if (sm_strcasecmp(&line[1], "quit") == 0)
1N/A {
1N/A CurEnv->e_id = NULL;
1N/A finis(true, true, ExitStat);
1N/A /* NOTREACHED */
1N/A }
1N/A if (sm_strcasecmp(&line[1], "mx") == 0)
1N/A {
1N/A#if NAMED_BIND
1N/A /* look up MX records */
1N/A int nmx;
1N/A auto int rcode;
1N/A char *mxhosts[MAXMXHOSTS + 1];
1N/A
1N/A if (*p == '\0')
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Usage: /mx address\n");
1N/A return;
1N/A }
1N/A nmx = getmxrr(p, mxhosts, NULL, false, &rcode, true,
1N/A NULL);
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "getmxrr(%s) returns %d value(s):\n",
1N/A p, nmx);
1N/A for (i = 0; i < nmx; i++)
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "\t%s\n", mxhosts[i]);
1N/A#else /* NAMED_BIND */
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "No MX code compiled in\n");
1N/A#endif /* NAMED_BIND */
1N/A }
1N/A else if (sm_strcasecmp(&line[1], "canon") == 0)
1N/A {
1N/A char host[MAXHOSTNAMELEN];
1N/A
1N/A if (*p == '\0')
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Usage: /canon address\n");
1N/A return;
1N/A }
1N/A else if (sm_strlcpy(host, p, sizeof(host)) >= sizeof(host))
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Name too long\n");
1N/A return;
1N/A }
1N/A (void) getcanonname(host, sizeof(host), !HasWildcardMX,
1N/A NULL);
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "getcanonname(%s) returns %s\n",
1N/A p, host);
1N/A }
1N/A else if (sm_strcasecmp(&line[1], "map") == 0)
1N/A {
1N/A auto int rcode = EX_OK;
1N/A char *av[2];
1N/A
1N/A if (*p == '\0')
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Usage: /map mapname key\n");
1N/A return;
1N/A }
1N/A for (q = p; *q != '\0' && !(isascii(*q) && isspace(*q)); q++)
1N/A continue;
1N/A if (*q == '\0')
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "No key specified\n");
1N/A return;
1N/A }
1N/A *q++ = '\0';
1N/A map = stab(p, ST_MAP, ST_FIND);
1N/A if (map == NULL)
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Map named \"%s\" not found\n", p);
1N/A return;
1N/A }
1N/A if (!bitset(MF_OPEN, map->s_map.map_mflags) &&
1N/A !openmap(&(map->s_map)))
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Map named \"%s\" not open\n", p);
1N/A return;
1N/A }
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "map_lookup: %s (%s) ", p, q);
1N/A av[0] = q;
1N/A av[1] = NULL;
1N/A p = (*map->s_map.map_class->map_lookup)
1N/A (&map->s_map, q, av, &rcode);
1N/A if (p == NULL)
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "no match (%d)\n",
1N/A rcode);
1N/A else
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "returns %s (%d)\n", p,
1N/A rcode);
1N/A }
1N/A else if (sm_strcasecmp(&line[1], "try") == 0)
1N/A {
1N/A MAILER *m;
1N/A STAB *st;
1N/A auto int rcode = EX_OK;
1N/A
1N/A q = strpbrk(p, " \t");
1N/A if (q != NULL)
1N/A {
1N/A while (isascii(*q) && isspace(*q))
1N/A *q++ = '\0';
1N/A }
1N/A if (q == NULL || *q == '\0')
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Usage: /try mailer address\n");
1N/A return;
1N/A }
1N/A st = stab(p, ST_MAILER, ST_FIND);
1N/A if (st == NULL)
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Unknown mailer %s\n", p);
1N/A return;
1N/A }
1N/A m = st->s_mailer;
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Trying %s %s address %s for mailer %s\n",
1N/A bitset(RF_HEADERADDR, tryflags) ? "header"
1N/A : "envelope",
1N/A bitset(RF_SENDERADDR, tryflags) ? "sender"
1N/A : "recipient", q, p);
1N/A p = remotename(q, m, tryflags, &rcode, CurEnv);
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Rcode = %d, addr = %s\n",
1N/A rcode, p == NULL ? "<NULL>" : p);
1N/A e->e_to = NULL;
1N/A }
1N/A else if (sm_strcasecmp(&line[1], "tryflags") == 0)
1N/A {
1N/A if (*p == '\0')
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Usage: /tryflags [Hh|Ee][Ss|Rr]\n");
1N/A return;
1N/A }
1N/A for (; *p != '\0'; p++)
1N/A {
1N/A switch (*p)
1N/A {
1N/A case 'H':
1N/A case 'h':
1N/A tryflags |= RF_HEADERADDR;
1N/A break;
1N/A
1N/A case 'E':
1N/A case 'e':
1N/A tryflags &= ~RF_HEADERADDR;
1N/A break;
1N/A
1N/A case 'S':
1N/A case 's':
1N/A tryflags |= RF_SENDERADDR;
1N/A break;
1N/A
1N/A case 'R':
1N/A case 'r':
1N/A tryflags &= ~RF_SENDERADDR;
1N/A break;
1N/A }
1N/A }
1N/A exbuf[0] = bitset(RF_HEADERADDR, tryflags) ? 'h' : 'e';
1N/A exbuf[1] = ' ';
1N/A exbuf[2] = bitset(RF_SENDERADDR, tryflags) ? 's' : 'r';
1N/A exbuf[3] = '\0';
1N/A macdefine(&e->e_macro, A_TEMP,
1N/A macid("{addr_type}"), exbuf);
1N/A }
1N/A else if (sm_strcasecmp(&line[1], "parse") == 0)
1N/A {
1N/A if (*p == '\0')
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Usage: /parse address\n");
1N/A return;
1N/A }
1N/A q = crackaddr(p, e);
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Cracked address = ");
1N/A xputs(smioout, q);
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "\nParsing %s %s address\n",
1N/A bitset(RF_HEADERADDR, tryflags) ?
1N/A "header" : "envelope",
1N/A bitset(RF_SENDERADDR, tryflags) ?
1N/A "sender" : "recipient");
1N/A if (parseaddr(p, &a, tryflags, '\0', NULL, e, true)
1N/A == NULL)
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Cannot parse\n");
1N/A else if (a.q_host != NULL && a.q_host[0] != '\0')
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "mailer %s, host %s, user %s\n",
1N/A a.q_mailer->m_name,
1N/A a.q_host,
1N/A a.q_user);
1N/A else
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "mailer %s, user %s\n",
1N/A a.q_mailer->m_name,
1N/A a.q_user);
1N/A e->e_to = NULL;
1N/A }
1N/A else if (sm_strcasecmp(&line[1], "header") == 0)
1N/A {
1N/A unsigned long ul;
1N/A
1N/A ul = chompheader(p, CHHDR_CHECK|CHHDR_USER, NULL, e);
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "ul = %lu\n", ul);
1N/A }
1N/A else
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Unknown \"/\" command %s\n",
1N/A line);
1N/A }
1N/A (void) sm_io_flush(smioout, SM_TIME_DEFAULT);
1N/A return;
1N/A }
1N/A
1N/A for (p = line; isascii(*p) && isspace(*p); p++)
1N/A continue;
1N/A q = p;
1N/A while (*p != '\0' && !(isascii(*p) && isspace(*p)))
1N/A p++;
1N/A if (*p == '\0')
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "No address!\n");
1N/A return;
1N/A }
1N/A *p = '\0';
1N/A if (tTd(23, 101))
1N/A eightbit = to8bit(p + 1);
1N/A if (invalidaddr(p + 1, NULL, true))
1N/A return;
1N/A do
1N/A {
1N/A register char **pvp;
1N/A char pvpbuf[PSBUFSIZE];
1N/A
1N/A pvp = prescan(++p, ',', pvpbuf, sizeof(pvpbuf), &delimptr,
1N/A ConfigLevel >= 9 ? TokTypeNoC : ExtTokenTab, false);
1N/A if (pvp == NULL)
1N/A continue;
1N/A p = q;
1N/A while (*p != '\0')
1N/A {
1N/A int status;
1N/A
1N/A rs = strtorwset(p, NULL, ST_FIND);
1N/A if (rs < 0)
1N/A {
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "Undefined ruleset %s\n",
1N/A p);
1N/A break;
1N/A }
1N/A status = REWRITE(pvp, rs, e);
1N/A if (status != EX_OK)
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "== Ruleset %s (%d) status %d\n",
1N/A p, rs, status);
1N/A else if (eightbit)
1N/A {
1N/A cataddr(pvp, NULL, exbuf, sizeof(exbuf), '\0',
1N/A true);
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "cataddr: %s\n",
1N/A str2prt(exbuf));
1N/A }
1N/A while (*p != '\0' && *p++ != ',')
1N/A continue;
1N/A }
1N/A } while (*(p = delimptr) != '\0');
1N/A (void) sm_io_flush(smioout, SM_TIME_DEFAULT);
1N/A}
1N/A
1N/Astatic void
1N/Adump_class(s, id)
1N/A register STAB *s;
1N/A int id;
1N/A{
1N/A if (s->s_symtype != ST_CLASS)
1N/A return;
1N/A if (bitnset(bitidx(id), s->s_class))
1N/A (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
1N/A "%s\n", s->s_name);
1N/A}
1N/A
1N/A/*
1N/A** An exception type used to create QuickAbort exceptions.
1N/A** This is my first cut at converting QuickAbort from longjmp to exceptions.
1N/A** These exceptions have a single integer argument, which is the argument
1N/A** to longjmp in the original code (either 1 or 2). I don't know the
1N/A** significance of 1 vs 2: the calls to setjmp don't care.
1N/A*/
1N/A
1N/Aconst SM_EXC_TYPE_T EtypeQuickAbort =
1N/A{
1N/A SmExcTypeMagic,
1N/A "E:mta.quickabort",
1N/A "i",
1N/A sm_etype_printf,
1N/A "quick abort %0",
1N/A};