clnt_perror.c revision 1.24
11.24Sfvdl/*	$NetBSD: clnt_perror.c,v 1.24 2000/06/02 23:11:07 fvdl Exp $	*/
21.5Scgd
31.1Scgd/*
41.1Scgd * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
51.1Scgd * unrestricted use provided that this legend is included on all tape
61.1Scgd * media and as a part of the software program in whole or part.  Users
71.1Scgd * may copy or modify Sun RPC without charge, but are not authorized
81.1Scgd * to license or distribute it to anyone else except as part of a product or
91.1Scgd * program developed by the user.
101.1Scgd *
111.1Scgd * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
121.1Scgd * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
131.1Scgd * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
141.1Scgd *
151.1Scgd * Sun RPC is provided with no support and without any obligation on the
161.1Scgd * part of Sun Microsystems, Inc. to assist in its use, correction,
171.1Scgd * modification or enhancement.
181.1Scgd *
191.1Scgd * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
201.1Scgd * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
211.1Scgd * OR ANY PART THEREOF.
221.1Scgd *
231.1Scgd * In no event will Sun Microsystems, Inc. be liable for any lost revenue
241.1Scgd * or profits or other special, indirect and consequential damages, even if
251.1Scgd * Sun has been advised of the possibility of such damages.
261.1Scgd *
271.1Scgd * Sun Microsystems, Inc.
281.1Scgd * 2550 Garcia Avenue
291.1Scgd * Mountain View, California  94043
301.1Scgd */
311.1Scgd
321.10Schristos#include <sys/cdefs.h>
331.1Scgd#if defined(LIBC_SCCS) && !defined(lint)
341.10Schristos#if 0
351.10Schristosstatic char *sccsid = "@(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro";
361.10Schristosstatic char *sccsid = "@(#)clnt_perror.c	2.1 88/07/29 4.0 RPCSRC";
371.10Schristos#else
381.24Sfvdl__RCSID("$NetBSD: clnt_perror.c,v 1.24 2000/06/02 23:11:07 fvdl Exp $");
391.10Schristos#endif
401.1Scgd#endif
411.1Scgd
421.1Scgd/*
431.1Scgd * clnt_perror.c
441.1Scgd *
451.1Scgd * Copyright (C) 1984, Sun Microsystems, Inc.
461.1Scgd *
471.1Scgd */
481.11Sjtc#include "namespace.h"
491.14Slukem
501.18Slukem#include <assert.h>
511.1Scgd#include <stdio.h>
521.3Scgd#include <stdlib.h>
531.1Scgd#include <string.h>
541.14Slukem
551.1Scgd#include <rpc/rpc.h>
561.1Scgd#include <rpc/types.h>
571.1Scgd#include <rpc/auth.h>
581.1Scgd#include <rpc/clnt.h>
591.11Sjtc
601.11Sjtc#ifdef __weak_alias
611.23Smycroft__weak_alias(clnt_pcreateerror,_clnt_pcreateerror)
621.23Smycroft__weak_alias(clnt_perrno,_clnt_perrno)
631.23Smycroft__weak_alias(clnt_perror,_clnt_perror)
641.23Smycroft__weak_alias(clnt_spcreateerror,_clnt_spcreateerror)
651.23Smycroft__weak_alias(clnt_sperrno,_clnt_sperrno)
661.23Smycroft__weak_alias(clnt_sperror,_clnt_sperror)
671.11Sjtc#endif
681.1Scgd
691.1Scgdstatic char *buf;
701.17Schristosstatic size_t buflen;
711.1Scgd
721.10Schristosstatic char *_buf __P((void));
731.10Schristosstatic char *auth_errmsg __P((enum auth_stat));
741.10Schristos
751.1Scgdstatic char *
761.1Scgd_buf()
771.1Scgd{
781.1Scgd
791.16Slukem	buflen = 256;
801.13Slukem	if (buf == 0)
811.16Slukem		buf = (char *)malloc(buflen);
821.1Scgd	return (buf);
831.1Scgd}
841.1Scgd
851.1Scgd/*
861.1Scgd * Print reply error info
871.1Scgd */
881.1Scgdchar *
891.1Scgdclnt_sperror(rpch, s)
901.13Slukem	CLIENT *rpch;
911.13Slukem	char *s;
921.1Scgd{
931.1Scgd	struct rpc_err e;
941.1Scgd	char *err;
951.18Slukem	char *str;
961.21Sexplorer	char *strstart;
971.22Sdrochner	size_t len, i;
981.1Scgd
991.18Slukem	_DIAGASSERT(rpch != NULL);
1001.18Slukem	_DIAGASSERT(s != NULL);
1011.18Slukem
1021.22Sdrochner	str = _buf(); /* side effect: sets "buflen" */
1031.13Slukem	if (str == 0)
1041.13Slukem		return (0);
1051.22Sdrochner	len = buflen;
1061.21Sexplorer	strstart = str;
1071.1Scgd	CLNT_GETERR(rpch, &e);
1081.1Scgd
1091.9Smrg	i = snprintf(str, len, "%s: ", s);
1101.9Smrg	str += i;
1111.9Smrg	len -= i;
1121.9Smrg
1131.9Smrg	(void)strncpy(str, clnt_sperrno(e.re_status), len - 1);
1141.9Smrg	i = strlen(str);
1151.9Smrg	str += i;
1161.9Smrg	len -= i;
1171.1Scgd
1181.1Scgd	switch (e.re_status) {
1191.1Scgd	case RPC_SUCCESS:
1201.1Scgd	case RPC_CANTENCODEARGS:
1211.1Scgd	case RPC_CANTDECODERES:
1221.1Scgd	case RPC_TIMEDOUT:
1231.1Scgd	case RPC_PROGUNAVAIL:
1241.1Scgd	case RPC_PROCUNAVAIL:
1251.1Scgd	case RPC_CANTDECODEARGS:
1261.1Scgd	case RPC_SYSTEMERROR:
1271.1Scgd	case RPC_UNKNOWNHOST:
1281.1Scgd	case RPC_UNKNOWNPROTO:
1291.1Scgd	case RPC_PMAPFAILURE:
1301.1Scgd	case RPC_PROGNOTREGISTERED:
1311.1Scgd	case RPC_FAILED:
1321.1Scgd		break;
1331.1Scgd
1341.1Scgd	case RPC_CANTSEND:
1351.1Scgd	case RPC_CANTRECV:
1361.16Slukem		i = snprintf(str, len, "; errno = %s", strerror(e.re_errno));
1371.9Smrg		str += i;
1381.9Smrg		len -= i;
1391.1Scgd		break;
1401.1Scgd
1411.1Scgd	case RPC_VERSMISMATCH:
1421.16Slukem		i = snprintf(str, len, "; low version = %u, high version = %u",
1431.1Scgd			e.re_vers.low, e.re_vers.high);
1441.9Smrg		str += i;
1451.9Smrg		len -= i;
1461.1Scgd		break;
1471.1Scgd
1481.1Scgd	case RPC_AUTHERROR:
1491.1Scgd		err = auth_errmsg(e.re_why);
1501.9Smrg		i = snprintf(str, len, "; why = ");
1511.9Smrg		str += i;
1521.9Smrg		len -= i;
1531.1Scgd		if (err != NULL) {
1541.9Smrg			i = snprintf(str, len, "%s",err);
1551.1Scgd		} else {
1561.9Smrg			i = snprintf(str, len,
1571.1Scgd				"(unknown authentication error - %d)",
1581.1Scgd				(int) e.re_why);
1591.1Scgd		}
1601.9Smrg		str += i;
1611.9Smrg		len -= i;
1621.1Scgd		break;
1631.1Scgd
1641.1Scgd	case RPC_PROGVERSMISMATCH:
1651.16Slukem		i = snprintf(str, len, "; low version = %u, high version = %u",
1661.1Scgd			e.re_vers.low, e.re_vers.high);
1671.9Smrg		str += i;
1681.9Smrg		len -= i;
1691.1Scgd		break;
1701.1Scgd
1711.1Scgd	default:	/* unknown */
1721.16Slukem		i = snprintf(str, len, "; s1 = %u, s2 = %u",
1731.1Scgd			e.re_lb.s1, e.re_lb.s2);
1741.9Smrg		str += i;
1751.9Smrg		len -= i;
1761.1Scgd		break;
1771.1Scgd	}
1781.1Scgd	return(strstart) ;
1791.1Scgd}
1801.1Scgd
1811.1Scgdvoid
1821.1Scgdclnt_perror(rpch, s)
1831.13Slukem	CLIENT *rpch;
1841.13Slukem	char *s;
1851.1Scgd{
1861.18Slukem
1871.18Slukem	_DIAGASSERT(rpch != NULL);
1881.18Slukem	_DIAGASSERT(s != NULL);
1891.18Slukem
1901.14Slukem	(void) fprintf(stderr, "%s\n", clnt_sperror(rpch,s));
1911.1Scgd}
1921.1Scgd
1931.6Sjtcstatic const char *const rpc_errlist[] = {
1941.6Sjtc	"RPC: Success",				/*  0 - RPC_SUCCESS */
1951.6Sjtc	"RPC: Can't encode arguments",		/*  1 - RPC_CANTENCODEARGS */
1961.6Sjtc	"RPC: Can't decode result",		/*  2 - RPC_CANTDECODERES */
1971.6Sjtc	"RPC: Unable to send",			/*  3 - RPC_CANTSEND */
1981.6Sjtc	"RPC: Unable to receive",		/*  4 - RPC_CANTRECV */
1991.6Sjtc	"RPC: Timed out",			/*  5 - RPC_TIMEDOUT */
2001.6Sjtc	"RPC: Incompatible versions of RPC",	/*  6 - RPC_VERSMISMATCH */
2011.6Sjtc	"RPC: Authentication error",		/*  7 - RPC_AUTHERROR */
2021.6Sjtc	"RPC: Program unavailable",		/*  8 - RPC_PROGUNAVAIL */
2031.6Sjtc	"RPC: Program/version mismatch",	/*  9 - RPC_PROGVERSMISMATCH */
2041.6Sjtc	"RPC: Procedure unavailable",		/* 10 - RPC_PROCUNAVAIL */
2051.6Sjtc	"RPC: Server can't decode arguments",	/* 11 - RPC_CANTDECODEARGS */
2061.6Sjtc	"RPC: Remote system error",		/* 12 - RPC_SYSTEMERROR */
2071.6Sjtc	"RPC: Unknown host",			/* 13 - RPC_UNKNOWNHOST */
2081.6Sjtc	"RPC: Port mapper failure",		/* 14 - RPC_PMAPFAILURE */
2091.6Sjtc	"RPC: Program not registered",		/* 15 - RPC_PROGNOTREGISTERED */
2101.6Sjtc	"RPC: Failed (unspecified error)",	/* 16 - RPC_FAILED */
2111.6Sjtc	"RPC: Unknown protocol"			/* 17 - RPC_UNKNOWNPROTO */
2121.1Scgd};
2131.1Scgd
2141.1Scgd
2151.1Scgd/*
2161.1Scgd * This interface for use by clntrpc
2171.1Scgd */
2181.1Scgdchar *
2191.1Scgdclnt_sperrno(stat)
2201.1Scgd	enum clnt_stat stat;
2211.1Scgd{
2221.6Sjtc	unsigned int errnum = stat;
2231.6Sjtc
2241.6Sjtc	if (errnum < (sizeof(rpc_errlist)/sizeof(rpc_errlist[0])))
2251.15Schristos		/* LINTED interface problem */
2261.7Scgd		return (char *)rpc_errlist[errnum];
2271.6Sjtc
2281.1Scgd	return ("RPC: (unknown error code)");
2291.1Scgd}
2301.1Scgd
2311.1Scgdvoid
2321.1Scgdclnt_perrno(num)
2331.1Scgd	enum clnt_stat num;
2341.1Scgd{
2351.14Slukem	(void) fprintf(stderr, "%s\n", clnt_sperrno(num));
2361.1Scgd}
2371.1Scgd
2381.1Scgd
2391.1Scgdchar *
2401.1Scgdclnt_spcreateerror(s)
2411.13Slukem	char *s;
2421.1Scgd{
2431.18Slukem	char *str;
2441.22Sdrochner	size_t len, i;
2451.1Scgd
2461.18Slukem	_DIAGASSERT(s != NULL);
2471.18Slukem
2481.22Sdrochner	str = _buf(); /* side effect: sets "buflen" */
2491.13Slukem	if (str == 0)
2501.13Slukem		return(0);
2511.22Sdrochner	len = buflen;
2521.9Smrg	i = snprintf(str, len, "%s: ", s);
2531.9Smrg	len -= i;
2541.9Smrg	(void)strncat(str, clnt_sperrno(rpc_createerr.cf_stat), len - 1);
2551.1Scgd	switch (rpc_createerr.cf_stat) {
2561.1Scgd	case RPC_PMAPFAILURE:
2571.9Smrg		(void) strncat(str, " - ", len - 1);
2581.9Smrg		(void) strncat(str,
2591.9Smrg		    clnt_sperrno(rpc_createerr.cf_error.re_status), len - 4);
2601.1Scgd		break;
2611.1Scgd
2621.1Scgd	case RPC_SYSTEMERROR:
2631.9Smrg		(void)strncat(str, " - ", len - 1);
2641.9Smrg		(void)strncat(str, strerror(rpc_createerr.cf_error.re_errno),
2651.9Smrg		    len - 4);
2661.10Schristos		break;
2671.10Schristos
2681.10Schristos	case RPC_CANTSEND:
2691.10Schristos	case RPC_CANTDECODERES:
2701.10Schristos	case RPC_CANTENCODEARGS:
2711.10Schristos	case RPC_SUCCESS:
2721.10Schristos	case RPC_UNKNOWNPROTO:
2731.10Schristos	case RPC_PROGNOTREGISTERED:
2741.10Schristos	case RPC_FAILED:
2751.10Schristos	case RPC_UNKNOWNHOST:
2761.10Schristos	case RPC_CANTDECODEARGS:
2771.10Schristos	case RPC_PROCUNAVAIL:
2781.10Schristos	case RPC_PROGVERSMISMATCH:
2791.10Schristos	case RPC_PROGUNAVAIL:
2801.10Schristos	case RPC_AUTHERROR:
2811.10Schristos	case RPC_VERSMISMATCH:
2821.10Schristos	case RPC_TIMEDOUT:
2831.10Schristos	case RPC_CANTRECV:
2841.24Sfvdl	default:
2851.1Scgd		break;
2861.1Scgd	}
2871.1Scgd	return (str);
2881.1Scgd}
2891.1Scgd
2901.1Scgdvoid
2911.1Scgdclnt_pcreateerror(s)
2921.13Slukem	char *s;
2931.1Scgd{
2941.18Slukem
2951.18Slukem	_DIAGASSERT(s != NULL);
2961.18Slukem
2971.14Slukem	(void) fprintf(stderr, "%s\n", clnt_spcreateerror(s));
2981.1Scgd}
2991.1Scgd
3001.6Sjtcstatic const char *const auth_errlist[] = {
3011.6Sjtc	"Authentication OK",			/* 0 - AUTH_OK */
3021.6Sjtc	"Invalid client credential",		/* 1 - AUTH_BADCRED */
3031.6Sjtc	"Server rejected credential",		/* 2 - AUTH_REJECTEDCRED */
3041.6Sjtc	"Invalid client verifier", 		/* 3 - AUTH_BADVERF */
3051.6Sjtc	"Server rejected verifier", 		/* 4 - AUTH_REJECTEDVERF */
3061.6Sjtc	"Client credential too weak",		/* 5 - AUTH_TOOWEAK */
3071.6Sjtc	"Invalid server verifier",		/* 6 - AUTH_INVALIDRESP */
3081.6Sjtc	"Failed (unspecified error)"		/* 7 - AUTH_FAILED */
3091.1Scgd};
3101.1Scgd
3111.1Scgdstatic char *
3121.1Scgdauth_errmsg(stat)
3131.1Scgd	enum auth_stat stat;
3141.1Scgd{
3151.6Sjtc	unsigned int errnum = stat;
3161.6Sjtc
3171.6Sjtc	if (errnum < (sizeof(auth_errlist)/sizeof(auth_errlist[0])))
3181.15Schristos		/* LINTED interface problem */
3191.7Scgd		return (char *)auth_errlist[errnum];
3201.1Scgd
3211.1Scgd	return(NULL);
3221.1Scgd}
323