source: rtems/cpukit/librpc/src/rpc/clnt_perror.c @ 37da47a

4.104.115
Last change on this file since 37da47a was 37da47a, checked in by Ralf Corsepius <ralf.corsepius@…>, on 03/28/10 at 02:40:16

Add HAVE_CONFIG_H support to let files receive configure defines.

  • Property mode set to 100644
File size: 6.6 KB
Line 
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part.  Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
8 *
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
12 *
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
16 *
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
20 *
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
24 *
25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California  94043
28 */
29
30#if defined(LIBC_SCCS) && !defined(lint)
31/*static char *sccsid = "from: @(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro";*/
32/*static char *sccsid = "from: @(#)clnt_perror.c        2.1 88/07/29 4.0 RPCSRC";*/
33static char *rcsid = "$FreeBSD: src/lib/libc/rpc/clnt_perror.c,v 1.11 1999/08/28 00:00:35 peter Exp $";
34#endif
35
36/*
37 * clnt_perror.c
38 *
39 * Copyright (C) 1984, Sun Microsystems, Inc.
40 *
41 */
42
43#ifdef HAVE_CONFIG_H
44#include "config.h"
45#endif
46
47#include <stdio.h>
48#include <stdlib.h>
49#include <string.h>
50#include <rpc/rpc.h>
51#include <rpc/types.h>
52#include <rpc/auth.h>
53#include <rpc/clnt.h>
54
55static char *auth_errmsg(enum auth_stat stat);
56#define CLNT_PERROR_BUFLEN 256
57
58#define buf (rtems_rpc_task_variables->clnt_perror_buf)
59
60static char *
61_buf(void)
62{
63
64        if (buf == 0)
65                buf = (char *)malloc(CLNT_PERROR_BUFLEN);
66        return (buf);
67}
68
69/*
70 * Print reply error info
71 */
72char *
73clnt_sperror(
74        CLIENT *rpch,
75        const char *s)
76{
77        struct rpc_err e;
78        char *err;
79        char *str = _buf();
80        char *strstart = str;
81
82        if (str == 0)
83                return (0);
84        CLNT_GETERR(rpch, &e);
85
86        (void) sprintf(str, "%s: %s", s, clnt_sperrno(e.re_status));
87        str += strlen(str);
88
89        switch (e.re_status) {
90        case RPC_SUCCESS:
91        case RPC_CANTENCODEARGS:
92        case RPC_CANTDECODERES:
93        case RPC_TIMEDOUT:
94        case RPC_PROGUNAVAIL:
95        case RPC_PROCUNAVAIL:
96        case RPC_CANTDECODEARGS:
97        case RPC_SYSTEMERROR:
98        case RPC_UNKNOWNHOST:
99        case RPC_UNKNOWNPROTO:
100        case RPC_PMAPFAILURE:
101        case RPC_PROGNOTREGISTERED:
102        case RPC_FAILED:
103                break;
104
105        case RPC_CANTSEND:
106        case RPC_CANTRECV:
107                (void) snprintf(str, CLNT_PERROR_BUFLEN - (str - strstart),
108                        "; errno = %s\n", strerror(e.re_errno));
109                break;
110
111        case RPC_VERSMISMATCH:
112                (void) sprintf(str,
113                        "; low version = %lu, high version = %lu\n",
114                        (u_long)e.re_vers.low, (u_long)e.re_vers.high);
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\n",err);
123                } else {
124                        (void) sprintf(str,
125                                "(unknown authentication error - %d)\n",
126                                (int) e.re_why);
127                }
128                break;
129
130        case RPC_PROGVERSMISMATCH:
131                (void) sprintf(str,
132                        "; low version = %lu, high version = %lu\n",
133                        (u_long)e.re_vers.low, (u_long)e.re_vers.high);
134                break;
135
136        default:        /* unknown */
137                (void) sprintf(str,
138                        "; s1 = %lu, s2 = %lu\n",
139                        (long)e.re_lb.s1, (long)e.re_lb.s2);
140                break;
141        }
142        strstart[CLNT_PERROR_BUFLEN-2] = '\n';
143        strstart[CLNT_PERROR_BUFLEN-1] = '\0';
144        return(strstart) ;
145}
146
147void
148clnt_perror(
149        CLIENT *rpch,
150        const char *s)
151{
152        (void) fprintf(stderr,"%s\n",clnt_sperror(rpch,s));
153}
154
155
156static const char *const rpc_errlist[] = {
157        "RPC: Success",                         /*  0 - RPC_SUCCESS */
158        "RPC: Can't encode arguments",          /*  1 - RPC_CANTENCODEARGS */
159        "RPC: Can't decode result",             /*  2 - RPC_CANTDECODERES */
160        "RPC: Unable to send",                  /*  3 - RPC_CANTSEND */
161        "RPC: Unable to receive",               /*  4 - RPC_CANTRECV */
162        "RPC: Timed out",                       /*  5 - RPC_TIMEDOUT */
163        "RPC: Incompatible versions of RPC",    /*  6 - RPC_VERSMISMATCH */
164        "RPC: Authentication error",            /*  7 - RPC_AUTHERROR */
165        "RPC: Program unavailable",             /*  8 - RPC_PROGUNAVAIL */
166        "RPC: Program/version mismatch",        /*  9 - RPC_PROGVERSMISMATCH */
167        "RPC: Procedure unavailable",           /* 10 - RPC_PROCUNAVAIL */
168        "RPC: Server can't decode arguments",   /* 11 - RPC_CANTDECODEARGS */
169        "RPC: Remote system error",             /* 12 - RPC_SYSTEMERROR */
170        "RPC: Unknown host",                    /* 13 - RPC_UNKNOWNHOST */
171        "RPC: Port mapper failure",             /* 14 - RPC_PMAPFAILURE */
172        "RPC: Program not registered",          /* 15 - RPC_PROGNOTREGISTERED */
173        "RPC: Failed (unspecified error)",      /* 16 - RPC_FAILED */
174        "RPC: Unknown protocol"                 /* 17 - RPC_UNKNOWNPROTO */
175};
176
177
178/*
179 * This interface for use by clntrpc
180 */
181char *
182clnt_sperrno(
183        enum clnt_stat stat)
184{
185        unsigned int errnum = stat;
186
187        if (errnum < (sizeof(rpc_errlist)/sizeof(rpc_errlist[0])))
188                return (char *)rpc_errlist[errnum];
189
190        return ("RPC: (unknown error code)");
191}
192
193void
194clnt_perrno(
195        enum clnt_stat num)
196{
197        (void) fprintf(stderr,"%s\n",clnt_sperrno(num));
198}
199
200
201char *
202clnt_spcreateerror(
203        const char *s)
204{
205        char *str = _buf();
206
207        if (str == 0)
208                return(0);
209        switch (rpc_createerr.cf_stat) {
210        case RPC_PMAPFAILURE:
211                (void) snprintf(str, CLNT_PERROR_BUFLEN, "%s: %s - %s\n", s,
212                    clnt_sperrno(rpc_createerr.cf_stat),
213                    clnt_sperrno(rpc_createerr.cf_error.re_status));
214                break;
215
216        case RPC_SYSTEMERROR:
217                (void) snprintf(str, CLNT_PERROR_BUFLEN, "%s: %s - %s\n", s,
218                    clnt_sperrno(rpc_createerr.cf_stat),
219                    strerror(rpc_createerr.cf_error.re_errno));
220                break;
221        default:
222                (void) snprintf(str, CLNT_PERROR_BUFLEN, "%s: %s\n", s,
223                clnt_sperrno(rpc_createerr.cf_stat));
224                break;
225        }
226        str[CLNT_PERROR_BUFLEN-2] = '\n';
227        str[CLNT_PERROR_BUFLEN-1] = '\0';
228        return (str);
229}
230
231void
232clnt_pcreateerror(
233        const char *s)
234{
235        (void) fprintf(stderr,"%s\n",clnt_spcreateerror(s));
236}
237
238static const char *const auth_errlist[] = {
239        "Authentication OK",                    /* 0 - AUTH_OK */
240        "Invalid client credential",            /* 1 - AUTH_BADCRED */
241        "Server rejected credential",           /* 2 - AUTH_REJECTEDCRED */
242        "Invalid client verifier",              /* 3 - AUTH_BADVERF */
243        "Server rejected verifier",             /* 4 - AUTH_REJECTEDVERF */
244        "Client credential too weak",           /* 5 - AUTH_TOOWEAK */
245        "Invalid server verifier",              /* 6 - AUTH_INVALIDRESP */
246        "Failed (unspecified error)"            /* 7 - AUTH_FAILED */
247};
248
249static char *
250auth_errmsg(
251        enum auth_stat stat)
252{
253        unsigned int errnum = stat;
254
255        if (errnum < (sizeof(auth_errlist)/sizeof(auth_errlist[0])))
256                return (char *)auth_errlist[errnum];
257
258        return(NULL);
259}
Note: See TracBrowser for help on using the repository browser.