xref: /freebsd/contrib/sendmail/src/sysexits.c (revision 06f25ae9f1d6020a600a10f713046203d1a82570)
1c2aa98e2SPeter Wemm /*
206f25ae9SGregory Neil Shapiro  * Copyright (c) 1998, 1999 Sendmail, Inc. and its suppliers.
306f25ae9SGregory Neil Shapiro  *	All rights reserved.
4c2aa98e2SPeter Wemm  * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
5c2aa98e2SPeter Wemm  * Copyright (c) 1988, 1993
6c2aa98e2SPeter Wemm  *	The Regents of the University of California.  All rights reserved.
7c2aa98e2SPeter Wemm  *
8c2aa98e2SPeter Wemm  * By using this file, you agree to the terms and conditions set
9c2aa98e2SPeter Wemm  * forth in the LICENSE file which can be found at the top level of
10c2aa98e2SPeter Wemm  * the sendmail distribution.
11c2aa98e2SPeter Wemm  *
12c2aa98e2SPeter Wemm  */
13c2aa98e2SPeter Wemm 
14c2aa98e2SPeter Wemm #ifndef lint
1506f25ae9SGregory Neil Shapiro static char id[] = "@(#)$Id: sysexits.c,v 8.25 1999/09/23 19:59:24 ca Exp $";
1606f25ae9SGregory Neil Shapiro #endif /* ! lint */
17c2aa98e2SPeter Wemm 
1806f25ae9SGregory Neil Shapiro #include <sendmail.h>
19c2aa98e2SPeter Wemm 
20c2aa98e2SPeter Wemm /*
21c2aa98e2SPeter Wemm **  SYSEXITS.C -- error messages corresponding to sysexits.h
22c2aa98e2SPeter Wemm **
23c2aa98e2SPeter Wemm **	If the first character of the string is a colon, interpolate
24c2aa98e2SPeter Wemm **	the current errno after the rest of the string.
25c2aa98e2SPeter Wemm */
26c2aa98e2SPeter Wemm 
27c2aa98e2SPeter Wemm char *SysExMsg[] =
28c2aa98e2SPeter Wemm {
2906f25ae9SGregory Neil Shapiro 	/* 64 USAGE */		" 500 5.0.0 Bad usage",
3006f25ae9SGregory Neil Shapiro 	/* 65 DATAERR */	" 501 5.6.0 Data format error",
3106f25ae9SGregory Neil Shapiro 	/* 66 NOINPUT */	":550 5.3.0 Cannot open input",
3206f25ae9SGregory Neil Shapiro 	/* 67 NOUSER */		" 550 5.1.1 User unknown",
3306f25ae9SGregory Neil Shapiro 	/* 68 NOHOST */		" 550 5.1.2 Host unknown",
3406f25ae9SGregory Neil Shapiro 	/* 69 UNAVAILABLE */	" 554 5.0.0 Service unavailable",
3506f25ae9SGregory Neil Shapiro 	/* 70 SOFTWARE */	":554 5.3.0 Internal error",
3606f25ae9SGregory Neil Shapiro 	/* 71 OSERR */		":451 4.0.0 Operating system error",
3706f25ae9SGregory Neil Shapiro 	/* 72 OSFILE */		":554 5.3.5 System file missing",
3806f25ae9SGregory Neil Shapiro 	/* 73 CANTCREAT */	":550 5.0.0 Can't create output",
3906f25ae9SGregory Neil Shapiro 	/* 74 IOERR */		":451 4.0.0 I/O error",
4006f25ae9SGregory Neil Shapiro 	/* 75 TEMPFAIL */	" 450 4.0.0 Deferred",
4106f25ae9SGregory Neil Shapiro 	/* 76 PROTOCOL */	" 554 5.5.0 Remote protocol error",
4206f25ae9SGregory Neil Shapiro 	/* 77 NOPERM */		":550 5.0.0 Insufficient permission",
4306f25ae9SGregory Neil Shapiro 	/* 78 CONFIG */		" 554 5.3.5 Local configuration error",
44c2aa98e2SPeter Wemm };
45c2aa98e2SPeter Wemm 
46c2aa98e2SPeter Wemm int N_SysEx = sizeof(SysExMsg) / sizeof(SysExMsg[0]);
4706f25ae9SGregory Neil Shapiro 
4806f25ae9SGregory Neil Shapiro static char *SysExitMsg[] =
4906f25ae9SGregory Neil Shapiro {
5006f25ae9SGregory Neil Shapiro 	"command line usage error",
5106f25ae9SGregory Neil Shapiro 	"data format error",
5206f25ae9SGregory Neil Shapiro 	"cannot open input",
5306f25ae9SGregory Neil Shapiro 	"addressee unknown",
5406f25ae9SGregory Neil Shapiro 	"host name unknown",
5506f25ae9SGregory Neil Shapiro 	"service unavailable",
5606f25ae9SGregory Neil Shapiro 	"internal software error",
5706f25ae9SGregory Neil Shapiro 	"system error (e.g., can't fork)",
5806f25ae9SGregory Neil Shapiro 	"critical OS file missing",
5906f25ae9SGregory Neil Shapiro 	"can't create (user) output file",
6006f25ae9SGregory Neil Shapiro 	"input/output error",
6106f25ae9SGregory Neil Shapiro 	"temp failure; user is invited to retry",
6206f25ae9SGregory Neil Shapiro 	"remote error in protocol",
6306f25ae9SGregory Neil Shapiro 	"permission denied",
6406f25ae9SGregory Neil Shapiro 	"configuration error"
6506f25ae9SGregory Neil Shapiro };
6606f25ae9SGregory Neil Shapiro 
67c2aa98e2SPeter Wemm /*
68c2aa98e2SPeter Wemm **  DSNTOEXITSTAT -- convert DSN-style error code to EX_ style.
69c2aa98e2SPeter Wemm **
70c2aa98e2SPeter Wemm **	Parameters:
71c2aa98e2SPeter Wemm **		dsncode -- the text of the DSN-style code.
72c2aa98e2SPeter Wemm **
73c2aa98e2SPeter Wemm **	Returns:
74c2aa98e2SPeter Wemm **		The corresponding exit status.
75c2aa98e2SPeter Wemm */
76c2aa98e2SPeter Wemm 
77c2aa98e2SPeter Wemm int
78c2aa98e2SPeter Wemm dsntoexitstat(dsncode)
79c2aa98e2SPeter Wemm 	char *dsncode;
80c2aa98e2SPeter Wemm {
81c2aa98e2SPeter Wemm 	int code2, code3;
82c2aa98e2SPeter Wemm 
83c2aa98e2SPeter Wemm 	/* first the easy cases.... */
84c2aa98e2SPeter Wemm 	if (*dsncode == '2')
85c2aa98e2SPeter Wemm 		return EX_OK;
86c2aa98e2SPeter Wemm 	if (*dsncode == '4')
87c2aa98e2SPeter Wemm 		return EX_TEMPFAIL;
88c2aa98e2SPeter Wemm 
89c2aa98e2SPeter Wemm 	/* now decode the other two field parts */
90c2aa98e2SPeter Wemm 	if (*++dsncode == '.')
91c2aa98e2SPeter Wemm 		dsncode++;
92c2aa98e2SPeter Wemm 	code2 = atoi(dsncode);
93c2aa98e2SPeter Wemm 	while (*dsncode != '\0' && *dsncode != '.')
94c2aa98e2SPeter Wemm 		dsncode++;
95c2aa98e2SPeter Wemm 	if (*dsncode != '\0')
96c2aa98e2SPeter Wemm 		dsncode++;
97c2aa98e2SPeter Wemm 	code3 = atoi(dsncode);
98c2aa98e2SPeter Wemm 
99c2aa98e2SPeter Wemm 	/* and do a nested switch to work them out */
100c2aa98e2SPeter Wemm 	switch (code2)
101c2aa98e2SPeter Wemm 	{
102c2aa98e2SPeter Wemm 	  case 0:	/* Other or Undefined status */
103c2aa98e2SPeter Wemm 		return EX_UNAVAILABLE;
104c2aa98e2SPeter Wemm 
105c2aa98e2SPeter Wemm 	  case 1:	/* Address Status */
106c2aa98e2SPeter Wemm 		switch (code3)
107c2aa98e2SPeter Wemm 		{
108c2aa98e2SPeter Wemm 		  case 0:	/* Other Address Status */
109c2aa98e2SPeter Wemm 			return EX_DATAERR;
110c2aa98e2SPeter Wemm 
111c2aa98e2SPeter Wemm 		  case 1:	/* Bad destination mailbox address */
112c2aa98e2SPeter Wemm 		  case 6:	/* Mailbox has moved, No forwarding address */
113c2aa98e2SPeter Wemm 			return EX_NOUSER;
114c2aa98e2SPeter Wemm 
115c2aa98e2SPeter Wemm 		  case 2:	/* Bad destination system address */
116c2aa98e2SPeter Wemm 		  case 8:	/* Bad senders system address */
117c2aa98e2SPeter Wemm 			return EX_NOHOST;
118c2aa98e2SPeter Wemm 
119c2aa98e2SPeter Wemm 		  case 3:	/* Bad destination mailbox address syntax */
120c2aa98e2SPeter Wemm 		  case 7:	/* Bad senders mailbox address syntax */
121c2aa98e2SPeter Wemm 			return EX_USAGE;
122c2aa98e2SPeter Wemm 
123c2aa98e2SPeter Wemm 		  case 4:	/* Destination mailbox address ambiguous */
124c2aa98e2SPeter Wemm 			return EX_UNAVAILABLE;
125c2aa98e2SPeter Wemm 
126c2aa98e2SPeter Wemm 		  case 5:	/* Destination address valid */
127c2aa98e2SPeter Wemm 			return EX_OK;
128c2aa98e2SPeter Wemm 		}
129c2aa98e2SPeter Wemm 		break;
130c2aa98e2SPeter Wemm 
131c2aa98e2SPeter Wemm 	  case 2:	/* Mailbox Status */
132c2aa98e2SPeter Wemm 		switch (code3)
133c2aa98e2SPeter Wemm 		{
134c2aa98e2SPeter Wemm 		  case 0:	/* Other or Undefined mailbox status */
13506f25ae9SGregory Neil Shapiro 		  case 1:	/* Mailbox disabled, not accepting messages */
136c2aa98e2SPeter Wemm 		  case 2:	/* Mailbox full */
137c2aa98e2SPeter Wemm 		  case 4:	/* Mailing list expansion problem */
138c2aa98e2SPeter Wemm 			return EX_UNAVAILABLE;
139c2aa98e2SPeter Wemm 
140c2aa98e2SPeter Wemm 		  case 3:	/* Message length exceeds administrative lim */
141c2aa98e2SPeter Wemm 			return EX_DATAERR;
142c2aa98e2SPeter Wemm 		}
143c2aa98e2SPeter Wemm 		break;
144c2aa98e2SPeter Wemm 
145c2aa98e2SPeter Wemm 	  case 3:	/* System Status */
146c2aa98e2SPeter Wemm 		return EX_OSERR;
147c2aa98e2SPeter Wemm 
148c2aa98e2SPeter Wemm 	  case 4:	/* Network and Routing Status */
149c2aa98e2SPeter Wemm 		switch (code3)
150c2aa98e2SPeter Wemm 		{
151c2aa98e2SPeter Wemm 		  case 0:	/* Other or undefined network or routing stat */
152c2aa98e2SPeter Wemm 			return EX_IOERR;
153c2aa98e2SPeter Wemm 
154c2aa98e2SPeter Wemm 		  case 1:	/* No answer from host */
155c2aa98e2SPeter Wemm 		  case 3:	/* Routing server failure */
156c2aa98e2SPeter Wemm 		  case 5:	/* Network congestion */
157c2aa98e2SPeter Wemm 			return EX_TEMPFAIL;
158c2aa98e2SPeter Wemm 
159c2aa98e2SPeter Wemm 		  case 2:	/* Bad connection */
160c2aa98e2SPeter Wemm 			return EX_IOERR;
161c2aa98e2SPeter Wemm 
162c2aa98e2SPeter Wemm 		  case 4:	/* Unable to route */
163c2aa98e2SPeter Wemm 			return EX_PROTOCOL;
164c2aa98e2SPeter Wemm 
165c2aa98e2SPeter Wemm 		  case 6:	/* Routing loop detected */
166c2aa98e2SPeter Wemm 			return EX_CONFIG;
167c2aa98e2SPeter Wemm 
168c2aa98e2SPeter Wemm 		  case 7:	/* Delivery time expired */
169c2aa98e2SPeter Wemm 			return EX_UNAVAILABLE;
170c2aa98e2SPeter Wemm 		}
171c2aa98e2SPeter Wemm 		break;
172c2aa98e2SPeter Wemm 
173c2aa98e2SPeter Wemm 	  case 5:	/* Protocol Status */
174c2aa98e2SPeter Wemm 		return EX_PROTOCOL;
175c2aa98e2SPeter Wemm 
176c2aa98e2SPeter Wemm 	  case 6:	/* Message Content or Media Status */
177c2aa98e2SPeter Wemm 		return EX_UNAVAILABLE;
178c2aa98e2SPeter Wemm 
179c2aa98e2SPeter Wemm 	  case 7:	/* Security Status */
180c2aa98e2SPeter Wemm 		return EX_DATAERR;
181c2aa98e2SPeter Wemm 	}
182c2aa98e2SPeter Wemm 	return EX_CONFIG;
183c2aa98e2SPeter Wemm }
18406f25ae9SGregory Neil Shapiro 
18506f25ae9SGregory Neil Shapiro /*
18606f25ae9SGregory Neil Shapiro **  EXITSTAT -- convert EX_ value to error text.
18706f25ae9SGregory Neil Shapiro **
18806f25ae9SGregory Neil Shapiro **	Parameters:
18906f25ae9SGregory Neil Shapiro **		excode -- rstatus which might consists of an EX_* value.
19006f25ae9SGregory Neil Shapiro **
19106f25ae9SGregory Neil Shapiro **	Returns:
19206f25ae9SGregory Neil Shapiro **		The corresponding error text or the original string.
19306f25ae9SGregory Neil Shapiro */
19406f25ae9SGregory Neil Shapiro 
19506f25ae9SGregory Neil Shapiro char *
19606f25ae9SGregory Neil Shapiro exitstat(excode)
19706f25ae9SGregory Neil Shapiro 	char *excode;
19806f25ae9SGregory Neil Shapiro {
19906f25ae9SGregory Neil Shapiro 	char *c;
20006f25ae9SGregory Neil Shapiro 	int i;
20106f25ae9SGregory Neil Shapiro 
20206f25ae9SGregory Neil Shapiro 	if (excode == NULL || *excode == '\0')
20306f25ae9SGregory Neil Shapiro 		return excode;
20406f25ae9SGregory Neil Shapiro 	i = 0;
20506f25ae9SGregory Neil Shapiro 	for (c = excode; *c != '\0'; c++)
20606f25ae9SGregory Neil Shapiro 	{
20706f25ae9SGregory Neil Shapiro 		if (isascii(*c) && isdigit(*c))
20806f25ae9SGregory Neil Shapiro 			i = i * 10 + (*c - '0');
20906f25ae9SGregory Neil Shapiro 		else
21006f25ae9SGregory Neil Shapiro 			return excode;
21106f25ae9SGregory Neil Shapiro 	}
21206f25ae9SGregory Neil Shapiro 	i -= EX__BASE;
21306f25ae9SGregory Neil Shapiro 	if (i >= 0 && i <= N_SysEx)
21406f25ae9SGregory Neil Shapiro 		return SysExitMsg[i];
21506f25ae9SGregory Neil Shapiro 	return excode;
21606f25ae9SGregory Neil Shapiro }
217