err.c (7c478bd95313f5f23a4c958a745db2134aa03244) err.c (058561cbaa119a6f2659bc27ef343e1b47266bb2)
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 */
13
14#pragma ident "%Z%%M% %I% %E% SMI"
15
16#include <sendmail.h>
17
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 */
13
14#pragma ident "%Z%%M% %I% %E% SMI"
15
16#include <sendmail.h>
17
18SM_RCSID("@(#)$Id: err.c,v 8.191 2003/01/10 02:16:46 ca Exp $")
18SM_RCSID("@(#)$Id: err.c,v 8.196 2006/11/10 23:14:08 ca Exp $")
19
20#if LDAPMAP
21# include <lber.h>
22# include <ldap.h> /* for LDAP error codes */
23#endif /* LDAPMAP */
24
25static void putoutmsg __P((char *, bool, bool));
26static void puterrmsg __P((char *));

--- 79 unchanged lines hidden (view full) ---

106** Raises E:mta.quickabort if QuickAbort is set.
107**
108** Side Effects:
109** increments Errors.
110** sets ExitStat.
111*/
112
113char MsgBuf[BUFSIZ*2]; /* text of most recent message */
19
20#if LDAPMAP
21# include <lber.h>
22# include <ldap.h> /* for LDAP error codes */
23#endif /* LDAPMAP */
24
25static void putoutmsg __P((char *, bool, bool));
26static void puterrmsg __P((char *));

--- 79 unchanged lines hidden (view full) ---

106** Raises E:mta.quickabort if QuickAbort is set.
107**
108** Side Effects:
109** increments Errors.
110** sets ExitStat.
111*/
112
113char MsgBuf[BUFSIZ*2]; /* text of most recent message */
114static char HeldMessageBuf[sizeof MsgBuf]; /* for held messages */
114static char HeldMessageBuf[sizeof(MsgBuf)]; /* for held messages */
115
116#if NAMED_BIND && !defined(NO_DATA)
117# define NO_DATA NO_ADDRESS
118#endif /* NAMED_BIND && !defined(NO_DATA) */
119
120void
121/*VARARGS1*/
122#ifdef __STDC__

--- 82 unchanged lines hidden (view full) ---

205 }
206
207 pw = sm_getpwuid(RealUid);
208 if (pw != NULL)
209 user = pw->pw_name;
210 else
211 {
212 user = ubuf;
115
116#if NAMED_BIND && !defined(NO_DATA)
117# define NO_DATA NO_ADDRESS
118#endif /* NAMED_BIND && !defined(NO_DATA) */
119
120void
121/*VARARGS1*/
122#ifdef __STDC__

--- 82 unchanged lines hidden (view full) ---

205 }
206
207 pw = sm_getpwuid(RealUid);
208 if (pw != NULL)
209 user = pw->pw_name;
210 else
211 {
212 user = ubuf;
213 (void) sm_snprintf(ubuf, sizeof ubuf, "UID%d", (int) RealUid);
213 (void) sm_snprintf(ubuf, sizeof(ubuf), "UID%d", (int) RealUid);
214 }
215
216 if (LogLevel > 0)
217 sm_syslog(panic ? LOG_ALERT : LOG_CRIT,
218 CurEnv == NULL ? NOQID : CurEnv->e_id,
219 "SYSERR(%s): %.900s",
220 user, errtxt);
221 switch (save_errno)

--- 95 unchanged lines hidden (view full) ---

317 case '5':
318 case '6':
319 if (CurEnv->e_rpool == NULL && CurEnv->e_message != NULL)
320 sm_free(CurEnv->e_message);
321 if (MsgBuf[0] == '6')
322 {
323 char buf[MAXLINE];
324
214 }
215
216 if (LogLevel > 0)
217 sm_syslog(panic ? LOG_ALERT : LOG_CRIT,
218 CurEnv == NULL ? NOQID : CurEnv->e_id,
219 "SYSERR(%s): %.900s",
220 user, errtxt);
221 switch (save_errno)

--- 95 unchanged lines hidden (view full) ---

317 case '5':
318 case '6':
319 if (CurEnv->e_rpool == NULL && CurEnv->e_message != NULL)
320 sm_free(CurEnv->e_message);
321 if (MsgBuf[0] == '6')
322 {
323 char buf[MAXLINE];
324
325 (void) sm_snprintf(buf, sizeof buf,
325 (void) sm_snprintf(buf, sizeof(buf),
326 "Postmaster warning: %.*s",
326 "Postmaster warning: %.*s",
327 (int) sizeof buf - 22, errtxt);
327 (int) sizeof(buf) - 22, errtxt);
328 CurEnv->e_message =
329 sm_rpool_strdup_x(CurEnv->e_rpool, buf);
330 }
331 else
332 {
333 CurEnv->e_message =
334 sm_rpool_strdup_x(CurEnv->e_rpool, errtxt);
335 }

--- 68 unchanged lines hidden (view full) ---

404 case '5':
405 case '6':
406 if (CurEnv->e_rpool == NULL && CurEnv->e_message != NULL)
407 sm_free(CurEnv->e_message);
408 if (MsgBuf[0] == '6')
409 {
410 char buf[MAXLINE];
411
328 CurEnv->e_message =
329 sm_rpool_strdup_x(CurEnv->e_rpool, buf);
330 }
331 else
332 {
333 CurEnv->e_message =
334 sm_rpool_strdup_x(CurEnv->e_rpool, errtxt);
335 }

--- 68 unchanged lines hidden (view full) ---

404 case '5':
405 case '6':
406 if (CurEnv->e_rpool == NULL && CurEnv->e_message != NULL)
407 sm_free(CurEnv->e_message);
408 if (MsgBuf[0] == '6')
409 {
410 char buf[MAXLINE];
411
412 (void) sm_snprintf(buf, sizeof buf,
412 (void) sm_snprintf(buf, sizeof(buf),
413 "Postmaster warning: %.*s",
413 "Postmaster warning: %.*s",
414 (int) sizeof buf - 22, errtxt);
414 (int) sizeof(buf) - 22, errtxt);
415 CurEnv->e_message =
416 sm_rpool_strdup_x(CurEnv->e_rpool, buf);
417 }
418 else
419 {
420 CurEnv->e_message =
421 sm_rpool_strdup_x(CurEnv->e_rpool, errtxt);
422 }

--- 102 unchanged lines hidden (view full) ---

525 case '8':
526 if (CurEnv->e_message != NULL)
527 break;
528 /* FALLTHROUGH */
529
530 case '5':
531 if (CurEnv->e_rpool == NULL && CurEnv->e_message != NULL)
532 sm_free(CurEnv->e_message);
415 CurEnv->e_message =
416 sm_rpool_strdup_x(CurEnv->e_rpool, buf);
417 }
418 else
419 {
420 CurEnv->e_message =
421 sm_rpool_strdup_x(CurEnv->e_rpool, errtxt);
422 }

--- 102 unchanged lines hidden (view full) ---

525 case '8':
526 if (CurEnv->e_message != NULL)
527 break;
528 /* FALLTHROUGH */
529
530 case '5':
531 if (CurEnv->e_rpool == NULL && CurEnv->e_message != NULL)
532 sm_free(CurEnv->e_message);
533 CurEnv->e_message =
534 sm_rpool_strdup_x(CurEnv->e_rpool, errtxt);
533 CurEnv->e_message = sm_rpool_strdup_x(CurEnv->e_rpool, errtxt);
535 break;
536 }
537}
538/*
539** PUTOUTMSG -- output error message to transcript and channel
540**
541** Parameters:
542** msg -- message to output (in SMTP format).

--- 12 unchanged lines hidden (view full) ---

555*/
556
557static void
558putoutmsg(msg, holdmsg, heldmsg)
559 char *msg;
560 bool holdmsg;
561 bool heldmsg;
562{
534 break;
535 }
536}
537/*
538** PUTOUTMSG -- output error message to transcript and channel
539**
540** Parameters:
541** msg -- message to output (in SMTP format).

--- 12 unchanged lines hidden (view full) ---

554*/
555
556static void
557putoutmsg(msg, holdmsg, heldmsg)
558 char *msg;
559 bool holdmsg;
560 bool heldmsg;
561{
563 char *errtxt = msg;
564 char msgcode = msg[0];
562 char msgcode = msg[0];
563 char *errtxt = msg;
564 char *id;
565
566 /* display for debugging */
567 if (tTd(54, 8))
568 sm_dprintf("--- %s%s%s\n", msg, holdmsg ? " (hold)" : "",
569 heldmsg ? " (held)" : "");
570
571 /* map warnings to something SMTP can handle */
572 if (msgcode == '6')
573 msg[0] = '5';
574 else if (msgcode == '8')
575 msg[0] = '4';
565
566 /* display for debugging */
567 if (tTd(54, 8))
568 sm_dprintf("--- %s%s%s\n", msg, holdmsg ? " (hold)" : "",
569 heldmsg ? " (held)" : "");
570
571 /* map warnings to something SMTP can handle */
572 if (msgcode == '6')
573 msg[0] = '5';
574 else if (msgcode == '8')
575 msg[0] = '4';
576 id = (CurEnv != NULL) ? CurEnv->e_id : NULL;
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))
577
578 /* output to transcript if serious */
579 if (!heldmsg && CurEnv != NULL && CurEnv->e_xfp != NULL &&
580 strchr("45", msg[0]) != NULL)
581 (void) sm_io_fprintf(CurEnv->e_xfp, SM_TIME_DEFAULT, "%s\n",
582 msg);
583
584 if (LogLevel > 14 && (OpMode == MD_SMTP || OpMode == MD_DAEMON))
584 sm_syslog(LOG_INFO, CurEnv->e_id,
585 sm_syslog(LOG_INFO, id,
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;
586 "--- %s%s%s", msg, holdmsg ? " (hold)" : "",
587 heldmsg ? " (held)" : "");
588
589 if (msgcode == '8')
590 msg[0] = '0';
591
592 /* output to channel if appropriate */
593 if (!Verbose && msg[0] == '0')
594 return;
595 if (holdmsg)
596 {
597 /* save for possible future display */
598 msg[0] = msgcode;
599 if (HeldMessageBuf[0] == '5' && msgcode == '4')
600 return;
600 (void) sm_strlcpy(HeldMessageBuf, msg, sizeof HeldMessageBuf);
601 (void) sm_strlcpy(HeldMessageBuf, msg, sizeof(HeldMessageBuf));
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)
602 return;
603 }
604
605 (void) sm_io_flush(smioout, SM_TIME_DEFAULT);
606
607 if (OutChannel == NULL)
608 return;
609

--- 38 unchanged lines hidden (view full) ---

648
649 if (InChannel == NULL || sm_io_eof(InChannel) ||
650 sm_io_error(InChannel) || strncmp(msg, "221", 3) == 0)
651 return;
652
653 /* can't call syserr, 'cause we are using MsgBuf */
654 HoldErrs = true;
655 if (LogLevel > 0)
655 sm_syslog(LOG_CRIT, CurEnv->e_id,
656 sm_syslog(LOG_CRIT, id,
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;
657 "SYSERR: putoutmsg (%s): error on output channel sending \"%s\": %s",
658 CURHOSTNAME,
659 shortenstring(msg, MAXSHORTSTR), sm_errstring(errno));
660#endif /* !PIPELINING */
661}
662/*
663** PUTERRMSG -- like putoutmsg, but does special processing for error messages
664**

--- 156 unchanged lines hidden (view full) ---

821 const char *num;
822 const char *enhsc;
823 int eno;
824 const char *fmt;
825 SM_VA_LOCAL_DECL
826{
827 char del;
828 int l;
828 int spaceleft = sizeof MsgBuf;
829 int spaceleft = sizeof(MsgBuf);
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 = ' ';
830 char *errtxt;
831
832 /* output the reply code */
833 if (ISSMTPCODE(fmt))
834 {
835 num = fmt;
836 fmt += 4;
837 }
838 if (num[3] == '-')
839 del = '-';
840 else
841 del = ' ';
841#if _FFR_SOFT_BOUNCE
842 if (SoftBounce && num[0] == '5')
843 {
844 /* replace 5 by 4 */
845 (void) sm_snprintf(eb, spaceleft, "4%2.2s%c", num + 1, del);
846 }
847 else
842 if (SoftBounce && num[0] == '5')
843 {
844 /* replace 5 by 4 */
845 (void) sm_snprintf(eb, spaceleft, "4%2.2s%c", num + 1, del);
846 }
847 else
848#endif /* _FFR_SOFT_BOUNCE */
849 (void) sm_snprintf(eb, spaceleft, "%3.3s%c", num, del);
848 (void) sm_snprintf(eb, spaceleft, "%3.3s%c", num, del);
850 eb += 4;
851 spaceleft -= 4;
852
853 if ((l = isenhsc(fmt, ' ' )) > 0 && l < spaceleft - 4)
854 {
855 /* copy enh.status code including trailing blank */
856 l++;
857 (void) sm_strlcpy(eb, fmt, l + 1);

--- 5 unchanged lines hidden (view full) ---

863 {
864 /* copy enh.status code */
865 (void) sm_strlcpy(eb, enhsc, l + 1);
866 eb[l] = ' ';
867 eb[++l] = '\0';
868 eb += l;
869 spaceleft -= l;
870 }
849 eb += 4;
850 spaceleft -= 4;
851
852 if ((l = isenhsc(fmt, ' ' )) > 0 && l < spaceleft - 4)
853 {
854 /* copy enh.status code including trailing blank */
855 l++;
856 (void) sm_strlcpy(eb, fmt, l + 1);

--- 5 unchanged lines hidden (view full) ---

862 {
863 /* copy enh.status code */
864 (void) sm_strlcpy(eb, enhsc, l + 1);
865 eb[l] = ' ';
866 eb[++l] = '\0';
867 eb += l;
868 spaceleft -= l;
869 }
871#if _FFR_SOFT_BOUNCE
872 if (SoftBounce && eb[-l] == '5')
873 {
874 /* replace 5 by 4 */
875 eb[-l] = '4';
876 }
870 if (SoftBounce && eb[-l] == '5')
871 {
872 /* replace 5 by 4 */
873 eb[-l] = '4';
874 }
877#endif /* _FFR_SOFT_BOUNCE */
878 errtxt = eb;
879
880 /* output the file name and line number */
881 if (FileName != NULL)
882 {
883 (void) sm_snprintf(eb, spaceleft, "%s: line %d: ",
884 shortenstring(FileName, 83), LineNumber);
885 eb += (l = strlen(eb));

--- 117 unchanged lines hidden (view full) ---

1003 {
1004 case ETIMEDOUT:
1005 case ECONNRESET:
1006 bp = buf;
1007#if HASSTRERROR
1008 err = strerror(errnum);
1009 if (err == NULL)
1010 {
875 errtxt = eb;
876
877 /* output the file name and line number */
878 if (FileName != NULL)
879 {
880 (void) sm_snprintf(eb, spaceleft, "%s: line %d: ",
881 shortenstring(FileName, 83), LineNumber);
882 eb += (l = strlen(eb));

--- 117 unchanged lines hidden (view full) ---

1000 {
1001 case ETIMEDOUT:
1002 case ECONNRESET:
1003 bp = buf;
1004#if HASSTRERROR
1005 err = strerror(errnum);
1006 if (err == NULL)
1007 {
1011 (void) sm_snprintf(errbuf, sizeof errbuf,
1008 (void) sm_snprintf(errbuf, sizeof(errbuf),
1012 "Error %d", errnum);
1013 err = errbuf;
1014 }
1015 (void) sm_strlcpy(bp, err, SPACELEFT(buf, bp));
1016#else /* HASSTRERROR */
1017 if (errnum >= 0 && errnum < sys_nerr)
1018 (void) sm_strlcpy(bp, sys_errlist[errnum],
1019 SPACELEFT(buf, bp));

--- 27 unchanged lines hidden (view full) ---

1047 (void) sm_snprintf(bp, SPACELEFT(buf, bp),
1048 " during %s", SmtpPhase);
1049 }
1050 return buf;
1051
1052 case EHOSTDOWN:
1053 if (CurHostName == NULL)
1054 break;
1009 "Error %d", errnum);
1010 err = errbuf;
1011 }
1012 (void) sm_strlcpy(bp, err, SPACELEFT(buf, bp));
1013#else /* HASSTRERROR */
1014 if (errnum >= 0 && errnum < sys_nerr)
1015 (void) sm_strlcpy(bp, sys_errlist[errnum],
1016 SPACELEFT(buf, bp));

--- 27 unchanged lines hidden (view full) ---

1044 (void) sm_snprintf(bp, SPACELEFT(buf, bp),
1045 " during %s", SmtpPhase);
1046 }
1047 return buf;
1048
1049 case EHOSTDOWN:
1050 if (CurHostName == NULL)
1051 break;
1055 (void) sm_snprintf(buf, sizeof buf, "Host %s is down",
1052 (void) sm_snprintf(buf, sizeof(buf), "Host %s is down",
1056 shortenstring(CurHostName, MAXSHORTSTR));
1057 return buf;
1058
1059 case ECONNREFUSED:
1060 if (CurHostName == NULL)
1061 break;
1053 shortenstring(CurHostName, MAXSHORTSTR));
1054 return buf;
1055
1056 case ECONNREFUSED:
1057 if (CurHostName == NULL)
1058 break;
1062 (void) sm_strlcpyn(buf, sizeof buf, 2, "Connection refused by ",
1059 (void) sm_strlcpyn(buf, sizeof(buf), 2, "Connection refused by ",
1063 shortenstring(CurHostName, MAXSHORTSTR));
1064 return buf;
1065
1066#if NAMED_BIND
1067 case HOST_NOT_FOUND + E_DNSBASE:
1068 dnsmsg = "host not found";
1069 break;
1070

--- 53 unchanged lines hidden (view full) ---

1124
1125 case E_SM_WRFILE:
1126 return "World readable file";
1127 }
1128
1129 if (dnsmsg != NULL)
1130 {
1131 bp = buf;
1060 shortenstring(CurHostName, MAXSHORTSTR));
1061 return buf;
1062
1063#if NAMED_BIND
1064 case HOST_NOT_FOUND + E_DNSBASE:
1065 dnsmsg = "host not found";
1066 break;
1067

--- 53 unchanged lines hidden (view full) ---

1121
1122 case E_SM_WRFILE:
1123 return "World readable file";
1124 }
1125
1126 if (dnsmsg != NULL)
1127 {
1128 bp = buf;
1132 bp += sm_strlcpy(bp, "Name server: ", sizeof buf);
1129 bp += sm_strlcpy(bp, "Name server: ", sizeof(buf));
1133 if (CurHostName != NULL)
1134 {
1135 (void) sm_strlcpyn(bp, SPACELEFT(buf, bp), 2,
1136 shortenstring(CurHostName, MAXSHORTSTR), ": ");
1137 bp += strlen(bp);
1138 }
1139 (void) sm_strlcpy(bp, dnsmsg, SPACELEFT(buf, bp));
1140 return buf;
1141 }
1142
1143#if LDAPMAP
1144 if (errnum >= E_LDAPBASE)
1145 return ldap_err2string(errnum - E_LDAPBASE);
1146#endif /* LDAPMAP */
1147
1148#if HASSTRERROR
1149 err = strerror(errnum);
1150 if (err == NULL)
1151 {
1130 if (CurHostName != NULL)
1131 {
1132 (void) sm_strlcpyn(bp, SPACELEFT(buf, bp), 2,
1133 shortenstring(CurHostName, MAXSHORTSTR), ": ");
1134 bp += strlen(bp);
1135 }
1136 (void) sm_strlcpy(bp, dnsmsg, SPACELEFT(buf, bp));
1137 return buf;
1138 }
1139
1140#if LDAPMAP
1141 if (errnum >= E_LDAPBASE)
1142 return ldap_err2string(errnum - E_LDAPBASE);
1143#endif /* LDAPMAP */
1144
1145#if HASSTRERROR
1146 err = strerror(errnum);
1147 if (err == NULL)
1148 {
1152 (void) sm_snprintf(buf, sizeof buf, "Error %d", errnum);
1149 (void) sm_snprintf(buf, sizeof(buf), "Error %d", errnum);
1153 return buf;
1154 }
1155 return err;
1156#else /* HASSTRERROR */
1157 if (errnum > 0 && errnum < sys_nerr)
1158 return sys_errlist[errnum];
1159
1150 return buf;
1151 }
1152 return err;
1153#else /* HASSTRERROR */
1154 if (errnum > 0 && errnum < sys_nerr)
1155 return sys_errlist[errnum];
1156
1160 (void) sm_snprintf(buf, sizeof buf, "Error %d", errnum);
1157 (void) sm_snprintf(buf, sizeof(buf), "Error %d", errnum);
1161 return buf;
1162#endif /* HASSTRERROR */
1163}
1158 return buf;
1159#endif /* HASSTRERROR */
1160}