1 /* @(#)clnt_perror.c 2.1 88/07/29 4.0 RPCSRC */
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.
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";
37 * Copyright (C) 1984, Sun Microsystems, Inc.
46 # include <libio/iolibio.h>
47 # define fputs(s, f) _IO_fputs (s, f)
50 static char *auth_errmsg (enum auth_stat stat
) internal_function
;
52 #ifdef _RPC_THREAD_SAFE_
54 * Making buf a preprocessor macro requires renaming the local
55 * buf variable in a few functions. Overriding a global variable
56 * with a local variable of the same name is a bad idea, anyway.
58 #define buf ((char *)RPC_THREAD_VARIABLE(clnt_perr_buf_s))
67 buf
= (char *) malloc (256);
72 * Print reply error info
75 clnt_sperror (CLIENT
* rpch
, const char *msg
)
86 CLNT_GETERR (rpch
, &e
);
88 len
= sprintf (str
, "%s: ", msg
);
91 str
= stpcpy (str
, clnt_sperrno (e
.re_status
));
96 case RPC_CANTENCODEARGS
:
97 case RPC_CANTDECODERES
:
100 case RPC_PROCUNAVAIL
:
101 case RPC_CANTDECODEARGS
:
102 case RPC_SYSTEMERROR
:
103 case RPC_UNKNOWNHOST
:
104 case RPC_UNKNOWNPROTO
:
105 case RPC_PMAPFAILURE
:
106 case RPC_PROGNOTREGISTERED
:
112 len
= sprintf (str
, "; errno = %s", __strerror_r (e
.re_errno
,
113 chrbuf
, sizeof chrbuf
));
117 case RPC_VERSMISMATCH
:
118 len
= sprintf (str
, _("; low version = %lu, high version = %lu"),
119 e
.re_vers
.low
, e
.re_vers
.high
);
124 err
= auth_errmsg (e
.re_why
);
125 str
= stpcpy (str
, _ ("; why = "));
128 str
= stpcpy (str
, err
);
132 len
= sprintf (str
, _("(unknown authentication error - %d)"),
138 case RPC_PROGVERSMISMATCH
:
139 len
= sprintf (str
, _("; low version = %lu, high version = %lu"),
140 e
.re_vers
.low
, e
.re_vers
.high
);
144 default: /* unknown */
145 len
= sprintf (str
, "; s1 = %lu, s2 = %lu", e
.re_lb
.s1
, e
.re_lb
.s2
);
155 clnt_perror (CLIENT
* rpch
, const char *msg
)
157 (void) fputs (clnt_sperror (rpch
, msg
), stderr
);
163 enum clnt_stat status
;
164 unsigned int message_off
;
167 static const char rpc_errstr
[] =
169 #define RPC_SUCCESS_IDX 0
172 #define RPC_CANTENCODEARGS_IDX (RPC_SUCCESS_IDX + sizeof "RPC: Success")
173 N_("RPC: Can't encode arguments")
175 #define RPC_CANTDECODERES_IDX (RPC_CANTENCODEARGS_IDX \
176 + sizeof "RPC: Can't encode arguments")
177 N_("RPC: Can't decode result")
179 #define RPC_CANTSEND_IDX (RPC_CANTDECODERES_IDX \
180 + sizeof "RPC: Can't decode result")
181 N_("RPC: Unable to send")
183 #define RPC_CANTRECV_IDX (RPC_CANTSEND_IDX \
184 + sizeof "RPC: Unable to send")
185 N_("RPC: Unable to receive")
187 #define RPC_TIMEDOUT_IDX (RPC_CANTRECV_IDX \
188 + sizeof "RPC: Unable to receive")
191 #define RPC_VERSMISMATCH_IDX (RPC_TIMEDOUT_IDX \
192 + sizeof "RPC: Timed out")
193 N_("RPC: Incompatible versions of RPC")
195 #define RPC_AUTHERROR_IDX (RPC_VERSMISMATCH_IDX \
196 + sizeof "RPC: Incompatible versions of RPC")
197 N_("RPC: Authentication error")
199 #define RPC_PROGUNAVAIL_IDX (RPC_AUTHERROR_IDX \
200 + sizeof "RPC: Authentication error")
201 N_("RPC: Program unavailable")
203 #define RPC_PROGVERSMISMATCH_IDX (RPC_PROGUNAVAIL_IDX \
204 + sizeof "RPC: Program unavailable")
205 N_("RPC: Program/version mismatch")
207 #define RPC_PROCUNAVAIL_IDX (RPC_PROGVERSMISMATCH_IDX \
208 + sizeof "RPC: Program/version mismatch")
209 N_("RPC: Procedure unavailable")
211 #define RPC_CANTDECODEARGS_IDX (RPC_PROCUNAVAIL_IDX \
212 + sizeof "RPC: Procedure unavailable")
213 N_("RPC: Server can't decode arguments")
215 #define RPC_SYSTEMERROR_IDX (RPC_CANTDECODEARGS_IDX \
216 + sizeof "RPC: Server can't decode arguments")
217 N_("RPC: Remote system error")
219 #define RPC_UNKNOWNHOST_IDX (RPC_SYSTEMERROR_IDX \
220 + sizeof "RPC: Remote system error")
221 N_("RPC: Unknown host")
223 #define RPC_UNKNOWNPROTO_IDX (RPC_UNKNOWNHOST_IDX \
224 + sizeof "RPC: Unknown host")
225 N_("RPC: Unknown protocol")
227 #define RPC_PMAPFAILURE_IDX (RPC_UNKNOWNPROTO_IDX \
228 + sizeof "RPC: Unknown protocol")
229 N_("RPC: Port mapper failure")
231 #define RPC_PROGNOTREGISTERED_IDX (RPC_PMAPFAILURE_IDX \
232 + sizeof "RPC: Port mapper failure")
233 N_("RPC: Program not registered")
235 #define RPC_FAILED_IDX (RPC_PROGNOTREGISTERED_IDX \
236 + sizeof "RPC: Program not registered")
237 N_("RPC: Failed (unspecified error)")
240 static const struct rpc_errtab rpc_errlist
[] =
242 { RPC_SUCCESS
, RPC_SUCCESS_IDX
},
243 { RPC_CANTENCODEARGS
, RPC_CANTENCODEARGS_IDX
},
244 { RPC_CANTDECODERES
, RPC_CANTDECODERES_IDX
},
245 { RPC_CANTSEND
, RPC_CANTSEND_IDX
},
246 { RPC_CANTRECV
, RPC_CANTRECV_IDX
},
247 { RPC_TIMEDOUT
, RPC_TIMEDOUT_IDX
},
248 { RPC_VERSMISMATCH
, RPC_VERSMISMATCH_IDX
},
249 { RPC_AUTHERROR
, RPC_AUTHERROR_IDX
},
250 { RPC_PROGUNAVAIL
, RPC_PROGUNAVAIL_IDX
},
251 { RPC_PROGVERSMISMATCH
, RPC_PROGVERSMISMATCH_IDX
},
252 { RPC_PROCUNAVAIL
, RPC_PROCUNAVAIL_IDX
},
253 { RPC_CANTDECODEARGS
, RPC_CANTDECODEARGS_IDX
},
254 { RPC_SYSTEMERROR
, RPC_SYSTEMERROR_IDX
},
255 { RPC_UNKNOWNHOST
, RPC_UNKNOWNHOST_IDX
},
256 { RPC_UNKNOWNPROTO
, RPC_UNKNOWNPROTO_IDX
},
257 { RPC_PMAPFAILURE
, RPC_PMAPFAILURE_IDX
},
258 { RPC_PROGNOTREGISTERED
, RPC_PROGNOTREGISTERED_IDX
},
259 { RPC_FAILED
, RPC_FAILED_IDX
}
264 * This interface for use by clntrpc
267 clnt_sperrno (enum clnt_stat stat
)
271 for (i
= 0; i
< sizeof (rpc_errlist
) / sizeof (struct rpc_errtab
); i
++)
273 if (rpc_errlist
[i
].status
== stat
)
275 return _(rpc_errstr
+ rpc_errlist
[i
].message_off
);
278 return _("RPC: (unknown error code)");
282 clnt_perrno (enum clnt_stat num
)
284 (void) fputs (clnt_sperrno (num
), stderr
);
289 clnt_spcreateerror (const char *msg
)
295 struct rpc_createerr
*ce
;
299 ce
= &get_rpc_createerr ();
300 len
= sprintf (str
, "%s: ", msg
);
302 cp
= stpcpy (cp
, clnt_sperrno (ce
->cf_stat
));
305 case RPC_PMAPFAILURE
:
306 cp
= stpcpy (stpcpy (cp
, " - "),
307 clnt_sperrno (ce
->cf_error
.re_status
));
310 case RPC_SYSTEMERROR
:
311 cp
= stpcpy (stpcpy (cp
, " - "),
312 __strerror_r (ce
->cf_error
.re_errno
,
313 chrbuf
, sizeof chrbuf
));
324 clnt_pcreateerror (const char *msg
)
326 (void) fputs (clnt_spcreateerror (msg
), stderr
);
331 enum auth_stat status
;
332 unsigned int message_off
;
335 static const char auth_errstr
[] =
337 #define AUTH_OK_IDX 0
338 N_("Authentication OK")
340 #define AUTH_BADCRED_IDX (AUTH_OK_IDX + sizeof "Authentication OK")
341 N_("Invalid client credential")
343 #define AUTH_REJECTEDCRED_IDX (AUTH_BADCRED_IDX \
344 + sizeof "Invalid client credential")
345 N_("Server rejected credential")
347 #define AUTH_BADVERF_IDX (AUTH_REJECTEDCRED_IDX \
348 + sizeof "Server rejected credential")
349 N_("Invalid client verifier")
351 #define AUTH_REJECTEDVERF_IDX (AUTH_BADVERF_IDX \
352 + sizeof "Invalid client verifier")
353 N_("Server rejected verifier")
355 #define AUTH_TOOWEAK_IDX (AUTH_REJECTEDVERF_IDX \
356 + sizeof "Server rejected verifier")
357 N_("Client credential too weak")
359 #define AUTH_INVALIDRESP_IDX (AUTH_TOOWEAK_IDX \
360 + sizeof "Client credential too weak")
361 N_("Invalid server verifier")
363 #define AUTH_FAILED_IDX (AUTH_INVALIDRESP_IDX \
364 + sizeof "Invalid server verifier")
365 N_("Failed (unspecified error)")
368 static const struct auth_errtab auth_errlist
[] =
370 { AUTH_OK
, AUTH_OK_IDX
},
371 { AUTH_BADCRED
, AUTH_BADCRED_IDX
},
372 { AUTH_REJECTEDCRED
, AUTH_REJECTEDCRED_IDX
},
373 { AUTH_BADVERF
, AUTH_BADVERF_IDX
},
374 { AUTH_REJECTEDVERF
, AUTH_REJECTEDVERF_IDX
},
375 { AUTH_TOOWEAK
, AUTH_TOOWEAK_IDX
},
376 { AUTH_INVALIDRESP
, AUTH_INVALIDRESP_IDX
},
377 { AUTH_FAILED
, AUTH_FAILED_IDX
}
382 auth_errmsg (enum auth_stat stat
)
386 for (i
= 0; i
< sizeof (auth_errlist
) / sizeof (struct auth_errtab
); i
++)
388 if (auth_errlist
[i
].status
== stat
)
390 return _(auth_errstr
+ auth_errlist
[i
].message_off
);
397 static void __attribute__ ((unused
))
402 text_set_element (__libc_subfreeres
, free_mem
);