Remade for development-2.1.90
[glibc/pb-stable.git] / sunrpc / clnt_perr.c
blob7896499f82c8ab4ee8d7c76f86d8e591e7a0f04b
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/types.h>
44 #include <rpc/auth.h>
45 #include <rpc/clnt.h>
47 #ifdef USE_IN_LIBIO
48 # include <libio/iolibio.h>
49 # define fputs(s, f) _IO_fputs (s, f)
50 #endif
52 static char *auth_errmsg (enum auth_stat stat) internal_function;
54 static char *buf;
56 static char *
57 _buf (void)
59 if (buf == NULL)
60 buf = (char *) malloc (256);
61 return buf;
65 * Print reply error info
67 char *
68 clnt_sperror (CLIENT * rpch, const char *msg)
70 char buf[1024];
71 struct rpc_err e;
72 char *err;
73 char *str = _buf ();
74 char *strstart = str;
75 int len;
77 if (str == NULL)
78 return NULL;
79 CLNT_GETERR (rpch, &e);
81 len = sprintf (str, "%s: ", msg);
82 str += len;
84 str = stpcpy (str, clnt_sperrno (e.re_status));
86 switch (e.re_status)
88 case RPC_SUCCESS:
89 case RPC_CANTENCODEARGS:
90 case RPC_CANTDECODERES:
91 case RPC_TIMEDOUT:
92 case RPC_PROGUNAVAIL:
93 case RPC_PROCUNAVAIL:
94 case RPC_CANTDECODEARGS:
95 case RPC_SYSTEMERROR:
96 case RPC_UNKNOWNHOST:
97 case RPC_UNKNOWNPROTO:
98 case RPC_PMAPFAILURE:
99 case RPC_PROGNOTREGISTERED:
100 case RPC_FAILED:
101 break;
103 case RPC_CANTSEND:
104 case RPC_CANTRECV:
105 len = sprintf (str, "; errno = %s", __strerror_r (e.re_errno,
106 buf, sizeof buf));
107 str += len;
108 break;
110 case RPC_VERSMISMATCH:
111 len= sprintf (str, _("; low version = %lu, high version = %lu"),
112 e.re_vers.low, e.re_vers.high);
113 str += len;
114 break;
116 case RPC_AUTHERROR:
117 err = auth_errmsg (e.re_why);
118 str = stpcpy (str, _ ("; why = "));
119 if (err != NULL)
121 str = stpcpy (str, err);
123 else
125 len = sprintf (str, _("(unknown authentication error - %d)"),
126 (int) e.re_why);
127 str += len;
129 break;
131 case RPC_PROGVERSMISMATCH:
132 len = sprintf (str, _("; low version = %lu, high version = %lu"),
133 e.re_vers.low, e.re_vers.high);
134 str += len;
135 break;
137 default: /* unknown */
138 len = sprintf (str, "; s1 = %lu, s2 = %lu", e.re_lb.s1, e.re_lb.s2);
139 str += len;
140 break;
142 *str = '\n';
143 *++str = '\0';
144 return (strstart);
147 void
148 clnt_perror (CLIENT * rpch, const char *msg)
150 (void) fputs (clnt_sperror (rpch, msg), stderr);
154 struct rpc_errtab
156 enum clnt_stat status;
157 unsigned int message_off;
160 static const char rpc_errstr[] =
162 #define RPC_SUCCESS_IDX 0
163 N_("RPC: Success")
164 "\0"
165 #define RPC_CANTENCODEARGS_IDX (RPC_SUCCESS_IDX + sizeof "RPC: Success")
166 N_("RPC: Can't encode arguments")
167 "\0"
168 #define RPC_CANTDECODERES_IDX (RPC_CANTENCODEARGS_IDX \
169 + sizeof "RPC: Can't encode arguments")
170 N_("RPC: Can't decode result")
171 "\0"
172 #define RPC_CANTSEND_IDX (RPC_CANTDECODERES_IDX \
173 + sizeof "RPC: Can't decode result")
174 N_("RPC: Unable to send")
175 "\0"
176 #define RPC_CANTRECV_IDX (RPC_CANTSEND_IDX \
177 + sizeof "RPC: Unable to send")
178 N_("RPC: Unable to receive")
179 "\0"
180 #define RPC_TIMEDOUT_IDX (RPC_CANTRECV_IDX \
181 + sizeof "RPC: Unable to receive")
182 N_("RPC: Timed out")
183 "\0"
184 #define RPC_VERSMISMATCH_IDX (RPC_TIMEDOUT_IDX \
185 + sizeof "RPC: Timed out")
186 N_("RPC: Incompatible versions of RPC")
187 "\0"
188 #define RPC_AUTHERROR_IDX (RPC_VERSMISMATCH_IDX \
189 + sizeof "RPC: Incompatible versions of RPC")
190 N_("RPC: Authentication error")
191 "\0"
192 #define RPC_PROGUNAVAIL_IDX (RPC_AUTHERROR_IDX \
193 + sizeof "RPC: Authentication error")
194 N_("RPC: Program unavailable")
195 "\0"
196 #define RPC_PROGVERSMISMATCH_IDX (RPC_PROGUNAVAIL_IDX \
197 + sizeof "RPC: Program unavailable")
198 N_("RPC: Program/version mismatch")
199 "\0"
200 #define RPC_PROCUNAVAIL_IDX (RPC_PROGVERSMISMATCH_IDX \
201 + sizeof "RPC: Program/version mismatch")
202 N_("RPC: Procedure unavailable")
203 "\0"
204 #define RPC_CANTDECODEARGS_IDX (RPC_PROCUNAVAIL_IDX \
205 + sizeof "RPC: Procedure unavailable")
206 N_("RPC: Server can't decode arguments")
207 "\0"
208 #define RPC_SYSTEMERROR_IDX (RPC_CANTDECODEARGS_IDX \
209 + sizeof "RPC: Server can't decode arguments")
210 N_("RPC: Remote system error")
211 "\0"
212 #define RPC_UNKNOWNHOST_IDX (RPC_SYSTEMERROR_IDX \
213 + sizeof "RPC: Remote system error")
214 N_("RPC: Unknown host")
215 "\0"
216 #define RPC_UNKNOWNPROTO_IDX (RPC_UNKNOWNHOST_IDX \
217 + sizeof "RPC: Unknown host")
218 N_("RPC: Unknown protocol")
219 "\0"
220 #define RPC_PMAPFAILURE_IDX (RPC_UNKNOWNPROTO_IDX \
221 + sizeof "RPC: Unknown protocol")
222 N_("RPC: Port mapper failure")
223 "\0"
224 #define RPC_PROGNOTREGISTERED_IDX (RPC_PMAPFAILURE_IDX \
225 + sizeof "RPC: Port mapper failure")
226 N_("RPC: Program not registered")
227 "\0"
228 #define RPC_FAILED_IDX (RPC_PROGNOTREGISTERED_IDX \
229 + sizeof "RPC: Program not registered")
230 N_("RPC: Failed (unspecified error)")
233 static const struct rpc_errtab rpc_errlist[] =
235 { RPC_SUCCESS, RPC_SUCCESS_IDX },
236 { RPC_CANTENCODEARGS, RPC_CANTENCODEARGS_IDX },
237 { RPC_CANTDECODERES, RPC_CANTDECODERES_IDX },
238 { RPC_CANTSEND, RPC_CANTSEND_IDX },
239 { RPC_CANTRECV, RPC_CANTRECV_IDX },
240 { RPC_TIMEDOUT, RPC_TIMEDOUT_IDX },
241 { RPC_VERSMISMATCH, RPC_VERSMISMATCH_IDX },
242 { RPC_AUTHERROR, RPC_AUTHERROR_IDX },
243 { RPC_PROGUNAVAIL, RPC_PROGUNAVAIL_IDX },
244 { RPC_PROGVERSMISMATCH, RPC_PROGVERSMISMATCH },
245 { RPC_PROCUNAVAIL, RPC_PROCUNAVAIL_IDX },
246 { RPC_CANTDECODEARGS, RPC_CANTDECODEARGS_IDX },
247 { RPC_SYSTEMERROR, RPC_SYSTEMERROR_IDX },
248 { RPC_UNKNOWNHOST, RPC_UNKNOWNHOST_IDX },
249 { RPC_UNKNOWNPROTO, RPC_UNKNOWNPROTO_IDX },
250 { RPC_PMAPFAILURE, RPC_PMAPFAILURE_IDX },
251 { RPC_PROGNOTREGISTERED, RPC_PROGNOTREGISTERED_IDX },
252 { RPC_FAILED, RPC_FAILED_IDX }
257 * This interface for use by clntrpc
259 char *
260 clnt_sperrno (enum clnt_stat stat)
262 size_t i;
264 for (i = 0; i < sizeof (rpc_errlist) / sizeof (struct rpc_errtab); i++)
266 if (rpc_errlist[i].status == stat)
268 return _(rpc_errstr + rpc_errlist[i].message_off);
271 return _("RPC: (unknown error code)");
274 void
275 clnt_perrno (enum clnt_stat num)
277 (void) fputs (clnt_sperrno (num), stderr);
281 char *
282 clnt_spcreateerror (const char *msg)
284 char buf[1024];
285 char *str = _buf ();
286 char *cp;
287 int len;
289 if (str == NULL)
290 return NULL;
291 len = sprintf (str, "%s: ", msg);
292 cp = str + len;
293 cp = stpcpy (cp, clnt_sperrno (rpc_createerr.cf_stat));
294 switch (rpc_createerr.cf_stat)
296 case RPC_PMAPFAILURE:
297 cp = stpcpy (stpcpy (cp, " - "),
298 clnt_sperrno (rpc_createerr.cf_error.re_status));
299 break;
301 case RPC_SYSTEMERROR:
302 cp = stpcpy (stpcpy (cp, " - "),
303 __strerror_r (rpc_createerr.cf_error.re_errno,
304 buf, sizeof buf));
305 break;
306 default:
307 break;
309 *cp = '\n';
310 *++cp = '\0';
311 return str;
314 void
315 clnt_pcreateerror (const char *msg)
317 (void) fputs (clnt_spcreateerror (msg), stderr);
320 struct auth_errtab
322 enum auth_stat status;
323 unsigned int message_off;
326 static const char auth_errstr[] =
328 #define AUTH_OK_IDX 0
329 N_("Authentication OK")
330 "\0"
331 #define AUTH_BADCRED_IDX (AUTH_OK_IDX + sizeof "Authentication OK")
332 N_("Invalid client credential")
333 "\0"
334 #define AUTH_REJECTEDCRED_IDX (AUTH_BADCRED_IDX \
335 + sizeof "Invalid client credential")
336 N_("Server rejected credential")
337 "\0"
338 #define AUTH_BADVERF_IDX (AUTH_REJECTEDCRED_IDX \
339 + sizeof "Server rejected credential")
340 N_("Invalid client verifier")
341 "\0"
342 #define AUTH_REJECTEDVERF_IDX (AUTH_BADVERF_IDX \
343 + sizeof "Invalid client verifier")
344 N_("Server rejected verifier")
345 "\0"
346 #define AUTH_TOOWEAK_IDX (AUTH_REJECTEDVERF_IDX \
347 + sizeof "Server rejected verifier")
348 N_("Client credential too weak")
349 "\0"
350 #define AUTH_INVALIDRESP_IDX (AUTH_TOOWEAK_IDX \
351 + sizeof "Client credential too weak")
352 N_("Invalid server verifier")
353 "\0"
354 #define AUTH_FAILED_IDX (AUTH_INVALIDRESP_IDX \
355 + sizeof "Invalid server verifier")
356 N_("Failed (unspecified error)")
359 static const struct auth_errtab auth_errlist[] =
361 { AUTH_OK, AUTH_OK_IDX },
362 { AUTH_BADCRED, AUTH_BADCRED_IDX },
363 { AUTH_REJECTEDCRED, AUTH_REJECTEDCRED_IDX },
364 { AUTH_BADVERF, AUTH_BADVERF_IDX },
365 { AUTH_REJECTEDVERF, AUTH_REJECTEDVERF_IDX },
366 { AUTH_TOOWEAK, AUTH_TOOWEAK_IDX },
367 { AUTH_INVALIDRESP, AUTH_INVALIDRESP_IDX },
368 { AUTH_FAILED, AUTH_FAILED_IDX }
371 static char *
372 internal_function
373 auth_errmsg (enum auth_stat stat)
375 size_t i;
377 for (i = 0; i < sizeof (auth_errlist) / sizeof (struct auth_errtab); i++)
379 if (auth_errlist[i].status == stat)
381 return _(auth_errstr + auth_errlist[i].message_off);
384 return NULL;