1 /*
2 * Copyright (c) 1998-2001 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
18 SM_RCSID("@(#)$Id: sysexits.c,v 8.33.4.1 2002/09/09 02:42:37 gshapiro Exp $")
19
20 /*
21 ** DSNTOEXITSTAT -- convert DSN-style error code to EX_ style.
22 **
23 ** Parameters:
24 ** dsncode -- the text of the DSN-style code.
25 **
26 ** Returns:
27 ** The corresponding exit status.
28 */
29
30 int
31 dsntoexitstat(dsncode)
32 char *dsncode;
33 {
34 int code2, code3;
35
36 /* first the easy cases.... */
37 if (*dsncode == '2')
38 return EX_OK;
39 if (*dsncode == '4')
40 return EX_TEMPFAIL;
41
42 /* reject other illegal values */
43 if (*dsncode != '5')
44 return EX_CONFIG;
45
46 /* now decode the other two field parts */
47 if (*++dsncode == '.')
48 dsncode++;
49 code2 = atoi(dsncode);
50 while (*dsncode != '\0' && *dsncode != '.')
51 dsncode++;
52 if (*dsncode != '\0')
53 dsncode++;
54 code3 = atoi(dsncode);
55
56 /* and do a nested switch to work them out */
57 switch (code2)
58 {
59 case 0: /* Other or Undefined status */
60 return EX_UNAVAILABLE;
61
62 case 1: /* Address Status */
63 switch (code3)
64 {
65 case 0: /* Other Address Status */
66 return EX_DATAERR;
67
68 case 1: /* Bad destination mailbox address */
69 case 6: /* Mailbox has moved, No forwarding address */
70 return EX_NOUSER;
71
72 case 2: /* Bad destination system address */
73 case 8: /* Bad senders system address */
74 return EX_NOHOST;
75
76 case 3: /* Bad destination mailbox address syntax */
77 case 7: /* Bad senders mailbox address syntax */
78 return EX_USAGE;
79
80 case 4: /* Destination mailbox address ambiguous */
81 return EX_UNAVAILABLE;
82
83 case 5: /* Destination address valid */
84 /* According to RFC1893, this can't happen */
85 return EX_CONFIG;
86 }
87 break;
88
89 case 2: /* Mailbox Status */
90 switch (code3)
91 {
92 case 0: /* Other or Undefined mailbox status */
93 case 1: /* Mailbox disabled, not accepting messages */
94 case 2: /* Mailbox full */
95 case 4: /* Mailing list expansion problem */
96 return EX_UNAVAILABLE;
97
98 case 3: /* Message length exceeds administrative lim */
99 return EX_DATAERR;
100 }
101 break;
102
103 case 3: /* System Status */
104 return EX_OSERR;
105
106 case 4: /* Network and Routing Status */
107 switch (code3)
108 {
109 case 0: /* Other or undefined network or routing stat */
110 return EX_IOERR;
111
112 case 1: /* No answer from host */
113 case 3: /* Routing server failure */
114 case 5: /* Network congestion */
115 return EX_TEMPFAIL;
116
117 case 2: /* Bad connection */
118 return EX_IOERR;
119
120 case 4: /* Unable to route */
121 return EX_PROTOCOL;
122
123 case 6: /* Routing loop detected */
124 return EX_CONFIG;
125
126 case 7: /* Delivery time expired */
127 return EX_UNAVAILABLE;
128 }
129 break;
130
131 case 5: /* Protocol Status */
132 return EX_PROTOCOL;
133
134 case 6: /* Message Content or Media Status */
135 return EX_UNAVAILABLE;
136
137 case 7: /* Security Status */
138 return EX_DATAERR;
139 }
140 return EX_UNAVAILABLE;
141 }
142 /*
143 ** EXITSTAT -- convert EX_ value to error text.
144 **
145 ** Parameters:
146 ** excode -- rstatus which might consists of an EX_* value.
147 **
148 ** Returns:
149 ** The corresponding error text or the original string.
150 */
151
152 char *
exitstat(excode)153 exitstat(excode)
154 char *excode;
155 {
156 char *c;
157 int i;
158 char *exitmsg;
159
160 if (excode == NULL || *excode == '\0')
161 return excode;
162 i = (int) strtol(excode, &c, 10);
163 if (*c != '\0')
164 return excode;
165 exitmsg = sm_sysexitmsg(i);
166 if (exitmsg != NULL)
167 return exitmsg;
168 return excode;
169 }
170