* Copyright (c) 1983 Eric P. Allman
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)err.c 8.2 (Berkeley) 7/11/93";
** SYSERR -- Print error message.
** Prints an error message via printf to the diagnostic
** output. If LOG is defined, it logs it also.
** If the first character of the syserr message is `!' it will
** log this as an ALERT message and exit immediately. This can
** leave queue files in an indeterminate state, so it should not
** f -- the format string
** a, b, c, d, e -- parameters
** Through TopFrame if QuickAbort is set.
char MsgBuf
[BUFSIZ
*2]; /* text of most recent message */
syserr(const char *fmt
, ...)
/* format and output the error message */
fmtmsg(MsgBuf
, (char *) NULL
, p
, olderrno
, fmt
, ap
);
/* determine exit status if not already set */
syslog(panic
? LOG_ALERT
: LOG_CRIT
, "%s: SYSERR: %s",
CurEnv
->e_id
== NULL
? "NOQUEUE" : CurEnv
->e_id
,
** USRERR -- Signal user error.
** This is much like syserr except it is for user errors.
** fmt, a, b, c, d -- printf strings
** Through TopFrame if QuickAbort is set.
usrerr(const char *fmt
, ...)
fmtmsg(MsgBuf
, CurEnv
->e_to
, "501", 0, fmt
, ap
);
if (LogLevel
> 3 && LogUsrErrs
)
syslog(LOG_NOTICE
, "%s: %s",
CurEnv
->e_id
== NULL
? "NOQUEUE" : CurEnv
->e_id
,
** MESSAGE -- print message (not necessarily an error)
** msg -- the message (printf fmt) -- it can begin with
** an SMTP reply code. If not, 050 is assumed.
** a, b, c, d, e -- printf arguments
message(const char *msg
, ...)
fmtmsg(MsgBuf
, CurEnv
->e_to
, "050", 0, msg
, ap
);
putoutmsg(MsgBuf
, FALSE
);
** NMESSAGE -- print message (not necessarily an error)
** Just like "message" except it never puts the to... tag on.
** num -- the default ARPANET error number (in ascii)
** msg -- the message (printf fmt) -- if it begins
** with three digits, this number overrides num.
** a, b, c, d, e -- printf arguments
nmessage(const char *msg
, ...)
fmtmsg(MsgBuf
, (char *) NULL
, "050", 0, msg
, ap
);
putoutmsg(MsgBuf
, FALSE
);
** PUTOUTMSG -- output error message to transcript and channel
** msg -- message to output (in SMTP format).
** holdmsg -- if TRUE, don't output a copy of the message to
** Outputs msg to the transcript.
** If appropriate, outputs it to the channel.
** Deletes SMTP reply code number as appropriate.
/* output to transcript if serious */
if (CurEnv
->e_xfp
!= NULL
&& (msg
[0] == '4' || msg
[0] == '5'))
fprintf(CurEnv
->e_xfp
, "%s\n", msg
);
/* output to channel if appropriate */
if (holdmsg
|| (!Verbose
&& msg
[0] == '0'))
fprintf(OutChannel
, "%s\r\n", msg
);
fprintf(OutChannel
, "%s\n", &msg
[4]);
if (TrafficLogFile
!= NULL
)
fprintf(TrafficLogFile
, "%05d >>> %s\n", getpid(),
OpMode
== MD_SMTP
? msg
: &msg
[4]);
(void) fflush(OutChannel
);
/* error on output -- if reporting lost channel, just ignore it */
if (feof(InChannel
) || ferror(InChannel
))
/* can't call syserr, 'cause we are using MsgBuf */
"%s: SYSERR: putoutmsg (%s): error on output channel sending \"%s\"",
CurEnv
->e_id
== NULL
? "NOQUEUE" : CurEnv
->e_id
,
** PUTERRMSG -- like putoutmsg, but does special processing for error messages
** msg -- the message to output.
** Sets the fatal error bit in the envelope as appropriate.
/* output the message as usual */
putoutmsg(msg
, HoldErrs
);
CurEnv
->e_flags
|= EF_FATALERRS
;
** FMTMSG -- format a message into buffer.
** eb -- error buffer to get result.
** to -- the recipient tag for this message.
** num -- arpanet error number.
** en -- the error number to display.
** fmt -- format of string.
** a, b, c, d, e -- arguments.
fmtmsg(eb
, to
, num
, eno
, fmt
, ap
)
/* output the reply code */
if (isdigit(fmt
[0]) && isdigit(fmt
[1]) && isdigit(fmt
[2]))
(void) sprintf(eb
, "%3.3s%c", num
, del
);
/* output the file name and line number */
(void) sprintf(eb
, "%s: line %d: ", FileName
, LineNumber
);
/* output the "to" person */
if (to
!= NULL
&& to
[0] != '\0')
(void) sprintf(eb
, "%s... ", to
);
(void) vsprintf(eb
, fmt
, ap
);
/* output the error code, if any */
(void) sprintf(eb
, ": %s", errstring(eno
));
if (CurEnv
->e_message
== NULL
&& strchr("45", num
[0]) != NULL
)
CurEnv
->e_message
= newstr(meb
);
** ERRSTRING -- return string description of error code
** errno -- the error number to translate
** A string description of errno.
extern const char *const sys_errlist
[];
static char buf
[MAXLINE
];
** Handle special network error codes.
** These are 4.2/4.3bsd specific; they should be in daemon.c.
(void) strcpy(buf
, sys_errlist
[errno
]);
(void) strcat(buf
, " during ");
(void) strcat(buf
, SmtpPhase
);
(void) strcat(buf
, " with ");
(void) strcat(buf
, CurHostName
);
(void) sprintf(buf
, "Host %s is down", CurHostName
);
(void) sprintf(buf
, "Connection refused by %s", CurHostName
);
case HOST_NOT_FOUND
+ MAX_ERRNO
:
return ("Name server: host not found");
case TRY_AGAIN
+ MAX_ERRNO
:
return ("Name server: host name lookup failure");
case NO_RECOVERY
+ MAX_ERRNO
:
return ("Name server: non-recoverable error");
case NO_DATA
+ MAX_ERRNO
:
return ("Name server: no data known for name");
if (errno
> 0 && errno
< sys_nerr
)
return (sys_errlist
[errno
]);
(void) sprintf(buf
, "Error %d", errno
);