1 /* $NetBSD: clnt_perror.c,v 1.5 1995/02/25 03:01:39 cgd Exp $ */ 2 3 /* 4 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 5 * unrestricted use provided that this legend is included on all tape 6 * media and as a part of the software program in whole or part. Users 7 * may copy or modify Sun RPC without charge, but are not authorized 8 * to license or distribute it to anyone else except as part of a product or 9 * program developed by the user. 10 * 11 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 12 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 13 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 14 * 15 * Sun RPC is provided with no support and without any obligation on the 16 * part of Sun Microsystems, Inc. to assist in its use, correction, 17 * modification or enhancement. 18 * 19 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 20 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 21 * OR ANY PART THEREOF. 22 * 23 * In no event will Sun Microsystems, Inc. be liable for any lost revenue 24 * or profits or other special, indirect and consequential damages, even if 25 * Sun has been advised of the possibility of such damages. 26 * 27 * Sun Microsystems, Inc. 28 * 2550 Garcia Avenue 29 * Mountain View, California 94043 30 */ 31 32 #if defined(LIBC_SCCS) && !defined(lint) 33 /*static char *sccsid = "from: @(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro";*/ 34 /*static char *sccsid = "from: @(#)clnt_perror.c 2.1 88/07/29 4.0 RPCSRC";*/ 35 static char *rcsid = "$NetBSD: clnt_perror.c,v 1.5 1995/02/25 03:01:39 cgd Exp $"; 36 #endif 37 38 /* 39 * clnt_perror.c 40 * 41 * Copyright (C) 1984, Sun Microsystems, Inc. 42 * 43 */ 44 #include <stdio.h> 45 #include <stdlib.h> 46 #include <string.h> 47 #include <rpc/rpc.h> 48 #include <rpc/types.h> 49 #include <rpc/auth.h> 50 #include <rpc/clnt.h> 51 52 static char *auth_errmsg(); 53 54 static char *buf; 55 56 static char * 57 _buf() 58 { 59 60 if (buf == 0) 61 buf = (char *)malloc(256); 62 return (buf); 63 } 64 65 /* 66 * Print reply error info 67 */ 68 char * 69 clnt_sperror(rpch, s) 70 CLIENT *rpch; 71 char *s; 72 { 73 struct rpc_err e; 74 void clnt_perrno(); 75 char *err; 76 char *str = _buf(); 77 char *strstart = str; 78 79 if (str == 0) 80 return (0); 81 CLNT_GETERR(rpch, &e); 82 83 (void) sprintf(str, "%s: ", s); 84 str += strlen(str); 85 86 (void) strcpy(str, 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) sprintf(str, "; errno = %s", 108 strerror(e.re_errno)); 109 str += strlen(str); 110 break; 111 112 case RPC_VERSMISMATCH: 113 (void) sprintf(str, 114 "; low version = %lu, high version = %lu", 115 e.re_vers.low, e.re_vers.high); 116 str += strlen(str); 117 break; 118 119 case RPC_AUTHERROR: 120 err = auth_errmsg(e.re_why); 121 (void) sprintf(str,"; why = "); 122 str += strlen(str); 123 if (err != NULL) { 124 (void) sprintf(str, "%s",err); 125 } else { 126 (void) sprintf(str, 127 "(unknown authentication error - %d)", 128 (int) e.re_why); 129 } 130 str += strlen(str); 131 break; 132 133 case RPC_PROGVERSMISMATCH: 134 (void) sprintf(str, 135 "; low version = %lu, high version = %lu", 136 e.re_vers.low, e.re_vers.high); 137 str += strlen(str); 138 break; 139 140 default: /* unknown */ 141 (void) sprintf(str, 142 "; s1 = %lu, s2 = %lu", 143 e.re_lb.s1, e.re_lb.s2); 144 str += strlen(str); 145 break; 146 } 147 (void) sprintf(str, "\n"); 148 return(strstart) ; 149 } 150 151 void 152 clnt_perror(rpch, s) 153 CLIENT *rpch; 154 char *s; 155 { 156 (void) fprintf(stderr,"%s\n",clnt_sperror(rpch,s)); 157 } 158 159 160 struct rpc_errtab { 161 enum clnt_stat status; 162 char *message; 163 }; 164 165 static const struct rpc_errtab rpc_errlist[] = { 166 { RPC_SUCCESS, 167 "RPC: Success" }, 168 { RPC_CANTENCODEARGS, 169 "RPC: Can't encode arguments" }, 170 { RPC_CANTDECODERES, 171 "RPC: Can't decode result" }, 172 { RPC_CANTSEND, 173 "RPC: Unable to send" }, 174 { RPC_CANTRECV, 175 "RPC: Unable to receive" }, 176 { RPC_TIMEDOUT, 177 "RPC: Timed out" }, 178 { RPC_VERSMISMATCH, 179 "RPC: Incompatible versions of RPC" }, 180 { RPC_AUTHERROR, 181 "RPC: Authentication error" }, 182 { RPC_PROGUNAVAIL, 183 "RPC: Program unavailable" }, 184 { RPC_PROGVERSMISMATCH, 185 "RPC: Program/version mismatch" }, 186 { RPC_PROCUNAVAIL, 187 "RPC: Procedure unavailable" }, 188 { RPC_CANTDECODEARGS, 189 "RPC: Server can't decode arguments" }, 190 { RPC_SYSTEMERROR, 191 "RPC: Remote system error" }, 192 { RPC_UNKNOWNHOST, 193 "RPC: Unknown host" }, 194 { RPC_UNKNOWNPROTO, 195 "RPC: Unknown protocol" }, 196 { RPC_PMAPFAILURE, 197 "RPC: Port mapper failure" }, 198 { RPC_PROGNOTREGISTERED, 199 "RPC: Program not registered"}, 200 { RPC_FAILED, 201 "RPC: Failed (unspecified error)"} 202 }; 203 204 205 /* 206 * This interface for use by clntrpc 207 */ 208 char * 209 clnt_sperrno(stat) 210 enum clnt_stat stat; 211 { 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 return ("RPC: (unknown error code)"); 220 } 221 222 void 223 clnt_perrno(num) 224 enum clnt_stat num; 225 { 226 (void) fprintf(stderr,"%s\n",clnt_sperrno(num)); 227 } 228 229 230 char * 231 clnt_spcreateerror(s) 232 char *s; 233 { 234 char *str = _buf(); 235 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; 246 247 case RPC_SYSTEMERROR: 248 (void) strcat(str, " - "); 249 (void) strcat(str, strerror(rpc_createerr.cf_error.re_errno)); 250 break; 251 } 252 (void) strcat(str, "\n"); 253 return (str); 254 } 255 256 void 257 clnt_pcreateerror(s) 258 char *s; 259 { 260 (void) fprintf(stderr,"%s\n",clnt_spcreateerror(s)); 261 } 262 263 struct auth_errtab { 264 enum auth_stat status; 265 char *message; 266 }; 267 268 static const struct auth_errtab auth_errlist[] = { 269 { AUTH_OK, 270 "Authentication OK" }, 271 { AUTH_BADCRED, 272 "Invalid client credential" }, 273 { AUTH_REJECTEDCRED, 274 "Server rejected credential" }, 275 { AUTH_BADVERF, 276 "Invalid client verifier" }, 277 { AUTH_REJECTEDVERF, 278 "Server rejected verifier" }, 279 { AUTH_TOOWEAK, 280 "Client credential too weak" }, 281 { AUTH_INVALIDRESP, 282 "Invalid server verifier" }, 283 { AUTH_FAILED, 284 "Failed (unspecified error)" }, 285 }; 286 287 static char * 288 auth_errmsg(stat) 289 enum auth_stat stat; 290 { 291 int i; 292 293 for (i = 0; i < sizeof(auth_errlist)/sizeof(struct auth_errtab); i++) { 294 if (auth_errlist[i].status == stat) { 295 return(auth_errlist[i].message); 296 } 297 } 298 return(NULL); 299 } 300