13311Seric # include "sendmail.h" 2295Seric 3*9372Seric SCCSID(@(#)err.c 3.36 11/28/82); 4406Seric 5295Seric /* 61514Seric ** SYSERR -- Print error message. 7295Seric ** 8295Seric ** Prints an error message via printf to the diagnostic 9295Seric ** output. If LOG is defined, it logs it also. 10295Seric ** 11295Seric ** Parameters: 12295Seric ** f -- the format string 13295Seric ** a, b, c, d, e -- parameters 14295Seric ** 15295Seric ** Returns: 164084Seric ** none 177762Seric ** Through TopFrame if QuickAbort is set. 18295Seric ** 19295Seric ** Side Effects: 201514Seric ** increments Errors. 211514Seric ** sets ExitStat. 22295Seric */ 23295Seric 244084Seric # ifdef lint 254084Seric int sys_nerr; 264084Seric char *sys_errlist[]; 274084Seric # endif lint 287525Seric static char MsgBuf[BUFSIZ*2]; /* text of most recent message */ 294084Seric 30295Seric /*VARARGS1*/ 31295Seric syserr(fmt, a, b, c, d, e) 32295Seric char *fmt; 33295Seric { 347957Seric extern char Arpa_PSyserr[]; 357957Seric extern char Arpa_TSyserr[]; 367957Seric register char *p; 37295Seric 387525Seric /* format and output the error message */ 397957Seric if (errno == 0) 407957Seric p = Arpa_PSyserr; 417957Seric else 427957Seric p = Arpa_TSyserr; 437957Seric fmtmsg(MsgBuf, (char *) NULL, p, fmt, a, b, c, d, e); 449108Seric putmsg(MsgBuf, HoldErrs); 454063Seric 46295Seric /* determine exit status if not already set */ 47295Seric if (ExitStat == EX_OK) 48295Seric { 49295Seric if (errno == 0) 50295Seric ExitStat = EX_SOFTWARE; 51295Seric else 521598Seric ExitStat = EX_OSERR; 53295Seric } 54295Seric 55*9372Seric /* insure that we have a queue id for logging */ 567810Seric (void) queuename(CurEnv, '\0'); 57295Seric # ifdef LOG 587674Seric if (LogLevel > 0) 597810Seric syslog(LOG_ERR, "%s: %s", CurEnv->e_id, &MsgBuf[4]); 60295Seric # endif LOG 61295Seric errno = 0; 627762Seric if (QuickAbort) 637762Seric longjmp(TopFrame, 2); 64295Seric } 65295Seric /* 66295Seric ** USRERR -- Signal user error. 67295Seric ** 68295Seric ** This is much like syserr except it is for user errors. 69295Seric ** 70295Seric ** Parameters: 71295Seric ** fmt, a, b, c, d -- printf strings 72295Seric ** 73295Seric ** Returns: 744084Seric ** none 757762Seric ** Through TopFrame if QuickAbort is set. 76295Seric ** 77295Seric ** Side Effects: 781514Seric ** increments Errors. 79295Seric */ 80295Seric 81295Seric /*VARARGS1*/ 82295Seric usrerr(fmt, a, b, c, d, e) 83295Seric char *fmt; 84295Seric { 85295Seric extern char SuprErrs; 864167Seric extern char Arpa_Usrerr[]; 87295Seric 88295Seric if (SuprErrs) 894084Seric return; 90295Seric 917613Seric fmtmsg(MsgBuf, CurEnv->e_to, Arpa_Usrerr, fmt, a, b, c, d, e); 929108Seric putmsg(MsgBuf, HoldErrs); 938239Seric 947762Seric if (QuickAbort) 957762Seric longjmp(TopFrame, 1); 964063Seric } 974063Seric /* 984063Seric ** MESSAGE -- print message (not necessarily an error) 994063Seric ** 1004063Seric ** Parameters: 1014063Seric ** num -- the default ARPANET error number (in ascii) 1024063Seric ** msg -- the message (printf fmt) -- if it begins 1034063Seric ** with a digit, this number overrides num. 1044063Seric ** a, b, c, d, e -- printf arguments 1054063Seric ** 1064063Seric ** Returns: 1074063Seric ** none 1084063Seric ** 1094063Seric ** Side Effects: 1104063Seric ** none. 1114063Seric */ 1124063Seric 1134084Seric /*VARARGS2*/ 1144063Seric message(num, msg, a, b, c, d, e) 1154063Seric register char *num; 1164063Seric register char *msg; 1174063Seric { 1184711Seric errno = 0; 1197525Seric fmtmsg(MsgBuf, CurEnv->e_to, num, msg, a, b, c, d, e); 1209108Seric putmsg(MsgBuf, FALSE); 1217613Seric } 1227613Seric /* 1238239Seric ** NMESSAGE -- print message (not necessarily an error) 1248239Seric ** 1258239Seric ** Just like "message" except it never puts the to... tag on. 1268239Seric ** 1278239Seric ** Parameters: 1288239Seric ** num -- the default ARPANET error number (in ascii) 1298239Seric ** msg -- the message (printf fmt) -- if it begins 1308239Seric ** with a digit, this number overrides num. 1318239Seric ** a, b, c, d, e -- printf arguments 1328239Seric ** 1338239Seric ** Returns: 1348239Seric ** none 1358239Seric ** 1368239Seric ** Side Effects: 1378239Seric ** none. 1388239Seric */ 1398239Seric 1408239Seric /*VARARGS2*/ 1418239Seric nmessage(num, msg, a, b, c, d, e) 1428239Seric register char *num; 1438239Seric register char *msg; 1448239Seric { 1458239Seric errno = 0; 1469346Seric fmtmsg(MsgBuf, (char *) NULL, num, msg, a, b, c, d, e); 1479108Seric putmsg(MsgBuf, FALSE); 1488239Seric } 1498239Seric /* 1507613Seric ** PUTMSG -- output error message to transcript and channel 1517613Seric ** 1527613Seric ** Parameters: 1537613Seric ** msg -- message to output (in SMTP format). 1549108Seric ** holdmsg -- if TRUE, don't output a copy of the message to 1559108Seric ** our output channel. 1567613Seric ** 1577613Seric ** Returns: 1587613Seric ** none. 1597613Seric ** 1607613Seric ** Side Effects: 1617613Seric ** Outputs msg to the transcript. 1627613Seric ** If appropriate, outputs it to the channel. 1637613Seric ** Deletes SMTP reply code number as appropriate. 1647613Seric */ 1654711Seric 1669108Seric putmsg(msg, holdmsg) 1677613Seric char *msg; 1689108Seric bool holdmsg; 1697613Seric { 1704711Seric /* output to transcript */ 1719336Seric if (Xscript != NULL) 1729277Seric fprintf(Xscript, "%s\n", OpMode == MD_SMTP ? msg : &msg[4]); 1734711Seric 1744711Seric /* output to channel if appropriate */ 1759108Seric if (!holdmsg && (Verbose || msg[0] != '0')) 1764063Seric { 1777275Seric (void) fflush(stdout); 1789277Seric if (OpMode == MD_SMTP || OpMode == MD_ARPAFTP) 1797613Seric fprintf(OutChannel, "%s\r\n", msg); 1804711Seric else 1817613Seric fprintf(OutChannel, "%s\n", &msg[4]); 1824711Seric (void) fflush(OutChannel); 1834063Seric } 1848239Seric 1858239Seric /* determine error status */ 1868239Seric switch (msg[0]) 1878239Seric { 1888239Seric case '5': 1899336Seric CurEnv->e_flags |= EF_FATALERRS; 1908239Seric /* fall through.... */ 1918239Seric 1928239Seric case '4': 1938239Seric Errors++; 1948239Seric break; 1958239Seric } 1964711Seric } 1974711Seric /* 1984711Seric ** FMTMSG -- format a message into buffer. 1994711Seric ** 2004711Seric ** Parameters: 2014711Seric ** eb -- error buffer to get result. 2024711Seric ** to -- the recipient tag for this message. 2034711Seric ** num -- arpanet error number. 2044711Seric ** fmt -- format of string. 2054711Seric ** a, b, c, d, e -- arguments. 2064711Seric ** 2074711Seric ** Returns: 2084711Seric ** none. 2094711Seric ** 2104711Seric ** Side Effects: 2114711Seric ** none. 2124711Seric */ 2134063Seric 2144834Seric /*VARARGS4*/ 2154711Seric static 2164711Seric fmtmsg(eb, to, num, fmt, a, b, c, d, e) 2174711Seric register char *eb; 2184711Seric char *to; 2194711Seric char *num; 2204711Seric char *fmt; 2214711Seric { 2224711Seric char del; 2234711Seric 2244711Seric /* output the reply code */ 2254711Seric if (isdigit(*fmt)) 2264577Seric { 2274711Seric num = fmt; 2284711Seric fmt += 4; 2294711Seric } 2304711Seric if (num[3] == '-') 2314711Seric del = '-'; 2324711Seric else 2334711Seric del = ' '; 2344711Seric (void) sprintf(eb, "%3.3s%c", num, del); 2354711Seric eb += 4; 2364063Seric 237*9372Seric /* output the file name and line number */ 238*9372Seric if (FileName != NULL) 239*9372Seric { 240*9372Seric (void) sprintf(eb, "%s: line %d: ", FileName, LineNumber); 241*9372Seric eb += strlen(eb); 242*9372Seric } 243*9372Seric 2444711Seric /* output the "to" person */ 2454711Seric if (to != NULL && to[0] != '\0') 2464711Seric { 2474711Seric (void) sprintf(eb, "%s... ", to); 2485201Seric while (*eb != '\0') 2495201Seric *eb++ &= 0177; 2504711Seric } 2514711Seric 2524711Seric /* output the message */ 2534711Seric (void) sprintf(eb, fmt, a, b, c, d, e); 2545201Seric while (*eb != '\0') 2555201Seric *eb++ &= 0177; 2564711Seric 2574711Seric /* output the error code, if any */ 2584711Seric if (errno != 0) 2594711Seric { 2604711Seric extern int sys_nerr; 2614711Seric extern char *sys_errlist[]; 2624711Seric if (errno < sys_nerr && errno > 0) 2634711Seric (void) sprintf(eb, ": %s", sys_errlist[errno]); 2644577Seric else 2654711Seric (void) sprintf(eb, ": error %d", errno); 2664711Seric eb += strlen(eb); 2674577Seric } 268295Seric } 269