13311Seric # include "sendmail.h" 2295Seric # ifdef LOG 32775Seric # include <syslog.h> 4295Seric # endif LOG 5295Seric 6*7613Seric SCCSID(@(#)err.c 3.25 07/31/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 307525Seric 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[]; 377525Seric char *saveto = CurEnv->e_to; 38295Seric 397525Seric /* format and output the error message */ 40*7613Seric fmtmsg(MsgBuf, NULL, Arpa_Syserr, fmt, a, b, c, d, e); 41*7613Seric putmsg(MsgBuf); 424063Seric 437525Seric /* mark the error as having occured */ 441514Seric Errors++; 456048Seric FatalErrors = TRUE; 46295Seric 47295Seric /* determine exit status if not already set */ 48295Seric if (ExitStat == EX_OK) 49295Seric { 50295Seric if (errno == 0) 51295Seric ExitStat = EX_SOFTWARE; 52295Seric else 531598Seric ExitStat = EX_OSERR; 54295Seric } 55295Seric 56295Seric # ifdef LOG 577525Seric syslog(LOG_ERR, "%s->%s: %s", CurEnv->e_from.q_paddr, CurEnv->e_to, &MsgBuf[4]); 58295Seric # endif LOG 59295Seric errno = 0; 60295Seric } 61295Seric /* 62295Seric ** USRERR -- Signal user error. 63295Seric ** 64295Seric ** This is much like syserr except it is for user errors. 65295Seric ** 66295Seric ** Parameters: 67295Seric ** fmt, a, b, c, d -- printf strings 68295Seric ** 69295Seric ** Returns: 704084Seric ** none 71295Seric ** 72295Seric ** Side Effects: 731514Seric ** increments Errors. 74295Seric */ 75295Seric 76295Seric /*VARARGS1*/ 77295Seric usrerr(fmt, a, b, c, d, e) 78295Seric char *fmt; 79295Seric { 80295Seric extern char SuprErrs; 814167Seric extern char Arpa_Usrerr[]; 82295Seric 83295Seric if (SuprErrs) 844084Seric return; 854063Seric Errors++; 866048Seric FatalErrors = TRUE; 87295Seric 88*7613Seric fmtmsg(MsgBuf, CurEnv->e_to, Arpa_Usrerr, fmt, a, b, c, d, e); 89*7613Seric putmsg(MsgBuf); 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; 1137525Seric fmtmsg(MsgBuf, CurEnv->e_to, num, msg, a, b, c, d, e); 114*7613Seric putmsg(MsgBuf); 115*7613Seric } 116*7613Seric /* 117*7613Seric ** PUTMSG -- output error message to transcript and channel 118*7613Seric ** 119*7613Seric ** Parameters: 120*7613Seric ** msg -- message to output (in SMTP format). 121*7613Seric ** 122*7613Seric ** Returns: 123*7613Seric ** none. 124*7613Seric ** 125*7613Seric ** Side Effects: 126*7613Seric ** Outputs msg to the transcript. 127*7613Seric ** If appropriate, outputs it to the channel. 128*7613Seric ** Deletes SMTP reply code number as appropriate. 129*7613Seric */ 1304711Seric 131*7613Seric putmsg(msg) 132*7613Seric char *msg; 133*7613Seric { 1344711Seric /* output to transcript */ 135*7613Seric fprintf(Xscript, "%s\n", Smtp ? msg : &msg[4]); 1364711Seric 1374711Seric /* output to channel if appropriate */ 138*7613Seric if (!HoldErrs && (Verbose || msg[0] != '0')) 1394063Seric { 1407275Seric (void) fflush(stdout); 1414711Seric if (ArpaMode) 142*7613Seric fprintf(OutChannel, "%s\r\n", msg); 1434711Seric else 144*7613Seric fprintf(OutChannel, "%s\n", &msg[4]); 1454711Seric (void) fflush(OutChannel); 1464063Seric } 1474711Seric } 1484711Seric /* 1494711Seric ** FMTMSG -- format a message into buffer. 1504711Seric ** 1514711Seric ** Parameters: 1524711Seric ** eb -- error buffer to get result. 1534711Seric ** to -- the recipient tag for this message. 1544711Seric ** num -- arpanet error number. 1554711Seric ** fmt -- format of string. 1564711Seric ** a, b, c, d, e -- arguments. 1574711Seric ** 1584711Seric ** Returns: 1594711Seric ** none. 1604711Seric ** 1614711Seric ** Side Effects: 1624711Seric ** none. 1634711Seric */ 1644063Seric 1654834Seric /*VARARGS4*/ 1664711Seric static 1674711Seric fmtmsg(eb, to, num, fmt, a, b, c, d, e) 1684711Seric register char *eb; 1694711Seric char *to; 1704711Seric char *num; 1714711Seric char *fmt; 1724711Seric { 1734711Seric char del; 1744711Seric 1754711Seric /* output the reply code */ 1764711Seric if (isdigit(*fmt)) 1774577Seric { 1784711Seric num = fmt; 1794711Seric fmt += 4; 1804711Seric } 1814711Seric if (num[3] == '-') 1824711Seric del = '-'; 1834711Seric else 1844711Seric del = ' '; 1854711Seric (void) sprintf(eb, "%3.3s%c", num, del); 1864711Seric eb += 4; 1874063Seric 1884711Seric /* output the "to" person */ 1894711Seric if (to != NULL && to[0] != '\0') 1904711Seric { 1914711Seric (void) sprintf(eb, "%s... ", to); 1925201Seric while (*eb != '\0') 1935201Seric *eb++ &= 0177; 1944711Seric } 1954711Seric 1964711Seric /* output the message */ 1974711Seric (void) sprintf(eb, fmt, a, b, c, d, e); 1985201Seric while (*eb != '\0') 1995201Seric *eb++ &= 0177; 2004711Seric 2014711Seric /* output the error code, if any */ 2024711Seric if (errno != 0) 2034711Seric { 2044711Seric extern int sys_nerr; 2054711Seric extern char *sys_errlist[]; 2064711Seric if (errno < sys_nerr && errno > 0) 2074711Seric (void) sprintf(eb, ": %s", sys_errlist[errno]); 2084577Seric else 2094711Seric (void) sprintf(eb, ": error %d", errno); 2104711Seric eb += strlen(eb); 2114577Seric } 212295Seric } 213