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