190792Sgshapiro/*
2261363Sgshapiro * Copyright (c) 2001 Proofpoint, Inc. and its suppliers.
390792Sgshapiro *	All rights reserved.
490792Sgshapiro *
590792Sgshapiro * By using this file, you agree to the terms and conditions set
690792Sgshapiro * forth in the LICENSE file which can be found at the top level of
790792Sgshapiro * the sendmail distribution.
890792Sgshapiro */
990792Sgshapiro
1090792Sgshapiro#include <sm/gen.h>
11266692SgshapiroSM_RCSID("@(#)$Id: strexit.c,v 1.6 2013-11-22 20:51:43 ca Exp $")
1290792Sgshapiro#include <sm/string.h>
1390792Sgshapiro#include <sm/sysexits.h>
1490792Sgshapiro
1590792Sgshapiro/*
1690792Sgshapiro**  SM_STREXIT -- convert EX_* value from <sm/sysexits.h> to a character string
1790792Sgshapiro**
1890792Sgshapiro**	This function is analogous to strerror(), except that it
1990792Sgshapiro**	operates on EX_* values from <sm/sysexits.h>.
2090792Sgshapiro**
2190792Sgshapiro**	Parameters:
2290792Sgshapiro**		ex -- EX_* value
2390792Sgshapiro**
2490792Sgshapiro**	Results:
2590792Sgshapiro**		pointer to a static message string
2690792Sgshapiro*/
2790792Sgshapiro
2890792Sgshapirochar *
2990792Sgshapirosm_strexit(ex)
3090792Sgshapiro	int ex;
3190792Sgshapiro{
3290792Sgshapiro	char *msg;
3390792Sgshapiro	static char buf[64];
3490792Sgshapiro
3590792Sgshapiro	msg = sm_sysexitmsg(ex);
3690792Sgshapiro	if (msg == NULL)
3790792Sgshapiro	{
3890792Sgshapiro		(void) sm_snprintf(buf, sizeof buf, "Unknown exit status %d",
3990792Sgshapiro				   ex);
4090792Sgshapiro		msg = buf;
4190792Sgshapiro	}
4290792Sgshapiro	return msg;
4390792Sgshapiro}
4490792Sgshapiro
4590792Sgshapiro/*
4690792Sgshapiro**  SM_SYSEXITMSG -- convert an EX_* value to a character string, or NULL
4790792Sgshapiro**
4890792Sgshapiro**	Parameters:
4990792Sgshapiro**		ex -- EX_* value
5090792Sgshapiro**
5190792Sgshapiro**	Results:
5290792Sgshapiro**		If ex is a known exit value, then a pointer to a static
5390792Sgshapiro**		message string is returned.  Otherwise NULL is returned.
5490792Sgshapiro*/
5590792Sgshapiro
5690792Sgshapirochar *
5790792Sgshapirosm_sysexitmsg(ex)
5890792Sgshapiro	int ex;
5990792Sgshapiro{
6090792Sgshapiro	char *msg;
6190792Sgshapiro
6290792Sgshapiro	msg = sm_sysexmsg(ex);
6390792Sgshapiro	if (msg != NULL)
6490792Sgshapiro		return &msg[11];
6590792Sgshapiro	else
6690792Sgshapiro		return msg;
6790792Sgshapiro}
6890792Sgshapiro
6990792Sgshapiro/*
7090792Sgshapiro**  SM_SYSEXMSG -- convert an EX_* value to a character string, or NULL
7190792Sgshapiro**
7290792Sgshapiro**	Parameters:
7390792Sgshapiro**		ex -- EX_* value
7490792Sgshapiro**
7590792Sgshapiro**	Results:
7690792Sgshapiro**		If ex is a known exit value, then a pointer to a static
7790792Sgshapiro**		string is returned.  Otherwise NULL is returned.
7890792Sgshapiro**		The string contains the following fixed width fields:
7990792Sgshapiro**		 [0]	':' if there is an errno value associated with this
8090792Sgshapiro**			exit value, otherwise ' '.
8190792Sgshapiro**		 [1,3]	3 digit SMTP error code
8290792Sgshapiro**		 [4]	' '
8390792Sgshapiro**		 [5,9]	3 digit SMTP extended error code
8490792Sgshapiro**		 [10]	' '
8590792Sgshapiro**		 [11,]	message string
8690792Sgshapiro*/
8790792Sgshapiro
8890792Sgshapirochar *
8990792Sgshapirosm_sysexmsg(ex)
9090792Sgshapiro	int ex;
9190792Sgshapiro{
9290792Sgshapiro	switch (ex)
9390792Sgshapiro	{
9490792Sgshapiro	  case EX_USAGE:
9590792Sgshapiro		return " 500 5.0.0 Command line usage error";
9690792Sgshapiro	  case EX_DATAERR:
9790792Sgshapiro		return " 501 5.6.0 Data format error";
9890792Sgshapiro	  case EX_NOINPUT:
9990792Sgshapiro		return ":550 5.3.0 Cannot open input";
10090792Sgshapiro	  case EX_NOUSER:
10190792Sgshapiro		return " 550 5.1.1 User unknown";
10290792Sgshapiro	  case EX_NOHOST:
10390792Sgshapiro		return " 550 5.1.2 Host unknown";
10490792Sgshapiro	  case EX_UNAVAILABLE:
10590792Sgshapiro		return " 554 5.0.0 Service unavailable";
10690792Sgshapiro	  case EX_SOFTWARE:
10790792Sgshapiro		return ":554 5.3.0 Internal error";
10890792Sgshapiro	  case EX_OSERR:
10990792Sgshapiro		return ":451 4.0.0 Operating system error";
11090792Sgshapiro	  case EX_OSFILE:
11190792Sgshapiro		return ":554 5.3.5 System file missing";
11290792Sgshapiro	  case EX_CANTCREAT:
11390792Sgshapiro		return ":550 5.0.0 Can't create output";
11490792Sgshapiro	  case EX_IOERR:
11590792Sgshapiro		return ":451 4.0.0 I/O error";
11690792Sgshapiro	  case EX_TEMPFAIL:
11790792Sgshapiro		return " 450 4.0.0 Deferred";
11890792Sgshapiro	  case EX_PROTOCOL:
11990792Sgshapiro		return " 554 5.5.0 Remote protocol error";
12090792Sgshapiro	  case EX_NOPERM:
12190792Sgshapiro		return ":550 5.0.0 Insufficient permission";
12290792Sgshapiro	  case EX_CONFIG:
12390792Sgshapiro		return " 554 5.3.5 Local configuration error";
12490792Sgshapiro	  default:
12590792Sgshapiro		return NULL;
12690792Sgshapiro	}
12790792Sgshapiro}
128