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.
30 #include <sys/cdefs.h>
35 * Copyright (C) 1984, Sun Microsystems, Inc.
44 #include <rpc/types.h>
50 static char *_buf(void);
51 static char *auth_errmsg(enum auth_stat
);
52 #define CLNT_PERROR_BUFLEN 256
59 buf
= (char *)malloc(CLNT_PERROR_BUFLEN
);
64 * Print reply error info
77 if (rpch
== NULL
|| s
== NULL
)
80 str
= _buf(); /* side effect: sets CLNT_PERROR_BUFLEN */
83 len
= CLNT_PERROR_BUFLEN
;
85 CLNT_GETERR(rpch
, &e
);
87 if (snprintf(str
, len
, "%s: ", s
) > 0) {
93 (void)strncpy(str
, clnt_sperrno(e
.re_status
), len
- 1);
98 switch (e
.re_status
) {
100 case RPC_CANTENCODEARGS
:
101 case RPC_CANTDECODERES
:
103 case RPC_PROGUNAVAIL
:
104 case RPC_PROCUNAVAIL
:
105 case RPC_CANTDECODEARGS
:
106 case RPC_SYSTEMERROR
:
107 case RPC_UNKNOWNHOST
:
108 case RPC_UNKNOWNPROTO
:
109 case RPC_PMAPFAILURE
:
110 case RPC_PROGNOTREGISTERED
:
116 snprintf(str
, len
, "; errno = %s", strerror(e
.re_errno
));
124 case RPC_VERSMISMATCH
:
125 snprintf(str
, len
, "; low version = %u, high version = %u",
126 e
.re_vers
.low
, e
.re_vers
.high
);
135 err
= auth_errmsg(e
.re_why
);
136 snprintf(str
, len
, "; why = ");
143 snprintf(str
, len
, "%s",err
);
146 "(unknown authentication error - %d)",
156 case RPC_PROGVERSMISMATCH
:
157 snprintf(str
, len
, "; low version = %u, high version = %u",
158 e
.re_vers
.low
, e
.re_vers
.high
);
166 default: /* unknown */
167 snprintf(str
, len
, "; s1 = %u, s2 = %u",
168 e
.re_lb
.s1
, e
.re_lb
.s2
);
176 strstart
[CLNT_PERROR_BUFLEN
-1] = '\0';
186 if (rpch
== NULL
|| s
== NULL
)
189 (void) fprintf(stderr
, "%s\n", clnt_sperror(rpch
,s
));
192 static const char *const rpc_errlist
[] = {
193 "RPC: Success", /* 0 - RPC_SUCCESS */
194 "RPC: Can't encode arguments", /* 1 - RPC_CANTENCODEARGS */
195 "RPC: Can't decode result", /* 2 - RPC_CANTDECODERES */
196 "RPC: Unable to send", /* 3 - RPC_CANTSEND */
197 "RPC: Unable to receive", /* 4 - RPC_CANTRECV */
198 "RPC: Timed out", /* 5 - RPC_TIMEDOUT */
199 "RPC: Incompatible versions of RPC", /* 6 - RPC_VERSMISMATCH */
200 "RPC: Authentication error", /* 7 - RPC_AUTHERROR */
201 "RPC: Program unavailable", /* 8 - RPC_PROGUNAVAIL */
202 "RPC: Program/version mismatch", /* 9 - RPC_PROGVERSMISMATCH */
203 "RPC: Procedure unavailable", /* 10 - RPC_PROCUNAVAIL */
204 "RPC: Server can't decode arguments", /* 11 - RPC_CANTDECODEARGS */
205 "RPC: Remote system error", /* 12 - RPC_SYSTEMERROR */
206 "RPC: Unknown host", /* 13 - RPC_UNKNOWNHOST */
207 "RPC: Port mapper failure", /* 14 - RPC_PMAPFAILURE */
208 "RPC: Program not registered", /* 15 - RPC_PROGNOTREGISTERED */
209 "RPC: Failed (unspecified error)", /* 16 - RPC_FAILED */
210 "RPC: Unknown protocol" /* 17 - RPC_UNKNOWNPROTO */
215 * This interface for use by clntrpc
221 unsigned int errnum
= stat
;
223 if (errnum
< (sizeof(rpc_errlist
)/sizeof(rpc_errlist
[0])))
224 /* LINTED interface problem */
225 return (char *)rpc_errlist
[errnum
];
227 return ("RPC: (unknown error code)");
234 (void) fprintf(stderr
, "%s\n", clnt_sperrno(num
));
239 clnt_spcreateerror(s
)
248 str
= _buf(); /* side effect: sets CLNT_PERROR_BUFLEN */
251 len
= CLNT_PERROR_BUFLEN
;
252 snprintf(str
, len
, "%s: ", s
);
256 (void)strncat(str
, clnt_sperrno(rpc_createerr
.cf_stat
), len
- 1);
257 switch (rpc_createerr
.cf_stat
) {
258 case RPC_PMAPFAILURE
:
259 (void) strncat(str
, " - ", len
- 1);
260 err
= clnt_sperrno(rpc_createerr
.cf_error
.re_status
);
262 (void) strncat(str
, err
+5, len
-5);
263 switch(rpc_createerr
.cf_error
.re_status
) {
268 snprintf(str
+i
, len
, ": errno %d (%s)",
269 rpc_createerr
.cf_error
.re_errno
,
270 strerror(rpc_createerr
.cf_error
.re_errno
));
277 case RPC_SYSTEMERROR
:
278 (void)strncat(str
, " - ", len
- 1);
279 (void)strncat(str
, strerror(rpc_createerr
.cf_error
.re_errno
),
284 case RPC_CANTDECODERES
:
285 case RPC_CANTENCODEARGS
:
287 case RPC_UNKNOWNPROTO
:
288 case RPC_PROGNOTREGISTERED
:
290 case RPC_UNKNOWNHOST
:
291 case RPC_CANTDECODEARGS
:
292 case RPC_PROCUNAVAIL
:
293 case RPC_PROGVERSMISMATCH
:
294 case RPC_PROGUNAVAIL
:
296 case RPC_VERSMISMATCH
:
302 str
[CLNT_PERROR_BUFLEN
-1] = '\0';
314 (void) fprintf(stderr
, "%s\n", clnt_spcreateerror(s
));
317 static const char *const auth_errlist
[] = {
318 "Authentication OK", /* 0 - AUTH_OK */
319 "Invalid client credential", /* 1 - AUTH_BADCRED */
320 "Server rejected credential", /* 2 - AUTH_REJECTEDCRED */
321 "Invalid client verifier", /* 3 - AUTH_BADVERF */
322 "Server rejected verifier", /* 4 - AUTH_REJECTEDVERF */
323 "Client credential too weak", /* 5 - AUTH_TOOWEAK */
324 "Invalid server verifier", /* 6 - AUTH_INVALIDRESP */
325 "Failed (unspecified error)" /* 7 - AUTH_FAILED */
332 unsigned int errnum
= stat
;
334 if (errnum
< (sizeof(auth_errlist
)/sizeof(auth_errlist
[0])))
335 /* LINTED interface problem */
336 return (char *)auth_errlist
[errnum
];