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>
39 #include <shlib-compat.h>
41 static char *auth_errmsg (enum auth_stat stat
);
43 #ifdef _RPC_THREAD_SAFE_
45 * Making buf a preprocessor macro requires renaming the local
46 * buf variable in a few functions. Overriding a global variable
47 * with a local variable of the same name is a bad idea, anyway.
49 #define buf RPC_THREAD_VARIABLE(clnt_perr_buf_s)
55 * Print reply error info
58 clnt_sperror (CLIENT
* rpch
, const char *msg
)
61 CLNT_GETERR (rpch
, &e
);
63 const char *errstr
= clnt_sperrno (e
.re_status
);
72 case RPC_CANTENCODEARGS
:
73 case RPC_CANTDECODERES
:
77 case RPC_CANTDECODEARGS
:
80 case RPC_UNKNOWNPROTO
:
82 case RPC_PROGNOTREGISTERED
:
84 res
= __asprintf (&str
, "%s: %s\n", msg
, errstr
);
89 res
= __asprintf (&str
, "%s: %s; errno = %s\n",
90 msg
, errstr
, __strerror_r (e
.re_errno
,
91 chrbuf
, sizeof chrbuf
));
94 case RPC_VERSMISMATCH
:
95 res
= __asprintf (&str
,
96 _("%s: %s; low version = %lu, high version = %lu"),
97 msg
, errstr
, e
.re_vers
.low
, e
.re_vers
.high
);
101 tmpstr
= auth_errmsg (e
.re_why
);
103 res
= __asprintf (&str
, _("%s: %s; why = %s\n"), msg
, errstr
, tmpstr
);
105 res
= __asprintf (&str
, _("\
106 %s: %s; why = (unknown authentication error - %d)\n"),
107 msg
, errstr
, (int) e
.re_why
);
110 case RPC_PROGVERSMISMATCH
:
111 res
= __asprintf (&str
,
112 _("%s: %s; low version = %lu, high version = %lu"),
113 msg
, errstr
, e
.re_vers
.low
, e
.re_vers
.high
);
116 default: /* unknown */
117 res
= __asprintf (&str
, "%s: %s; s1 = %lu, s2 = %lu",
118 msg
, errstr
, e
.re_lb
.s1
, e
.re_lb
.s2
);
131 libc_hidden_nolink_sunrpc (clnt_sperror
, GLIBC_2_0
)
134 clnt_perror (CLIENT
* rpch
, const char *msg
)
136 (void) __fxprintf (NULL
, "%s", clnt_sperror (rpch
, msg
));
138 #ifdef EXPORT_RPC_SYMBOLS
139 libc_hidden_def (clnt_perror
)
141 libc_hidden_nolink_sunrpc (clnt_perror
, GLIBC_2_0
)
147 enum clnt_stat status
;
148 unsigned int message_off
;
151 static const char rpc_errstr
[] =
153 #define RPC_SUCCESS_IDX 0
156 #define RPC_CANTENCODEARGS_IDX (RPC_SUCCESS_IDX + sizeof "RPC: Success")
157 N_("RPC: Can't encode arguments")
159 #define RPC_CANTDECODERES_IDX (RPC_CANTENCODEARGS_IDX \
160 + sizeof "RPC: Can't encode arguments")
161 N_("RPC: Can't decode result")
163 #define RPC_CANTSEND_IDX (RPC_CANTDECODERES_IDX \
164 + sizeof "RPC: Can't decode result")
165 N_("RPC: Unable to send")
167 #define RPC_CANTRECV_IDX (RPC_CANTSEND_IDX \
168 + sizeof "RPC: Unable to send")
169 N_("RPC: Unable to receive")
171 #define RPC_TIMEDOUT_IDX (RPC_CANTRECV_IDX \
172 + sizeof "RPC: Unable to receive")
175 #define RPC_VERSMISMATCH_IDX (RPC_TIMEDOUT_IDX \
176 + sizeof "RPC: Timed out")
177 N_("RPC: Incompatible versions of RPC")
179 #define RPC_AUTHERROR_IDX (RPC_VERSMISMATCH_IDX \
180 + sizeof "RPC: Incompatible versions of RPC")
181 N_("RPC: Authentication error")
183 #define RPC_PROGUNAVAIL_IDX (RPC_AUTHERROR_IDX \
184 + sizeof "RPC: Authentication error")
185 N_("RPC: Program unavailable")
187 #define RPC_PROGVERSMISMATCH_IDX (RPC_PROGUNAVAIL_IDX \
188 + sizeof "RPC: Program unavailable")
189 N_("RPC: Program/version mismatch")
191 #define RPC_PROCUNAVAIL_IDX (RPC_PROGVERSMISMATCH_IDX \
192 + sizeof "RPC: Program/version mismatch")
193 N_("RPC: Procedure unavailable")
195 #define RPC_CANTDECODEARGS_IDX (RPC_PROCUNAVAIL_IDX \
196 + sizeof "RPC: Procedure unavailable")
197 N_("RPC: Server can't decode arguments")
199 #define RPC_SYSTEMERROR_IDX (RPC_CANTDECODEARGS_IDX \
200 + sizeof "RPC: Server can't decode arguments")
201 N_("RPC: Remote system error")
203 #define RPC_UNKNOWNHOST_IDX (RPC_SYSTEMERROR_IDX \
204 + sizeof "RPC: Remote system error")
205 N_("RPC: Unknown host")
207 #define RPC_UNKNOWNPROTO_IDX (RPC_UNKNOWNHOST_IDX \
208 + sizeof "RPC: Unknown host")
209 N_("RPC: Unknown protocol")
211 #define RPC_PMAPFAILURE_IDX (RPC_UNKNOWNPROTO_IDX \
212 + sizeof "RPC: Unknown protocol")
213 N_("RPC: Port mapper failure")
215 #define RPC_PROGNOTREGISTERED_IDX (RPC_PMAPFAILURE_IDX \
216 + sizeof "RPC: Port mapper failure")
217 N_("RPC: Program not registered")
219 #define RPC_FAILED_IDX (RPC_PROGNOTREGISTERED_IDX \
220 + sizeof "RPC: Program not registered")
221 N_("RPC: Failed (unspecified error)")
224 static const struct rpc_errtab rpc_errlist
[] =
226 { RPC_SUCCESS
, RPC_SUCCESS_IDX
},
227 { RPC_CANTENCODEARGS
, RPC_CANTENCODEARGS_IDX
},
228 { RPC_CANTDECODERES
, RPC_CANTDECODERES_IDX
},
229 { RPC_CANTSEND
, RPC_CANTSEND_IDX
},
230 { RPC_CANTRECV
, RPC_CANTRECV_IDX
},
231 { RPC_TIMEDOUT
, RPC_TIMEDOUT_IDX
},
232 { RPC_VERSMISMATCH
, RPC_VERSMISMATCH_IDX
},
233 { RPC_AUTHERROR
, RPC_AUTHERROR_IDX
},
234 { RPC_PROGUNAVAIL
, RPC_PROGUNAVAIL_IDX
},
235 { RPC_PROGVERSMISMATCH
, RPC_PROGVERSMISMATCH_IDX
},
236 { RPC_PROCUNAVAIL
, RPC_PROCUNAVAIL_IDX
},
237 { RPC_CANTDECODEARGS
, RPC_CANTDECODEARGS_IDX
},
238 { RPC_SYSTEMERROR
, RPC_SYSTEMERROR_IDX
},
239 { RPC_UNKNOWNHOST
, RPC_UNKNOWNHOST_IDX
},
240 { RPC_UNKNOWNPROTO
, RPC_UNKNOWNPROTO_IDX
},
241 { RPC_PMAPFAILURE
, RPC_PMAPFAILURE_IDX
},
242 { RPC_PROGNOTREGISTERED
, RPC_PROGNOTREGISTERED_IDX
},
243 { RPC_FAILED
, RPC_FAILED_IDX
}
248 * This interface for use by clntrpc
251 clnt_sperrno (enum clnt_stat stat
)
255 for (i
= 0; i
< sizeof (rpc_errlist
) / sizeof (struct rpc_errtab
); i
++)
257 if (rpc_errlist
[i
].status
== stat
)
259 return _(rpc_errstr
+ rpc_errlist
[i
].message_off
);
262 return _("RPC: (unknown error code)");
264 libc_hidden_def (clnt_sperrno
)
267 clnt_perrno (enum clnt_stat num
)
269 (void) __fxprintf (NULL
, "%s", clnt_sperrno (num
));
271 #ifdef EXPORT_RPC_SYMBOLS
272 libc_hidden_def (clnt_perrno
)
274 libc_hidden_nolink_sunrpc (clnt_perrno
, GLIBC_2_0
)
278 clnt_spcreateerror (const char *msg
)
280 struct rpc_createerr
*ce
= &get_rpc_createerr ();
283 const char *connector
= "";
284 const char *errstr
= "";
287 case RPC_PMAPFAILURE
:
289 errstr
= clnt_sperrno (ce
->cf_error
.re_status
);
292 case RPC_SYSTEMERROR
:
294 errstr
= __strerror_r (ce
->cf_error
.re_errno
, chrbuf
, sizeof chrbuf
);
302 if (__asprintf (&str
, "%s: %s%s%s\n",
303 msg
, clnt_sperrno (ce
->cf_stat
), connector
, errstr
) < 0)
312 libc_hidden_nolink_sunrpc (clnt_spcreateerror
, GLIBC_2_0
)
315 clnt_pcreateerror (const char *msg
)
317 (void) __fxprintf (NULL
, "%s", clnt_spcreateerror (msg
));
319 #ifdef EXPORT_RPC_SYMBOLS
320 libc_hidden_def (clnt_pcreateerror
)
322 libc_hidden_nolink_sunrpc (clnt_pcreateerror
, GLIBC_2_0
)
327 enum auth_stat status
;
328 unsigned int message_off
;
331 static const char auth_errstr
[] =
333 #define AUTH_OK_IDX 0
334 N_("Authentication OK")
336 #define AUTH_BADCRED_IDX (AUTH_OK_IDX + sizeof "Authentication OK")
337 N_("Invalid client credential")
339 #define AUTH_REJECTEDCRED_IDX (AUTH_BADCRED_IDX \
340 + sizeof "Invalid client credential")
341 N_("Server rejected credential")
343 #define AUTH_BADVERF_IDX (AUTH_REJECTEDCRED_IDX \
344 + sizeof "Server rejected credential")
345 N_("Invalid client verifier")
347 #define AUTH_REJECTEDVERF_IDX (AUTH_BADVERF_IDX \
348 + sizeof "Invalid client verifier")
349 N_("Server rejected verifier")
351 #define AUTH_TOOWEAK_IDX (AUTH_REJECTEDVERF_IDX \
352 + sizeof "Server rejected verifier")
353 N_("Client credential too weak")
355 #define AUTH_INVALIDRESP_IDX (AUTH_TOOWEAK_IDX \
356 + sizeof "Client credential too weak")
357 N_("Invalid server verifier")
359 #define AUTH_FAILED_IDX (AUTH_INVALIDRESP_IDX \
360 + sizeof "Invalid server verifier")
361 N_("Failed (unspecified error)")
364 static const struct auth_errtab auth_errlist
[] =
366 { AUTH_OK
, AUTH_OK_IDX
},
367 { AUTH_BADCRED
, AUTH_BADCRED_IDX
},
368 { AUTH_REJECTEDCRED
, AUTH_REJECTEDCRED_IDX
},
369 { AUTH_BADVERF
, AUTH_BADVERF_IDX
},
370 { AUTH_REJECTEDVERF
, AUTH_REJECTEDVERF_IDX
},
371 { AUTH_TOOWEAK
, AUTH_TOOWEAK_IDX
},
372 { AUTH_INVALIDRESP
, AUTH_INVALIDRESP_IDX
},
373 { 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. */