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