summaryrefslogtreecommitdiff
path: root/gnu/usr.sbin/sendmail/libsm/strexit.c
blob: ce591a13b6966414b833c97d34be6298bf732273 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * Copyright (c) 2001 Sendmail, Inc. and its suppliers.
 *	All rights reserved.
 *
 * By using this file, you agree to the terms and conditions set
 * forth in the LICENSE file which can be found at the top level of
 * the sendmail distribution.
 */

#include <sm/gen.h>
SM_RCSID("@(#)$Sendmail: strexit.c,v 1.5 2001/09/11 04:04:49 gshapiro Exp $")
#include <sm/string.h>
#include <sm/sysexits.h>

/*
**  SM_STREXIT -- convert EX_* value from <sm/sysexits.h> to a character string
**
**	This function is analogous to strerror(), except that it
**	operates on EX_* values from <sm/sysexits.h>.
**
**	Parameters:
**		ex -- EX_* value
**
**	Results:
**		pointer to a static message string
*/

char *
sm_strexit(ex)
	int ex;
{
	char *msg;
	static char buf[64];

	msg = sm_sysexitmsg(ex);
	if (msg == NULL)
	{
		(void) sm_snprintf(buf, sizeof buf, "Unknown exit status %d",
				   ex);
		msg = buf;
	}
	return msg;
}

/*
**  SM_SYSEXITMSG -- convert an EX_* value to a character string, or NULL
**
**	Parameters:
**		ex -- EX_* value
**
**	Results:
**		If ex is a known exit value, then a pointer to a static
**		message string is returned.  Otherwise NULL is returned.
*/

char *
sm_sysexitmsg(ex)
	int ex;
{
	char *msg;

	msg = sm_sysexmsg(ex);
	if (msg != NULL)
		return &msg[11];
	else
		return msg;
}

/*
**  SM_SYSEXMSG -- convert an EX_* value to a character string, or NULL
**
**	Parameters:
**		ex -- EX_* value
**
**	Results:
**		If ex is a known exit value, then a pointer to a static
**		string is returned.  Otherwise NULL is returned.
**		The string contains the following fixed width fields:
**		 [0]	':' if there is an errno value associated with this
**			exit value, otherwise ' '.
**		 [1,3]	3 digit SMTP error code
**		 [4]	' '
**		 [5,9]	3 digit SMTP extended error code
**		 [10]	' '
**		 [11,]	message string
*/

char *
sm_sysexmsg(ex)
	int ex;
{
	switch (ex)
	{
	  case EX_USAGE:
		return " 500 5.0.0 Command line usage error";
	  case EX_DATAERR:
		return " 501 5.6.0 Data format error";
	  case EX_NOINPUT:
		return ":550 5.3.0 Cannot open input";
	  case EX_NOUSER:
		return " 550 5.1.1 User unknown";
	  case EX_NOHOST:
		return " 550 5.1.2 Host unknown";
	  case EX_UNAVAILABLE:
		return " 554 5.0.0 Service unavailable";
	  case EX_SOFTWARE:
		return ":554 5.3.0 Internal error";
	  case EX_OSERR:
		return ":451 4.0.0 Operating system error";
	  case EX_OSFILE:
		return ":554 5.3.5 System file missing";
	  case EX_CANTCREAT:
		return ":550 5.0.0 Can't create output";
	  case EX_IOERR:
		return ":451 4.0.0 I/O error";
	  case EX_TEMPFAIL:
		return " 450 4.0.0 Deferred";
	  case EX_PROTOCOL:
		return " 554 5.5.0 Remote protocol error";
	  case EX_NOPERM:
		return ":550 5.0.0 Insufficient permission";
	  case EX_CONFIG:
		return " 554 5.3.5 Local configuration error";
	  default:
		return NULL;
	}
}