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
);
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)
51 * Print reply error info
54 clnt_sperror (CLIENT
* rpch
, const char *msg
)
57 CLNT_GETERR (rpch
, &e
);
59 const char *errstr
= clnt_sperrno (e
.re_status
);
68 case RPC_CANTENCODEARGS
:
69 case RPC_CANTDECODERES
:
73 case RPC_CANTDECODEARGS
:
76 case RPC_UNKNOWNPROTO
:
78 case RPC_PROGNOTREGISTERED
:
80 res
= __asprintf (&str
, "%s: %s\n", msg
, errstr
);
85 res
= __asprintf (&str
, "%s: %s; errno = %s\n",
86 msg
, errstr
, __strerror_r (e
.re_errno
,
87 chrbuf
, sizeof chrbuf
));
90 case RPC_VERSMISMATCH
:
91 res
= __asprintf (&str
,
92 _("%s: %s; low version = %lu, high version = %lu"),
93 msg
, errstr
, e
.re_vers
.low
, e
.re_vers
.high
);
97 tmpstr
= auth_errmsg (e
.re_why
);
99 res
= __asprintf (&str
, _("%s: %s; why = %s\n"), msg
, errstr
, tmpstr
);
101 res
= __asprintf (&str
, _("\
102 %s: %s; why = (unknown authentication error - %d)\n"),
103 msg
, errstr
, (int) e
.re_why
);
106 case RPC_PROGVERSMISMATCH
:
107 res
= __asprintf (&str
,
108 _("%s: %s; low version = %lu, high version = %lu"),
109 msg
, errstr
, e
.re_vers
.low
, e
.re_vers
.high
);
112 default: /* unknown */
113 res
= __asprintf (&str
, "%s: %s; s1 = %lu, s2 = %lu",
114 msg
, errstr
, e
.re_lb
.s1
, e
.re_lb
.s2
);
127 libc_hidden_nolink_sunrpc (clnt_sperror
, GLIBC_2_0
)
130 clnt_perror (CLIENT
* rpch
, const char *msg
)
132 (void) __fxprintf (NULL
, "%s", clnt_sperror (rpch
, msg
));
134 #ifdef EXPORT_RPC_SYMBOLS
135 libc_hidden_def (clnt_perror
)
137 libc_hidden_nolink_sunrpc (clnt_perror
, GLIBC_2_0
)
143 enum clnt_stat status
;
144 unsigned int message_off
;
147 static const char rpc_errstr
[] =
149 #define RPC_SUCCESS_IDX 0
152 #define RPC_CANTENCODEARGS_IDX (RPC_SUCCESS_IDX + sizeof "RPC: Success")
153 N_("RPC: Can't encode arguments")
155 #define RPC_CANTDECODERES_IDX (RPC_CANTENCODEARGS_IDX \
156 + sizeof "RPC: Can't encode arguments")
157 N_("RPC: Can't decode result")
159 #define RPC_CANTSEND_IDX (RPC_CANTDECODERES_IDX \
160 + sizeof "RPC: Can't decode result")
161 N_("RPC: Unable to send")
163 #define RPC_CANTRECV_IDX (RPC_CANTSEND_IDX \
164 + sizeof "RPC: Unable to send")
165 N_("RPC: Unable to receive")
167 #define RPC_TIMEDOUT_IDX (RPC_CANTRECV_IDX \
168 + sizeof "RPC: Unable to receive")
171 #define RPC_VERSMISMATCH_IDX (RPC_TIMEDOUT_IDX \
172 + sizeof "RPC: Timed out")
173 N_("RPC: Incompatible versions of RPC")
175 #define RPC_AUTHERROR_IDX (RPC_VERSMISMATCH_IDX \
176 + sizeof "RPC: Incompatible versions of RPC")
177 N_("RPC: Authentication error")
179 #define RPC_PROGUNAVAIL_IDX (RPC_AUTHERROR_IDX \
180 + sizeof "RPC: Authentication error")
181 N_("RPC: Program unavailable")
183 #define RPC_PROGVERSMISMATCH_IDX (RPC_PROGUNAVAIL_IDX \
184 + sizeof "RPC: Program unavailable")
185 N_("RPC: Program/version mismatch")
187 #define RPC_PROCUNAVAIL_IDX (RPC_PROGVERSMISMATCH_IDX \
188 + sizeof "RPC: Program/version mismatch")
189 N_("RPC: Procedure unavailable")
191 #define RPC_CANTDECODEARGS_IDX (RPC_PROCUNAVAIL_IDX \
192 + sizeof "RPC: Procedure unavailable")
193 N_("RPC: Server can't decode arguments")
195 #define RPC_SYSTEMERROR_IDX (RPC_CANTDECODEARGS_IDX \
196 + sizeof "RPC: Server can't decode arguments")
197 N_("RPC: Remote system error")
199 #define RPC_UNKNOWNHOST_IDX (RPC_SYSTEMERROR_IDX \
200 + sizeof "RPC: Remote system error")
201 N_("RPC: Unknown host")
203 #define RPC_UNKNOWNPROTO_IDX (RPC_UNKNOWNHOST_IDX \
204 + sizeof "RPC: Unknown host")
205 N_("RPC: Unknown protocol")
207 #define RPC_PMAPFAILURE_IDX (RPC_UNKNOWNPROTO_IDX \
208 + sizeof "RPC: Unknown protocol")
209 N_("RPC: Port mapper failure")
211 #define RPC_PROGNOTREGISTERED_IDX (RPC_PMAPFAILURE_IDX \
212 + sizeof "RPC: Port mapper failure")
213 N_("RPC: Program not registered")
215 #define RPC_FAILED_IDX (RPC_PROGNOTREGISTERED_IDX \
216 + sizeof "RPC: Program not registered")
217 N_("RPC: Failed (unspecified error)")
220 static const struct rpc_errtab rpc_errlist
[] =
222 { RPC_SUCCESS
, RPC_SUCCESS_IDX
},
223 { RPC_CANTENCODEARGS
, RPC_CANTENCODEARGS_IDX
},
224 { RPC_CANTDECODERES
, RPC_CANTDECODERES_IDX
},
225 { RPC_CANTSEND
, RPC_CANTSEND_IDX
},
226 { RPC_CANTRECV
, RPC_CANTRECV_IDX
},
227 { RPC_TIMEDOUT
, RPC_TIMEDOUT_IDX
},
228 { RPC_VERSMISMATCH
, RPC_VERSMISMATCH_IDX
},
229 { RPC_AUTHERROR
, RPC_AUTHERROR_IDX
},
230 { RPC_PROGUNAVAIL
, RPC_PROGUNAVAIL_IDX
},
231 { RPC_PROGVERSMISMATCH
, RPC_PROGVERSMISMATCH_IDX
},
232 { RPC_PROCUNAVAIL
, RPC_PROCUNAVAIL_IDX
},
233 { RPC_CANTDECODEARGS
, RPC_CANTDECODEARGS_IDX
},
234 { RPC_SYSTEMERROR
, RPC_SYSTEMERROR_IDX
},
235 { RPC_UNKNOWNHOST
, RPC_UNKNOWNHOST_IDX
},
236 { RPC_UNKNOWNPROTO
, RPC_UNKNOWNPROTO_IDX
},
237 { RPC_PMAPFAILURE
, RPC_PMAPFAILURE_IDX
},
238 { RPC_PROGNOTREGISTERED
, RPC_PROGNOTREGISTERED_IDX
},
239 { RPC_FAILED
, RPC_FAILED_IDX
}
244 * This interface for use by clntrpc
247 clnt_sperrno (enum clnt_stat stat
)
251 for (i
= 0; i
< sizeof (rpc_errlist
) / sizeof (struct rpc_errtab
); i
++)
253 if (rpc_errlist
[i
].status
== stat
)
255 return _(rpc_errstr
+ rpc_errlist
[i
].message_off
);
258 return _("RPC: (unknown error code)");
260 #ifdef EXPORT_RPC_SYMBOLS
261 libc_hidden_def (clnt_sperrno
)
263 libc_hidden_nolink_sunrpc (clnt_sperrno
, GLIBC_2_0
)
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. */