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