1 /* $NetBSD: clnt_perror.c,v 1.24 2000/06/02 23:11:07 fvdl Exp $ */
5 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
6 * unrestricted use provided that this legend is included on all tape
7 * media and as a part of the software program in whole or part. Users
8 * may copy or modify Sun RPC without charge, but are not authorized
9 * to license or distribute it to anyone else except as part of a product or
10 * program developed by the user.
12 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
13 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
14 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
16 * Sun RPC is provided with no support and without any obligation on the
17 * part of Sun Microsystems, Inc. to assist in its use, correction,
18 * modification or enhancement.
20 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
21 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
22 * OR ANY PART THEREOF.
24 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
25 * or profits or other special, indirect and consequential damages, even if
26 * Sun has been advised of the possibility of such damages.
28 * Sun Microsystems, Inc.
30 * Mountain View, California 94043
33 #if defined(LIBC_SCCS) && !defined(lint)
34 static char *sccsid2 = "@(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro";
35 static char *sccsid = "@(#)clnt_perror.c 2.1 88/07/29 4.0 RPCSRC";
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
43 * Copyright (C) 1984, Sun Microsystems, Inc.
46 #include "namespace.h"
53 #include <rpc/types.h>
56 #include "un-namespace.h"
60 static char *_buf(void);
61 static char *auth_errmsg(enum auth_stat);
62 #define CLNT_PERROR_BUFLEN 256
69 buf = (char *)malloc(CLNT_PERROR_BUFLEN);
74 * Print reply error info
90 str = _buf(); /* side effect: sets CLNT_PERROR_BUFLEN */
93 len = CLNT_PERROR_BUFLEN;
95 CLNT_GETERR(rpch, &e);
97 if ((i = snprintf(str, len, "%s: ", s)) > 0) {
102 (void)strncpy(str, clnt_sperrno(e.re_status), len - 1);
107 switch (e.re_status) {
109 case RPC_CANTENCODEARGS:
110 case RPC_CANTDECODERES:
112 case RPC_PROGUNAVAIL:
113 case RPC_PROCUNAVAIL:
114 case RPC_CANTDECODEARGS:
115 case RPC_SYSTEMERROR:
116 case RPC_UNKNOWNHOST:
117 case RPC_UNKNOWNPROTO:
118 case RPC_PMAPFAILURE:
119 case RPC_PROGNOTREGISTERED:
125 i = snprintf(str, len, "; errno = %s", strerror(e.re_errno));
132 case RPC_VERSMISMATCH:
133 i = snprintf(str, len, "; low version = %u, high version = %u",
134 e.re_vers.low, e.re_vers.high);
142 err = auth_errmsg(e.re_why);
143 i = snprintf(str, len, "; why = ");
149 i = snprintf(str, len, "%s",err);
151 i = snprintf(str, len,
152 "(unknown authentication error - %d)",
161 case RPC_PROGVERSMISMATCH:
162 i = snprintf(str, len, "; low version = %u, high version = %u",
163 e.re_vers.low, e.re_vers.high);
170 default: /* unknown */
171 i = snprintf(str, len, "; s1 = %u, s2 = %u",
172 e.re_lb.s1, e.re_lb.s2);
179 strstart[CLNT_PERROR_BUFLEN-1] = '\0';
189 assert(rpch != NULL);
192 (void) fprintf(stderr, "%s\n", clnt_sperror(rpch,s));
195 static const char *const rpc_errlist[] = {
196 "RPC: Success", /* 0 - RPC_SUCCESS */
197 "RPC: Can't encode arguments", /* 1 - RPC_CANTENCODEARGS */
198 "RPC: Can't decode result", /* 2 - RPC_CANTDECODERES */
199 "RPC: Unable to send", /* 3 - RPC_CANTSEND */
200 "RPC: Unable to receive", /* 4 - RPC_CANTRECV */
201 "RPC: Timed out", /* 5 - RPC_TIMEDOUT */
202 "RPC: Incompatible versions of RPC", /* 6 - RPC_VERSMISMATCH */
203 "RPC: Authentication error", /* 7 - RPC_AUTHERROR */
204 "RPC: Program unavailable", /* 8 - RPC_PROGUNAVAIL */
205 "RPC: Program/version mismatch", /* 9 - RPC_PROGVERSMISMATCH */
206 "RPC: Procedure unavailable", /* 10 - RPC_PROCUNAVAIL */
207 "RPC: Server can't decode arguments", /* 11 - RPC_CANTDECODEARGS */
208 "RPC: Remote system error", /* 12 - RPC_SYSTEMERROR */
209 "RPC: Unknown host", /* 13 - RPC_UNKNOWNHOST */
210 "RPC: Port mapper failure", /* 14 - RPC_PMAPFAILURE */
211 "RPC: Program not registered", /* 15 - RPC_PROGNOTREGISTERED */
212 "RPC: Failed (unspecified error)", /* 16 - RPC_FAILED */
213 "RPC: Unknown protocol" /* 17 - RPC_UNKNOWNPROTO */
218 * This interface for use by clntrpc
224 unsigned int errnum = stat;
226 if (errnum < (sizeof(rpc_errlist)/sizeof(rpc_errlist[0])))
227 /* LINTED interface problem */
228 return (char *)rpc_errlist[errnum];
230 return ("RPC: (unknown error code)");
237 (void) fprintf(stderr, "%s\n", clnt_sperrno(num));
242 clnt_spcreateerror(s)
250 str = _buf(); /* side effect: sets CLNT_PERROR_BUFLEN */
253 len = CLNT_PERROR_BUFLEN;
254 i = snprintf(str, len, "%s: ", s);
257 (void)strncat(str, clnt_sperrno(rpc_createerr.cf_stat), len - 1);
258 switch (rpc_createerr.cf_stat) {
259 case RPC_PMAPFAILURE:
260 (void) strncat(str, " - ", len - 1);
262 clnt_sperrno(rpc_createerr.cf_error.re_status), len - 4);
265 case RPC_SYSTEMERROR:
266 (void)strncat(str, " - ", len - 1);
267 (void)strncat(str, strerror(rpc_createerr.cf_error.re_errno),
272 case RPC_CANTDECODERES:
273 case RPC_CANTENCODEARGS:
275 case RPC_UNKNOWNPROTO:
276 case RPC_PROGNOTREGISTERED:
278 case RPC_UNKNOWNHOST:
279 case RPC_CANTDECODEARGS:
280 case RPC_PROCUNAVAIL:
281 case RPC_PROGVERSMISMATCH:
282 case RPC_PROGUNAVAIL:
284 case RPC_VERSMISMATCH:
290 str[CLNT_PERROR_BUFLEN-1] = '\0';
301 (void) fprintf(stderr, "%s\n", clnt_spcreateerror(s));
304 static const char *const auth_errlist[] = {
305 "Authentication OK", /* 0 - AUTH_OK */
306 "Invalid client credential", /* 1 - AUTH_BADCRED */
307 "Server rejected credential", /* 2 - AUTH_REJECTEDCRED */
308 "Invalid client verifier", /* 3 - AUTH_BADVERF */
309 "Server rejected verifier", /* 4 - AUTH_REJECTEDVERF */
310 "Client credential too weak", /* 5 - AUTH_TOOWEAK */
311 "Invalid server verifier", /* 6 - AUTH_INVALIDRESP */
312 "Failed (unspecified error)", /* 7 - AUTH_FAILED */
313 "Kerberos generic error", /* 8 - AUTH_KERB_GENERIC*/
314 "Kerberos credential expired", /* 9 - AUTH_TIMEEXPIRE */
315 "Bad kerberos ticket file", /* 10 - AUTH_TKT_FILE */
316 "Can't decode kerberos authenticator", /* 11 - AUTH_DECODE */
317 "Address wrong in kerberos ticket", /* 12 - AUTH_NET_ADDR */
318 "GSS-API crediential problem", /* 13 - RPCSEC_GSS_CREDPROBLEM */
319 "GSS-API context problem" /* 14 - RPCSEC_GSS_CTXPROBLEM */
326 unsigned int errnum = stat;
328 if (errnum < (sizeof(auth_errlist)/sizeof(auth_errlist[0])))
329 /* LINTED interface problem */
330 return (char *)auth_errlist[errnum];