xref: /csrg-svn/usr.sbin/sendmail/src/err.c (revision 7525)
13311Seric # include "sendmail.h"
2295Seric # ifdef LOG
32775Seric # include <syslog.h>
4295Seric # endif LOG
5295Seric 
6*7525Seric SCCSID(@(#)err.c	3.24		07/25/82);
7406Seric 
8295Seric /*
91514Seric **  SYSERR -- Print error message.
10295Seric **
11295Seric **	Prints an error message via printf to the diagnostic
12295Seric **	output.  If LOG is defined, it logs it also.
13295Seric **
14295Seric **	Parameters:
15295Seric **		f -- the format string
16295Seric **		a, b, c, d, e -- parameters
17295Seric **
18295Seric **	Returns:
194084Seric **		none
20295Seric **
21295Seric **	Side Effects:
221514Seric **		increments Errors.
231514Seric **		sets ExitStat.
24295Seric */
25295Seric 
264084Seric # ifdef lint
274084Seric int	sys_nerr;
284084Seric char	*sys_errlist[];
294084Seric # endif lint
30*7525Seric static char	MsgBuf[BUFSIZ*2];	/* text of most recent message */
314084Seric 
32295Seric /*VARARGS1*/
33295Seric syserr(fmt, a, b, c, d, e)
34295Seric 	char *fmt;
35295Seric {
364167Seric 	extern char Arpa_Syserr[];
37*7525Seric 	char *saveto = CurEnv->e_to;
38295Seric 
39*7525Seric 	/* format and output the error message */
40*7525Seric 	CurEnv->e_to = NULL;
41*7525Seric 	message(Arpa_Syserr, fmt, a, b, c, d, e);
42*7525Seric 	CurEnv->e_to = saveto;
434063Seric 
44*7525Seric 	/* mark the error as having occured */
451514Seric 	Errors++;
466048Seric 	FatalErrors = TRUE;
47295Seric 
48295Seric 	/* determine exit status if not already set */
49295Seric 	if (ExitStat == EX_OK)
50295Seric 	{
51295Seric 		if (errno == 0)
52295Seric 			ExitStat = EX_SOFTWARE;
53295Seric 		else
541598Seric 			ExitStat = EX_OSERR;
55295Seric 	}
56295Seric 
57295Seric # ifdef LOG
58*7525Seric 	syslog(LOG_ERR, "%s->%s: %s", CurEnv->e_from.q_paddr, CurEnv->e_to, &MsgBuf[4]);
59295Seric # endif LOG
60295Seric 	errno = 0;
61295Seric }
62295Seric /*
63295Seric **  USRERR -- Signal user error.
64295Seric **
65295Seric **	This is much like syserr except it is for user errors.
66295Seric **
67295Seric **	Parameters:
68295Seric **		fmt, a, b, c, d -- printf strings
69295Seric **
70295Seric **	Returns:
714084Seric **		none
72295Seric **
73295Seric **	Side Effects:
741514Seric **		increments Errors.
75295Seric */
76295Seric 
77295Seric /*VARARGS1*/
78295Seric usrerr(fmt, a, b, c, d, e)
79295Seric 	char *fmt;
80295Seric {
81295Seric 	extern char SuprErrs;
824167Seric 	extern char Arpa_Usrerr[];
83295Seric 
84295Seric 	if (SuprErrs)
854084Seric 		return;
864063Seric 	Errors++;
876048Seric 	FatalErrors = TRUE;
88295Seric 
894167Seric 	message(Arpa_Usrerr, fmt, a, b, c, d, e);
904063Seric }
914063Seric /*
924063Seric **  MESSAGE -- print message (not necessarily an error)
934063Seric **
944063Seric **	Parameters:
954063Seric **		num -- the default ARPANET error number (in ascii)
964063Seric **		msg -- the message (printf fmt) -- if it begins
974063Seric **			with a digit, this number overrides num.
984063Seric **		a, b, c, d, e -- printf arguments
994063Seric **
1004063Seric **	Returns:
1014063Seric **		none
1024063Seric **
1034063Seric **	Side Effects:
1044063Seric **		none.
1054063Seric */
1064063Seric 
1074084Seric /*VARARGS2*/
1084063Seric message(num, msg, a, b, c, d, e)
1094063Seric 	register char *num;
1104063Seric 	register char *msg;
1114063Seric {
1124711Seric 	errno = 0;
113*7525Seric 	fmtmsg(MsgBuf, CurEnv->e_to, num, msg, a, b, c, d, e);
1144711Seric 
1154711Seric 	/* output to transcript */
116*7525Seric 	fprintf(Xscript, "%s\n", Smtp ? MsgBuf : &MsgBuf[4]);
1174711Seric 
1184711Seric 	/* output to channel if appropriate */
119*7525Seric 	if (!HoldErrs && (Verbose || MsgBuf[0] != '0'))
1204063Seric 	{
1217275Seric 		(void) fflush(stdout);
1224711Seric 		if (ArpaMode)
123*7525Seric 			fprintf(OutChannel, "%s\r\n", MsgBuf);
1244711Seric 		else
125*7525Seric 			fprintf(OutChannel, "%s\n", &MsgBuf[4]);
1264711Seric 		(void) fflush(OutChannel);
1274063Seric 	}
1284711Seric }
1294711Seric /*
1304711Seric **  FMTMSG -- format a message into buffer.
1314711Seric **
1324711Seric **	Parameters:
1334711Seric **		eb -- error buffer to get result.
1344711Seric **		to -- the recipient tag for this message.
1354711Seric **		num -- arpanet error number.
1364711Seric **		fmt -- format of string.
1374711Seric **		a, b, c, d, e -- arguments.
1384711Seric **
1394711Seric **	Returns:
1404711Seric **		none.
1414711Seric **
1424711Seric **	Side Effects:
1434711Seric **		none.
1444711Seric */
1454063Seric 
1464834Seric /*VARARGS4*/
1474711Seric static
1484711Seric fmtmsg(eb, to, num, fmt, a, b, c, d, e)
1494711Seric 	register char *eb;
1504711Seric 	char *to;
1514711Seric 	char *num;
1524711Seric 	char *fmt;
1534711Seric {
1544711Seric 	char del;
1554711Seric 
1564711Seric 	/* output the reply code */
1574711Seric 	if (isdigit(*fmt))
1584577Seric 	{
1594711Seric 		num = fmt;
1604711Seric 		fmt += 4;
1614711Seric 	}
1624711Seric 	if (num[3] == '-')
1634711Seric 		del = '-';
1644711Seric 	else
1654711Seric 		del = ' ';
1664711Seric 	(void) sprintf(eb, "%3.3s%c", num, del);
1674711Seric 	eb += 4;
1684063Seric 
1694711Seric 	/* output the "to" person */
1704711Seric 	if (to != NULL && to[0] != '\0')
1714711Seric 	{
1724711Seric 		(void) sprintf(eb, "%s... ", to);
1735201Seric 		while (*eb != '\0')
1745201Seric 			*eb++ &= 0177;
1754711Seric 	}
1764711Seric 
1774711Seric 	/* output the message */
1784711Seric 	(void) sprintf(eb, fmt, a, b, c, d, e);
1795201Seric 	while (*eb != '\0')
1805201Seric 		*eb++ &= 0177;
1814711Seric 
1824711Seric 	/* output the error code, if any */
1834711Seric 	if (errno != 0)
1844711Seric 	{
1854711Seric 		extern int sys_nerr;
1864711Seric 		extern char *sys_errlist[];
1874711Seric 		if (errno < sys_nerr && errno > 0)
1884711Seric 			(void) sprintf(eb, ": %s", sys_errlist[errno]);
1894577Seric 		else
1904711Seric 			(void) sprintf(eb, ": error %d", errno);
1914711Seric 		eb += strlen(eb);
1924577Seric 	}
193295Seric }
194