]>
Commit | Line | Data |
---|---|---|
03fb6eb0 A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
ad21edcc A |
6 | * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights |
7 | * Reserved. This file contains Original Code and/or Modifications of | |
8 | * Original Code as defined in and that are subject to the Apple Public | |
9 | * Source License Version 1.1 (the "License"). You may not use this file | |
10 | * except in compliance with the License. Please obtain a copy of the | |
11 | * License at http://www.apple.com/publicsource and read it before using | |
12 | * this file. | |
03fb6eb0 A |
13 | * |
14 | * The Original Code and all software distributed under the License are | |
ad21edcc | 15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
03fb6eb0 A |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
ad21edcc A |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the |
19 | * License for the specific language governing rights and limitations | |
20 | * under the License. | |
03fb6eb0 A |
21 | * |
22 | * @APPLE_LICENSE_HEADER_END@ | |
23 | */ | |
24 | /* | |
25 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for | |
26 | * unrestricted use provided that this legend is included on all tape | |
27 | * media and as a part of the software program in whole or part. Users | |
28 | * may copy or modify Sun RPC without charge, but are not authorized | |
29 | * to license or distribute it to anyone else except as part of a product or | |
30 | * program developed by the user. | |
31 | * | |
32 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE | |
33 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR | |
34 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. | |
35 | * | |
36 | * Sun RPC is provided with no support and without any obligation on the | |
37 | * part of Sun Microsystems, Inc. to assist in its use, correction, | |
38 | * modification or enhancement. | |
39 | * | |
40 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE | |
41 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC | |
42 | * OR ANY PART THEREOF. | |
43 | * | |
44 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue | |
45 | * or profits or other special, indirect and consequential damages, even if | |
46 | * Sun has been advised of the possibility of such damages. | |
47 | * | |
48 | * Sun Microsystems, Inc. | |
49 | * 2550 Garcia Avenue | |
50 | * Mountain View, California 94043 | |
51 | */ | |
52 | ||
53 | #if defined(LIBC_SCCS) && !defined(lint) | |
54 | /*static char *sccsid = "from: @(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro";*/ | |
55 | /*static char *sccsid = "from: @(#)clnt_perror.c 2.1 88/07/29 4.0 RPCSRC";*/ | |
ccd4a120 | 56 | static char *rcsid = "$Id: clnt_perror.c,v 1.4 2003/06/23 17:24:59 majka Exp $"; |
03fb6eb0 A |
57 | #endif |
58 | ||
59 | /* | |
60 | * clnt_perror.c | |
61 | * | |
62 | * Copyright (C) 1984, Sun Microsystems, Inc. | |
63 | * | |
64 | */ | |
65 | #include <stdio.h> | |
3b7c7bd7 | 66 | #include <stdlib.h> |
03fb6eb0 A |
67 | #include <string.h> |
68 | #include <rpc/rpc.h> | |
69 | #include <rpc/types.h> | |
70 | #include <rpc/auth.h> | |
71 | #include <rpc/clnt.h> | |
72 | ||
73 | static char *auth_errmsg(); | |
74 | ||
75 | static char *buf; | |
76 | ||
77 | static char * | |
78 | _buf() | |
79 | { | |
80 | ||
81 | if (buf == 0) | |
82 | buf = (char *)malloc(256); | |
83 | return (buf); | |
84 | } | |
85 | ||
86 | /* | |
87 | * Print reply error info | |
88 | */ | |
89 | char * | |
90 | clnt_sperror(rpch, s) | |
91 | CLIENT *rpch; | |
92 | char *s; | |
93 | { | |
94 | struct rpc_err e; | |
95 | void clnt_perrno(); | |
96 | char *err; | |
97 | char *str = _buf(); | |
98 | char *strstart = str; | |
99 | ||
100 | if (str == 0) | |
101 | return (0); | |
102 | CLNT_GETERR(rpch, &e); | |
103 | ||
104 | (void) sprintf(str, "%s: ", s); | |
105 | str += strlen(str); | |
106 | ||
107 | (void) strcpy(str, clnt_sperrno(e.re_status)); | |
108 | str += strlen(str); | |
109 | ||
110 | switch (e.re_status) { | |
111 | case RPC_SUCCESS: | |
112 | case RPC_CANTENCODEARGS: | |
113 | case RPC_CANTDECODERES: | |
114 | case RPC_TIMEDOUT: | |
115 | case RPC_PROGUNAVAIL: | |
116 | case RPC_PROCUNAVAIL: | |
117 | case RPC_CANTDECODEARGS: | |
118 | case RPC_SYSTEMERROR: | |
119 | case RPC_UNKNOWNHOST: | |
120 | case RPC_UNKNOWNPROTO: | |
121 | case RPC_PMAPFAILURE: | |
122 | case RPC_PROGNOTREGISTERED: | |
123 | case RPC_FAILED: | |
124 | break; | |
125 | ||
126 | case RPC_CANTSEND: | |
127 | case RPC_CANTRECV: | |
128 | (void) sprintf(str, "; errno = %s", | |
129 | strerror(e.re_errno)); | |
130 | str += strlen(str); | |
131 | break; | |
132 | ||
133 | case RPC_VERSMISMATCH: | |
b3dd680f A |
134 | #ifdef __LP64__ |
135 | (void) sprintf(str, "; low version = %u, high version = %u", e.re_vers.low, e.re_vers.high); | |
136 | #else | |
137 | (void) sprintf(str, "; low version = %lu, high version = %lu", e.re_vers.low, e.re_vers.high); | |
138 | #endif | |
03fb6eb0 A |
139 | str += strlen(str); |
140 | break; | |
141 | ||
142 | case RPC_AUTHERROR: | |
143 | err = auth_errmsg(e.re_why); | |
144 | (void) sprintf(str,"; why = "); | |
145 | str += strlen(str); | |
146 | if (err != NULL) { | |
147 | (void) sprintf(str, "%s",err); | |
148 | } else { | |
149 | (void) sprintf(str, | |
150 | "(unknown authentication error - %d)", | |
151 | (int) e.re_why); | |
152 | } | |
153 | str += strlen(str); | |
154 | break; | |
155 | ||
156 | case RPC_PROGVERSMISMATCH: | |
b3dd680f A |
157 | #ifdef __LP64__ |
158 | (void) sprintf(str, "; low version = %u, high version = %u", e.re_vers.low, e.re_vers.high); | |
159 | #else | |
160 | (void) sprintf(str, "; low version = %lu, high version = %lu", e.re_vers.low, e.re_vers.high); | |
161 | #endif | |
03fb6eb0 A |
162 | str += strlen(str); |
163 | break; | |
164 | ||
165 | default: /* unknown */ | |
b3dd680f A |
166 | #ifdef __LP64__ |
167 | (void) sprintf(str, "; s1 = %u, s2 = %u", e.re_lb.s1, e.re_lb.s2); | |
168 | #else | |
169 | (void) sprintf(str, "; s1 = %lu, s2 = %lu", e.re_lb.s1, e.re_lb.s2); | |
170 | #endif | |
03fb6eb0 A |
171 | str += strlen(str); |
172 | break; | |
173 | } | |
174 | (void) sprintf(str, "\n"); | |
175 | return(strstart) ; | |
176 | } | |
177 | ||
178 | void | |
179 | clnt_perror(rpch, s) | |
180 | CLIENT *rpch; | |
181 | char *s; | |
182 | { | |
183 | (void) fprintf(stderr,"%s",clnt_sperror(rpch,s)); | |
184 | } | |
185 | ||
186 | ||
187 | struct rpc_errtab { | |
188 | enum clnt_stat status; | |
189 | char *message; | |
190 | }; | |
191 | ||
192 | static struct rpc_errtab rpc_errlist[] = { | |
193 | { RPC_SUCCESS, | |
194 | "RPC: Success" }, | |
195 | { RPC_CANTENCODEARGS, | |
196 | "RPC: Can't encode arguments" }, | |
197 | { RPC_CANTDECODERES, | |
198 | "RPC: Can't decode result" }, | |
199 | { RPC_CANTSEND, | |
200 | "RPC: Unable to send" }, | |
201 | { RPC_CANTRECV, | |
202 | "RPC: Unable to receive" }, | |
203 | { RPC_TIMEDOUT, | |
204 | "RPC: Timed out" }, | |
205 | { RPC_VERSMISMATCH, | |
206 | "RPC: Incompatible versions of RPC" }, | |
207 | { RPC_AUTHERROR, | |
208 | "RPC: Authentication error" }, | |
209 | { RPC_PROGUNAVAIL, | |
210 | "RPC: Program unavailable" }, | |
211 | { RPC_PROGVERSMISMATCH, | |
212 | "RPC: Program/version mismatch" }, | |
213 | { RPC_PROCUNAVAIL, | |
214 | "RPC: Procedure unavailable" }, | |
215 | { RPC_CANTDECODEARGS, | |
216 | "RPC: Server can't decode arguments" }, | |
217 | { RPC_SYSTEMERROR, | |
218 | "RPC: Remote system error" }, | |
219 | { RPC_UNKNOWNHOST, | |
220 | "RPC: Unknown host" }, | |
221 | { RPC_UNKNOWNPROTO, | |
222 | "RPC: Unknown protocol" }, | |
223 | { RPC_PMAPFAILURE, | |
224 | "RPC: Port mapper failure" }, | |
225 | { RPC_PROGNOTREGISTERED, | |
226 | "RPC: Program not registered"}, | |
227 | { RPC_FAILED, | |
228 | "RPC: Failed (unspecified error)"} | |
229 | }; | |
230 | ||
231 | ||
232 | /* | |
233 | * This interface for use by clntrpc | |
234 | */ | |
235 | char * | |
236 | clnt_sperrno(stat) | |
237 | enum clnt_stat stat; | |
238 | { | |
239 | int i; | |
240 | ||
241 | for (i = 0; i < sizeof(rpc_errlist)/sizeof(struct rpc_errtab); i++) { | |
242 | if (rpc_errlist[i].status == stat) { | |
243 | return (rpc_errlist[i].message); | |
244 | } | |
245 | } | |
246 | return ("RPC: (unknown error code)"); | |
247 | } | |
248 | ||
249 | void | |
250 | clnt_perrno(num) | |
251 | enum clnt_stat num; | |
252 | { | |
253 | (void) fprintf(stderr,"%s",clnt_sperrno(num)); | |
254 | } | |
255 | ||
256 | ||
257 | char * | |
258 | clnt_spcreateerror(s) | |
259 | char *s; | |
260 | { | |
03fb6eb0 A |
261 | char *str = _buf(); |
262 | ||
263 | if (str == 0) | |
264 | return(0); | |
265 | (void) sprintf(str, "%s: ", s); | |
266 | (void) strcat(str, clnt_sperrno(rpc_createerr.cf_stat)); | |
267 | switch (rpc_createerr.cf_stat) { | |
268 | case RPC_PMAPFAILURE: | |
269 | (void) strcat(str, " - "); | |
270 | (void) strcat(str, | |
271 | clnt_sperrno(rpc_createerr.cf_error.re_status)); | |
272 | break; | |
273 | ||
274 | case RPC_SYSTEMERROR: | |
275 | (void) strcat(str, " - "); | |
276 | if (rpc_createerr.cf_error.re_errno > 0 | |
277 | && rpc_createerr.cf_error.re_errno < sys_nerr) | |
278 | (void) strcat(str, | |
279 | strerror(rpc_createerr.cf_error.re_errno)); | |
280 | else | |
281 | (void) sprintf(&str[strlen(str)], "Error %d", | |
282 | rpc_createerr.cf_error.re_errno); | |
283 | break; | |
ccd4a120 | 284 | default: break; |
03fb6eb0 A |
285 | } |
286 | (void) strcat(str, "\n"); | |
287 | return (str); | |
288 | } | |
289 | ||
290 | void | |
291 | clnt_pcreateerror(s) | |
292 | char *s; | |
293 | { | |
294 | (void) fprintf(stderr,"%s",clnt_spcreateerror(s)); | |
295 | } | |
296 | ||
297 | struct auth_errtab { | |
298 | enum auth_stat status; | |
299 | char *message; | |
300 | }; | |
301 | ||
302 | static struct auth_errtab auth_errlist[] = { | |
303 | { AUTH_OK, | |
304 | "Authentication OK" }, | |
305 | { AUTH_BADCRED, | |
306 | "Invalid client credential" }, | |
307 | { AUTH_REJECTEDCRED, | |
308 | "Server rejected credential" }, | |
309 | { AUTH_BADVERF, | |
310 | "Invalid client verifier" }, | |
311 | { AUTH_REJECTEDVERF, | |
312 | "Server rejected verifier" }, | |
313 | { AUTH_TOOWEAK, | |
314 | "Client credential too weak" }, | |
315 | { AUTH_INVALIDRESP, | |
316 | "Invalid server verifier" }, | |
317 | { AUTH_FAILED, | |
318 | "Failed (unspecified error)" }, | |
319 | }; | |
320 | ||
321 | static char * | |
322 | auth_errmsg(stat) | |
323 | enum auth_stat stat; | |
324 | { | |
325 | int i; | |
326 | ||
327 | for (i = 0; i < sizeof(auth_errlist)/sizeof(struct auth_errtab); i++) { | |
328 | if (auth_errlist[i].status == stat) { | |
329 | return(auth_errlist[i].message); | |
330 | } | |
331 | } | |
332 | return(NULL); | |
333 | } |