* sysdeps/m68k/fpu/s_isinf.c (INTDEFX): Define to get correct
[glibc.git] / sunrpc / clnt_perr.c
blob4e2efafeaae04ab2de94dac9846634ebcf96ea14
1 /* @(#)clnt_perror.c 2.1 88/07/29 4.0 RPCSRC */
2 /*
3 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
4 * unrestricted use provided that this legend is included on all tape
5 * media and as a part of the software program in whole or part. Users
6 * may copy or modify Sun RPC without charge, but are not authorized
7 * to license or distribute it to anyone else except as part of a product or
8 * program developed by the user.
10 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 * Sun RPC is provided with no support and without any obligation on the
15 * part of Sun Microsystems, Inc. to assist in its use, correction,
16 * modification or enhancement.
18 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20 * OR ANY PART THEREOF.
22 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23 * or profits or other special, indirect and consequential damages, even if
24 * Sun has been advised of the possibility of such damages.
26 * Sun Microsystems, Inc.
27 * 2550 Garcia Avenue
28 * Mountain View, California 94043
30 #if !defined(lint) && defined(SCCSIDS)
31 static char sccsid[] = "@(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro";
32 #endif
35 * clnt_perror.c
37 * Copyright (C) 1984, Sun Microsystems, Inc.
40 #include <stdio.h>
41 #include <string.h>
42 #include <libintl.h>
43 #include <rpc/rpc.h>
45 #ifdef USE_IN_LIBIO
46 # include <wchar.h>
47 # include <libio/iolibio.h>
48 # define fputs(s, f) INTUSE(_IO_fputs) (s, f)
49 #endif
51 static char *auth_errmsg (enum auth_stat stat) internal_function;
53 #ifdef _RPC_THREAD_SAFE_
55 * Making buf a preprocessor macro requires renaming the local
56 * buf variable in a few functions. Overriding a global variable
57 * with a local variable of the same name is a bad idea, anyway.
59 #define buf ((char *)RPC_THREAD_VARIABLE(clnt_perr_buf_s))
60 #else
61 static char *buf;
62 #endif
64 static char *
65 _buf (void)
67 if (buf == NULL)
68 buf = (char *) malloc (256);
69 return buf;
73 * Print reply error info
75 char *
76 clnt_sperror (CLIENT * rpch, const char *msg)
78 char chrbuf[1024];
79 struct rpc_err e;
80 char *err;
81 char *str = _buf ();
82 char *strstart = str;
83 int len;
85 if (str == NULL)
86 return NULL;
87 CLNT_GETERR (rpch, &e);
89 len = sprintf (str, "%s: ", msg);
90 str += len;
92 str = stpcpy (str, clnt_sperrno (e.re_status));
94 switch (e.re_status)
96 case RPC_SUCCESS:
97 case RPC_CANTENCODEARGS:
98 case RPC_CANTDECODERES:
99 case RPC_TIMEDOUT:
100 case RPC_PROGUNAVAIL:
101 case RPC_PROCUNAVAIL:
102 case RPC_CANTDECODEARGS:
103 case RPC_SYSTEMERROR:
104 case RPC_UNKNOWNHOST:
105 case RPC_UNKNOWNPROTO:
106 case RPC_PMAPFAILURE:
107 case RPC_PROGNOTREGISTERED:
108 case RPC_FAILED:
109 break;
111 case RPC_CANTSEND:
112 case RPC_CANTRECV:
113 len = sprintf (str, "; errno = %s", __strerror_r (e.re_errno,
114 chrbuf, sizeof chrbuf));
115 str += len;
116 break;
118 case RPC_VERSMISMATCH:
119 len= sprintf (str, _("; low version = %lu, high version = %lu"),
120 e.re_vers.low, e.re_vers.high);
121 str += len;
122 break;
124 case RPC_AUTHERROR:
125 err = auth_errmsg (e.re_why);
126 str = stpcpy (str, _ ("; why = "));
127 if (err != NULL)
129 str = stpcpy (str, err);
131 else
133 len = sprintf (str, _("(unknown authentication error - %d)"),
134 (int) e.re_why);
135 str += len;
137 break;
139 case RPC_PROGVERSMISMATCH:
140 len = sprintf (str, _("; low version = %lu, high version = %lu"),
141 e.re_vers.low, e.re_vers.high);
142 str += len;
143 break;
145 default: /* unknown */
146 len = sprintf (str, "; s1 = %lu, s2 = %lu", e.re_lb.s1, e.re_lb.s2);
147 str += len;
148 break;
150 *str = '\n';
151 *++str = '\0';
152 return (strstart);
155 void
156 clnt_perror (CLIENT * rpch, const char *msg)
158 #ifdef USE_IN_LIBIO
159 if (_IO_fwide (stderr, 0) > 0)
160 (void) __fwprintf (stderr, L"%s", clnt_sperror (rpch, msg));
161 else
162 #endif
163 (void) fputs (clnt_sperror (rpch, msg), stderr);
167 struct rpc_errtab
169 enum clnt_stat status;
170 unsigned int message_off;
173 static const char rpc_errstr[] =
175 #define RPC_SUCCESS_IDX 0
176 N_("RPC: Success")
177 "\0"
178 #define RPC_CANTENCODEARGS_IDX (RPC_SUCCESS_IDX + sizeof "RPC: Success")
179 N_("RPC: Can't encode arguments")
180 "\0"
181 #define RPC_CANTDECODERES_IDX (RPC_CANTENCODEARGS_IDX \
182 + sizeof "RPC: Can't encode arguments")
183 N_("RPC: Can't decode result")
184 "\0"
185 #define RPC_CANTSEND_IDX (RPC_CANTDECODERES_IDX \
186 + sizeof "RPC: Can't decode result")
187 N_("RPC: Unable to send")
188 "\0"
189 #define RPC_CANTRECV_IDX (RPC_CANTSEND_IDX \
190 + sizeof "RPC: Unable to send")
191 N_("RPC: Unable to receive")
192 "\0"
193 #define RPC_TIMEDOUT_IDX (RPC_CANTRECV_IDX \
194 + sizeof "RPC: Unable to receive")
195 N_("RPC: Timed out")
196 "\0"
197 #define RPC_VERSMISMATCH_IDX (RPC_TIMEDOUT_IDX \
198 + sizeof "RPC: Timed out")
199 N_("RPC: Incompatible versions of RPC")
200 "\0"
201 #define RPC_AUTHERROR_IDX (RPC_VERSMISMATCH_IDX \
202 + sizeof "RPC: Incompatible versions of RPC")
203 N_("RPC: Authentication error")
204 "\0"
205 #define RPC_PROGUNAVAIL_IDX (RPC_AUTHERROR_IDX \
206 + sizeof "RPC: Authentication error")
207 N_("RPC: Program unavailable")
208 "\0"
209 #define RPC_PROGVERSMISMATCH_IDX (RPC_PROGUNAVAIL_IDX \
210 + sizeof "RPC: Program unavailable")
211 N_("RPC: Program/version mismatch")
212 "\0"
213 #define RPC_PROCUNAVAIL_IDX (RPC_PROGVERSMISMATCH_IDX \
214 + sizeof "RPC: Program/version mismatch")
215 N_("RPC: Procedure unavailable")
216 "\0"
217 #define RPC_CANTDECODEARGS_IDX (RPC_PROCUNAVAIL_IDX \
218 + sizeof "RPC: Procedure unavailable")
219 N_("RPC: Server can't decode arguments")
220 "\0"
221 #define RPC_SYSTEMERROR_IDX (RPC_CANTDECODEARGS_IDX \
222 + sizeof "RPC: Server can't decode arguments")
223 N_("RPC: Remote system error")
224 "\0"
225 #define RPC_UNKNOWNHOST_IDX (RPC_SYSTEMERROR_IDX \
226 + sizeof "RPC: Remote system error")
227 N_("RPC: Unknown host")
228 "\0"
229 #define RPC_UNKNOWNPROTO_IDX (RPC_UNKNOWNHOST_IDX \
230 + sizeof "RPC: Unknown host")
231 N_("RPC: Unknown protocol")
232 "\0"
233 #define RPC_PMAPFAILURE_IDX (RPC_UNKNOWNPROTO_IDX \
234 + sizeof "RPC: Unknown protocol")
235 N_("RPC: Port mapper failure")
236 "\0"
237 #define RPC_PROGNOTREGISTERED_IDX (RPC_PMAPFAILURE_IDX \
238 + sizeof "RPC: Port mapper failure")
239 N_("RPC: Program not registered")
240 "\0"
241 #define RPC_FAILED_IDX (RPC_PROGNOTREGISTERED_IDX \
242 + sizeof "RPC: Program not registered")
243 N_("RPC: Failed (unspecified error)")
246 static const struct rpc_errtab rpc_errlist[] =
248 { RPC_SUCCESS, RPC_SUCCESS_IDX },
249 { RPC_CANTENCODEARGS, RPC_CANTENCODEARGS_IDX },
250 { RPC_CANTDECODERES, RPC_CANTDECODERES_IDX },
251 { RPC_CANTSEND, RPC_CANTSEND_IDX },
252 { RPC_CANTRECV, RPC_CANTRECV_IDX },
253 { RPC_TIMEDOUT, RPC_TIMEDOUT_IDX },
254 { RPC_VERSMISMATCH, RPC_VERSMISMATCH_IDX },
255 { RPC_AUTHERROR, RPC_AUTHERROR_IDX },
256 { RPC_PROGUNAVAIL, RPC_PROGUNAVAIL_IDX },
257 { RPC_PROGVERSMISMATCH, RPC_PROGVERSMISMATCH_IDX },
258 { RPC_PROCUNAVAIL, RPC_PROCUNAVAIL_IDX },
259 { RPC_CANTDECODEARGS, RPC_CANTDECODEARGS_IDX },
260 { RPC_SYSTEMERROR, RPC_SYSTEMERROR_IDX },
261 { RPC_UNKNOWNHOST, RPC_UNKNOWNHOST_IDX },
262 { RPC_UNKNOWNPROTO, RPC_UNKNOWNPROTO_IDX },
263 { RPC_PMAPFAILURE, RPC_PMAPFAILURE_IDX },
264 { RPC_PROGNOTREGISTERED, RPC_PROGNOTREGISTERED_IDX },
265 { RPC_FAILED, RPC_FAILED_IDX }
270 * This interface for use by clntrpc
272 char *
273 clnt_sperrno (enum clnt_stat stat)
275 size_t i;
277 for (i = 0; i < sizeof (rpc_errlist) / sizeof (struct rpc_errtab); i++)
279 if (rpc_errlist[i].status == stat)
281 return _(rpc_errstr + rpc_errlist[i].message_off);
284 return _("RPC: (unknown error code)");
287 void
288 clnt_perrno (enum clnt_stat num)
290 #ifdef USE_IN_LIBIO
291 if (_IO_fwide (stderr, 0) > 0)
292 (void) __fwprintf (stderr, L"%s", clnt_sperrno (num));
293 else
294 #endif
295 (void) fputs (clnt_sperrno (num), stderr);
299 char *
300 clnt_spcreateerror (const char *msg)
302 char chrbuf[1024];
303 char *str = _buf ();
304 char *cp;
305 int len;
306 struct rpc_createerr *ce;
308 if (str == NULL)
309 return NULL;
310 ce = &get_rpc_createerr ();
311 len = sprintf (str, "%s: ", msg);
312 cp = str + len;
313 cp = stpcpy (cp, clnt_sperrno (ce->cf_stat));
314 switch (ce->cf_stat)
316 case RPC_PMAPFAILURE:
317 cp = stpcpy (stpcpy (cp, " - "),
318 clnt_sperrno (ce->cf_error.re_status));
319 break;
321 case RPC_SYSTEMERROR:
322 cp = stpcpy (stpcpy (cp, " - "),
323 __strerror_r (ce->cf_error.re_errno,
324 chrbuf, sizeof chrbuf));
325 break;
326 default:
327 break;
329 *cp = '\n';
330 *++cp = '\0';
331 return str;
334 void
335 clnt_pcreateerror (const char *msg)
337 #ifdef USE_IN_LIBIO
338 if (_IO_fwide (stderr, 0) > 0)
339 (void) __fwprintf (stderr, L"%s", clnt_spcreateerror (msg));
340 else
341 #endif
342 (void) fputs (clnt_spcreateerror (msg), stderr);
345 struct auth_errtab
347 enum auth_stat status;
348 unsigned int message_off;
351 static const char auth_errstr[] =
353 #define AUTH_OK_IDX 0
354 N_("Authentication OK")
355 "\0"
356 #define AUTH_BADCRED_IDX (AUTH_OK_IDX + sizeof "Authentication OK")
357 N_("Invalid client credential")
358 "\0"
359 #define AUTH_REJECTEDCRED_IDX (AUTH_BADCRED_IDX \
360 + sizeof "Invalid client credential")
361 N_("Server rejected credential")
362 "\0"
363 #define AUTH_BADVERF_IDX (AUTH_REJECTEDCRED_IDX \
364 + sizeof "Server rejected credential")
365 N_("Invalid client verifier")
366 "\0"
367 #define AUTH_REJECTEDVERF_IDX (AUTH_BADVERF_IDX \
368 + sizeof "Invalid client verifier")
369 N_("Server rejected verifier")
370 "\0"
371 #define AUTH_TOOWEAK_IDX (AUTH_REJECTEDVERF_IDX \
372 + sizeof "Server rejected verifier")
373 N_("Client credential too weak")
374 "\0"
375 #define AUTH_INVALIDRESP_IDX (AUTH_TOOWEAK_IDX \
376 + sizeof "Client credential too weak")
377 N_("Invalid server verifier")
378 "\0"
379 #define AUTH_FAILED_IDX (AUTH_INVALIDRESP_IDX \
380 + sizeof "Invalid server verifier")
381 N_("Failed (unspecified error)")
384 static const struct auth_errtab auth_errlist[] =
386 { AUTH_OK, AUTH_OK_IDX },
387 { AUTH_BADCRED, AUTH_BADCRED_IDX },
388 { AUTH_REJECTEDCRED, AUTH_REJECTEDCRED_IDX },
389 { AUTH_BADVERF, AUTH_BADVERF_IDX },
390 { AUTH_REJECTEDVERF, AUTH_REJECTEDVERF_IDX },
391 { AUTH_TOOWEAK, AUTH_TOOWEAK_IDX },
392 { AUTH_INVALIDRESP, AUTH_INVALIDRESP_IDX },
393 { AUTH_FAILED, AUTH_FAILED_IDX }
396 static char *
397 internal_function
398 auth_errmsg (enum auth_stat stat)
400 size_t i;
402 for (i = 0; i < sizeof (auth_errlist) / sizeof (struct auth_errtab); i++)
404 if (auth_errlist[i].status == stat)
406 return _(auth_errstr + auth_errlist[i].message_off);
409 return NULL;
413 static void __attribute__ ((unused))
414 free_mem (void)
416 free (buf);
418 text_set_element (__libc_subfreeres, free_mem);