xref: /csrg-svn/usr.sbin/sendmail/src/err.c (revision 4834)
13311Seric # include "sendmail.h"
2295Seric # ifdef LOG
32775Seric # include <syslog.h>
4295Seric # endif LOG
5295Seric 
6*4834Seric static char	SccsId[] = "@(#)err.c	3.16	11/08/81";
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
304084Seric 
31295Seric /*VARARGS1*/
32295Seric syserr(fmt, a, b, c, d, e)
33295Seric 	char *fmt;
34295Seric {
35295Seric 	static char errbuf[MAXLINE+1];
364167Seric 	extern char Arpa_Syserr[];
37295Seric 
384711Seric 	/* format the error message */
39*4834Seric 	fmtmsg(errbuf, (char *) NULL, Arpa_Syserr, fmt, a, b, c, d, e);
404063Seric 
414711Seric 	/* output error message to transcript */
424711Seric 	fprintf(Xscript, "%s\n", errbuf);
434711Seric 
444711Seric 	/* output error message to output channel if appropriate */
454711Seric 	if (!HoldErrs)
46295Seric 	{
474711Seric 		if (ArpaMode)
484711Seric 			fprintf(OutChannel, "%s\r\n", errbuf);
49295Seric 		else
504711Seric 			fprintf(OutChannel, "sendmail: %s\n", &errbuf[4]);
514711Seric 		(void) fflush(OutChannel);
52295Seric 	}
534063Seric 
541514Seric 	Errors++;
55295Seric 
56295Seric 	/* determine exit status if not already set */
57295Seric 	if (ExitStat == EX_OK)
58295Seric 	{
59295Seric 		if (errno == 0)
60295Seric 			ExitStat = EX_SOFTWARE;
61295Seric 		else
621598Seric 			ExitStat = EX_OSERR;
63295Seric 	}
64295Seric 
65295Seric # ifdef LOG
664316Seric 	syslog(LOG_ERR, "%s->%s: %s", From.q_paddr, To, &errbuf[4]);
67295Seric # endif LOG
68295Seric 	errno = 0;
69295Seric }
70295Seric /*
71295Seric **  USRERR -- Signal user error.
72295Seric **
73295Seric **	This is much like syserr except it is for user errors.
74295Seric **
75295Seric **	Parameters:
76295Seric **		fmt, a, b, c, d -- printf strings
77295Seric **
78295Seric **	Returns:
794084Seric **		none
80295Seric **
81295Seric **	Side Effects:
821514Seric **		increments Errors.
83295Seric */
84295Seric 
85295Seric /*VARARGS1*/
86295Seric usrerr(fmt, a, b, c, d, e)
87295Seric 	char *fmt;
88295Seric {
89295Seric 	extern char SuprErrs;
904167Seric 	extern char Arpa_Usrerr[];
91295Seric 
92295Seric 	if (SuprErrs)
934084Seric 		return;
944063Seric 	Errors++;
95295Seric 
964167Seric 	message(Arpa_Usrerr, fmt, a, b, c, d, e);
974063Seric }
984063Seric /*
994063Seric **  MESSAGE -- print message (not necessarily an error)
1004063Seric **
1014063Seric **	Parameters:
1024063Seric **		num -- the default ARPANET error number (in ascii)
1034063Seric **		msg -- the message (printf fmt) -- if it begins
1044063Seric **			with a digit, this number overrides num.
1054063Seric **		a, b, c, d, e -- printf arguments
1064063Seric **
1074063Seric **	Returns:
1084063Seric **		none
1094063Seric **
1104063Seric **	Side Effects:
1114063Seric **		none.
1124063Seric */
1134063Seric 
1144084Seric /*VARARGS2*/
1154063Seric message(num, msg, a, b, c, d, e)
1164063Seric 	register char *num;
1174063Seric 	register char *msg;
1184063Seric {
1194711Seric 	char errbuf[MAXLINE];
1204711Seric 
1214711Seric 	errno = 0;
1224711Seric 	fmtmsg(errbuf, To, num, msg, a, b, c, d, e);
1234711Seric 
1244711Seric 	/* output to transcript */
1254711Seric 	fprintf(Xscript, "%s\n", errbuf);
1264711Seric 
1274711Seric 	/* output to channel if appropriate */
1284711Seric 	if (!HoldErrs)
1294063Seric 	{
1304711Seric 		if (ArpaMode)
1314711Seric 			fprintf(OutChannel, "%s\r\n", errbuf);
1324711Seric 		else
1334711Seric 			fprintf(OutChannel, "%s\n", &errbuf[4]);
1344711Seric 		(void) fflush(OutChannel);
1354063Seric 	}
1364711Seric }
1374711Seric /*
1384711Seric **  FMTMSG -- format a message into buffer.
1394711Seric **
1404711Seric **	Parameters:
1414711Seric **		eb -- error buffer to get result.
1424711Seric **		to -- the recipient tag for this message.
1434711Seric **		num -- arpanet error number.
1444711Seric **		fmt -- format of string.
1454711Seric **		a, b, c, d, e -- arguments.
1464711Seric **
1474711Seric **	Returns:
1484711Seric **		none.
1494711Seric **
1504711Seric **	Side Effects:
1514711Seric **		none.
1524711Seric */
1534063Seric 
154*4834Seric /*VARARGS4*/
1554711Seric static
1564711Seric fmtmsg(eb, to, num, fmt, a, b, c, d, e)
1574711Seric 	register char *eb;
1584711Seric 	char *to;
1594711Seric 	char *num;
1604711Seric 	char *fmt;
1614711Seric {
1624711Seric 	char del;
1634711Seric 
1644711Seric 	/* output the reply code */
1654711Seric 	if (isdigit(*fmt))
1664577Seric 	{
1674711Seric 		num = fmt;
1684711Seric 		fmt += 4;
1694711Seric 	}
1704711Seric 	if (num[3] == '-')
1714711Seric 		del = '-';
1724711Seric 	else
1734711Seric 		del = ' ';
1744711Seric 	(void) sprintf(eb, "%3.3s%c", num, del);
1754711Seric 	eb += 4;
1764063Seric 
1774711Seric 	/* output the "to" person */
1784711Seric 	if (to != NULL && to[0] != '\0')
1794711Seric 	{
1804711Seric 		(void) sprintf(eb, "%s... ", to);
1814711Seric 		eb += strlen(eb);
1824711Seric 	}
1834711Seric 
1844711Seric 	/* output the message */
1854711Seric 	(void) sprintf(eb, fmt, a, b, c, d, e);
1864711Seric 	eb += strlen(eb);
1874711Seric 
1884711Seric 	/* output the error code, if any */
1894711Seric 	if (errno != 0)
1904711Seric 	{
1914711Seric 		extern int sys_nerr;
1924711Seric 		extern char *sys_errlist[];
1934711Seric 		if (errno < sys_nerr && errno > 0)
1944711Seric 			(void) sprintf(eb, ": %s", sys_errlist[errno]);
1954577Seric 		else
1964711Seric 			(void) sprintf(eb, ": error %d", errno);
1974711Seric 		eb += strlen(eb);
1984577Seric 	}
199295Seric }
200