]>
Commit | Line | Data |
---|---|---|
28f540f4 RM |
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. | |
cbd3dceb | 9 | * |
28f540f4 RM |
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. | |
cbd3dceb | 13 | * |
28f540f4 RM |
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. | |
cbd3dceb | 17 | * |
28f540f4 RM |
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. | |
cbd3dceb | 21 | * |
28f540f4 RM |
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. | |
cbd3dceb | 25 | * |
28f540f4 RM |
26 | * Sun Microsystems, Inc. |
27 | * 2550 Garcia Avenue | |
28 | * Mountain View, California 94043 | |
29 | */ | |
30 | #if !defined(lint) && defined(SCCSIDS) | |
31 | static char sccsid[] = "@(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro"; | |
32 | #endif | |
33 | ||
34 | /* | |
35 | * clnt_perror.c | |
36 | * | |
37 | * Copyright (C) 1984, Sun Microsystems, Inc. | |
38 | * | |
39 | */ | |
40 | #include <stdio.h> | |
e7fd8a39 | 41 | #include <string.h> |
28f540f4 RM |
42 | #include <rpc/types.h> |
43 | #include <rpc/auth.h> | |
44 | #include <rpc/clnt.h> | |
45 | ||
e7fd8a39 | 46 | static char *auth_errmsg (enum auth_stat stat); |
28f540f4 RM |
47 | |
48 | static char *buf; | |
49 | ||
50 | static char * | |
e7fd8a39 | 51 | _buf (void) |
28f540f4 | 52 | { |
e7fd8a39 UD |
53 | if (buf == NULL) |
54 | buf = (char *) malloc (256); | |
55 | return buf; | |
28f540f4 RM |
56 | } |
57 | ||
58 | /* | |
59 | * Print reply error info | |
60 | */ | |
61 | char * | |
e7fd8a39 | 62 | clnt_sperror (CLIENT * rpch, const char *msg) |
28f540f4 | 63 | { |
e7fd8a39 UD |
64 | char buf[1024]; |
65 | struct rpc_err e; | |
66 | char *err; | |
67 | char *str = _buf (); | |
68 | char *strstart = str; | |
69 | int len; | |
70 | ||
71 | if (str == NULL) | |
72 | return NULL; | |
73 | CLNT_GETERR (rpch, &e); | |
74 | ||
75 | len = sprintf (str, "%s: ", msg); | |
76 | str += len; | |
77 | ||
78 | str = stpcpy (str, clnt_sperrno (e.re_status)); | |
79 | ||
80 | switch (e.re_status) | |
81 | { | |
82 | case RPC_SUCCESS: | |
83 | case RPC_CANTENCODEARGS: | |
84 | case RPC_CANTDECODERES: | |
85 | case RPC_TIMEDOUT: | |
86 | case RPC_PROGUNAVAIL: | |
87 | case RPC_PROCUNAVAIL: | |
88 | case RPC_CANTDECODEARGS: | |
89 | case RPC_SYSTEMERROR: | |
90 | case RPC_UNKNOWNHOST: | |
91 | case RPC_UNKNOWNPROTO: | |
92 | case RPC_PMAPFAILURE: | |
93 | case RPC_PROGNOTREGISTERED: | |
94 | case RPC_FAILED: | |
95 | break; | |
96 | ||
97 | case RPC_CANTSEND: | |
98 | case RPC_CANTRECV: | |
99 | len = sprintf (str, "; errno = %s", strerror_r (e.re_errno, | |
100 | buf, sizeof buf)); | |
101 | str += len; | |
102 | break; | |
103 | ||
104 | case RPC_VERSMISMATCH: | |
105 | len= sprintf (str, _("; low version = %lu, high version = %lu"), | |
106 | e.re_vers.low, e.re_vers.high); | |
107 | str += len; | |
108 | break; | |
109 | ||
110 | case RPC_AUTHERROR: | |
111 | err = auth_errmsg (e.re_why); | |
112 | str = stpcpy (str, _ ("; why = ")); | |
113 | if (err != NULL) | |
114 | { | |
115 | str = stpcpy (str, err); | |
116 | } | |
117 | else | |
118 | { | |
119 | len = sprintf (str, _("(unknown authentication error - %d)"), | |
120 | (int) e.re_why); | |
121 | str += len; | |
28f540f4 | 122 | } |
e7fd8a39 UD |
123 | break; |
124 | ||
125 | case RPC_PROGVERSMISMATCH: | |
126 | len = sprintf (str, _("; low version = %lu, high version = %lu"), | |
127 | e.re_vers.low, e.re_vers.high); | |
128 | str += len; | |
129 | break; | |
130 | ||
131 | default: /* unknown */ | |
132 | len = sprintf (str, "; s1 = %lu, s2 = %lu", e.re_lb.s1, e.re_lb.s2); | |
133 | str += len; | |
134 | break; | |
135 | } | |
136 | *str = '\n'; | |
137 | return (strstart); | |
28f540f4 RM |
138 | } |
139 | ||
140 | void | |
e7fd8a39 | 141 | clnt_perror (CLIENT * rpch, const char *msg) |
28f540f4 | 142 | { |
e7fd8a39 | 143 | (void) fputs (clnt_sperror (rpch, msg), stderr); |
28f540f4 RM |
144 | } |
145 | ||
146 | ||
e7fd8a39 UD |
147 | struct rpc_errtab |
148 | { | |
149 | enum clnt_stat status; | |
150 | const char *message; | |
28f540f4 RM |
151 | }; |
152 | ||
e7fd8a39 UD |
153 | static const struct rpc_errtab rpc_errlist[] = |
154 | { | |
155 | {RPC_SUCCESS, | |
156 | N_("RPC: Success")}, | |
157 | {RPC_CANTENCODEARGS, | |
158 | N_("RPC: Can't encode arguments")}, | |
159 | {RPC_CANTDECODERES, | |
160 | N_("RPC: Can't decode result")}, | |
161 | {RPC_CANTSEND, | |
162 | N_("RPC: Unable to send")}, | |
163 | {RPC_CANTRECV, | |
164 | N_("RPC: Unable to receive")}, | |
165 | {RPC_TIMEDOUT, | |
166 | N_("RPC: Timed out")}, | |
167 | {RPC_VERSMISMATCH, | |
168 | N_("RPC: Incompatible versions of RPC")}, | |
169 | {RPC_AUTHERROR, | |
170 | N_("RPC: Authentication error")}, | |
171 | {RPC_PROGUNAVAIL, | |
172 | N_("RPC: Program unavailable")}, | |
173 | {RPC_PROGVERSMISMATCH, | |
174 | N_("RPC: Program/version mismatch")}, | |
175 | {RPC_PROCUNAVAIL, | |
176 | N_("RPC: Procedure unavailable")}, | |
177 | {RPC_CANTDECODEARGS, | |
178 | N_("RPC: Server can't decode arguments")}, | |
179 | {RPC_SYSTEMERROR, | |
180 | N_("RPC: Remote system error")}, | |
181 | {RPC_UNKNOWNHOST, | |
182 | N_("RPC: Unknown host")}, | |
183 | {RPC_UNKNOWNPROTO, | |
184 | N_("RPC: Unknown protocol")}, | |
185 | {RPC_PMAPFAILURE, | |
186 | N_("RPC: Port mapper failure")}, | |
187 | {RPC_PROGNOTREGISTERED, | |
188 | N_("RPC: Program not registered")}, | |
189 | {RPC_FAILED, | |
190 | N_("RPC: Failed (unspecified error)")} | |
28f540f4 RM |
191 | }; |
192 | ||
193 | ||
194 | /* | |
195 | * This interface for use by clntrpc | |
196 | */ | |
197 | char * | |
e7fd8a39 | 198 | clnt_sperrno (enum clnt_stat stat) |
28f540f4 | 199 | { |
e7fd8a39 | 200 | int i; |
28f540f4 | 201 | |
e7fd8a39 UD |
202 | for (i = 0; i < sizeof (rpc_errlist) / sizeof (struct rpc_errtab); i++) |
203 | { | |
204 | if (rpc_errlist[i].status == stat) | |
205 | { | |
206 | return _(rpc_errlist[i].message); | |
28f540f4 | 207 | } |
e7fd8a39 UD |
208 | } |
209 | return _("RPC: (unknown error code)"); | |
28f540f4 RM |
210 | } |
211 | ||
212 | void | |
e7fd8a39 | 213 | clnt_perrno (enum clnt_stat num) |
28f540f4 | 214 | { |
e7fd8a39 | 215 | (void) fputs (clnt_sperrno (num), stderr); |
28f540f4 RM |
216 | } |
217 | ||
218 | ||
219 | char * | |
e7fd8a39 | 220 | clnt_spcreateerror (const char *msg) |
28f540f4 | 221 | { |
e7fd8a39 UD |
222 | char buf[1024]; |
223 | char *str = _buf (); | |
224 | char *cp; | |
225 | int len; | |
226 | ||
227 | if (str == NULL) | |
228 | return NULL; | |
229 | len = sprintf (str, "%s: ", msg); | |
230 | cp = str + len; | |
231 | cp = stpcpy (cp, clnt_sperrno (rpc_createerr.cf_stat)); | |
232 | switch (rpc_createerr.cf_stat) | |
233 | { | |
234 | case RPC_PMAPFAILURE: | |
235 | cp = stpcpy (cp, " - "); | |
236 | cp = stpcpy (cp, clnt_sperrno (rpc_createerr.cf_error.re_status)); | |
237 | break; | |
238 | ||
239 | case RPC_SYSTEMERROR: | |
240 | cp = stpcpy (str, " - "); | |
241 | if (rpc_createerr.cf_error.re_errno > 0 | |
242 | && rpc_createerr.cf_error.re_errno < sys_nerr) | |
243 | cp = stpcpy (str, strerror_r (rpc_createerr.cf_error.re_errno, | |
244 | buf, sizeof buf)); | |
245 | else | |
246 | { | |
247 | len = sprintf (cp, _("Error %d"), rpc_createerr.cf_error.re_errno); | |
248 | cp += len; | |
28f540f4 | 249 | } |
e7fd8a39 UD |
250 | break; |
251 | default: | |
252 | break; | |
253 | } | |
254 | *cp = '\n'; | |
255 | return str; | |
28f540f4 RM |
256 | } |
257 | ||
258 | void | |
e7fd8a39 | 259 | clnt_pcreateerror (const char *msg) |
28f540f4 | 260 | { |
e7fd8a39 | 261 | (void) fputs (clnt_spcreateerror (msg), stderr); |
28f540f4 RM |
262 | } |
263 | ||
e7fd8a39 UD |
264 | struct auth_errtab |
265 | { | |
266 | enum auth_stat status; | |
267 | const char *message; | |
28f540f4 RM |
268 | }; |
269 | ||
e7fd8a39 UD |
270 | static const struct auth_errtab auth_errlist[] = |
271 | { | |
272 | {AUTH_OK, | |
273 | N_("Authentication OK")}, | |
274 | {AUTH_BADCRED, | |
275 | N_("Invalid client credential")}, | |
276 | {AUTH_REJECTEDCRED, | |
277 | N_("Server rejected credential")}, | |
278 | {AUTH_BADVERF, | |
279 | N_("Invalid client verifier")}, | |
280 | {AUTH_REJECTEDVERF, | |
281 | N_("Server rejected verifier")}, | |
282 | {AUTH_TOOWEAK, | |
283 | N_("Client credential too weak")}, | |
284 | {AUTH_INVALIDRESP, | |
285 | N_("Invalid server verifier")}, | |
286 | {AUTH_FAILED, | |
287 | N_("Failed (unspecified error)")}, | |
28f540f4 RM |
288 | }; |
289 | ||
290 | static char * | |
e7fd8a39 | 291 | auth_errmsg (enum auth_stat stat) |
28f540f4 | 292 | { |
e7fd8a39 | 293 | size_t i; |
28f540f4 | 294 | |
e7fd8a39 UD |
295 | for (i = 0; i < sizeof (auth_errlist) / sizeof (struct auth_errtab); i++) |
296 | { | |
297 | if (auth_errlist[i].status == stat) | |
298 | { | |
299 | return _(auth_errlist[i].message); | |
28f540f4 | 300 | } |
e7fd8a39 UD |
301 | } |
302 | return NULL; | |
28f540f4 | 303 | } |