1 | #include <machine/rtems-bsd-user-space.h> |
---|
2 | |
---|
3 | /* $NetBSD: clnt_perror.c,v 1.24 2000/06/02 23:11:07 fvdl Exp $ */ |
---|
4 | |
---|
5 | |
---|
6 | /*- |
---|
7 | * Copyright (c) 2009, Sun Microsystems, Inc. |
---|
8 | * All rights reserved. |
---|
9 | * |
---|
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. |
---|
20 | * |
---|
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. |
---|
32 | */ |
---|
33 | |
---|
34 | #if defined(LIBC_SCCS) && !defined(lint) |
---|
35 | static char *sccsid2 = "@(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro"; |
---|
36 | static char *sccsid = "@(#)clnt_perror.c 2.1 88/07/29 4.0 RPCSRC"; |
---|
37 | #endif |
---|
38 | #include <sys/cdefs.h> |
---|
39 | __FBSDID("$FreeBSD$"); |
---|
40 | |
---|
41 | /* |
---|
42 | * clnt_perror.c |
---|
43 | * |
---|
44 | * Copyright (C) 1984, Sun Microsystems, Inc. |
---|
45 | * |
---|
46 | */ |
---|
47 | #include "namespace.h" |
---|
48 | #include <assert.h> |
---|
49 | #include <stdio.h> |
---|
50 | #include <stdlib.h> |
---|
51 | #include <string.h> |
---|
52 | |
---|
53 | #include <rpc/rpc.h> |
---|
54 | #include <rpc/types.h> |
---|
55 | #include <rpc/auth.h> |
---|
56 | #include <rpc/clnt.h> |
---|
57 | #include "un-namespace.h" |
---|
58 | |
---|
59 | static char *buf; |
---|
60 | |
---|
61 | static char *_buf(void); |
---|
62 | static char *auth_errmsg(enum auth_stat); |
---|
63 | #define CLNT_PERROR_BUFLEN 256 |
---|
64 | |
---|
65 | static char * |
---|
66 | _buf() |
---|
67 | { |
---|
68 | |
---|
69 | if (buf == 0) |
---|
70 | buf = (char *)malloc(CLNT_PERROR_BUFLEN); |
---|
71 | return (buf); |
---|
72 | } |
---|
73 | |
---|
74 | /* |
---|
75 | * Print reply error info |
---|
76 | */ |
---|
77 | char * |
---|
78 | clnt_sperror(rpch, s) |
---|
79 | CLIENT *rpch; |
---|
80 | const char *s; |
---|
81 | { |
---|
82 | struct rpc_err e; |
---|
83 | char *err; |
---|
84 | char *str; |
---|
85 | char *strstart; |
---|
86 | size_t len, i; |
---|
87 | |
---|
88 | assert(rpch != NULL); |
---|
89 | assert(s != NULL); |
---|
90 | |
---|
91 | str = _buf(); /* side effect: sets CLNT_PERROR_BUFLEN */ |
---|
92 | if (str == 0) |
---|
93 | return (0); |
---|
94 | len = CLNT_PERROR_BUFLEN; |
---|
95 | strstart = str; |
---|
96 | CLNT_GETERR(rpch, &e); |
---|
97 | |
---|
98 | if ((i = snprintf(str, len, "%s: ", s)) > 0) { |
---|
99 | str += i; |
---|
100 | len -= i; |
---|
101 | } |
---|
102 | |
---|
103 | (void)strncpy(str, clnt_sperrno(e.re_status), len - 1); |
---|
104 | i = strlen(str); |
---|
105 | str += i; |
---|
106 | len -= i; |
---|
107 | |
---|
108 | switch (e.re_status) { |
---|
109 | case RPC_SUCCESS: |
---|
110 | case RPC_CANTENCODEARGS: |
---|
111 | case RPC_CANTDECODERES: |
---|
112 | case RPC_TIMEDOUT: |
---|
113 | case RPC_PROGUNAVAIL: |
---|
114 | case RPC_PROCUNAVAIL: |
---|
115 | case RPC_CANTDECODEARGS: |
---|
116 | case RPC_SYSTEMERROR: |
---|
117 | case RPC_UNKNOWNHOST: |
---|
118 | case RPC_UNKNOWNPROTO: |
---|
119 | case RPC_PMAPFAILURE: |
---|
120 | case RPC_PROGNOTREGISTERED: |
---|
121 | case RPC_FAILED: |
---|
122 | break; |
---|
123 | |
---|
124 | case RPC_CANTSEND: |
---|
125 | case RPC_CANTRECV: |
---|
126 | i = snprintf(str, len, "; errno = %s", strerror(e.re_errno)); |
---|
127 | if (i > 0) { |
---|
128 | str += i; |
---|
129 | len -= i; |
---|
130 | } |
---|
131 | break; |
---|
132 | |
---|
133 | case RPC_VERSMISMATCH: |
---|
134 | i = snprintf(str, len, "; low version = %u, high version = %u", |
---|
135 | e.re_vers.low, e.re_vers.high); |
---|
136 | if (i > 0) { |
---|
137 | str += i; |
---|
138 | len -= i; |
---|
139 | } |
---|
140 | break; |
---|
141 | |
---|
142 | case RPC_AUTHERROR: |
---|
143 | err = auth_errmsg(e.re_why); |
---|
144 | i = snprintf(str, len, "; why = "); |
---|
145 | if (i > 0) { |
---|
146 | str += i; |
---|
147 | len -= i; |
---|
148 | } |
---|
149 | if (err != NULL) { |
---|
150 | i = snprintf(str, len, "%s",err); |
---|
151 | } else { |
---|
152 | i = snprintf(str, len, |
---|
153 | "(unknown authentication error - %d)", |
---|
154 | (int) e.re_why); |
---|
155 | } |
---|
156 | if (i > 0) { |
---|
157 | str += i; |
---|
158 | len -= i; |
---|
159 | } |
---|
160 | break; |
---|
161 | |
---|
162 | case RPC_PROGVERSMISMATCH: |
---|
163 | i = snprintf(str, len, "; low version = %u, high version = %u", |
---|
164 | e.re_vers.low, e.re_vers.high); |
---|
165 | if (i > 0) { |
---|
166 | str += i; |
---|
167 | len -= i; |
---|
168 | } |
---|
169 | break; |
---|
170 | |
---|
171 | default: /* unknown */ |
---|
172 | i = snprintf(str, len, "; s1 = %u, s2 = %u", |
---|
173 | e.re_lb.s1, e.re_lb.s2); |
---|
174 | if (i > 0) { |
---|
175 | str += i; |
---|
176 | len -= i; |
---|
177 | } |
---|
178 | break; |
---|
179 | } |
---|
180 | strstart[CLNT_PERROR_BUFLEN-1] = '\0'; |
---|
181 | return(strstart) ; |
---|
182 | } |
---|
183 | |
---|
184 | void |
---|
185 | clnt_perror(rpch, s) |
---|
186 | CLIENT *rpch; |
---|
187 | const char *s; |
---|
188 | { |
---|
189 | |
---|
190 | assert(rpch != NULL); |
---|
191 | assert(s != NULL); |
---|
192 | |
---|
193 | (void) fprintf(stderr, "%s\n", clnt_sperror(rpch,s)); |
---|
194 | } |
---|
195 | |
---|
196 | static const char *const rpc_errlist[] = { |
---|
197 | "RPC: Success", /* 0 - RPC_SUCCESS */ |
---|
198 | "RPC: Can't encode arguments", /* 1 - RPC_CANTENCODEARGS */ |
---|
199 | "RPC: Can't decode result", /* 2 - RPC_CANTDECODERES */ |
---|
200 | "RPC: Unable to send", /* 3 - RPC_CANTSEND */ |
---|
201 | "RPC: Unable to receive", /* 4 - RPC_CANTRECV */ |
---|
202 | "RPC: Timed out", /* 5 - RPC_TIMEDOUT */ |
---|
203 | "RPC: Incompatible versions of RPC", /* 6 - RPC_VERSMISMATCH */ |
---|
204 | "RPC: Authentication error", /* 7 - RPC_AUTHERROR */ |
---|
205 | "RPC: Program unavailable", /* 8 - RPC_PROGUNAVAIL */ |
---|
206 | "RPC: Program/version mismatch", /* 9 - RPC_PROGVERSMISMATCH */ |
---|
207 | "RPC: Procedure unavailable", /* 10 - RPC_PROCUNAVAIL */ |
---|
208 | "RPC: Server can't decode arguments", /* 11 - RPC_CANTDECODEARGS */ |
---|
209 | "RPC: Remote system error", /* 12 - RPC_SYSTEMERROR */ |
---|
210 | "RPC: Unknown host", /* 13 - RPC_UNKNOWNHOST */ |
---|
211 | "RPC: Port mapper failure", /* 14 - RPC_PMAPFAILURE */ |
---|
212 | "RPC: Program not registered", /* 15 - RPC_PROGNOTREGISTERED */ |
---|
213 | "RPC: Failed (unspecified error)", /* 16 - RPC_FAILED */ |
---|
214 | "RPC: Unknown protocol" /* 17 - RPC_UNKNOWNPROTO */ |
---|
215 | }; |
---|
216 | |
---|
217 | |
---|
218 | /* |
---|
219 | * This interface for use by clntrpc |
---|
220 | */ |
---|
221 | char * |
---|
222 | clnt_sperrno(stat) |
---|
223 | enum clnt_stat stat; |
---|
224 | { |
---|
225 | unsigned int errnum = stat; |
---|
226 | |
---|
227 | if (errnum < (sizeof(rpc_errlist)/sizeof(rpc_errlist[0]))) |
---|
228 | /* LINTED interface problem */ |
---|
229 | return (char *)rpc_errlist[errnum]; |
---|
230 | |
---|
231 | return ("RPC: (unknown error code)"); |
---|
232 | } |
---|
233 | |
---|
234 | void |
---|
235 | clnt_perrno(num) |
---|
236 | enum clnt_stat num; |
---|
237 | { |
---|
238 | (void) fprintf(stderr, "%s\n", clnt_sperrno(num)); |
---|
239 | } |
---|
240 | |
---|
241 | |
---|
242 | char * |
---|
243 | clnt_spcreateerror(s) |
---|
244 | const char *s; |
---|
245 | { |
---|
246 | char *str; |
---|
247 | size_t len, i; |
---|
248 | |
---|
249 | assert(s != NULL); |
---|
250 | |
---|
251 | str = _buf(); /* side effect: sets CLNT_PERROR_BUFLEN */ |
---|
252 | if (str == 0) |
---|
253 | return(0); |
---|
254 | len = CLNT_PERROR_BUFLEN; |
---|
255 | i = snprintf(str, len, "%s: ", s); |
---|
256 | if (i > 0) |
---|
257 | len -= i; |
---|
258 | (void)strncat(str, clnt_sperrno(rpc_createerr.cf_stat), len - 1); |
---|
259 | switch (rpc_createerr.cf_stat) { |
---|
260 | case RPC_PMAPFAILURE: |
---|
261 | (void) strncat(str, " - ", len - 1); |
---|
262 | (void) strncat(str, |
---|
263 | clnt_sperrno(rpc_createerr.cf_error.re_status), len - 4); |
---|
264 | break; |
---|
265 | |
---|
266 | case RPC_SYSTEMERROR: |
---|
267 | (void)strncat(str, " - ", len - 1); |
---|
268 | (void)strncat(str, strerror(rpc_createerr.cf_error.re_errno), |
---|
269 | len - 4); |
---|
270 | break; |
---|
271 | |
---|
272 | case RPC_CANTSEND: |
---|
273 | case RPC_CANTDECODERES: |
---|
274 | case RPC_CANTENCODEARGS: |
---|
275 | case RPC_SUCCESS: |
---|
276 | case RPC_UNKNOWNPROTO: |
---|
277 | case RPC_PROGNOTREGISTERED: |
---|
278 | case RPC_FAILED: |
---|
279 | case RPC_UNKNOWNHOST: |
---|
280 | case RPC_CANTDECODEARGS: |
---|
281 | case RPC_PROCUNAVAIL: |
---|
282 | case RPC_PROGVERSMISMATCH: |
---|
283 | case RPC_PROGUNAVAIL: |
---|
284 | case RPC_AUTHERROR: |
---|
285 | case RPC_VERSMISMATCH: |
---|
286 | case RPC_TIMEDOUT: |
---|
287 | case RPC_CANTRECV: |
---|
288 | default: |
---|
289 | break; |
---|
290 | } |
---|
291 | str[CLNT_PERROR_BUFLEN-1] = '\0'; |
---|
292 | return (str); |
---|
293 | } |
---|
294 | |
---|
295 | void |
---|
296 | clnt_pcreateerror(s) |
---|
297 | const char *s; |
---|
298 | { |
---|
299 | |
---|
300 | assert(s != NULL); |
---|
301 | |
---|
302 | (void) fprintf(stderr, "%s\n", clnt_spcreateerror(s)); |
---|
303 | } |
---|
304 | |
---|
305 | static const char *const auth_errlist[] = { |
---|
306 | "Authentication OK", /* 0 - AUTH_OK */ |
---|
307 | "Invalid client credential", /* 1 - AUTH_BADCRED */ |
---|
308 | "Server rejected credential", /* 2 - AUTH_REJECTEDCRED */ |
---|
309 | "Invalid client verifier", /* 3 - AUTH_BADVERF */ |
---|
310 | "Server rejected verifier", /* 4 - AUTH_REJECTEDVERF */ |
---|
311 | "Client credential too weak", /* 5 - AUTH_TOOWEAK */ |
---|
312 | "Invalid server verifier", /* 6 - AUTH_INVALIDRESP */ |
---|
313 | "Failed (unspecified error)", /* 7 - AUTH_FAILED */ |
---|
314 | "Kerberos generic error", /* 8 - AUTH_KERB_GENERIC*/ |
---|
315 | "Kerberos credential expired", /* 9 - AUTH_TIMEEXPIRE */ |
---|
316 | "Bad kerberos ticket file", /* 10 - AUTH_TKT_FILE */ |
---|
317 | "Can't decode kerberos authenticator", /* 11 - AUTH_DECODE */ |
---|
318 | "Address wrong in kerberos ticket", /* 12 - AUTH_NET_ADDR */ |
---|
319 | "GSS-API crediential problem", /* 13 - RPCSEC_GSS_CREDPROBLEM */ |
---|
320 | "GSS-API context problem" /* 14 - RPCSEC_GSS_CTXPROBLEM */ |
---|
321 | }; |
---|
322 | |
---|
323 | static char * |
---|
324 | auth_errmsg(stat) |
---|
325 | enum auth_stat stat; |
---|
326 | { |
---|
327 | unsigned int errnum = stat; |
---|
328 | |
---|
329 | if (errnum < (sizeof(auth_errlist)/sizeof(auth_errlist[0]))) |
---|
330 | /* LINTED interface problem */ |
---|
331 | return (char *)auth_errlist[errnum]; |
---|
332 | |
---|
333 | return(NULL); |
---|
334 | } |
---|