xref: /csrg-svn/usr.sbin/sendmail/src/err.c (revision 4162)
1295Seric # include <stdio.h>
24063Seric # include <ctype.h>
33311Seric # include "sendmail.h"
4295Seric # ifdef LOG
52775Seric # include <syslog.h>
6295Seric # endif LOG
7295Seric 
8*4162Seric static char	SccsId[] = "@(#)err.c	3.7	08/18/81";
9406Seric 
10*4162Seric extern bool	HasXscrpt;
11*4162Seric 
12295Seric /*
131514Seric **  SYSERR -- Print error message.
14295Seric **
15295Seric **	Prints an error message via printf to the diagnostic
16295Seric **	output.  If LOG is defined, it logs it also.
17295Seric **
18295Seric **	Parameters:
19295Seric **		f -- the format string
20295Seric **		a, b, c, d, e -- parameters
21295Seric **
22295Seric **	Returns:
234084Seric **		none
24295Seric **
25295Seric **	Side Effects:
261514Seric **		increments Errors.
271514Seric **		sets ExitStat.
28295Seric */
29295Seric 
304084Seric # ifdef lint
314084Seric int	sys_nerr;
324084Seric char	*sys_errlist[];
334084Seric # endif lint
344084Seric 
35295Seric /*VARARGS1*/
36295Seric syserr(fmt, a, b, c, d, e)
37295Seric 	char *fmt;
38295Seric {
39295Seric 	static char errbuf[MAXLINE+1];
40295Seric 	extern char *sys_errlist[];
41295Seric 	extern int sys_nerr;
424063Seric 	register char *eb = errbuf;
43295Seric 
444063Seric 	/* add arpanet error number if not present */
454063Seric 	if (!isdigit(*fmt))
464063Seric 	{
474084Seric 		(void) strcpy(eb, "455 ");
484063Seric 		eb += 4;
494063Seric 	}
504063Seric 
514063Seric 	/* put error message into buffer */
524084Seric 	(void) sprintf(eb, fmt, a, b, c, d, e);
53295Seric 	if (errno != 0)
54295Seric 	{
554063Seric 		eb += strlen(eb);
56295Seric 		if (errno < sys_nerr && errno > 0)
574084Seric 			(void) sprintf(eb, ": %s", sys_errlist[errno]);
58295Seric 		else
594084Seric 			(void) sprintf(eb, ": error %d", errno);
60295Seric 	}
614063Seric 
62*4162Seric 	if (ArpaMode != ARPA_NONE && !HasXscrpt)
634077Seric 		printf("%s\r\n", errbuf);
644063Seric 	else
654063Seric 		printf("sendmail: %s\n", &errbuf[4]);
664084Seric 	(void) fflush(stdout);
671514Seric 	Errors++;
68295Seric 
69295Seric 	/* determine exit status if not already set */
70295Seric 	if (ExitStat == EX_OK)
71295Seric 	{
72295Seric 		if (errno == 0)
73295Seric 			ExitStat = EX_SOFTWARE;
74295Seric 		else
751598Seric 			ExitStat = EX_OSERR;
76295Seric 	}
77295Seric 
78295Seric # ifdef LOG
792775Seric 	syslog(LOG_ERR, "%s->%s: %s", From.q_paddr, To, errbuf);
80295Seric # endif LOG
81295Seric 	errno = 0;
82295Seric }
83295Seric /*
84295Seric **  USRERR -- Signal user error.
85295Seric **
86295Seric **	This is much like syserr except it is for user errors.
87295Seric **
88295Seric **	Parameters:
89295Seric **		fmt, a, b, c, d -- printf strings
90295Seric **
91295Seric **	Returns:
924084Seric **		none
93295Seric **
94295Seric **	Side Effects:
951514Seric **		increments Errors.
96295Seric */
97295Seric 
98295Seric /*VARARGS1*/
99295Seric usrerr(fmt, a, b, c, d, e)
100295Seric 	char *fmt;
101295Seric {
102295Seric 	extern char SuprErrs;
103295Seric 
104295Seric 	if (SuprErrs)
1054084Seric 		return;
1064063Seric 	Errors++;
107295Seric 
1084063Seric 	message("450", fmt, a, b, c, d, e);
1094063Seric }
1104063Seric /*
1114063Seric **  MESSAGE -- print message (not necessarily an error)
1124063Seric **
1134063Seric **	Parameters:
1144063Seric **		num -- the default ARPANET error number (in ascii)
1154063Seric **		msg -- the message (printf fmt) -- if it begins
1164063Seric **			with a digit, this number overrides num.
1174063Seric **		a, b, c, d, e -- printf arguments
1184063Seric **
1194063Seric **	Returns:
1204063Seric **		none
1214063Seric **
1224063Seric **	Side Effects:
1234063Seric **		none.
1244063Seric */
1254063Seric 
1264084Seric /*VARARGS2*/
1274063Seric message(num, msg, a, b, c, d, e)
1284063Seric 	register char *num;
1294063Seric 	register char *msg;
1304063Seric {
1314063Seric 	/* compute error number */
1324063Seric 	if (isdigit(*msg))
1334063Seric 	{
1344063Seric 		num = msg;
1354063Seric 		msg += 4;
1364063Seric 	}
1374063Seric 
1384063Seric 	/* print arpa format header if needed */
139*4162Seric 	if (ArpaMode != ARPA_NONE && !HasXscrpt)
1404063Seric 		printf("%.3s ", num);
1414063Seric 
1424063Seric 	if (To != NULL && To[0] != '\0')
143295Seric 		printf("%s... ", To);
1444063Seric 	printf(msg, a, b, c, d, e);
145*4162Seric 	if (ArpaMode != ARPA_NONE && !HasXscrpt)
1464077Seric 		printf("\r");
147295Seric 	printf("\n");
1484084Seric 	(void) fflush(stdout);
149295Seric }
150