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