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