4 * Copyright (c) 2010, 2011, Oracle America, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
16 * * Neither the name of the "Oracle America, Inc." nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <libio/iolibio.h>
40 static char *auth_errmsg (enum auth_stat stat
) internal_function
;
42 #ifdef _RPC_THREAD_SAFE_
44 * Making buf a preprocessor macro requires renaming the local
45 * buf variable in a few functions. Overriding a global variable
46 * with a local variable of the same name is a bad idea, anyway.
48 #define buf RPC_THREAD_VARIABLE(clnt_perr_buf_s)
54 * Print reply error info
57 clnt_sperror (CLIENT
* rpch
, const char *msg
)
60 CLNT_GETERR (rpch
, &e
);
62 const char *errstr
= clnt_sperrno (e
.re_status
);
71 case RPC_CANTENCODEARGS
:
72 case RPC_CANTDECODERES
:
76 case RPC_CANTDECODEARGS
:
79 case RPC_UNKNOWNPROTO
:
81 case RPC_PROGNOTREGISTERED
:
83 res
= __asprintf (&str
, "%s: %s\n", msg
, errstr
);
88 res
= __asprintf (&str
, "%s: %s; errno = %s\n",
89 msg
, errstr
, __strerror_r (e
.re_errno
,
90 chrbuf
, sizeof chrbuf
));
93 case RPC_VERSMISMATCH
:
94 res
= __asprintf (&str
,
95 _("%s: %s; low version = %lu, high version = %lu"),
96 msg
, errstr
, e
.re_vers
.low
, e
.re_vers
.high
);
100 tmpstr
= auth_errmsg (e
.re_why
);
102 res
= __asprintf (&str
, _("%s: %s; why = %s\n"), msg
, errstr
, tmpstr
);
104 res
= __asprintf (&str
, _("\
105 %s: %s; why = (unknown authentication error - %d)\n"),
106 msg
, errstr
, (int) e
.re_why
);
109 case RPC_PROGVERSMISMATCH
:
110 res
= __asprintf (&str
,
111 _("%s: %s; low version = %lu, high version = %lu"),
112 msg
, errstr
, e
.re_vers
.low
, e
.re_vers
.high
);
115 default: /* unknown */
116 res
= __asprintf (&str
, "%s: %s; s1 = %lu, s2 = %lu",
117 msg
, errstr
, e
.re_lb
.s1
, e
.re_lb
.s2
);
130 libc_hidden_nolink (clnt_sperror
, GLIBC_2_0
)
133 clnt_perror (CLIENT
* rpch
, const char *msg
)
135 (void) __fxprintf (NULL
, "%s", clnt_sperror (rpch
, msg
));
137 #ifdef EXPORT_RPC_SYMBOLS
138 libc_hidden_def (clnt_perror
)
140 libc_hidden_nolink (clnt_perror
, GLIBC_2_0
)
146 enum clnt_stat status
;
147 unsigned int message_off
;
150 static const char rpc_errstr
[] =
152 #define RPC_SUCCESS_IDX 0
155 #define RPC_CANTENCODEARGS_IDX (RPC_SUCCESS_IDX + sizeof "RPC: Success")
156 N_("RPC: Can't encode arguments")
158 #define RPC_CANTDECODERES_IDX (RPC_CANTENCODEARGS_IDX \
159 + sizeof "RPC: Can't encode arguments")
160 N_("RPC: Can't decode result")
162 #define RPC_CANTSEND_IDX (RPC_CANTDECODERES_IDX \
163 + sizeof "RPC: Can't decode result")
164 N_("RPC: Unable to send")
166 #define RPC_CANTRECV_IDX (RPC_CANTSEND_IDX \
167 + sizeof "RPC: Unable to send")
168 N_("RPC: Unable to receive")
170 #define RPC_TIMEDOUT_IDX (RPC_CANTRECV_IDX \
171 + sizeof "RPC: Unable to receive")
174 #define RPC_VERSMISMATCH_IDX (RPC_TIMEDOUT_IDX \
175 + sizeof "RPC: Timed out")
176 N_("RPC: Incompatible versions of RPC")
178 #define RPC_AUTHERROR_IDX (RPC_VERSMISMATCH_IDX \
179 + sizeof "RPC: Incompatible versions of RPC")
180 N_("RPC: Authentication error")
182 #define RPC_PROGUNAVAIL_IDX (RPC_AUTHERROR_IDX \
183 + sizeof "RPC: Authentication error")
184 N_("RPC: Program unavailable")
186 #define RPC_PROGVERSMISMATCH_IDX (RPC_PROGUNAVAIL_IDX \
187 + sizeof "RPC: Program unavailable")
188 N_("RPC: Program/version mismatch")
190 #define RPC_PROCUNAVAIL_IDX (RPC_PROGVERSMISMATCH_IDX \
191 + sizeof "RPC: Program/version mismatch")
192 N_("RPC: Procedure unavailable")
194 #define RPC_CANTDECODEARGS_IDX (RPC_PROCUNAVAIL_IDX \
195 + sizeof "RPC: Procedure unavailable")
196 N_("RPC: Server can't decode arguments")
198 #define RPC_SYSTEMERROR_IDX (RPC_CANTDECODEARGS_IDX \
199 + sizeof "RPC: Server can't decode arguments")
200 N_("RPC: Remote system error")
202 #define RPC_UNKNOWNHOST_IDX (RPC_SYSTEMERROR_IDX \
203 + sizeof "RPC: Remote system error")
204 N_("RPC: Unknown host")
206 #define RPC_UNKNOWNPROTO_IDX (RPC_UNKNOWNHOST_IDX \
207 + sizeof "RPC: Unknown host")
208 N_("RPC: Unknown protocol")
210 #define RPC_PMAPFAILURE_IDX (RPC_UNKNOWNPROTO_IDX \
211 + sizeof "RPC: Unknown protocol")
212 N_("RPC: Port mapper failure")
214 #define RPC_PROGNOTREGISTERED_IDX (RPC_PMAPFAILURE_IDX \
215 + sizeof "RPC: Port mapper failure")
216 N_("RPC: Program not registered")
218 #define RPC_FAILED_IDX (RPC_PROGNOTREGISTERED_IDX \
219 + sizeof "RPC: Program not registered")
220 N_("RPC: Failed (unspecified error)")
223 static const struct rpc_errtab rpc_errlist
[] =
225 { RPC_SUCCESS
, RPC_SUCCESS_IDX
},
226 { RPC_CANTENCODEARGS
, RPC_CANTENCODEARGS_IDX
},
227 { RPC_CANTDECODERES
, RPC_CANTDECODERES_IDX
},
228 { RPC_CANTSEND
, RPC_CANTSEND_IDX
},
229 { RPC_CANTRECV
, RPC_CANTRECV_IDX
},
230 { RPC_TIMEDOUT
, RPC_TIMEDOUT_IDX
},
231 { RPC_VERSMISMATCH
, RPC_VERSMISMATCH_IDX
},
232 { RPC_AUTHERROR
, RPC_AUTHERROR_IDX
},
233 { RPC_PROGUNAVAIL
, RPC_PROGUNAVAIL_IDX
},
234 { RPC_PROGVERSMISMATCH
, RPC_PROGVERSMISMATCH_IDX
},
235 { RPC_PROCUNAVAIL
, RPC_PROCUNAVAIL_IDX
},
236 { RPC_CANTDECODEARGS
, RPC_CANTDECODEARGS_IDX
},
237 { RPC_SYSTEMERROR
, RPC_SYSTEMERROR_IDX
},
238 { RPC_UNKNOWNHOST
, RPC_UNKNOWNHOST_IDX
},
239 { RPC_UNKNOWNPROTO
, RPC_UNKNOWNPROTO_IDX
},
240 { RPC_PMAPFAILURE
, RPC_PMAPFAILURE_IDX
},
241 { RPC_PROGNOTREGISTERED
, RPC_PROGNOTREGISTERED_IDX
},
242 { RPC_FAILED
, RPC_FAILED_IDX
}
247 * This interface for use by clntrpc
250 clnt_sperrno (enum clnt_stat stat
)
254 for (i
= 0; i
< sizeof (rpc_errlist
) / sizeof (struct rpc_errtab
); i
++)
256 if (rpc_errlist
[i
].status
== stat
)
258 return _(rpc_errstr
+ rpc_errlist
[i
].message_off
);
261 return _("RPC: (unknown error code)");
263 libc_hidden_def (clnt_sperrno
)
266 clnt_perrno (enum clnt_stat num
)
268 (void) __fxprintf (NULL
, "%s", clnt_sperrno (num
));
270 #ifdef EXPORT_RPC_SYMBOLS
271 libc_hidden_def (clnt_perrno
)
273 libc_hidden_nolink (clnt_perrno
, GLIBC_2_0
)
277 clnt_spcreateerror (const char *msg
)
279 struct rpc_createerr
*ce
= &get_rpc_createerr ();
282 const char *connector
= "";
283 const char *errstr
= "";
286 case RPC_PMAPFAILURE
:
288 errstr
= clnt_sperrno (ce
->cf_error
.re_status
);
291 case RPC_SYSTEMERROR
:
293 errstr
= __strerror_r (ce
->cf_error
.re_errno
, chrbuf
, sizeof chrbuf
);
301 if (__asprintf (&str
, "%s: %s%s%s\n",
302 msg
, clnt_sperrno (ce
->cf_stat
), connector
, errstr
) < 0)
311 libc_hidden_nolink (clnt_spcreateerror
, GLIBC_2_0
)
314 clnt_pcreateerror (const char *msg
)
316 (void) __fxprintf (NULL
, "%s", clnt_spcreateerror (msg
));
318 #ifdef EXPORT_RPC_SYMBOLS
319 libc_hidden_def (clnt_pcreateerror
)
321 libc_hidden_nolink (clnt_pcreateerror
, GLIBC_2_0
)
326 enum auth_stat status
;
327 unsigned int message_off
;
330 static const char auth_errstr
[] =
332 #define AUTH_OK_IDX 0
333 N_("Authentication OK")
335 #define AUTH_BADCRED_IDX (AUTH_OK_IDX + sizeof "Authentication OK")
336 N_("Invalid client credential")
338 #define AUTH_REJECTEDCRED_IDX (AUTH_BADCRED_IDX \
339 + sizeof "Invalid client credential")
340 N_("Server rejected credential")
342 #define AUTH_BADVERF_IDX (AUTH_REJECTEDCRED_IDX \
343 + sizeof "Server rejected credential")
344 N_("Invalid client verifier")
346 #define AUTH_REJECTEDVERF_IDX (AUTH_BADVERF_IDX \
347 + sizeof "Invalid client verifier")
348 N_("Server rejected verifier")
350 #define AUTH_TOOWEAK_IDX (AUTH_REJECTEDVERF_IDX \
351 + sizeof "Server rejected verifier")
352 N_("Client credential too weak")
354 #define AUTH_INVALIDRESP_IDX (AUTH_TOOWEAK_IDX \
355 + sizeof "Client credential too weak")
356 N_("Invalid server verifier")
358 #define AUTH_FAILED_IDX (AUTH_INVALIDRESP_IDX \
359 + sizeof "Invalid server verifier")
360 N_("Failed (unspecified error)")
363 static const struct auth_errtab auth_errlist
[] =
365 { AUTH_OK
, AUTH_OK_IDX
},
366 { AUTH_BADCRED
, AUTH_BADCRED_IDX
},
367 { AUTH_REJECTEDCRED
, AUTH_REJECTEDCRED_IDX
},
368 { AUTH_BADVERF
, AUTH_BADVERF_IDX
},
369 { AUTH_REJECTEDVERF
, AUTH_REJECTEDVERF_IDX
},
370 { AUTH_TOOWEAK
, AUTH_TOOWEAK_IDX
},
371 { AUTH_INVALIDRESP
, AUTH_INVALIDRESP_IDX
},
372 { AUTH_FAILED
, AUTH_FAILED_IDX
}
377 auth_errmsg (enum auth_stat stat
)
381 for (i
= 0; i
< sizeof (auth_errlist
) / sizeof (struct auth_errtab
); i
++)
383 if (auth_errlist
[i
].status
== stat
)
385 return _(auth_errstr
+ auth_errlist
[i
].message_off
);
392 libc_freeres_fn (free_mem
)
394 /* Not libc_freeres_ptr, since buf is a macro. */