/*
* Copyright (c) 1998-2004, 2006, 2007 Sendmail, Inc. and its suppliers.
* All rights reserved.
* Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the sendmail distribution.
*
*/
#include <sendmail.h>
#include <sm/sendmail.h>
/*
** SETUPHEADERS -- initialize headers in symbol table
**
** Parameters:
** none
**
** Returns:
** none
*/
void
{
STAB *s;
{
}
}
/*
** DOCHOMPHEADER -- process and save a header line.
**
** Called by chompheader.
**
** Parameters:
** line -- header as a text line.
** pflag -- flags for chompheader() (from sendmail.h)
** hdrp -- a pointer to the place to save the header.
** e -- the envelope including this header.
**
** Returns:
** flags for this header.
**
** Side Effects:
** The header is saved on the header list.
** Contents of 'line' are destroyed.
*/
static unsigned long
char *line;
int pflag;
ENVELOPE *e;
{
register char *p;
register HDR *h;
char *fname;
char *fvalue;
bool cond = false;
bool dropfrom;
bool headeronly;
STAB *s;
bool nullheader = false;
if (!headeronly)
/* strip off options */
p = line;
{
int c;
register char *q;
q = strchr(++p, '?');
if (q == NULL)
goto hse;
*q = '\0';
c = *p & 0377;
/* possibly macro conditional */
if (c == MACROEXPAND)
{
/* catch ?$? */
if (*++p == '\0')
{
*q = '?';
goto hse;
}
mid = (unsigned char) *p++;
/* catch ?$abc? */
if (*p != '\0')
{
*q = '?';
goto hse;
}
}
else if (*p == '$')
{
/* catch ?$? */
if (*++p == '\0')
{
*q = '?';
goto hse;
}
{
SM_ASSERT(p <= q);
}
else
p++;
/* catch ?$abc? */
if (*p != '\0')
{
*q = '?';
goto hse;
}
}
else
{
while (*p != '\0')
{
if (!isascii(*p))
{
*q = '?';
goto hse;
}
cond = true;
p++;
}
}
p = q + 1;
}
/* find canonical name */
fname = p;
p++;
fvalue = p;
p++;
{
hse:
return 0;
}
*fvalue = '\0';
fvalue = p;
/* if the field is null, go ahead and use the default */
p++;
if (*p == '\0')
nullheader = true;
/* security scan: long field names are end-of-header */
return H_EOH;
/* check to see if it represents a ruleset call */
{
p++;
if ((*p++ & 0377) == CALLSUBR)
{
auto char *endp;
bool strc;
if (strc)
++p;
{
*endp = '\0';
if (LogLevel > 9 &&
"Warning: redefined ruleset for header=%s, old=%s, new=%s",
s->s_header.hi_ruleset, p);
if (!strc)
}
return 0;
}
}
/* see if it is a known type */
if (s != NULL)
else
hi = &NormalHeader;
{
if (s == NULL)
sm_dprintf("no header flags match\n");
else
sm_dprintf("header match, flags=%lx, ruleset=%s\n",
: hi->hi_ruleset);
}
/* see if this is a resent message */
/* if this is an Errors-To: header keep track of it now */
/* if this means "end of header" quit now */
/*
** Horrible hack to work around problem with Lotus Notes SMTP
** mail gateway, which generates From: headers with newlines in
** them and the <address> on the second line. Although this is
** legal RFC 822, many MUAs don't handle this properly and thus
** never find the actual address.
*/
{
*p = ' ';
}
/*
** If there is a check ruleset, verify it against the header.
*/
{
int rscheckflags;
char *rs;
/* no ruleset? look for default */
{
if (s != NULL)
{
}
}
{
int l, k;
l = 0;
qval[l++] = '"';
/* - 3 to avoid problems with " at the end */
/* should be sizeof(qval), not MAXNAME */
{
switch (fvalue[k])
{
/* XXX other control chars? */
case '\011': /* ht */
case '\012': /* nl */
case '\013': /* vt */
case '\014': /* np */
case '\015': /* cr */
qval[l++] = ' ';
break;
case '"':
qval[l++] = '\\';
/* FALLTHROUGH */
default:
break;
}
}
qval[l++] = '"';
qval[l] = '\0';
if (k >= MAXNAME)
{
if (LogLevel > 9)
"Warning: truncated header '%s' before check with '%s' len=%d max=%d",
}
else
}
}
/*
** Drop explicit From: if same as what we would generate.
** This is to make MH (which doesn't always give a full name)
** insert the full name information in all circumstances.
*/
dropfrom = false;
p = "resent-from";
p += 7;
{
{
sm_dprintf("comparing header from (%s) against default (%s or %s)\n",
}
dropfrom = true;
}
/* delete default value for this header */
{
{
if (nullheader)
{
/* user-supplied value was null */
return 0;
}
if (dropfrom)
{
/* make this look like the user entered it */
}
if (!cond)
{
/* copy conditions from default case */
sizeof(mopts));
}
}
}
/* create a new node */
*hp = h;
/* strip EOH flag if parsing MIME headers */
if (headeronly)
/* hack to see if this is a new format message */
{
e->e_flags &= ~EF_OLDSTYLE;
}
return h->h_flags;
}
/*
** CHOMPHEADER -- process and save a header line.
**
** Called by collect, readcf, and readqf to deal with header lines.
** This is just a wrapper for dochompheader().
**
** Parameters:
** line -- header as a text line.
** pflag -- flags for chompheader() (from sendmail.h)
** hdrp -- a pointer to the place to save the header.
** e -- the envelope including this header.
**
** Returns:
** flags for this header.
**
** Side Effects:
** The header is saved on the header list.
** Contents of 'line' are destroyed.
*/
unsigned long
char *line;
int pflag;
register ENVELOPE *e;
{
unsigned long rval;
{
sm_dprintf("chompheader: ");
sm_dprintf("\n");
}
/* quote this if user (not config file) input */
{
int xbufs;
{
sm_dprintf("chompheader: quoted: ");
sm_dprintf("\n");
}
}
else
return rval;
}
/*
** ALLOCHEADER -- allocate a header entry
**
** Parameters:
** field -- the name of the header field (will not be copied).
** value -- the value of the field (will be copied).
** flags -- flags to add to h_flags.
** rp -- resource pool for allocations
** space -- add leading space?
**
** Returns:
** Pointer to a newly allocated and populated HDR.
**
** Notes:
** o field and value must be in internal format, i.e.,
** metacharacters must be "quoted", see quote_internal_chars().
** o maybe add more flags to decide:
** - whether to convert value to an internal format
*/
static HDR *
char *field;
char *value;
int flags;
SM_RPOOL_T *rp;
bool space;
{
HDR *h;
STAB *s;
/* find info struct */
/* allocate space for new header */
if (space)
{
size_t l;
char *n;
SM_ASSERT(l + 2 > l);
n[0] = ' ';
n[1] = '\0';
h->h_value = n;
}
else
if (s != NULL)
h->h_macro = '\0';
return h;
}
/*
** ADDHEADER -- add a header entry to the end of the queue.
**
** This bypasses the special checking of chompheader.
**
** Parameters:
** field -- the name of the header field (will not be copied).
** value -- the value of the field (will be copied).
** flags -- flags to add to h_flags.
** e -- envelope.
** space -- add leading space?
**
** Returns:
** none.
**
** Side Effects:
** adds the field on the list of headers for this envelope.
**
** Notes: field and value must be in internal format, i.e.,
** metacharacters must be "quoted", see quote_internal_chars().
*/
void
char *field;
char *value;
int flags;
ENVELOPE *e;
bool space;
{
register HDR *h;
/* find current place in list -- keep back pointer? */
{
break;
}
/* allocate space for new header */
*hp = h;
}
/*
** INSHEADER -- insert a header entry at the specified index
** This bypasses the special checking of chompheader.
**
** Parameters:
** idx -- index into the header list at which to insert
** field -- the name of the header field (will be copied).
** value -- the value of the field (will be copied).
** flags -- flags to add to h_flags.
** e -- envelope.
** space -- add leading space?
**
** Returns:
** none.
**
** Side Effects:
** inserts the field on the list of headers for this envelope.
**
** Notes:
** - field and value must be in internal format, i.e.,
** metacharacters must be "quoted", see quote_internal_chars().
** - the header list contains headers that might not be
** sent "out" (see putheader(): "skip"), hence there is no
** reliable way to insert a header at an exact position
** (except at the front or end).
*/
void
int idx;
char *field;
char *value;
int flags;
ENVELOPE *e;
bool space;
{
/* allocate space for new header */
/* find insertion position */
{
e->e_header = h;
}
{
}
else
{
}
}
/*
** HVALUE -- return value of a header.
**
** Only "real" fields (i.e., ones that have not been supplied
** as a default) are used.
**
** Parameters:
** field -- the field name.
** header -- the header list.
**
** Returns:
** pointer to the value part (internal format).
** NULL if not found.
**
** Side Effects:
** none.
*/
char *
char *field;
{
register HDR *h;
{
{
char *s;
s = h->h_value;
if (s == NULL)
return NULL;
s++;
return s;
}
}
return NULL;
}
/*
** ISHEADER -- predicate telling if argument is a header.
**
** A line is a header if it has a single word followed by
** optional white space followed by a colon.
**
** Header fields beginning with two dashes, although technically
** permitted by RFC822, are automatically rejected in order
** to make MIME work out. Without this we could have a technically
** legal header such as ``--"foo:bar"'' that would also be a legal
** MIME separator.
**
** Parameters:
** h -- string to check for possible headerness.
**
** Returns:
** true if h is a header.
** false otherwise.
**
** Side Effects:
** none.
*/
bool
isheader(h)
char *h;
{
char *s;
s = h;
if (s[0] == '-' && s[1] == '-')
return false;
while (*s > ' ' && *s != ':' && *s != '\0')
s++;
if (h == s)
return false;
/* following technically violates RFC822 */
s++;
return (*s == ':');
}
/*
** EATHEADER -- run through the stored header and extract info.
**
** Parameters:
** e -- the envelope to process.
** full -- if set, do full processing (e.g., compute
** message priority). This should not be set
** when reading a queue file because some info
** needed to compute the priority is wrong.
** log -- call logsender()?
**
** Returns:
** none.
**
** Side Effects:
** Sets a bunch of global variables from information
** in the collected header.
*/
void
register ENVELOPE *e;
bool full;
bool log;
{
register HDR *h;
register char *p;
int hopcnt = 0;
/*
** Set up macros for possible expansion in headers.
*/
else
/* full name of from person */
if (p != NULL)
{
if (!rfc822_string(p))
{
/*
** Quote a full name with special characters
** as a comment so crackaddr() doesn't destroy
** the name portion of the address.
*/
}
}
sm_dprintf("----- collected header -----\n");
{
{
sm_dprintf("<NULL>\n");
continue;
}
/* do early binding */
{
{
sm_dprintf("(");
sm_dprintf(") ");
}
if (buf[0] != '\0' &&
{
}
}
{
sm_dprintf("\n");
}
/* count the number of times it has been processed */
hopcnt++;
/* send to this person if we so desire */
{
#if 0
#endif /* 0 */
NULLADDR, &e->e_sendqueue, 0, e);
#if 0
/*
** Change functionality so a fatal error on an
** address doesn't affect the entire envelope.
*/
/* delete fatal errors generated by this address */
e->e_flags &= ~EF_FATALERRS;
#endif /* 0 */
}
/* save the message-id for logging */
p = "resent-message-id";
p += 7;
if (sm_strcasecmp(h->h_field, p) == 0)
{
e->e_msgid++;
e->e_msgid);
}
}
sm_dprintf("----------------------------\n");
/* if we are just verifying (that is, sendmail -t -bv), drop out now */
return;
/* store hop count */
if (hopcnt > e->e_hopcount)
{
e->e_hopcount = hopcnt;
}
/* message priority */
if (p != NULL)
if (e->e_class < 0)
e->e_timeoutclass = TOC_NONURGENT;
else if (e->e_class > 0)
e->e_timeoutclass = TOC_URGENT;
if (full)
{
e->e_msgpriority = e->e_msgsize
- e->e_class * WkClassFact
+ e->e_nrcpts * WkRecipFact;
}
/* check for DSN to properly set e_timeoutclass */
if (p != NULL)
{
bool oldsupr;
char **pvp;
extern unsigned char MimeTokenTab[256];
/* tokenize header */
SuprErrs = true;
MimeTokenTab, false);
{
/* Look for report-type=delivery-status */
{
/* skip to semicolon separator */
pvp++;
/* skip semicolon */
break;
/* look for report-type */
continue;
/* skip equal */
continue;
/* check value */
"delivery-status") == 0)
e->e_timeoutclass = TOC_DSN;
/* found report-type, no need to continue */
break;
}
}
}
/* message timeout priority */
if (p != NULL)
{
/* (this should be in the configuration file) */
if (sm_strcasecmp(p, "urgent") == 0)
e->e_timeoutclass = TOC_URGENT;
else if (sm_strcasecmp(p, "normal") == 0)
e->e_timeoutclass = TOC_NORMAL;
else if (sm_strcasecmp(p, "non-urgent") == 0)
e->e_timeoutclass = TOC_NONURGENT;
e->e_timeoutclass = TOC_DSN;
}
e->e_timeoutclass = TOC_DSN;
/* date message originated */
if (p == NULL)
if (p != NULL)
/* check to see if this is a MIME message */
if ((e->e_bodytype != NULL &&
{
e->e_flags |= EF_IS_MIME;
if (HasEightBits)
e->e_bodytype = "8BITMIME";
}
{
/* this may be an RFC 1049 message */
p = strpbrk(p, ";/");
if (p == NULL || *p == ';')
{
/* yep, it is */
e->e_flags |= EF_DONT_MIME;
}
}
/*
** From person in antiquated ARPANET mode
** required by UK Grey Book e-mail gateways (sigh)
*/
if (OpMode == MD_ARPAFTP)
{
{
break;
}
{
sm_dprintf("eatheader: setsender(*%s == %s)\n",
}
}
/*
** Log collection information.
*/
sm_dprintf("eatheader: e_id=%s, EF_LOGSENDER=%d, LogLevel=%d, log=%d\n",
log);
{
e->e_flags &= ~EF_LOGSENDER;
}
}
/*
** LOGSENDER -- log sender information
**
** Parameters:
** e -- the envelope to log
** msgid -- the message id
**
** Returns:
** none
*/
void
register ENVELOPE *e;
char *msgid;
{
char *name;
register char *sbp;
register char *p;
/* don't allow newlines in the message-id */
/* XXX do we still need this? sm_syslog() replaces control chars */
{
size_t l;
if (l > sizeof(mbuf) - 1)
l = sizeof(mbuf) - 1;
mbuf[l] = '\0';
p = mbuf;
*p++ = ' ';
}
name = "[RESPONSE]";
/* EMPTY */
;
else if (RealHostName == NULL)
name = "localhost";
else if (RealHostName[0] == '[')
name = RealHostName;
else
{
{
" (%.100s)",
}
}
/* some versions of syslog only take 5 printf args */
#if (SYSLOG_BUFSIZE) >= 256
"from=%.200s, size=%ld, class=%d, nrcpts=%d",
{
", msgid=%.100s", mbuf);
}
if (e->e_bodytype != NULL)
{
", bodytype=%.20s", e->e_bodytype);
}
p = macvalue('r', e);
if (p != NULL)
{
", proto=%.20s", p);
}
if (p != NULL)
{
", daemon=%.20s", p);
}
#else /* (SYSLOG_BUFSIZE) >= 256 */
"from=%s",
83));
"size=%ld, class=%ld, nrcpts=%d",
"msgid=%s",
*sbp = '\0';
if (e->e_bodytype != NULL)
{
"bodytype=%.20s, ", e->e_bodytype);
}
p = macvalue('r', e);
if (p != NULL)
{
"proto=%.20s, ", p);
}
#endif /* (SYSLOG_BUFSIZE) >= 256 */
}
/*
** PRIENCODE -- encode external priority names into internal values.
**
** Parameters:
** p -- priority in ascii.
**
** Returns:
** priority as a numeric level.
**
** Side Effects:
** none.
*/
static int
priencode(p)
char *p;
{
register int i;
for (i = 0; i < NumPriorities; i++)
{
return Priorities[i].pri_val;
}
/* unknown priority */
return 0;
}
/*
** CRACKADDR -- parse an address and turn it into a macro
**
** This doesn't actually parse the address -- it just extracts
** it and replaces it with "$g". The parse is totally ad hoc
** and isn't even guaranteed to leave something syntactically
** identical to what it started with. However, it does leave
** something semantically identical if possible, else at least
** syntactically correct.
**
** For example, it changes "Real Name <real@example.com> (Comment)"
** to "Real Name <$g> (Comment)".
**
** This algorithm has been cleaned up to handle a wider range
** of cases -- notably quoted and backslash escaped strings.
** This modification makes it substantially better at preserving
** the original syntax.
**
** Parameters:
** addr -- the address to be cracked.
** e -- the current envelope.
**
** Returns:
** a pointer to the new version.
**
** Side Effects:
** none.
**
** Warning:
** The return value is saved in local storage and should
** be copied if it is to be reused.
*/
/*
** Append a character to bp if we have room.
** If not, punt and return $g.
*/
#define SM_APPEND_CHAR(c) \
do \
{ \
if (SM_HAVE_ROOM) \
*bp++ = (c); \
else \
goto returng; \
} while (0)
#if MAXNAME < 10
#endif /* MAXNAME < 10 */
char *
register char *addr;
ENVELOPE *e;
{
register char *p;
register char c;
register char *bp;
char *buflim;
char *bufhead;
char *addrhead;
char *bufend;
/* skip over leading spaces but preserve them */
{
addr++;
}
/*
** Start by assuming we have no angle brackets. This will be
** adjusted later if we find them.
*/
bracklev = 0;
while ((c = *p++) != '\0')
{
/*
** Try to keep legal syntax using spare buffer space
** (maintained by buflim).
*/
if (copylev > 0)
SM_APPEND_CHAR(c);
/* check for backslash escapes */
if (c == '\\')
{
/* arrange to quote the address */
quoteit = true;
if ((c = *p++) == '\0')
{
/* too far */
p--;
goto putg;
}
if (copylev > 0)
SM_APPEND_CHAR(c);
goto putg;
}
/* check for quoted strings */
if (c == '"' && cmtlev <= 0)
{
if (copylev > 0 && SM_HAVE_ROOM)
{
if (realqmode)
buflim--;
else
buflim++;
}
continue;
}
if (qmode)
goto putg;
/* check for comments */
if (c == '(')
{
cmtlev++;
/* allow space for closing paren */
if (SM_HAVE_ROOM)
{
buflim--;
realcmtlev++;
if (copylev++ <= 0)
{
SM_APPEND_CHAR(' ');
SM_APPEND_CHAR(c);
}
}
}
if (cmtlev > 0)
{
if (c == ')')
{
cmtlev--;
copylev--;
if (SM_HAVE_ROOM)
{
realcmtlev--;
buflim++;
}
}
continue;
}
else if (c == ')')
{
/* syntax error: unmatched ) */
bp--;
}
/* count nesting on [ ... ] (for IPv6 domain literals) */
if (c == '[')
bracklev++;
else if (c == ']')
bracklev--;
/* check for group: list; syntax */
!gotcolon && !ColonOkInAddr)
{
register char *q;
/*
** Check for DECnet phase IV ``::'' (host::user)
** or DECnet phase V ``:.'' syntaxes. The latter
** covers ``user@DEC:.tay.myhost'' and
** ``DEC:.tay.myhost::user'' syntaxes (bletch).
*/
if (*p == ':' || *p == '.')
{
quoteit = true;
if (copylev > 0)
{
SM_APPEND_CHAR(c);
SM_APPEND_CHAR(*p);
}
p++;
goto putg;
}
gotcolon = true;
if (quoteit)
{
SM_APPEND_CHAR('"');
/* back up over the ':' and any spaces */
--p;
while (p > addr &&
continue;
p++;
}
for (q = addrhead; q < p; )
{
c = *q++;
if (quoteit && c == '"')
SM_APPEND_CHAR('\\');
SM_APPEND_CHAR(c);
}
if (quoteit)
{
bp--;
else
SM_APPEND_CHAR('"');
while ((c = *p++) != ':')
SM_APPEND_CHAR(c);
SM_APPEND_CHAR(c);
}
/* any trailing white space is part of group: */
{
SM_APPEND_CHAR(*p);
p++;
}
copylev = 0;
addrhead = p;
continue;
}
SM_APPEND_CHAR(c);
/* check for characters that may have to be quoted */
{
/*
** If these occur as the phrase part of a <>
** construct, but are not inside of () or already
** quoted, they will have to be quoted. Note that
** now (but don't actually do the quoting).
*/
quoteit = true;
}
/* check for angle brackets */
if (c == '<')
{
register char *q;
/* assume first of two angles is bogus */
if (gotangle)
quoteit = true;
gotangle = true;
/* oops -- have to change our mind */
anglelev = 1;
if (SM_HAVE_ROOM)
{
if (!addangle)
buflim--;
addangle = true;
}
if (quoteit)
{
SM_APPEND_CHAR('"');
/* back up over the '<' and any spaces */
--p;
while (p > addr &&
continue;
p++;
}
for (q = addrhead; q < p; )
{
c = *q++;
if (quoteit && c == '"')
{
SM_APPEND_CHAR('\\');
SM_APPEND_CHAR(c);
}
else
SM_APPEND_CHAR(c);
}
if (quoteit)
{
bp--;
else
SM_APPEND_CHAR('"');
while ((c = *p++) != '<')
SM_APPEND_CHAR(c);
SM_APPEND_CHAR(c);
}
copylev = 0;
continue;
}
if (c == '>')
{
if (anglelev > 0)
{
anglelev--;
if (SM_HAVE_ROOM)
{
if (addangle)
buflim++;
addangle = false;
}
}
else if (SM_HAVE_ROOM)
{
/* syntax error: unmatched > */
bp--;
quoteit = true;
continue;
}
if (copylev++ <= 0)
SM_APPEND_CHAR(c);
continue;
}
/* must be a real address character */
putg:
{
SM_APPEND_CHAR(' ');
SM_APPEND_CHAR('g');
putgmac = true;
}
}
/* repair any syntactic damage */
*bp++ = '"';
*bp++ = ')';
*bp++ = '>';
*bp = '\0';
goto success;
/* String too long, punt */
buf[0] = '<';
"Dropped invalid comments from header address");
{
sm_dprintf("crackaddr=>`");
sm_dprintf("'\n");
}
return buf;
}
/*
** PUTHEADER -- put the header part of a message from the in-core copy
**
** Parameters:
** mci -- the connection information.
** hdr -- the header to put.
** e -- envelope to use.
** flags -- MIME conversion flags.
**
** Returns:
** true iff header part was written successfully
**
** Side Effects:
** none.
*/
bool
register ENVELOPE *e;
int flags;
{
register HDR *h;
sm_dprintf("--- putheader, mailer = %s ---\n",
/*
** If we're in MIME mode, we're not really in the header of the
** message, just the header of one of the parts of the body of
** the message. Therefore MCIF_INHEADER should not be turned on.
*/
{
register char *p = h->h_value;
char *q;
{
xputs(sm_debug_file(), p);
}
/* Skip empty headers */
continue;
/* heuristic shortening of MIME fields to avoid MUA overflows */
if (MaxMimeFieldLength > 0 &&
wordinclass(h->h_field,
macid("{checkMIMEFieldHeaders}")))
{
len = fix_mime_header(h, e);
if (len > 0)
{
"Truncated MIME %s header due to field size (length = %ld) (possible attack)",
sm_dprintf(" truncated MIME %s header due to field size (length = %ld) (possible attack)\n",
h->h_field,
(unsigned long) len);
}
}
if (MaxMimeHeaderLength > 0 &&
wordinclass(h->h_field,
macid("{checkMIMETextHeaders}")))
{
{
"Truncated long MIME %s header (length = %ld) (possible attack)",
sm_dprintf(" truncated long MIME %s header (length = %ld) (possible attack)\n",
h->h_field,
(unsigned long) len);
}
}
if (MaxMimeHeaderLength > 0 &&
wordinclass(h->h_field,
macid("{checkMIMEHeaders}")))
{
if (shorten_rfc822_string(h->h_value,
{
if (len < MaxMimeHeaderLength)
{
/* we only rebalanced a bogus header */
"Fixed MIME %s header (possible attack)",
h->h_field);
sm_dprintf(" fixed MIME %s header (possible attack)\n",
h->h_field);
}
else
{
/* we actually shortened header */
"Truncated long MIME %s header (length = %ld) (possible attack)",
h->h_field,
(unsigned long) len);
sm_dprintf(" truncated long MIME %s header (length = %ld) (possible attack)\n",
h->h_field,
(unsigned long) len);
}
}
}
/*
** Suppress Content-Transfer-Encoding: if we are MIMEing
** and we are potentially converting from 8 bit to 7 bit
** MIME. If converting, add a new CTE header in
** mime8to7().
*/
{
sm_dprintf(" (skipped (content-transfer-encoding))\n");
continue;
}
{
sm_dprintf("\n");
if (!put_vanilla_header(h, p, mci))
goto writeerr;
continue;
}
(h->h_macro == '\0' ||
*q == '\0'))
{
sm_dprintf(" (skipped)\n");
continue;
}
/* handle Resent-... headers specially */
{
sm_dprintf(" (skipped (resent))\n");
continue;
}
/* suppress return receipts if requested */
{
sm_dprintf(" (skipped (receipt))\n");
continue;
}
/* macro expand value if generated internally */
{
p = buf;
if (*p == '\0')
{
sm_dprintf(" (skipped -- null value)\n");
continue;
}
}
{
/* Bcc: field -- either truncate or delete */
{
sm_dprintf(" (skipped -- bcc)\n");
}
else
{
/* no other recipient headers: truncate value */
h->h_field, ":");
goto writeerr;
}
continue;
}
sm_dprintf("\n");
{
/* address field */
oldstyle = false;
}
else
{
if (!put_vanilla_header(h, p, mci))
goto writeerr;
}
}
/*
** If we are converting this to a MIME message, add the
** MIME headers (but not in MIME mode!).
*/
#if MIME8TO7
{
goto writeerr;
{
defcharset(e));
goto writeerr;
}
goto writeerr;
}
#endif /* MIME8TO7 */
return true;
return false;
}
/*
** PUT_VANILLA_HEADER -- output a fairly ordinary header
**
** Parameters:
** h -- the structure describing this header
** v -- the value of this header
** mci -- the connection info for output
**
** Returns:
** true iff header was written successfully
*/
static bool
HDR *h;
char *v;
{
register char *nlp;
register char *obp;
int putflags;
{
int l;
l = nlp - v;
/*
** XXX This is broken for SPACELEFT()==0
** However, SPACELEFT() is always > 0 unless MAXLINE==1.
*/
goto writeerr;
v += l + 1;
if (*v != ' ' && *v != '\t')
*obp++ = ' ';
}
/* XXX This is broken for SPACELEFT()==0 */
return false;
}
/*
** COMMAIZE -- output a header field, making a comma-translated list.
**
** Parameters:
** h -- the header field to output.
** p -- the value to put in it.
** oldstyle -- true if this is an old style header.
** mci -- the connection information.
** e -- the envelope containing the message.
** putflags -- flags for putxline()
**
** Returns:
** true iff header field was written successfully
**
** Side Effects:
** outputs "p" to "mci".
*/
bool
register HDR *h;
register char *p;
bool oldstyle;
register ENVELOPE *e;
int putflags;
{
register char *obp;
bool firstone = true;
char **res;
/*
** Output the address list translated by the
** mailer and with commas.
*/
/* opos = strlen(obp); instead of the next 3 lines? */
if (opos > 201)
opos = 201;
spaces = 0;
{
++spaces;
++p;
}
if (spaces > 0)
{
/*
** Restrict number of spaces to half the length of buffer
** so the header field body can be put in here too.
** Note: this is a hack...
*/
"");
}
omax = 78;
/*
** Run through the list of values.
*/
while (*p != '\0')
{
register char *name;
register int c;
char savechar;
int flags;
auto int status;
/*
** Find the end of the name. New style names
** end with a comma, old style names end with
** a space character. However, spaces do not
** necessarily delimit an old-style name -- at
** signs mean keep going.
*/
/* find end of name */
p++;
name = p;
for (;;)
{
auto char *oldp;
p = oldp;
/* ignore addresses that can't be parsed */
{
name = p;
continue;
}
#endif /* _FFR_IGNORE_BOGUS_ADDR */
/* look to see if we have an at sign */
p++;
if (*p != '@')
{
p = oldp;
break;
}
++p;
p++;
}
/* at the end of one complete name */
/* strip off trailing white space */
while (p >= name &&
p--;
if (++p == name)
continue;
/*
** if prescan() failed go a bit backwards; this is a hack,
** there should be some better error recovery.
*/
--p;
savechar = *p;
*p = '\0';
/* translate the name to be relative */
flags |= RF_SENDERADDR;
#if USERDB
{
char *q;
if (q != NULL)
name = q;
}
#endif /* USERDB */
if (*name == '\0')
{
*p = savechar;
continue;
}
/* output the name with nice formatting */
if (!firstone)
opos += 2;
{
goto writeerr;
}
else if (!firstone)
{
obp += 2;
}
*obp++ = c;
firstone = false;
*p = savechar;
}
*obp = '\0';
else
return false;
}
/*
** COPYHEADER -- copy header list
**
** This routine is the equivalent of newstr for header lists
**
** Parameters:
** header -- list of header structures to copy.
** rpool -- resource pool, or NULL
**
** Returns:
** a copy of 'header'.
**
** Side Effects:
** none.
*/
HDR *
{
{
}
return ret;
}
/*
**
** Run through all of the parameters of a MIME header and
** possibly truncate and rebalance the parameter according
** to MaxMimeFieldLength.
**
** Parameters:
** e -- the current envelope
**
** Returns:
** length of last offending field, 0 if all ok.
**
** Side Effects:
** string modified in place
*/
static size_t
fix_mime_header(h, e)
HDR *h;
ENVELOPE *e;
{
char *end;
return 0;
/* Split on each ';' */
/* find_character() never returns NULL */
{
char *bp;
*end = '\0';
/* Shorten individual parameter */
{
if (len < MaxMimeFieldLength)
{
/* we only rebalanced a bogus field */
"Fixed MIME %s header field (possible attack)",
h->h_field);
sm_dprintf(" fixed MIME %s header field (possible attack)\n",
h->h_field);
}
else
{
/* we actually shortened the header */
}
}
/* Collapse the possibly shortened string with rest */
{
/* copy character by character due to overlap */
while (*ep != '\0')
*bp = '\0';
}
else
if (*end == '\0')
break;
/* Move past ';' */
}
return retlen;
}