1 /* $NetBSD: clnt_perror.c,v 1.24 2000/06/02 23:11:07 fvdl Exp $ */
5 * SPDX-License-Identifier: BSD-3-Clause
7 * Copyright (c) 2009, Sun Microsystems, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 * - Neither the name of Sun Microsystems, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
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 = 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 (void)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 (void) 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 (void) 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 (void)strncat(str, clnt_sperrno(rpc_createerr.cf_stat), len - 1);
245 switch (rpc_createerr.cf_stat) {
246 case RPC_PMAPFAILURE:
247 (void) strncat(str, " - ", len - 1);
249 clnt_sperrno(rpc_createerr.cf_error.re_status), len - 4);
252 case RPC_SYSTEMERROR:
253 (void)strncat(str, " - ", len - 1);
254 (void)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 (void) 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 */
299 "Kerberos generic error", /* 8 - AUTH_KERB_GENERIC*/
300 "Kerberos credential expired", /* 9 - AUTH_TIMEEXPIRE */
301 "Bad kerberos ticket file", /* 10 - AUTH_TKT_FILE */
302 "Can't decode kerberos authenticator", /* 11 - AUTH_DECODE */
303 "Address wrong in kerberos ticket", /* 12 - AUTH_NET_ADDR */
304 "GSS-API crediential problem", /* 13 - RPCSEC_GSS_CREDPROBLEM */
305 "GSS-API context problem" /* 14 - RPCSEC_GSS_CTXPROBLEM */
309 auth_errmsg(enum auth_stat stat)
311 unsigned int errnum = stat;
313 if (errnum < (sizeof(auth_errlist)/sizeof(auth_errlist[0])))
314 /* LINTED interface problem */
315 return (char *)auth_errlist[errnum];