Sat May 27 16:23:22 1995 Jim Meyering (meyering@comco.com)
[glibc.git] / sunrpc / clnt_perr.c
blob1876c7f163662116154e82634fe13f1f2b85d1e7
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.
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.
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.
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.
26 * Sun Microsystems, Inc.
27 * 2550 Garcia Avenue
28 * Mountain View, California 94043
30 #if !defined(lint) && defined(SCCSIDS)
31 static char sccsid[] = "@(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro";
32 #endif
35 * clnt_perror.c
37 * Copyright (C) 1984, Sun Microsystems, Inc.
40 #include <stdio.h>
42 #include <rpc/types.h>
43 #include <rpc/auth.h>
44 #include <rpc/clnt.h>
46 extern char *sys_errlist[];
47 /* extern char *sprintf(); --roland@gnu */
48 static char *auth_errmsg();
50 extern char *strcpy();
52 static char *buf;
54 static char *
55 _buf()
58 if (buf == 0)
59 buf = (char *)malloc(256);
60 return (buf);
64 * Print reply error info
66 char *
67 clnt_sperror(rpch, s)
68 CLIENT *rpch;
69 char *s;
71 struct rpc_err e;
72 void clnt_perrno();
73 char *err;
74 char *str = _buf();
75 char *strstart = str;
77 if (str == 0)
78 return (0);
79 CLNT_GETERR(rpch, &e);
81 (void) sprintf(str, "%s: ", s);
82 str += strlen(str);
84 (void) strcpy(str, clnt_sperrno(e.re_status));
85 str += strlen(str);
87 switch (e.re_status) {
88 case RPC_SUCCESS:
89 case RPC_CANTENCODEARGS:
90 case RPC_CANTDECODERES:
91 case RPC_TIMEDOUT:
92 case RPC_PROGUNAVAIL:
93 case RPC_PROCUNAVAIL:
94 case RPC_CANTDECODEARGS:
95 case RPC_SYSTEMERROR:
96 case RPC_UNKNOWNHOST:
97 case RPC_UNKNOWNPROTO:
98 case RPC_PMAPFAILURE:
99 case RPC_PROGNOTREGISTERED:
100 case RPC_FAILED:
101 break;
103 case RPC_CANTSEND:
104 case RPC_CANTRECV:
105 (void) sprintf(str, "; errno = %s",
106 sys_errlist[e.re_errno]);
107 str += strlen(str);
108 break;
110 case RPC_VERSMISMATCH:
111 (void) sprintf(str,
112 "; low version = %lu, high version = %lu",
113 e.re_vers.low, e.re_vers.high);
114 str += strlen(str);
115 break;
117 case RPC_AUTHERROR:
118 err = auth_errmsg(e.re_why);
119 (void) sprintf(str,"; why = ");
120 str += strlen(str);
121 if (err != NULL) {
122 (void) sprintf(str, "%s",err);
123 } else {
124 (void) sprintf(str,
125 "(unknown authentication error - %d)",
126 (int) e.re_why);
128 str += strlen(str);
129 break;
131 case RPC_PROGVERSMISMATCH:
132 (void) sprintf(str,
133 "; low version = %lu, high version = %lu",
134 e.re_vers.low, e.re_vers.high);
135 str += strlen(str);
136 break;
138 default: /* unknown */
139 (void) sprintf(str,
140 "; s1 = %lu, s2 = %lu",
141 e.re_lb.s1, e.re_lb.s2);
142 str += strlen(str);
143 break;
145 (void) sprintf(str, "\n");
146 return(strstart) ;
149 void
150 clnt_perror(rpch, s)
151 CLIENT *rpch;
152 char *s;
154 (void) fprintf(stderr,"%s",clnt_sperror(rpch,s));
158 struct rpc_errtab {
159 enum clnt_stat status;
160 char *message;
163 static struct rpc_errtab rpc_errlist[] = {
164 { RPC_SUCCESS,
165 "RPC: Success" },
166 { RPC_CANTENCODEARGS,
167 "RPC: Can't encode arguments" },
168 { RPC_CANTDECODERES,
169 "RPC: Can't decode result" },
170 { RPC_CANTSEND,
171 "RPC: Unable to send" },
172 { RPC_CANTRECV,
173 "RPC: Unable to receive" },
174 { RPC_TIMEDOUT,
175 "RPC: Timed out" },
176 { RPC_VERSMISMATCH,
177 "RPC: Incompatible versions of RPC" },
178 { RPC_AUTHERROR,
179 "RPC: Authentication error" },
180 { RPC_PROGUNAVAIL,
181 "RPC: Program unavailable" },
182 { RPC_PROGVERSMISMATCH,
183 "RPC: Program/version mismatch" },
184 { RPC_PROCUNAVAIL,
185 "RPC: Procedure unavailable" },
186 { RPC_CANTDECODEARGS,
187 "RPC: Server can't decode arguments" },
188 { RPC_SYSTEMERROR,
189 "RPC: Remote system error" },
190 { RPC_UNKNOWNHOST,
191 "RPC: Unknown host" },
192 { RPC_UNKNOWNPROTO,
193 "RPC: Unknown protocol" },
194 { RPC_PMAPFAILURE,
195 "RPC: Port mapper failure" },
196 { RPC_PROGNOTREGISTERED,
197 "RPC: Program not registered"},
198 { RPC_FAILED,
199 "RPC: Failed (unspecified error)"}
204 * This interface for use by clntrpc
206 char *
207 clnt_sperrno(stat)
208 enum clnt_stat stat;
210 int i;
212 for (i = 0; i < sizeof(rpc_errlist)/sizeof(struct rpc_errtab); i++) {
213 if (rpc_errlist[i].status == stat) {
214 return (rpc_errlist[i].message);
217 return ("RPC: (unknown error code)");
220 void
221 clnt_perrno(num)
222 enum clnt_stat num;
224 (void) fprintf(stderr,"%s",clnt_sperrno(num));
228 char *
229 clnt_spcreateerror(s)
230 char *s;
232 extern int sys_nerr;
233 extern char *sys_errlist[];
234 char *str = _buf();
236 if (str == 0)
237 return(0);
238 (void) sprintf(str, "%s: ", s);
239 (void) strcat(str, clnt_sperrno(rpc_createerr.cf_stat));
240 switch (rpc_createerr.cf_stat) {
241 case RPC_PMAPFAILURE:
242 (void) strcat(str, " - ");
243 (void) strcat(str,
244 clnt_sperrno(rpc_createerr.cf_error.re_status));
245 break;
247 case RPC_SYSTEMERROR:
248 (void) strcat(str, " - ");
249 if (rpc_createerr.cf_error.re_errno > 0
250 && rpc_createerr.cf_error.re_errno < sys_nerr)
251 (void) strcat(str,
252 sys_errlist[rpc_createerr.cf_error.re_errno]);
253 else
254 (void) sprintf(&str[strlen(str)], "Error %d",
255 rpc_createerr.cf_error.re_errno);
256 break;
258 (void) strcat(str, "\n");
259 return (str);
262 void
263 clnt_pcreateerror(s)
264 char *s;
266 (void) fprintf(stderr,"%s",clnt_spcreateerror(s));
269 struct auth_errtab {
270 enum auth_stat status;
271 char *message;
274 static struct auth_errtab auth_errlist[] = {
275 { AUTH_OK,
276 "Authentication OK" },
277 { AUTH_BADCRED,
278 "Invalid client credential" },
279 { AUTH_REJECTEDCRED,
280 "Server rejected credential" },
281 { AUTH_BADVERF,
282 "Invalid client verifier" },
283 { AUTH_REJECTEDVERF,
284 "Server rejected verifier" },
285 { AUTH_TOOWEAK,
286 "Client credential too weak" },
287 { AUTH_INVALIDRESP,
288 "Invalid server verifier" },
289 { AUTH_FAILED,
290 "Failed (unspecified error)" },
293 static char *
294 auth_errmsg(stat)
295 enum auth_stat stat;
297 int i;
299 for (i = 0; i < sizeof(auth_errlist)/sizeof(struct auth_errtab); i++) {
300 if (auth_errlist[i].status == stat) {
301 return(auth_errlist[i].message);
304 return(NULL);