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