1e4adba49Sdist /*
2759969d8Seric  * Copyright (c) 1983, 1995 Eric P. Allman
31e68d9deSbostic  * Copyright (c) 1988, 1993
41e68d9deSbostic  *	The Regents of the University of California.  All rights reserved.
524ec593eSbostic  *
6e1a0b129Sbostic  * %sccs.include.redist.c%
7e4adba49Sdist  */
8e4adba49Sdist 
9e4adba49Sdist #ifndef lint
10*7683b7b7Seric static char sccsid[] = "@(#)sysexits.c	8.5 (Berkeley) 05/24/95";
1124ec593eSbostic #endif /* not lint */
12e4adba49Sdist 
13*7683b7b7Seric #include <sendmail.h>
14f53bdc26Seric 
15aa1f92faSeric /*
160592cbb3Seric **  SYSEXITS.C -- error messages corresponding to sysexits.h
170592cbb3Seric **
180592cbb3Seric **	If the first character of the string is a colon, interpolate
190592cbb3Seric **	the current errno after the rest of the string.
20aa1f92faSeric */
210592cbb3Seric 
220592cbb3Seric char *SysExMsg[] =
230592cbb3Seric {
248b41bef2Seric 	/* 64 USAGE */		" 500 Bad usage",
258b41bef2Seric 	/* 65 DATAERR */	" 501 Data format error",
260592cbb3Seric 	/* 66 NOINPUT */	":550 Cannot open input",
278b41bef2Seric 	/* 67 NOUSER */		" 550 User unknown",
288b41bef2Seric 	/* 68 NOHOST */		" 550 Host unknown",
298b41bef2Seric 	/* 69 UNAVAILABLE */	" 554 Service unavailable",
300592cbb3Seric 	/* 70 SOFTWARE */	":554 Internal error",
310592cbb3Seric 	/* 71 OSERR */		":451 Operating system error",
320592cbb3Seric 	/* 72 OSFILE */		":554 System file missing",
330592cbb3Seric 	/* 73 CANTCREAT */	":550 Can't create output",
340592cbb3Seric 	/* 74 IOERR */		":451 I/O error",
358557d168Seric 	/* 75 TEMPFAIL */	" 250 Deferred",
368b41bef2Seric 	/* 76 PROTOCOL */	" 554 Remote protocol error",
370592cbb3Seric 	/* 77 NOPERM */		":550 Insufficient permission",
381de58830Sbostic 	/* 78 CONFIG */		" 554 Local configuration error",
39f53bdc26Seric };
40f53bdc26Seric 
411de58830Sbostic int N_SysEx = sizeof(SysExMsg) / sizeof(SysExMsg[0]);
42ddf2c9daSeric /*
43ddf2c9daSeric **  DSNTOEXITSTAT -- convert DSN-style error code to EX_ style.
44ddf2c9daSeric **
45ddf2c9daSeric **	Parameters:
46ddf2c9daSeric **		dsncode -- the text of the DSN-style code.
47ddf2c9daSeric **
48ddf2c9daSeric **	Returns:
49ddf2c9daSeric **		The corresponding exit status.
50ddf2c9daSeric */
51ddf2c9daSeric 
52ddf2c9daSeric int
dsntoexitstat(dsncode)53ddf2c9daSeric dsntoexitstat(dsncode)
54ddf2c9daSeric 	char *dsncode;
55ddf2c9daSeric {
56ddf2c9daSeric 	int code2, code3;
57ddf2c9daSeric 
58ddf2c9daSeric 	/* first the easy cases.... */
59ddf2c9daSeric 	if (*dsncode == '2')
60ddf2c9daSeric 		return EX_OK;
61ddf2c9daSeric 	if (*dsncode == '4')
62ddf2c9daSeric 		return EX_TEMPFAIL;
63ddf2c9daSeric 
64ddf2c9daSeric 	/* now decode the other two field parts */
65ddf2c9daSeric 	if (*++dsncode == '.')
66ddf2c9daSeric 		dsncode++;
67ddf2c9daSeric 	code2 = atoi(dsncode);
68ddf2c9daSeric 	while (*dsncode != '\0' && *dsncode != '.')
69ddf2c9daSeric 		dsncode++;
70ddf2c9daSeric 	if (*dsncode != '\0')
71ddf2c9daSeric 		dsncode++;
72ddf2c9daSeric 	code3 = atoi(dsncode);
73ddf2c9daSeric 
74ddf2c9daSeric 	/* and do a nested switch to work them out */
75ddf2c9daSeric 	switch (code2)
76ddf2c9daSeric 	{
77ddf2c9daSeric 	  case 0:	/* Other or Undefined status */
78ddf2c9daSeric 		return EX_UNAVAILABLE;
79ddf2c9daSeric 
80ddf2c9daSeric 	  case 1:	/* Address Status */
81ddf2c9daSeric 		switch (code3)
82ddf2c9daSeric 		{
83ddf2c9daSeric 		  case 0:	/* Other Address Status */
84ddf2c9daSeric 			return EX_DATAERR;
85ddf2c9daSeric 
867a294b0cSeric 		  case 1:	/* Bad destination mailbox address */
87ddf2c9daSeric 		  case 6:	/* Mailbox has moved, No forwarding address */
88ddf2c9daSeric 			return EX_NOUSER;
89ddf2c9daSeric 
907a294b0cSeric 		  case 2:	/* Bad destination system address */
917a294b0cSeric 		  case 8:	/* Bad senders system address */
92ddf2c9daSeric 			return EX_NOHOST;
93ddf2c9daSeric 
947a294b0cSeric 		  case 3:	/* Bad destination mailbox address syntax */
957a294b0cSeric 		  case 7:	/* Bad senders mailbox address syntax */
96ddf2c9daSeric 			return EX_USAGE;
97ddf2c9daSeric 
987a294b0cSeric 		  case 4:	/* Destination mailbox address ambiguous */
99ddf2c9daSeric 			return EX_UNAVAILABLE;
100ddf2c9daSeric 
1017a294b0cSeric 		  case 5:	/* Destination address valid */
102ddf2c9daSeric 			return EX_OK;
103ddf2c9daSeric 		}
104ddf2c9daSeric 		break;
105ddf2c9daSeric 
106ddf2c9daSeric 	  case 2:	/* Mailbox Status */
107ddf2c9daSeric 		switch (code3)
108ddf2c9daSeric 		{
109ddf2c9daSeric 		  case 0:	/* Other or Undefined mailbox status */
110ddf2c9daSeric 		  case 1:	/* Mailbox disabled, not acccepting messages */
111ddf2c9daSeric 		  case 2:	/* Mailbox full */
112ddf2c9daSeric 		  case 4:	/* Mailing list expansion problem */
113ddf2c9daSeric 			return EX_UNAVAILABLE;
114ddf2c9daSeric 
115ddf2c9daSeric 		  case 3:	/* Message length exceeds administrative lim */
116ddf2c9daSeric 			return EX_DATAERR;
117ddf2c9daSeric 		}
118ddf2c9daSeric 		break;
119ddf2c9daSeric 
120ddf2c9daSeric 	  case 3:	/* System Status */
121ddf2c9daSeric 		return EX_OSERR;
122ddf2c9daSeric 
123ddf2c9daSeric 	  case 4:	/* Network and Routing Status */
124ddf2c9daSeric 		switch (code3)
125ddf2c9daSeric 		{
126ddf2c9daSeric 		  case 0:	/* Other or undefined network or routing stat */
127ddf2c9daSeric 			return EX_IOERR;
128ddf2c9daSeric 
129ddf2c9daSeric 		  case 1:	/* No answer from host */
130ddf2c9daSeric 		  case 3:	/* Routing server failure */
131ddf2c9daSeric 		  case 5:	/* Network congestion */
132ddf2c9daSeric 			return EX_TEMPFAIL;
133ddf2c9daSeric 
134ddf2c9daSeric 		  case 2:	/* Bad connection */
135ddf2c9daSeric 			return EX_IOERR;
136ddf2c9daSeric 
137ddf2c9daSeric 		  case 4:	/* Unable to route */
138ddf2c9daSeric 			return EX_PROTOCOL;
139ddf2c9daSeric 
140ddf2c9daSeric 		  case 6:	/* Routing loop detected */
141ddf2c9daSeric 			return EX_CONFIG;
142ddf2c9daSeric 
143ddf2c9daSeric 		  case 7:	/* Delivery time expired */
144ddf2c9daSeric 			return EX_UNAVAILABLE;
145ddf2c9daSeric 		}
146ddf2c9daSeric 		break;
147ddf2c9daSeric 
148ddf2c9daSeric 	  case 5:	/* Protocol Status */
149ddf2c9daSeric 		return EX_PROTOCOL;
150ddf2c9daSeric 
151ddf2c9daSeric 	  case 6:	/* Message Content or Media Status */
152ddf2c9daSeric 		return EX_UNAVAILABLE;
153ddf2c9daSeric 
154ddf2c9daSeric 	  case 7:	/* Security Status */
155ddf2c9daSeric 		return EX_DATAERR;
156ddf2c9daSeric 	}
157ddf2c9daSeric 	return EX_CONFIG;
158ddf2c9daSeric }
159