xref: /freebsd/contrib/sendmail/src/sysexits.c (revision c2aa98e247e56d5266d789dfc9b90b524b0019fe)
1c2aa98e2SPeter Wemm /*
2c2aa98e2SPeter Wemm  * Copyright (c) 1998 Sendmail, Inc.  All rights reserved.
3c2aa98e2SPeter Wemm  * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
4c2aa98e2SPeter Wemm  * Copyright (c) 1988, 1993
5c2aa98e2SPeter Wemm  *	The Regents of the University of California.  All rights reserved.
6c2aa98e2SPeter Wemm  *
7c2aa98e2SPeter Wemm  * By using this file, you agree to the terms and conditions set
8c2aa98e2SPeter Wemm  * forth in the LICENSE file which can be found at the top level of
9c2aa98e2SPeter Wemm  * the sendmail distribution.
10c2aa98e2SPeter Wemm  *
11c2aa98e2SPeter Wemm  */
12c2aa98e2SPeter Wemm 
13c2aa98e2SPeter Wemm #ifndef lint
14c2aa98e2SPeter Wemm static char sccsid[] = "@(#)sysexits.c	8.13 (Berkeley) 5/24/98";
15c2aa98e2SPeter Wemm #endif /* not lint */
16c2aa98e2SPeter Wemm 
17c2aa98e2SPeter Wemm #include "sendmail.h"
18c2aa98e2SPeter Wemm 
19c2aa98e2SPeter Wemm /*
20c2aa98e2SPeter Wemm **  SYSEXITS.C -- error messages corresponding to sysexits.h
21c2aa98e2SPeter Wemm **
22c2aa98e2SPeter Wemm **	If the first character of the string is a colon, interpolate
23c2aa98e2SPeter Wemm **	the current errno after the rest of the string.
24c2aa98e2SPeter Wemm */
25c2aa98e2SPeter Wemm 
26c2aa98e2SPeter Wemm char *SysExMsg[] =
27c2aa98e2SPeter Wemm {
28c2aa98e2SPeter Wemm 	/* 64 USAGE */		" 500 Bad usage",
29c2aa98e2SPeter Wemm 	/* 65 DATAERR */	" 501 Data format error",
30c2aa98e2SPeter Wemm 	/* 66 NOINPUT */	":550 Cannot open input",
31c2aa98e2SPeter Wemm 	/* 67 NOUSER */		" 550 User unknown",
32c2aa98e2SPeter Wemm 	/* 68 NOHOST */		" 550 Host unknown",
33c2aa98e2SPeter Wemm 	/* 69 UNAVAILABLE */	" 554 Service unavailable",
34c2aa98e2SPeter Wemm 	/* 70 SOFTWARE */	":554 Internal error",
35c2aa98e2SPeter Wemm 	/* 71 OSERR */		":451 Operating system error",
36c2aa98e2SPeter Wemm 	/* 72 OSFILE */		":554 System file missing",
37c2aa98e2SPeter Wemm 	/* 73 CANTCREAT */	":550 Can't create output",
38c2aa98e2SPeter Wemm 	/* 74 IOERR */		":451 I/O error",
39c2aa98e2SPeter Wemm 	/* 75 TEMPFAIL */	" 250 Deferred",
40c2aa98e2SPeter Wemm 	/* 76 PROTOCOL */	" 554 Remote protocol error",
41c2aa98e2SPeter Wemm 	/* 77 NOPERM */		":550 Insufficient permission",
42c2aa98e2SPeter Wemm 	/* 78 CONFIG */		" 554 Local configuration error",
43c2aa98e2SPeter Wemm };
44c2aa98e2SPeter Wemm 
45c2aa98e2SPeter Wemm int N_SysEx = sizeof(SysExMsg) / sizeof(SysExMsg[0]);
46c2aa98e2SPeter Wemm /*
47c2aa98e2SPeter Wemm **  DSNTOEXITSTAT -- convert DSN-style error code to EX_ style.
48c2aa98e2SPeter Wemm **
49c2aa98e2SPeter Wemm **	Parameters:
50c2aa98e2SPeter Wemm **		dsncode -- the text of the DSN-style code.
51c2aa98e2SPeter Wemm **
52c2aa98e2SPeter Wemm **	Returns:
53c2aa98e2SPeter Wemm **		The corresponding exit status.
54c2aa98e2SPeter Wemm */
55c2aa98e2SPeter Wemm 
56c2aa98e2SPeter Wemm int
57c2aa98e2SPeter Wemm dsntoexitstat(dsncode)
58c2aa98e2SPeter Wemm 	char *dsncode;
59c2aa98e2SPeter Wemm {
60c2aa98e2SPeter Wemm 	int code2, code3;
61c2aa98e2SPeter Wemm 
62c2aa98e2SPeter Wemm 	/* first the easy cases.... */
63c2aa98e2SPeter Wemm 	if (*dsncode == '2')
64c2aa98e2SPeter Wemm 		return EX_OK;
65c2aa98e2SPeter Wemm 	if (*dsncode == '4')
66c2aa98e2SPeter Wemm 		return EX_TEMPFAIL;
67c2aa98e2SPeter Wemm 
68c2aa98e2SPeter Wemm 	/* now decode the other two field parts */
69c2aa98e2SPeter Wemm 	if (*++dsncode == '.')
70c2aa98e2SPeter Wemm 		dsncode++;
71c2aa98e2SPeter Wemm 	code2 = atoi(dsncode);
72c2aa98e2SPeter Wemm 	while (*dsncode != '\0' && *dsncode != '.')
73c2aa98e2SPeter Wemm 		dsncode++;
74c2aa98e2SPeter Wemm 	if (*dsncode != '\0')
75c2aa98e2SPeter Wemm 		dsncode++;
76c2aa98e2SPeter Wemm 	code3 = atoi(dsncode);
77c2aa98e2SPeter Wemm 
78c2aa98e2SPeter Wemm 	/* and do a nested switch to work them out */
79c2aa98e2SPeter Wemm 	switch (code2)
80c2aa98e2SPeter Wemm 	{
81c2aa98e2SPeter Wemm 	  case 0:	/* Other or Undefined status */
82c2aa98e2SPeter Wemm 		return EX_UNAVAILABLE;
83c2aa98e2SPeter Wemm 
84c2aa98e2SPeter Wemm 	  case 1:	/* Address Status */
85c2aa98e2SPeter Wemm 		switch (code3)
86c2aa98e2SPeter Wemm 		{
87c2aa98e2SPeter Wemm 		  case 0:	/* Other Address Status */
88c2aa98e2SPeter Wemm 			return EX_DATAERR;
89c2aa98e2SPeter Wemm 
90c2aa98e2SPeter Wemm 		  case 1:	/* Bad destination mailbox address */
91c2aa98e2SPeter Wemm 		  case 6:	/* Mailbox has moved, No forwarding address */
92c2aa98e2SPeter Wemm 			return EX_NOUSER;
93c2aa98e2SPeter Wemm 
94c2aa98e2SPeter Wemm 		  case 2:	/* Bad destination system address */
95c2aa98e2SPeter Wemm 		  case 8:	/* Bad senders system address */
96c2aa98e2SPeter Wemm 			return EX_NOHOST;
97c2aa98e2SPeter Wemm 
98c2aa98e2SPeter Wemm 		  case 3:	/* Bad destination mailbox address syntax */
99c2aa98e2SPeter Wemm 		  case 7:	/* Bad senders mailbox address syntax */
100c2aa98e2SPeter Wemm 			return EX_USAGE;
101c2aa98e2SPeter Wemm 
102c2aa98e2SPeter Wemm 		  case 4:	/* Destination mailbox address ambiguous */
103c2aa98e2SPeter Wemm 			return EX_UNAVAILABLE;
104c2aa98e2SPeter Wemm 
105c2aa98e2SPeter Wemm 		  case 5:	/* Destination address valid */
106c2aa98e2SPeter Wemm 			return EX_OK;
107c2aa98e2SPeter Wemm 		}
108c2aa98e2SPeter Wemm 		break;
109c2aa98e2SPeter Wemm 
110c2aa98e2SPeter Wemm 	  case 2:	/* Mailbox Status */
111c2aa98e2SPeter Wemm 		switch (code3)
112c2aa98e2SPeter Wemm 		{
113c2aa98e2SPeter Wemm 		  case 0:	/* Other or Undefined mailbox status */
114c2aa98e2SPeter Wemm 		  case 1:	/* Mailbox disabled, not acccepting messages */
115c2aa98e2SPeter Wemm 		  case 2:	/* Mailbox full */
116c2aa98e2SPeter Wemm 		  case 4:	/* Mailing list expansion problem */
117c2aa98e2SPeter Wemm 			return EX_UNAVAILABLE;
118c2aa98e2SPeter Wemm 
119c2aa98e2SPeter Wemm 		  case 3:	/* Message length exceeds administrative lim */
120c2aa98e2SPeter Wemm 			return EX_DATAERR;
121c2aa98e2SPeter Wemm 		}
122c2aa98e2SPeter Wemm 		break;
123c2aa98e2SPeter Wemm 
124c2aa98e2SPeter Wemm 	  case 3:	/* System Status */
125c2aa98e2SPeter Wemm 		return EX_OSERR;
126c2aa98e2SPeter Wemm 
127c2aa98e2SPeter Wemm 	  case 4:	/* Network and Routing Status */
128c2aa98e2SPeter Wemm 		switch (code3)
129c2aa98e2SPeter Wemm 		{
130c2aa98e2SPeter Wemm 		  case 0:	/* Other or undefined network or routing stat */
131c2aa98e2SPeter Wemm 			return EX_IOERR;
132c2aa98e2SPeter Wemm 
133c2aa98e2SPeter Wemm 		  case 1:	/* No answer from host */
134c2aa98e2SPeter Wemm 		  case 3:	/* Routing server failure */
135c2aa98e2SPeter Wemm 		  case 5:	/* Network congestion */
136c2aa98e2SPeter Wemm 			return EX_TEMPFAIL;
137c2aa98e2SPeter Wemm 
138c2aa98e2SPeter Wemm 		  case 2:	/* Bad connection */
139c2aa98e2SPeter Wemm 			return EX_IOERR;
140c2aa98e2SPeter Wemm 
141c2aa98e2SPeter Wemm 		  case 4:	/* Unable to route */
142c2aa98e2SPeter Wemm 			return EX_PROTOCOL;
143c2aa98e2SPeter Wemm 
144c2aa98e2SPeter Wemm 		  case 6:	/* Routing loop detected */
145c2aa98e2SPeter Wemm 			return EX_CONFIG;
146c2aa98e2SPeter Wemm 
147c2aa98e2SPeter Wemm 		  case 7:	/* Delivery time expired */
148c2aa98e2SPeter Wemm 			return EX_UNAVAILABLE;
149c2aa98e2SPeter Wemm 		}
150c2aa98e2SPeter Wemm 		break;
151c2aa98e2SPeter Wemm 
152c2aa98e2SPeter Wemm 	  case 5:	/* Protocol Status */
153c2aa98e2SPeter Wemm 		return EX_PROTOCOL;
154c2aa98e2SPeter Wemm 
155c2aa98e2SPeter Wemm 	  case 6:	/* Message Content or Media Status */
156c2aa98e2SPeter Wemm 		return EX_UNAVAILABLE;
157c2aa98e2SPeter Wemm 
158c2aa98e2SPeter Wemm 	  case 7:	/* Security Status */
159c2aa98e2SPeter Wemm 		return EX_DATAERR;
160c2aa98e2SPeter Wemm 	}
161c2aa98e2SPeter Wemm 	return EX_CONFIG;
162c2aa98e2SPeter Wemm }
163