2 * Copyright (c) 2009, Sun Microsystems, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * - Neither the name of Sun Microsystems, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
28 * @(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro
29 * @(#)clnt_perror.c 2.1 88/07/29 4.0 RPCSRC
30 * $NetBSD: clnt_perror.c,v 1.24 2000/06/02 23:11:07 fvdl Exp $
31 * $FreeBSD: src/lib/libc/rpc/clnt_perror.c,v 1.17 2004/10/16 06:11:34 obrien Exp $
37 * Copyright (C) 1984, Sun Microsystems, Inc.
40 #include "namespace.h"
47 #include <rpc/types.h>
50 #include "un-namespace.h"
54 static char *_buf(void);
55 static char *auth_errmsg(enum auth_stat);
56 #define CLNT_PERROR_BUFLEN 256
63 buf = (char *)malloc(CLNT_PERROR_BUFLEN);
68 * Print reply error info
71 clnt_sperror(CLIENT *rpch, const char *s)
82 str = _buf(); /* side effect: sets CLNT_PERROR_BUFLEN */
85 len = CLNT_PERROR_BUFLEN;
87 CLNT_GETERR(rpch, &e);
89 if ((i = snprintf(str, len, "%s: ", s)) > 0) {
94 strncpy(str, clnt_sperrno(e.re_status), len - 1);
99 switch (e.re_status) {
101 case RPC_CANTENCODEARGS:
102 case RPC_CANTDECODERES:
104 case RPC_PROGUNAVAIL:
105 case RPC_PROCUNAVAIL:
106 case RPC_CANTDECODEARGS:
107 case RPC_SYSTEMERROR:
108 case RPC_UNKNOWNHOST:
109 case RPC_UNKNOWNPROTO:
110 case RPC_PMAPFAILURE:
111 case RPC_PROGNOTREGISTERED:
117 i = snprintf(str, len, "; errno = %s", strerror(e.re_errno));
124 case RPC_VERSMISMATCH:
125 i = snprintf(str, len, "; low version = %u, high version = %u",
126 e.re_vers.low, e.re_vers.high);
134 err = auth_errmsg(e.re_why);
135 i = snprintf(str, len, "; why = ");
141 i = snprintf(str, len, "%s",err);
143 i = snprintf(str, len,
144 "(unknown authentication error - %d)",
153 case RPC_PROGVERSMISMATCH:
154 i = snprintf(str, len, "; low version = %u, high version = %u",
155 e.re_vers.low, e.re_vers.high);
162 default: /* unknown */
163 i = snprintf(str, len, "; s1 = %u, s2 = %u",
164 e.re_lb.s1, e.re_lb.s2);
171 strstart[CLNT_PERROR_BUFLEN-1] = '\0';
176 clnt_perror(CLIENT *rpch, const char *s)
179 assert(rpch != NULL);
182 fprintf(stderr, "%s\n", clnt_sperror(rpch,s));
185 static const char *const rpc_errlist[] = {
186 "RPC: Success", /* 0 - RPC_SUCCESS */
187 "RPC: Can't encode arguments", /* 1 - RPC_CANTENCODEARGS */
188 "RPC: Can't decode result", /* 2 - RPC_CANTDECODERES */
189 "RPC: Unable to send", /* 3 - RPC_CANTSEND */
190 "RPC: Unable to receive", /* 4 - RPC_CANTRECV */
191 "RPC: Timed out", /* 5 - RPC_TIMEDOUT */
192 "RPC: Incompatible versions of RPC", /* 6 - RPC_VERSMISMATCH */
193 "RPC: Authentication error", /* 7 - RPC_AUTHERROR */
194 "RPC: Program unavailable", /* 8 - RPC_PROGUNAVAIL */
195 "RPC: Program/version mismatch", /* 9 - RPC_PROGVERSMISMATCH */
196 "RPC: Procedure unavailable", /* 10 - RPC_PROCUNAVAIL */
197 "RPC: Server can't decode arguments", /* 11 - RPC_CANTDECODEARGS */
198 "RPC: Remote system error", /* 12 - RPC_SYSTEMERROR */
199 "RPC: Unknown host", /* 13 - RPC_UNKNOWNHOST */
200 "RPC: Port mapper failure", /* 14 - RPC_PMAPFAILURE */
201 "RPC: Program not registered", /* 15 - RPC_PROGNOTREGISTERED */
202 "RPC: Failed (unspecified error)", /* 16 - RPC_FAILED */
203 "RPC: Unknown protocol" /* 17 - RPC_UNKNOWNPROTO */
208 * This interface for use by clntrpc
211 clnt_sperrno(enum clnt_stat stat)
213 unsigned int errnum = stat;
215 if (errnum < (sizeof(rpc_errlist)/sizeof(rpc_errlist[0])))
216 /* LINTED interface problem */
217 return (char *)rpc_errlist[errnum];
219 return ("RPC: (unknown error code)");
223 clnt_perrno(enum clnt_stat num)
225 fprintf(stderr, "%s\n", clnt_sperrno(num));
230 clnt_spcreateerror(const char *s)
237 str = _buf(); /* side effect: sets CLNT_PERROR_BUFLEN */
240 len = CLNT_PERROR_BUFLEN;
241 i = snprintf(str, len, "%s: ", s);
244 strncat(str, clnt_sperrno(rpc_createerr.cf_stat), len - 1);
245 switch (rpc_createerr.cf_stat) {
246 case RPC_PMAPFAILURE:
247 strncat(str, " - ", len - 1);
249 clnt_sperrno(rpc_createerr.cf_error.re_status), len - 4);
252 case RPC_SYSTEMERROR:
253 strncat(str, " - ", len - 1);
254 strncat(str, strerror(rpc_createerr.cf_error.re_errno),
259 case RPC_CANTDECODERES:
260 case RPC_CANTENCODEARGS:
262 case RPC_UNKNOWNPROTO:
263 case RPC_PROGNOTREGISTERED:
265 case RPC_UNKNOWNHOST:
266 case RPC_CANTDECODEARGS:
267 case RPC_PROCUNAVAIL:
268 case RPC_PROGVERSMISMATCH:
269 case RPC_PROGUNAVAIL:
271 case RPC_VERSMISMATCH:
277 str[CLNT_PERROR_BUFLEN-1] = '\0';
282 clnt_pcreateerror(const char *s)
287 fprintf(stderr, "%s\n", clnt_spcreateerror(s));
290 static const char *const auth_errlist[] = {
291 "Authentication OK", /* 0 - AUTH_OK */
292 "Invalid client credential", /* 1 - AUTH_BADCRED */
293 "Server rejected credential", /* 2 - AUTH_REJECTEDCRED */
294 "Invalid client verifier", /* 3 - AUTH_BADVERF */
295 "Server rejected verifier", /* 4 - AUTH_REJECTEDVERF */
296 "Client credential too weak", /* 5 - AUTH_TOOWEAK */
297 "Invalid server verifier", /* 6 - AUTH_INVALIDRESP */
298 "Failed (unspecified error)" /* 7 - AUTH_FAILED */
302 auth_errmsg(enum auth_stat stat)
304 unsigned int errnum = stat;
306 if (errnum < (sizeof(auth_errlist)/sizeof(auth_errlist[0])))
307 /* LINTED interface problem */
308 return (char *)auth_errlist[errnum];