]> git.saurik.com Git - apple/libinfo.git/blame_incremental - rpc.subproj/clnt_perror.c
Libinfo-542.40.3.tar.gz
[apple/libinfo.git] / rpc.subproj / clnt_perror.c
... / ...
CommitLineData
1/*
2 * Copyright (c) 1999-2018 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
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";*/
56static char *rcsid = "$Id: clnt_perror.c,v 1.4 2003/06/23 17:24:59 majka Exp $";
57#endif
58
59/*
60 * clnt_perror.c
61 *
62 * Copyright (C) 1984, Sun Microsystems, Inc.
63 *
64 */
65#include "libinfo_common.h"
66
67#include <stdio.h>
68#include <stdlib.h>
69#include <string.h>
70#include <rpc/rpc.h>
71#include <rpc/types.h>
72#include <rpc/auth.h>
73#include <rpc/clnt.h>
74
75static char *auth_errmsg();
76
77static char *buf;
78
79static char *
80_buf()
81{
82
83 if (buf == 0)
84 buf = (char *)malloc(256);
85 return (buf);
86}
87
88/*
89 * Print reply error info
90 */
91LIBINFO_EXPORT
92char *
93clnt_sperror(rpch, s)
94 CLIENT *rpch;
95 char *s;
96{
97 struct rpc_err e;
98 void clnt_perrno();
99 char *err;
100 char *str = _buf();
101 char *strstart = str;
102
103 if (str == 0)
104 return (0);
105 CLNT_GETERR(rpch, &e);
106
107 (void) sprintf(str, "%s: ", s);
108 str += strlen(str);
109
110 (void) strcpy(str, clnt_sperrno(e.re_status));
111 str += strlen(str);
112
113 switch (e.re_status) {
114 case RPC_SUCCESS:
115 case RPC_CANTENCODEARGS:
116 case RPC_CANTDECODERES:
117 case RPC_TIMEDOUT:
118 case RPC_PROGUNAVAIL:
119 case RPC_PROCUNAVAIL:
120 case RPC_CANTDECODEARGS:
121 case RPC_SYSTEMERROR:
122 case RPC_UNKNOWNHOST:
123 case RPC_UNKNOWNPROTO:
124 case RPC_PMAPFAILURE:
125 case RPC_PROGNOTREGISTERED:
126 case RPC_FAILED:
127 break;
128
129 case RPC_CANTSEND:
130 case RPC_CANTRECV:
131 (void) sprintf(str, "; errno = %s",
132 strerror(e.re_errno));
133 str += strlen(str);
134 break;
135
136 case RPC_VERSMISMATCH:
137#ifdef __LP64__
138 (void) sprintf(str, "; low version = %u, high version = %u", e.re_vers.low, e.re_vers.high);
139#else
140 (void) sprintf(str, "; low version = %lu, high version = %lu", e.re_vers.low, e.re_vers.high);
141#endif
142 str += strlen(str);
143 break;
144
145 case RPC_AUTHERROR:
146 err = auth_errmsg(e.re_why);
147 (void) sprintf(str,"; why = ");
148 str += strlen(str);
149 if (err != NULL) {
150 (void) sprintf(str, "%s",err);
151 } else {
152 (void) sprintf(str,
153 "(unknown authentication error - %d)",
154 (int) e.re_why);
155 }
156 str += strlen(str);
157 break;
158
159 case RPC_PROGVERSMISMATCH:
160#ifdef __LP64__
161 (void) sprintf(str, "; low version = %u, high version = %u", e.re_vers.low, e.re_vers.high);
162#else
163 (void) sprintf(str, "; low version = %lu, high version = %lu", e.re_vers.low, e.re_vers.high);
164#endif
165 str += strlen(str);
166 break;
167
168 default: /* unknown */
169#ifdef __LP64__
170 (void) sprintf(str, "; s1 = %u, s2 = %u", e.re_lb.s1, e.re_lb.s2);
171#else
172 (void) sprintf(str, "; s1 = %lu, s2 = %lu", e.re_lb.s1, e.re_lb.s2);
173#endif
174 str += strlen(str);
175 break;
176 }
177 (void) sprintf(str, "\n");
178 return(strstart) ;
179}
180
181LIBINFO_EXPORT
182void
183clnt_perror(rpch, s)
184 CLIENT *rpch;
185 char *s;
186{
187 (void) fprintf(stderr,"%s",clnt_sperror(rpch,s));
188}
189
190
191struct rpc_errtab {
192 enum clnt_stat status;
193 char *message;
194};
195
196static struct rpc_errtab rpc_errlist[] = {
197 { RPC_SUCCESS,
198 "RPC: Success" },
199 { RPC_CANTENCODEARGS,
200 "RPC: Can't encode arguments" },
201 { RPC_CANTDECODERES,
202 "RPC: Can't decode result" },
203 { RPC_CANTSEND,
204 "RPC: Unable to send" },
205 { RPC_CANTRECV,
206 "RPC: Unable to receive" },
207 { RPC_TIMEDOUT,
208 "RPC: Timed out" },
209 { RPC_VERSMISMATCH,
210 "RPC: Incompatible versions of RPC" },
211 { RPC_AUTHERROR,
212 "RPC: Authentication error" },
213 { RPC_PROGUNAVAIL,
214 "RPC: Program unavailable" },
215 { RPC_PROGVERSMISMATCH,
216 "RPC: Program/version mismatch" },
217 { RPC_PROCUNAVAIL,
218 "RPC: Procedure unavailable" },
219 { RPC_CANTDECODEARGS,
220 "RPC: Server can't decode arguments" },
221 { RPC_SYSTEMERROR,
222 "RPC: Remote system error" },
223 { RPC_UNKNOWNHOST,
224 "RPC: Unknown host" },
225 { RPC_UNKNOWNPROTO,
226 "RPC: Unknown protocol" },
227 { RPC_PMAPFAILURE,
228 "RPC: Port mapper failure" },
229 { RPC_PROGNOTREGISTERED,
230 "RPC: Program not registered"},
231 { RPC_FAILED,
232 "RPC: Failed (unspecified error)"}
233};
234
235
236/*
237 * This interface for use by clntrpc
238 */
239LIBINFO_EXPORT
240char *
241clnt_sperrno(stat)
242 enum clnt_stat stat;
243{
244 int i;
245
246 for (i = 0; i < sizeof(rpc_errlist)/sizeof(struct rpc_errtab); i++) {
247 if (rpc_errlist[i].status == stat) {
248 return (rpc_errlist[i].message);
249 }
250 }
251 return ("RPC: (unknown error code)");
252}
253
254LIBINFO_EXPORT
255void
256clnt_perrno(num)
257 enum clnt_stat num;
258{
259 (void) fprintf(stderr,"%s",clnt_sperrno(num));
260}
261
262
263LIBINFO_EXPORT
264char *
265clnt_spcreateerror(s)
266 char *s;
267{
268 char *str = _buf();
269
270 if (str == 0)
271 return(0);
272 (void) sprintf(str, "%s: ", s);
273 (void) strcat(str, clnt_sperrno(rpc_createerr.cf_stat));
274 switch (rpc_createerr.cf_stat) {
275 case RPC_PMAPFAILURE:
276 (void) strcat(str, " - ");
277 (void) strcat(str,
278 clnt_sperrno(rpc_createerr.cf_error.re_status));
279 break;
280
281 case RPC_SYSTEMERROR:
282 (void) strcat(str, " - ");
283 if (rpc_createerr.cf_error.re_errno > 0
284 && rpc_createerr.cf_error.re_errno < sys_nerr)
285 (void) strcat(str,
286 strerror(rpc_createerr.cf_error.re_errno));
287 else
288 (void) sprintf(&str[strlen(str)], "Error %d",
289 rpc_createerr.cf_error.re_errno);
290 break;
291 default: break;
292 }
293 (void) strcat(str, "\n");
294 return (str);
295}
296
297LIBINFO_EXPORT
298void
299clnt_pcreateerror(s)
300 char *s;
301{
302 (void) fprintf(stderr,"%s",clnt_spcreateerror(s));
303}
304
305struct auth_errtab {
306 enum auth_stat status;
307 char *message;
308};
309
310static struct auth_errtab auth_errlist[] = {
311 { AUTH_OK,
312 "Authentication OK" },
313 { AUTH_BADCRED,
314 "Invalid client credential" },
315 { AUTH_REJECTEDCRED,
316 "Server rejected credential" },
317 { AUTH_BADVERF,
318 "Invalid client verifier" },
319 { AUTH_REJECTEDVERF,
320 "Server rejected verifier" },
321 { AUTH_TOOWEAK,
322 "Client credential too weak" },
323 { AUTH_INVALIDRESP,
324 "Invalid server verifier" },
325 { AUTH_FAILED,
326 "Failed (unspecified error)" },
327};
328
329static char *
330auth_errmsg(stat)
331 enum auth_stat stat;
332{
333 int i;
334
335 for (i = 0; i < sizeof(auth_errlist)/sizeof(struct auth_errtab); i++) {
336 if (auth_errlist[i].status == stat) {
337 return(auth_errlist[i].message);
338 }
339 }
340 return(NULL);
341}