xref: /freebsd/contrib/sendmail/libsm/strexit.c (revision eb1e8a82963684bac34c992a409a5f6ef6ed08c3)
1 /*
2  * Copyright (c) 2001 Proofpoint, Inc. and its suppliers.
3  *	All rights reserved.
4  *
5  * By using this file, you agree to the terms and conditions set
6  * forth in the LICENSE file which can be found at the top level of
7  * the sendmail distribution.
8  */
9 
10 #include <sm/gen.h>
11 SM_RCSID("@(#)$Id: strexit.c,v 1.6 2013-11-22 20:51:43 ca Exp $")
12 #include <sm/string.h>
13 #include <sm/sysexits.h>
14 
15 /*
16 **  SM_STREXIT -- convert EX_* value from <sm/sysexits.h> to a character string
17 **
18 **	This function is analogous to strerror(), except that it
19 **	operates on EX_* values from <sm/sysexits.h>.
20 **
21 **	Parameters:
22 **		ex -- EX_* value
23 **
24 **	Results:
25 **		pointer to a static message string
26 */
27 
28 char *
29 sm_strexit(ex)
30 	int ex;
31 {
32 	char *msg;
33 	static char buf[64];
34 
35 	msg = sm_sysexitmsg(ex);
36 	if (msg == NULL)
37 	{
38 		(void) sm_snprintf(buf, sizeof buf, "Unknown exit status %d",
39 				   ex);
40 		msg = buf;
41 	}
42 	return msg;
43 }
44 
45 /*
46 **  SM_SYSEXITMSG -- convert an EX_* value to a character string, or NULL
47 **
48 **	Parameters:
49 **		ex -- EX_* value
50 **
51 **	Results:
52 **		If ex is a known exit value, then a pointer to a static
53 **		message string is returned.  Otherwise NULL is returned.
54 */
55 
56 char *
57 sm_sysexitmsg(ex)
58 	int ex;
59 {
60 	char *msg;
61 
62 	msg = sm_sysexmsg(ex);
63 	if (msg != NULL)
64 		return &msg[11];
65 	else
66 		return msg;
67 }
68 
69 /*
70 **  SM_SYSEXMSG -- convert an EX_* value to a character string, or NULL
71 **
72 **	Parameters:
73 **		ex -- EX_* value
74 **
75 **	Results:
76 **		If ex is a known exit value, then a pointer to a static
77 **		string is returned.  Otherwise NULL is returned.
78 **		The string contains the following fixed width fields:
79 **		 [0]	':' if there is an errno value associated with this
80 **			exit value, otherwise ' '.
81 **		 [1,3]	3 digit SMTP error code
82 **		 [4]	' '
83 **		 [5,9]	3 digit SMTP extended error code
84 **		 [10]	' '
85 **		 [11,]	message string
86 */
87 
88 char *
89 sm_sysexmsg(ex)
90 	int ex;
91 {
92 	switch (ex)
93 	{
94 	  case EX_USAGE:
95 		return " 500 5.0.0 Command line usage error";
96 	  case EX_DATAERR:
97 		return " 501 5.6.0 Data format error";
98 	  case EX_NOINPUT:
99 		return ":550 5.3.0 Cannot open input";
100 	  case EX_NOUSER:
101 		return " 550 5.1.1 User unknown";
102 	  case EX_NOHOST:
103 		return " 550 5.1.2 Host unknown";
104 	  case EX_UNAVAILABLE:
105 		return " 554 5.0.0 Service unavailable";
106 	  case EX_SOFTWARE:
107 		return ":554 5.3.0 Internal error";
108 	  case EX_OSERR:
109 		return ":451 4.0.0 Operating system error";
110 	  case EX_OSFILE:
111 		return ":554 5.3.5 System file missing";
112 	  case EX_CANTCREAT:
113 		return ":550 5.0.0 Can't create output";
114 	  case EX_IOERR:
115 		return ":451 4.0.0 I/O error";
116 	  case EX_TEMPFAIL:
117 		return " 450 4.0.0 Deferred";
118 	  case EX_PROTOCOL:
119 		return " 554 5.5.0 Remote protocol error";
120 	  case EX_NOPERM:
121 		return ":550 5.0.0 Insufficient permission";
122 	  case EX_CONFIG:
123 		return " 554 5.3.5 Local configuration error";
124 	  default:
125 		return NULL;
126 	}
127 }
128