xref: /csrg-svn/usr.sbin/sendmail/src/err.c (revision 4711)
13311Seric # include "sendmail.h"
2295Seric # ifdef LOG
32775Seric # include <syslog.h>
4295Seric # endif LOG
5295Seric 
6*4711Seric static char	SccsId[] = "@(#)err.c	3.14	10/31/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 
38*4711Seric 	/* format the error message */
39*4711Seric 	fmtmsg(errbuf, Arpa_Syserr, NULL, fmt, a, b, c, d, e);
404063Seric 
41*4711Seric 	/* output error message to transcript */
42*4711Seric 	fprintf(Xscript, "%s\n", errbuf);
43*4711Seric 
44*4711Seric 	/* output error message to output channel if appropriate */
45*4711Seric 	if (!HoldErrs)
46295Seric 	{
47*4711Seric 		if (ArpaMode)
48*4711Seric 			fprintf(OutChannel, "%s\r\n", errbuf);
49295Seric 		else
50*4711Seric 			fprintf(OutChannel, "sendmail: %s\n", &errbuf[4]);
51*4711Seric 		(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 {
119*4711Seric 	char errbuf[MAXLINE];
120*4711Seric 
121*4711Seric 	errno = 0;
122*4711Seric 	fmtmsg(errbuf, To, num, msg, a, b, c, d, e);
123*4711Seric 
124*4711Seric 	/* output to transcript */
125*4711Seric 	fprintf(Xscript, "%s\n", errbuf);
126*4711Seric 
127*4711Seric 	/* output to channel if appropriate */
128*4711Seric 	if (!HoldErrs)
1294063Seric 	{
130*4711Seric 		if (ArpaMode)
131*4711Seric 			fprintf(OutChannel, "%s\r\n", errbuf);
132*4711Seric 		else
133*4711Seric 			fprintf(OutChannel, "%s\n", &errbuf[4]);
134*4711Seric 		(void) fflush(OutChannel);
1354063Seric 	}
136*4711Seric }
137*4711Seric /*
138*4711Seric **  FMTMSG -- format a message into buffer.
139*4711Seric **
140*4711Seric **	Parameters:
141*4711Seric **		eb -- error buffer to get result.
142*4711Seric **		to -- the recipient tag for this message.
143*4711Seric **		num -- arpanet error number.
144*4711Seric **		fmt -- format of string.
145*4711Seric **		a, b, c, d, e -- arguments.
146*4711Seric **
147*4711Seric **	Returns:
148*4711Seric **		none.
149*4711Seric **
150*4711Seric **	Side Effects:
151*4711Seric **		none.
152*4711Seric */
1534063Seric 
154*4711Seric static
155*4711Seric fmtmsg(eb, to, num, fmt, a, b, c, d, e)
156*4711Seric 	register char *eb;
157*4711Seric 	char *to;
158*4711Seric 	char *num;
159*4711Seric 	char *fmt;
160*4711Seric {
161*4711Seric 	char del;
162*4711Seric 
163*4711Seric 	/* output the reply code */
164*4711Seric 	if (isdigit(*fmt))
1654577Seric 	{
166*4711Seric 		num = fmt;
167*4711Seric 		fmt += 4;
168*4711Seric 	}
169*4711Seric 	if (num[3] == '-')
170*4711Seric 		del = '-';
171*4711Seric 	else
172*4711Seric 		del = ' ';
173*4711Seric 	(void) sprintf(eb, "%3.3s%c", num, del);
174*4711Seric 	eb += 4;
1754063Seric 
176*4711Seric 	/* output the "to" person */
177*4711Seric 	if (to != NULL && to[0] != '\0')
178*4711Seric 	{
179*4711Seric 		(void) sprintf(eb, "%s... ", to);
180*4711Seric 		eb += strlen(eb);
181*4711Seric 	}
182*4711Seric 
183*4711Seric 	/* output the message */
184*4711Seric 	(void) sprintf(eb, fmt, a, b, c, d, e);
185*4711Seric 	eb += strlen(eb);
186*4711Seric 
187*4711Seric 	/* output the error code, if any */
188*4711Seric 	if (errno != 0)
189*4711Seric 	{
190*4711Seric 		extern int sys_nerr;
191*4711Seric 		extern char *sys_errlist[];
192*4711Seric 		if (errno < sys_nerr && errno > 0)
193*4711Seric 			(void) sprintf(eb, ": %s", sys_errlist[errno]);
1944577Seric 		else
195*4711Seric 			(void) sprintf(eb, ": error %d", errno);
196*4711Seric 		eb += strlen(eb);
1974577Seric 	}
198295Seric }
199