1 /* $NetBSD: clnt_perror.c,v 1.8 1996/06/19 20:38:45 jtc 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.8 1996/06/19 20:38:45 jtc 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 return(strstart) ; 148 } 149 150 void 151 clnt_perror(rpch, s) 152 CLIENT *rpch; 153 char *s; 154 { 155 (void) fprintf(stderr,"%s\n",clnt_sperror(rpch,s)); 156 } 157 158 static const char *const rpc_errlist[] = { 159 "RPC: Success", /* 0 - RPC_SUCCESS */ 160 "RPC: Can't encode arguments", /* 1 - RPC_CANTENCODEARGS */ 161 "RPC: Can't decode result", /* 2 - RPC_CANTDECODERES */ 162 "RPC: Unable to send", /* 3 - RPC_CANTSEND */ 163 "RPC: Unable to receive", /* 4 - RPC_CANTRECV */ 164 "RPC: Timed out", /* 5 - RPC_TIMEDOUT */ 165 "RPC: Incompatible versions of RPC", /* 6 - RPC_VERSMISMATCH */ 166 "RPC: Authentication error", /* 7 - RPC_AUTHERROR */ 167 "RPC: Program unavailable", /* 8 - RPC_PROGUNAVAIL */ 168 "RPC: Program/version mismatch", /* 9 - RPC_PROGVERSMISMATCH */ 169 "RPC: Procedure unavailable", /* 10 - RPC_PROCUNAVAIL */ 170 "RPC: Server can't decode arguments", /* 11 - RPC_CANTDECODEARGS */ 171 "RPC: Remote system error", /* 12 - RPC_SYSTEMERROR */ 172 "RPC: Unknown host", /* 13 - RPC_UNKNOWNHOST */ 173 "RPC: Port mapper failure", /* 14 - RPC_PMAPFAILURE */ 174 "RPC: Program not registered", /* 15 - RPC_PROGNOTREGISTERED */ 175 "RPC: Failed (unspecified error)", /* 16 - RPC_FAILED */ 176 "RPC: Unknown protocol" /* 17 - RPC_UNKNOWNPROTO */ 177 }; 178 179 180 /* 181 * This interface for use by clntrpc 182 */ 183 char * 184 clnt_sperrno(stat) 185 enum clnt_stat stat; 186 { 187 int i; 188 189 unsigned int errnum = stat; 190 191 if (errnum < (sizeof(rpc_errlist)/sizeof(rpc_errlist[0]))) 192 return (char *)rpc_errlist[errnum]; 193 194 return ("RPC: (unknown error code)"); 195 } 196 197 void 198 clnt_perrno(num) 199 enum clnt_stat num; 200 { 201 (void) fprintf(stderr,"%s\n",clnt_sperrno(num)); 202 } 203 204 205 char * 206 clnt_spcreateerror(s) 207 char *s; 208 { 209 char *str = _buf(); 210 211 if (str == 0) 212 return(0); 213 (void) sprintf(str, "%s: ", s); 214 (void) strcat(str, clnt_sperrno(rpc_createerr.cf_stat)); 215 switch (rpc_createerr.cf_stat) { 216 case RPC_PMAPFAILURE: 217 (void) strcat(str, " - "); 218 (void) strcat(str, 219 clnt_sperrno(rpc_createerr.cf_error.re_status)); 220 break; 221 222 case RPC_SYSTEMERROR: 223 (void) strcat(str, " - "); 224 (void) strcat(str, strerror(rpc_createerr.cf_error.re_errno)); 225 break; 226 } 227 return (str); 228 } 229 230 void 231 clnt_pcreateerror(s) 232 char *s; 233 { 234 (void) fprintf(stderr,"%s\n",clnt_spcreateerror(s)); 235 } 236 237 static const char *const auth_errlist[] = { 238 "Authentication OK", /* 0 - AUTH_OK */ 239 "Invalid client credential", /* 1 - AUTH_BADCRED */ 240 "Server rejected credential", /* 2 - AUTH_REJECTEDCRED */ 241 "Invalid client verifier", /* 3 - AUTH_BADVERF */ 242 "Server rejected verifier", /* 4 - AUTH_REJECTEDVERF */ 243 "Client credential too weak", /* 5 - AUTH_TOOWEAK */ 244 "Invalid server verifier", /* 6 - AUTH_INVALIDRESP */ 245 "Failed (unspecified error)" /* 7 - AUTH_FAILED */ 246 }; 247 248 static char * 249 auth_errmsg(stat) 250 enum auth_stat stat; 251 { 252 unsigned int errnum = stat; 253 254 if (errnum < (sizeof(auth_errlist)/sizeof(auth_errlist[0]))) 255 return (char *)auth_errlist[errnum]; 256 257 return(NULL); 258 } 259