OSDN Git Service

Initial revision
[uclinux-h8/uClibc.git] / libc / inet / rpc / clnt_perror.c
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 extern char *sys_errlist[];
47 static char *auth_errmsg();
48
49 extern char *strcpy();
50
51 static char *buf;
52
53 static char *
54 _buf()
55 {
56
57         if (buf == 0)
58                 buf = (char *)malloc(256);
59         return (buf);
60 }
61
62 /*
63  * Print reply error info
64  */
65 char *
66 clnt_sperror(rpch, s)
67         CLIENT *rpch;
68         char *s;
69 {
70 #if 0
71         struct rpc_err e;
72         void clnt_perrno();
73         char *err;
74         char *str = _buf();
75         char *strstart = str;
76
77         if (str == 0)
78                 return (0);
79         CLNT_GETERR(rpch, &e);
80
81         (void) sprintf(str, "%s: ", s);  
82         str += strlen(str);
83
84         (void) strcpy(str, clnt_sperrno(e.re_status));  
85         str += strlen(str);
86
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;
102
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;
109
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;
116
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);
127                 }
128                 str += strlen(str);
129                 break;
130
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;
137
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;
144         }
145         (void) sprintf(str, "\n");
146         return(strstart) ;
147 #endif
148 }
149
150 void
151 clnt_perror(rpch, s)
152         CLIENT *rpch;
153         char *s;
154 {
155         (void) fprintf(stderr,"%s",clnt_sperror(rpch,s));
156 }
157
158
159 struct rpc_errtab {
160         enum clnt_stat status;
161         char *message;
162 };
163 #if 0
164 static struct rpc_errtab  rpc_errlist[] = {
165         { RPC_SUCCESS, 
166                 "RPC: Success" }, 
167         { RPC_CANTENCODEARGS, 
168                 "RPC: Can't encode arguments" },
169         { RPC_CANTDECODERES, 
170                 "RPC: Can't decode result" },
171         { RPC_CANTSEND, 
172                 "RPC: Unable to send" },
173         { RPC_CANTRECV, 
174                 "RPC: Unable to receive" },
175         { RPC_TIMEDOUT, 
176                 "RPC: Timed out" },
177         { RPC_VERSMISMATCH, 
178                 "RPC: Incompatible versions of RPC" },
179         { RPC_AUTHERROR, 
180                 "RPC: Authentication error" },
181         { RPC_PROGUNAVAIL, 
182                 "RPC: Program unavailable" },
183         { RPC_PROGVERSMISMATCH, 
184                 "RPC: Program/version mismatch" },
185         { RPC_PROCUNAVAIL, 
186                 "RPC: Procedure unavailable" },
187         { RPC_CANTDECODEARGS, 
188                 "RPC: Server can't decode arguments" },
189         { RPC_SYSTEMERROR, 
190                 "RPC: Remote system error" },
191         { RPC_UNKNOWNHOST, 
192                 "RPC: Unknown host" },
193         { RPC_UNKNOWNPROTO,
194                 "RPC: Unknown protocol" },
195         { RPC_PMAPFAILURE, 
196                 "RPC: Port mapper failure" },
197         { RPC_PROGNOTREGISTERED, 
198                 "RPC: Program not registered"},
199         { RPC_FAILED, 
200                 "RPC: Failed (unspecified error)"}
201 };
202 #endif
203
204 /*
205  * This interface for use by clntrpc
206  */
207 char *
208 clnt_sperrno(stat)
209         enum clnt_stat stat;
210 {
211 #if 0
212         int i;
213
214         for (i = 0; i < sizeof(rpc_errlist)/sizeof(struct rpc_errtab); i++) {
215                 if (rpc_errlist[i].status == stat) {
216                         return (rpc_errlist[i].message);
217                 }
218         }
219 #endif
220         return ("RPC: (unknown error code)");
221 }
222
223 void
224 clnt_perrno(num)
225         enum clnt_stat num;
226 {
227         (void) fprintf(stderr,"%s",clnt_sperrno(num));
228 }
229
230
231 char *
232 clnt_spcreateerror(s)
233         char *s;
234 {
235 #if 0
236         extern int sys_nerr;
237         extern char *sys_errlist[];
238         char *str = _buf();
239
240         if (str == 0)
241                 return(0);
242         (void) sprintf(str, "%s: ", s);
243         (void) strcat(str, clnt_sperrno(rpc_createerr.cf_stat));
244         switch (rpc_createerr.cf_stat) {
245         case RPC_PMAPFAILURE:
246                 (void) strcat(str, " - ");
247                 (void) strcat(str,
248                     clnt_sperrno(rpc_createerr.cf_error.re_status));
249                 break;
250
251         case RPC_SYSTEMERROR:
252                 (void) strcat(str, " - ");
253                 if (rpc_createerr.cf_error.re_errno > 0
254                     && rpc_createerr.cf_error.re_errno < sys_nerr)
255                         (void) strcat(str,
256                             sys_errlist[rpc_createerr.cf_error.re_errno]);
257                 else
258                         (void) sprintf(&str[strlen(str)], "Error %d",
259                             rpc_createerr.cf_error.re_errno);
260                 break;
261         }
262         (void) strcat(str, "\n");
263         return (str);
264 #endif
265 }
266
267 void
268 clnt_pcreateerror(s)
269         char *s;
270 {
271         (void) fprintf(stderr,"%s",clnt_spcreateerror(s));
272 }
273
274 struct auth_errtab {
275         enum auth_stat status;  
276         char *message;
277 };
278
279 static struct auth_errtab auth_errlist[] = {
280         { AUTH_OK,
281                 "Authentication OK" },
282         { AUTH_BADCRED,
283                 "Invalid client credential" },
284         { AUTH_REJECTEDCRED,
285                 "Server rejected credential" },
286         { AUTH_BADVERF,
287                 "Invalid client verifier" },
288         { AUTH_REJECTEDVERF,
289                 "Server rejected verifier" },
290         { AUTH_TOOWEAK,
291                 "Client credential too weak" },
292         { AUTH_INVALIDRESP,
293                 "Invalid server verifier" },
294         { AUTH_FAILED,
295                 "Failed (unspecified error)" },
296 };
297
298 static char *
299 auth_errmsg(stat)
300         enum auth_stat stat;
301 {
302         int i;
303
304         for (i = 0; i < sizeof(auth_errlist)/sizeof(struct auth_errtab); i++) {
305                 if (auth_errlist[i].status == stat) {
306                         return(auth_errlist[i].message);
307                 }
308         }
309         return(NULL);
310 }