err.c (132946) | err.c (168520) |
---|---|
1/* 2 * Copyright (c) 1998-2003 Sendmail, Inc. and its suppliers. 3 * All rights reserved. 4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved. 5 * Copyright (c) 1988, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * By using this file, you agree to the terms and conditions set 9 * forth in the LICENSE file which can be found at the top level of 10 * the sendmail distribution. 11 * | 1/* 2 * Copyright (c) 1998-2003 Sendmail, Inc. and its suppliers. 3 * All rights reserved. 4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved. 5 * Copyright (c) 1988, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * By using this file, you agree to the terms and conditions set 9 * forth in the LICENSE file which can be found at the top level of 10 * the sendmail distribution. 11 * |
12 * $FreeBSD: head/contrib/sendmail/src/err.c 168520 2007-04-09 01:44:16Z gshapiro $ |
|
12 */ 13 14#include <sendmail.h> 15 | 13 */ 14 15#include <sendmail.h> 16 |
16SM_RCSID("@(#)$Id: err.c,v 8.191 2003/01/10 02:16:46 ca Exp $") | 17SM_RCSID("@(#)$Id: err.c,v 8.196 2006/11/10 23:14:08 ca Exp $") |
17 18#if LDAPMAP 19# include <lber.h> 20# include <ldap.h> /* for LDAP error codes */ 21#endif /* LDAPMAP */ 22 23static void putoutmsg __P((char *, bool, bool)); 24static void puterrmsg __P((char *)); --- 79 unchanged lines hidden (view full) --- 104** Raises E:mta.quickabort if QuickAbort is set. 105** 106** Side Effects: 107** increments Errors. 108** sets ExitStat. 109*/ 110 111char MsgBuf[BUFSIZ*2]; /* text of most recent message */ | 18 19#if LDAPMAP 20# include <lber.h> 21# include <ldap.h> /* for LDAP error codes */ 22#endif /* LDAPMAP */ 23 24static void putoutmsg __P((char *, bool, bool)); 25static void puterrmsg __P((char *)); --- 79 unchanged lines hidden (view full) --- 105** Raises E:mta.quickabort if QuickAbort is set. 106** 107** Side Effects: 108** increments Errors. 109** sets ExitStat. 110*/ 111 112char MsgBuf[BUFSIZ*2]; /* text of most recent message */ |
112static char HeldMessageBuf[sizeof MsgBuf]; /* for held messages */ | 113static char HeldMessageBuf[sizeof(MsgBuf)]; /* for held messages */ |
113 114#if NAMED_BIND && !defined(NO_DATA) 115# define NO_DATA NO_ADDRESS 116#endif /* NAMED_BIND && !defined(NO_DATA) */ 117 118void 119/*VARARGS1*/ 120#ifdef __STDC__ --- 82 unchanged lines hidden (view full) --- 203 } 204 205 pw = sm_getpwuid(RealUid); 206 if (pw != NULL) 207 user = pw->pw_name; 208 else 209 { 210 user = ubuf; | 114 115#if NAMED_BIND && !defined(NO_DATA) 116# define NO_DATA NO_ADDRESS 117#endif /* NAMED_BIND && !defined(NO_DATA) */ 118 119void 120/*VARARGS1*/ 121#ifdef __STDC__ --- 82 unchanged lines hidden (view full) --- 204 } 205 206 pw = sm_getpwuid(RealUid); 207 if (pw != NULL) 208 user = pw->pw_name; 209 else 210 { 211 user = ubuf; |
211 (void) sm_snprintf(ubuf, sizeof ubuf, "UID%d", (int) RealUid); | 212 (void) sm_snprintf(ubuf, sizeof(ubuf), "UID%d", (int) RealUid); |
212 } 213 214 if (LogLevel > 0) 215 sm_syslog(panic ? LOG_ALERT : LOG_CRIT, 216 CurEnv == NULL ? NOQID : CurEnv->e_id, 217 "SYSERR(%s): %.900s", 218 user, errtxt); 219 switch (save_errno) --- 95 unchanged lines hidden (view full) --- 315 case '5': 316 case '6': 317 if (CurEnv->e_rpool == NULL && CurEnv->e_message != NULL) 318 sm_free(CurEnv->e_message); 319 if (MsgBuf[0] == '6') 320 { 321 char buf[MAXLINE]; 322 | 213 } 214 215 if (LogLevel > 0) 216 sm_syslog(panic ? LOG_ALERT : LOG_CRIT, 217 CurEnv == NULL ? NOQID : CurEnv->e_id, 218 "SYSERR(%s): %.900s", 219 user, errtxt); 220 switch (save_errno) --- 95 unchanged lines hidden (view full) --- 316 case '5': 317 case '6': 318 if (CurEnv->e_rpool == NULL && CurEnv->e_message != NULL) 319 sm_free(CurEnv->e_message); 320 if (MsgBuf[0] == '6') 321 { 322 char buf[MAXLINE]; 323 |
323 (void) sm_snprintf(buf, sizeof buf, | 324 (void) sm_snprintf(buf, sizeof(buf), |
324 "Postmaster warning: %.*s", | 325 "Postmaster warning: %.*s", |
325 (int) sizeof buf - 22, errtxt); | 326 (int) sizeof(buf) - 22, errtxt); |
326 CurEnv->e_message = 327 sm_rpool_strdup_x(CurEnv->e_rpool, buf); 328 } 329 else 330 { 331 CurEnv->e_message = 332 sm_rpool_strdup_x(CurEnv->e_rpool, errtxt); 333 } --- 68 unchanged lines hidden (view full) --- 402 case '5': 403 case '6': 404 if (CurEnv->e_rpool == NULL && CurEnv->e_message != NULL) 405 sm_free(CurEnv->e_message); 406 if (MsgBuf[0] == '6') 407 { 408 char buf[MAXLINE]; 409 | 327 CurEnv->e_message = 328 sm_rpool_strdup_x(CurEnv->e_rpool, buf); 329 } 330 else 331 { 332 CurEnv->e_message = 333 sm_rpool_strdup_x(CurEnv->e_rpool, errtxt); 334 } --- 68 unchanged lines hidden (view full) --- 403 case '5': 404 case '6': 405 if (CurEnv->e_rpool == NULL && CurEnv->e_message != NULL) 406 sm_free(CurEnv->e_message); 407 if (MsgBuf[0] == '6') 408 { 409 char buf[MAXLINE]; 410 |
410 (void) sm_snprintf(buf, sizeof buf, | 411 (void) sm_snprintf(buf, sizeof(buf), |
411 "Postmaster warning: %.*s", | 412 "Postmaster warning: %.*s", |
412 (int) sizeof buf - 22, errtxt); | 413 (int) sizeof(buf) - 22, errtxt); |
413 CurEnv->e_message = 414 sm_rpool_strdup_x(CurEnv->e_rpool, buf); 415 } 416 else 417 { 418 CurEnv->e_message = 419 sm_rpool_strdup_x(CurEnv->e_rpool, errtxt); 420 } --- 102 unchanged lines hidden (view full) --- 523 case '8': 524 if (CurEnv->e_message != NULL) 525 break; 526 /* FALLTHROUGH */ 527 528 case '5': 529 if (CurEnv->e_rpool == NULL && CurEnv->e_message != NULL) 530 sm_free(CurEnv->e_message); | 414 CurEnv->e_message = 415 sm_rpool_strdup_x(CurEnv->e_rpool, buf); 416 } 417 else 418 { 419 CurEnv->e_message = 420 sm_rpool_strdup_x(CurEnv->e_rpool, errtxt); 421 } --- 102 unchanged lines hidden (view full) --- 524 case '8': 525 if (CurEnv->e_message != NULL) 526 break; 527 /* FALLTHROUGH */ 528 529 case '5': 530 if (CurEnv->e_rpool == NULL && CurEnv->e_message != NULL) 531 sm_free(CurEnv->e_message); |
531 CurEnv->e_message = 532 sm_rpool_strdup_x(CurEnv->e_rpool, errtxt); | 532 CurEnv->e_message = sm_rpool_strdup_x(CurEnv->e_rpool, errtxt); |
533 break; 534 } 535} 536/* 537** PUTOUTMSG -- output error message to transcript and channel 538** 539** Parameters: 540** msg -- message to output (in SMTP format). --- 12 unchanged lines hidden (view full) --- 553*/ 554 555static void 556putoutmsg(msg, holdmsg, heldmsg) 557 char *msg; 558 bool holdmsg; 559 bool heldmsg; 560{ | 533 break; 534 } 535} 536/* 537** PUTOUTMSG -- output error message to transcript and channel 538** 539** Parameters: 540** msg -- message to output (in SMTP format). --- 12 unchanged lines hidden (view full) --- 553*/ 554 555static void 556putoutmsg(msg, holdmsg, heldmsg) 557 char *msg; 558 bool holdmsg; 559 bool heldmsg; 560{ |
561 char *errtxt = msg; | |
562 char msgcode = msg[0]; | 561 char msgcode = msg[0]; |
562 char *errtxt = msg; 563 char *id; |
|
563 564 /* display for debugging */ 565 if (tTd(54, 8)) 566 sm_dprintf("--- %s%s%s\n", msg, holdmsg ? " (hold)" : "", 567 heldmsg ? " (held)" : ""); 568 569 /* map warnings to something SMTP can handle */ 570 if (msgcode == '6') 571 msg[0] = '5'; 572 else if (msgcode == '8') 573 msg[0] = '4'; | 564 565 /* display for debugging */ 566 if (tTd(54, 8)) 567 sm_dprintf("--- %s%s%s\n", msg, holdmsg ? " (hold)" : "", 568 heldmsg ? " (held)" : ""); 569 570 /* map warnings to something SMTP can handle */ 571 if (msgcode == '6') 572 msg[0] = '5'; 573 else if (msgcode == '8') 574 msg[0] = '4'; |
575 id = (CurEnv != NULL) ? CurEnv->e_id : NULL; |
|
574 575 /* output to transcript if serious */ 576 if (!heldmsg && CurEnv != NULL && CurEnv->e_xfp != NULL && 577 strchr("45", msg[0]) != NULL) 578 (void) sm_io_fprintf(CurEnv->e_xfp, SM_TIME_DEFAULT, "%s\n", 579 msg); 580 581 if (LogLevel > 14 && (OpMode == MD_SMTP || OpMode == MD_DAEMON)) | 576 577 /* output to transcript if serious */ 578 if (!heldmsg && CurEnv != NULL && CurEnv->e_xfp != NULL && 579 strchr("45", msg[0]) != NULL) 580 (void) sm_io_fprintf(CurEnv->e_xfp, SM_TIME_DEFAULT, "%s\n", 581 msg); 582 583 if (LogLevel > 14 && (OpMode == MD_SMTP || OpMode == MD_DAEMON)) |
582 sm_syslog(LOG_INFO, CurEnv->e_id, | 584 sm_syslog(LOG_INFO, id, |
583 "--- %s%s%s", msg, holdmsg ? " (hold)" : "", 584 heldmsg ? " (held)" : ""); 585 586 if (msgcode == '8') 587 msg[0] = '0'; 588 589 /* output to channel if appropriate */ 590 if (!Verbose && msg[0] == '0') 591 return; 592 if (holdmsg) 593 { 594 /* save for possible future display */ 595 msg[0] = msgcode; 596 if (HeldMessageBuf[0] == '5' && msgcode == '4') 597 return; | 585 "--- %s%s%s", msg, holdmsg ? " (hold)" : "", 586 heldmsg ? " (held)" : ""); 587 588 if (msgcode == '8') 589 msg[0] = '0'; 590 591 /* output to channel if appropriate */ 592 if (!Verbose && msg[0] == '0') 593 return; 594 if (holdmsg) 595 { 596 /* save for possible future display */ 597 msg[0] = msgcode; 598 if (HeldMessageBuf[0] == '5' && msgcode == '4') 599 return; |
598 (void) sm_strlcpy(HeldMessageBuf, msg, sizeof HeldMessageBuf); | 600 (void) sm_strlcpy(HeldMessageBuf, msg, sizeof(HeldMessageBuf)); |
599 return; 600 } 601 602 (void) sm_io_flush(smioout, SM_TIME_DEFAULT); 603 604 if (OutChannel == NULL) 605 return; 606 --- 38 unchanged lines hidden (view full) --- 645 646 if (InChannel == NULL || sm_io_eof(InChannel) || 647 sm_io_error(InChannel) || strncmp(msg, "221", 3) == 0) 648 return; 649 650 /* can't call syserr, 'cause we are using MsgBuf */ 651 HoldErrs = true; 652 if (LogLevel > 0) | 601 return; 602 } 603 604 (void) sm_io_flush(smioout, SM_TIME_DEFAULT); 605 606 if (OutChannel == NULL) 607 return; 608 --- 38 unchanged lines hidden (view full) --- 647 648 if (InChannel == NULL || sm_io_eof(InChannel) || 649 sm_io_error(InChannel) || strncmp(msg, "221", 3) == 0) 650 return; 651 652 /* can't call syserr, 'cause we are using MsgBuf */ 653 HoldErrs = true; 654 if (LogLevel > 0) |
653 sm_syslog(LOG_CRIT, CurEnv->e_id, | 655 sm_syslog(LOG_CRIT, id, |
654 "SYSERR: putoutmsg (%s): error on output channel sending \"%s\": %s", 655 CURHOSTNAME, 656 shortenstring(msg, MAXSHORTSTR), sm_errstring(errno)); 657#endif /* !PIPELINING */ 658} 659/* 660** PUTERRMSG -- like putoutmsg, but does special processing for error messages 661** --- 156 unchanged lines hidden (view full) --- 818 const char *num; 819 const char *enhsc; 820 int eno; 821 const char *fmt; 822 SM_VA_LOCAL_DECL 823{ 824 char del; 825 int l; | 656 "SYSERR: putoutmsg (%s): error on output channel sending \"%s\": %s", 657 CURHOSTNAME, 658 shortenstring(msg, MAXSHORTSTR), sm_errstring(errno)); 659#endif /* !PIPELINING */ 660} 661/* 662** PUTERRMSG -- like putoutmsg, but does special processing for error messages 663** --- 156 unchanged lines hidden (view full) --- 820 const char *num; 821 const char *enhsc; 822 int eno; 823 const char *fmt; 824 SM_VA_LOCAL_DECL 825{ 826 char del; 827 int l; |
826 int spaceleft = sizeof MsgBuf; | 828 int spaceleft = sizeof(MsgBuf); |
827 char *errtxt; 828 829 /* output the reply code */ 830 if (ISSMTPCODE(fmt)) 831 { 832 num = fmt; 833 fmt += 4; 834 } 835 if (num[3] == '-') 836 del = '-'; 837 else 838 del = ' '; | 829 char *errtxt; 830 831 /* output the reply code */ 832 if (ISSMTPCODE(fmt)) 833 { 834 num = fmt; 835 fmt += 4; 836 } 837 if (num[3] == '-') 838 del = '-'; 839 else 840 del = ' '; |
839#if _FFR_SOFT_BOUNCE | |
840 if (SoftBounce && num[0] == '5') 841 { 842 /* replace 5 by 4 */ 843 (void) sm_snprintf(eb, spaceleft, "4%2.2s%c", num + 1, del); 844 } 845 else | 841 if (SoftBounce && num[0] == '5') 842 { 843 /* replace 5 by 4 */ 844 (void) sm_snprintf(eb, spaceleft, "4%2.2s%c", num + 1, del); 845 } 846 else |
846#endif /* _FFR_SOFT_BOUNCE */ 847 (void) sm_snprintf(eb, spaceleft, "%3.3s%c", num, del); | 847 (void) sm_snprintf(eb, spaceleft, "%3.3s%c", num, del); |
848 eb += 4; 849 spaceleft -= 4; 850 851 if ((l = isenhsc(fmt, ' ' )) > 0 && l < spaceleft - 4) 852 { 853 /* copy enh.status code including trailing blank */ 854 l++; 855 (void) sm_strlcpy(eb, fmt, l + 1); --- 5 unchanged lines hidden (view full) --- 861 { 862 /* copy enh.status code */ 863 (void) sm_strlcpy(eb, enhsc, l + 1); 864 eb[l] = ' '; 865 eb[++l] = '\0'; 866 eb += l; 867 spaceleft -= l; 868 } | 848 eb += 4; 849 spaceleft -= 4; 850 851 if ((l = isenhsc(fmt, ' ' )) > 0 && l < spaceleft - 4) 852 { 853 /* copy enh.status code including trailing blank */ 854 l++; 855 (void) sm_strlcpy(eb, fmt, l + 1); --- 5 unchanged lines hidden (view full) --- 861 { 862 /* copy enh.status code */ 863 (void) sm_strlcpy(eb, enhsc, l + 1); 864 eb[l] = ' '; 865 eb[++l] = '\0'; 866 eb += l; 867 spaceleft -= l; 868 } |
869#if _FFR_SOFT_BOUNCE | |
870 if (SoftBounce && eb[-l] == '5') 871 { 872 /* replace 5 by 4 */ 873 eb[-l] = '4'; 874 } | 869 if (SoftBounce && eb[-l] == '5') 870 { 871 /* replace 5 by 4 */ 872 eb[-l] = '4'; 873 } |
875#endif /* _FFR_SOFT_BOUNCE */ | |
876 errtxt = eb; 877 878 /* output the file name and line number */ 879 if (FileName != NULL) 880 { 881 (void) sm_snprintf(eb, spaceleft, "%s: line %d: ", 882 shortenstring(FileName, 83), LineNumber); 883 eb += (l = strlen(eb)); --- 117 unchanged lines hidden (view full) --- 1001 { 1002 case ETIMEDOUT: 1003 case ECONNRESET: 1004 bp = buf; 1005#if HASSTRERROR 1006 err = strerror(errnum); 1007 if (err == NULL) 1008 { | 874 errtxt = eb; 875 876 /* output the file name and line number */ 877 if (FileName != NULL) 878 { 879 (void) sm_snprintf(eb, spaceleft, "%s: line %d: ", 880 shortenstring(FileName, 83), LineNumber); 881 eb += (l = strlen(eb)); --- 117 unchanged lines hidden (view full) --- 999 { 1000 case ETIMEDOUT: 1001 case ECONNRESET: 1002 bp = buf; 1003#if HASSTRERROR 1004 err = strerror(errnum); 1005 if (err == NULL) 1006 { |
1009 (void) sm_snprintf(errbuf, sizeof errbuf, | 1007 (void) sm_snprintf(errbuf, sizeof(errbuf), |
1010 "Error %d", errnum); 1011 err = errbuf; 1012 } 1013 (void) sm_strlcpy(bp, err, SPACELEFT(buf, bp)); 1014#else /* HASSTRERROR */ 1015 if (errnum >= 0 && errnum < sys_nerr) 1016 (void) sm_strlcpy(bp, sys_errlist[errnum], 1017 SPACELEFT(buf, bp)); --- 27 unchanged lines hidden (view full) --- 1045 (void) sm_snprintf(bp, SPACELEFT(buf, bp), 1046 " during %s", SmtpPhase); 1047 } 1048 return buf; 1049 1050 case EHOSTDOWN: 1051 if (CurHostName == NULL) 1052 break; | 1008 "Error %d", errnum); 1009 err = errbuf; 1010 } 1011 (void) sm_strlcpy(bp, err, SPACELEFT(buf, bp)); 1012#else /* HASSTRERROR */ 1013 if (errnum >= 0 && errnum < sys_nerr) 1014 (void) sm_strlcpy(bp, sys_errlist[errnum], 1015 SPACELEFT(buf, bp)); --- 27 unchanged lines hidden (view full) --- 1043 (void) sm_snprintf(bp, SPACELEFT(buf, bp), 1044 " during %s", SmtpPhase); 1045 } 1046 return buf; 1047 1048 case EHOSTDOWN: 1049 if (CurHostName == NULL) 1050 break; |
1053 (void) sm_snprintf(buf, sizeof buf, "Host %s is down", | 1051 (void) sm_snprintf(buf, sizeof(buf), "Host %s is down", |
1054 shortenstring(CurHostName, MAXSHORTSTR)); 1055 return buf; 1056 1057 case ECONNREFUSED: 1058 if (CurHostName == NULL) 1059 break; | 1052 shortenstring(CurHostName, MAXSHORTSTR)); 1053 return buf; 1054 1055 case ECONNREFUSED: 1056 if (CurHostName == NULL) 1057 break; |
1060 (void) sm_strlcpyn(buf, sizeof buf, 2, "Connection refused by ", | 1058 (void) sm_strlcpyn(buf, sizeof(buf), 2, "Connection refused by ", |
1061 shortenstring(CurHostName, MAXSHORTSTR)); 1062 return buf; 1063 1064#if NAMED_BIND 1065 case HOST_NOT_FOUND + E_DNSBASE: 1066 dnsmsg = "host not found"; 1067 break; 1068 --- 53 unchanged lines hidden (view full) --- 1122 1123 case E_SM_WRFILE: 1124 return "World readable file"; 1125 } 1126 1127 if (dnsmsg != NULL) 1128 { 1129 bp = buf; | 1059 shortenstring(CurHostName, MAXSHORTSTR)); 1060 return buf; 1061 1062#if NAMED_BIND 1063 case HOST_NOT_FOUND + E_DNSBASE: 1064 dnsmsg = "host not found"; 1065 break; 1066 --- 53 unchanged lines hidden (view full) --- 1120 1121 case E_SM_WRFILE: 1122 return "World readable file"; 1123 } 1124 1125 if (dnsmsg != NULL) 1126 { 1127 bp = buf; |
1130 bp += sm_strlcpy(bp, "Name server: ", sizeof buf); | 1128 bp += sm_strlcpy(bp, "Name server: ", sizeof(buf)); |
1131 if (CurHostName != NULL) 1132 { 1133 (void) sm_strlcpyn(bp, SPACELEFT(buf, bp), 2, 1134 shortenstring(CurHostName, MAXSHORTSTR), ": "); 1135 bp += strlen(bp); 1136 } 1137 (void) sm_strlcpy(bp, dnsmsg, SPACELEFT(buf, bp)); 1138 return buf; 1139 } 1140 1141#if LDAPMAP 1142 if (errnum >= E_LDAPBASE) 1143 return ldap_err2string(errnum - E_LDAPBASE); 1144#endif /* LDAPMAP */ 1145 1146#if HASSTRERROR 1147 err = strerror(errnum); 1148 if (err == NULL) 1149 { | 1129 if (CurHostName != NULL) 1130 { 1131 (void) sm_strlcpyn(bp, SPACELEFT(buf, bp), 2, 1132 shortenstring(CurHostName, MAXSHORTSTR), ": "); 1133 bp += strlen(bp); 1134 } 1135 (void) sm_strlcpy(bp, dnsmsg, SPACELEFT(buf, bp)); 1136 return buf; 1137 } 1138 1139#if LDAPMAP 1140 if (errnum >= E_LDAPBASE) 1141 return ldap_err2string(errnum - E_LDAPBASE); 1142#endif /* LDAPMAP */ 1143 1144#if HASSTRERROR 1145 err = strerror(errnum); 1146 if (err == NULL) 1147 { |
1150 (void) sm_snprintf(buf, sizeof buf, "Error %d", errnum); | 1148 (void) sm_snprintf(buf, sizeof(buf), "Error %d", errnum); |
1151 return buf; 1152 } 1153 return err; 1154#else /* HASSTRERROR */ 1155 if (errnum > 0 && errnum < sys_nerr) 1156 return sys_errlist[errnum]; 1157 | 1149 return buf; 1150 } 1151 return err; 1152#else /* HASSTRERROR */ 1153 if (errnum > 0 && errnum < sys_nerr) 1154 return sys_errlist[errnum]; 1155 |
1158 (void) sm_snprintf(buf, sizeof buf, "Error %d", errnum); | 1156 (void) sm_snprintf(buf, sizeof(buf), "Error %d", errnum); |
1159 return buf; 1160#endif /* HASSTRERROR */ 1161} | 1157 return buf; 1158#endif /* HASSTRERROR */ 1159} |