-: 0:Source:clnt_perror.c -: 0:Graph:/var/tsitkova/Sources/v10/trunk/src/lib/rpc/clnt_perror.so.gcno -: 0:Data:/var/tsitkova/Sources/v10/trunk/src/lib/rpc/clnt_perror.so.gcda -: 0:Runs:959 -: 0:Programs:1 -: 1:/* @(#)clnt_perror.c 2.1 88/07/29 4.0 RPCSRC */ -: 2:/* -: 3: * Copyright (c) 2010, Oracle America, Inc. -: 4: * -: 5: * All rights reserved. -: 6: * -: 7: * Redistribution and use in source and binary forms, with or without -: 8: * modification, are permitted provided that the following conditions are met: -: 9: * -: 10: * * Redistributions of source code must retain the above copyright -: 11: * notice, this list of conditions and the following disclaimer. -: 12: * -: 13: * * Redistributions in binary form must reproduce the above copyright -: 14: * notice, this list of conditions and the following disclaimer in -: 15: * the documentation and/or other materials provided with the -: 16: * distribution. -: 17: * -: 18: * * Neither the name of the "Oracle America, Inc." nor the names of -: 19: * its contributors may be used to endorse or promote products -: 20: * derived from this software without specific prior written permission. -: 21: * -: 22: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS -: 23: * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -: 24: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -: 25: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -: 26: * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -: 27: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -: 28: * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -: 29: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -: 30: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -: 31: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -: 32: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -: 33: */ -: 34:#if !defined(lint) && defined(SCCSIDS) -: 35:static char sccsid[] = "@(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro"; -: 36:#endif -: 37: -: 38:/* -: 39: * clnt_perror.c -: 40: */ -: 41:#include -: 42:#include -: 43:#include -: 44: -: 45:#include -: 46:#include -: 47:#include -: 48: -: 49:#include "autoconf.h" -: 50: -: 51:#ifndef HAVE_STRERROR -: 52:#ifdef NEED_SYS_ERRLIST -: 53:extern char *sys_errlist[]; -: 54:#endif -: 55:extern int sys_nerr; -: 56:#undef strerror -: 57:#define strerror(N) (((N) > 0 && (N) < sys_nerr) ? sys_errlist[N] : (char *)0) -: 58:#endif /* HAVE_STRERROR */ -: 59:static char *auth_errmsg(enum auth_stat); -: 60: -: 61: -: 62: -: 63:static char *buf; -: 64: -: 65:static char * 12: 66:get_buf(void) -: 67:{ 12: 68: if (buf == NULL) 6: 69: buf = (char *)malloc(BUFSIZ); 12: 70: return (buf); -: 71:} -: 72: -: 73:/* -: 74: * Print reply error info -: 75: */ -: 76:char * 12: 77:clnt_sperror(CLIENT *rpch, char *s) -: 78:{ -: 79: struct rpc_err e; -: 80: void clnt_perrno(); -: 81: char *err; 12: 82: char *bufstart = get_buf(); 12: 83: char *str = bufstart; 12: 84: char *strstart = str; -: 85: char *strend; -: 86: 12: 87: if (str == 0) #####: 88: return (0); 12: 89: strend = str + BUFSIZ; 12: 90: CLNT_GETERR(rpch, &e); -: 91: 12: 92: strncpy (str, s, BUFSIZ - 1); 12: 93: str[BUFSIZ - 1] = 0; 12: 94: strncat (str, ": ", BUFSIZ - 1 - strlen (bufstart)); 12: 95: str += strlen(str); 12: 96: strncat (str, clnt_sperrno(e.re_status), BUFSIZ - 1 - strlen (bufstart)); 12: 97: strstart[BUFSIZ - 1] = '\0'; 12: 98: str += strlen(str); -: 99: 12: 100: switch (e.re_status) { -: 101: case RPC_SUCCESS: -: 102: case RPC_CANTENCODEARGS: -: 103: case RPC_CANTDECODERES: -: 104: case RPC_TIMEDOUT: -: 105: case RPC_PROGUNAVAIL: -: 106: case RPC_PROCUNAVAIL: -: 107: case RPC_CANTDECODEARGS: -: 108: case RPC_SYSTEMERROR: -: 109: case RPC_UNKNOWNHOST: -: 110: case RPC_UNKNOWNPROTO: -: 111: case RPC_PMAPFAILURE: -: 112: case RPC_PROGNOTREGISTERED: -: 113: case RPC_FAILED: 12: 114: break; -: 115: -: 116: case RPC_CANTSEND: -: 117: case RPC_CANTRECV: -: 118: /* 10 for the string */ #####: 119: if (str - bufstart + 10 + strlen(strerror(e.re_errno)) < BUFSIZ) #####: 120: (void) snprintf(str, strend-str, "; errno = %s", -: 121: strerror(e.re_errno)); #####: 122: str += strlen(str); #####: 123: break; -: 124: -: 125: case RPC_VERSMISMATCH: -: 126: /* 33 for the string, 22 for the numbers */ #####: 127: if(str - bufstart + 33 + 22 < BUFSIZ) #####: 128: (void) snprintf(str, strend-str, -: 129: "; low version = %lu, high version = %lu", -: 130: (u_long) e.re_vers.low, -: 131: (u_long) e.re_vers.high); #####: 132: str += strlen(str); #####: 133: break; -: 134: -: 135: case RPC_AUTHERROR: #####: 136: err = auth_errmsg(e.re_why); -: 137: /* 8 for the string */ #####: 138: if(str - bufstart + 8 < BUFSIZ) #####: 139: (void) snprintf(str, strend-str, "; why = "); #####: 140: str += strlen(str); #####: 141: if (err != NULL) { #####: 142: if(str - bufstart + strlen(err) < BUFSIZ) #####: 143: (void) snprintf(str, strend-str, "%s",err); -: 144: } else { -: 145: /* 33 for the string, 11 for the number */ #####: 146: if(str - bufstart + 33 + 11 < BUFSIZ) #####: 147: (void) snprintf(str, strend-str, -: 148: "(unknown authentication error - %d)", -: 149: (int) e.re_why); -: 150: } #####: 151: str += strlen(str); #####: 152: break; -: 153: -: 154: case RPC_PROGVERSMISMATCH: -: 155: /* 33 for the string, 22 for the numbers */ #####: 156: if(str - bufstart + 33 + 22 < BUFSIZ) #####: 157: (void) snprintf(str, strend-str, -: 158: "; low version = %lu, high version = %lu", -: 159: (u_long) e.re_vers.low, -: 160: (u_long) e.re_vers.high); #####: 161: str += strlen(str); #####: 162: break; -: 163: -: 164: default: /* unknown */ -: 165: /* 14 for the string, 22 for the numbers */ #####: 166: if(str - bufstart + 14 + 22 < BUFSIZ) #####: 167: (void) snprintf(str, strend-str, -: 168: "; s1 = %lu, s2 = %lu", -: 169: (u_long) e.re_lb.s1, -: 170: (u_long) e.re_lb.s2); #####: 171: str += strlen(str); -: 172: break; -: 173: } 12: 174: if (str - bufstart + 1 < BUFSIZ) 12: 175: (void) snprintf(str, strend-str, "\n"); 12: 176: return(strstart) ; -: 177:} -: 178: -: 179:void #####: 180:clnt_perror(CLIENT *rpch, char *s) -: 181:{ #####: 182: (void) fprintf(stderr,"%s",clnt_sperror(rpch,s)); #####: 183:} -: 184: -: 185: -: 186:struct rpc_errtab { -: 187: enum clnt_stat status; -: 188: char *message; -: 189:}; -: 190: -: 191:static struct rpc_errtab rpc_errlist[] = { -: 192: { RPC_SUCCESS, -: 193: "RPC: Success" }, -: 194: { RPC_CANTENCODEARGS, -: 195: "RPC: Can't encode arguments" }, -: 196: { RPC_CANTDECODERES, -: 197: "RPC: Can't decode result" }, -: 198: { RPC_CANTSEND, -: 199: "RPC: Unable to send" }, -: 200: { RPC_CANTRECV, -: 201: "RPC: Unable to receive" }, -: 202: { RPC_TIMEDOUT, -: 203: "RPC: Timed out" }, -: 204: { RPC_VERSMISMATCH, -: 205: "RPC: Incompatible versions of RPC" }, -: 206: { RPC_AUTHERROR, -: 207: "RPC: Authentication error" }, -: 208: { RPC_PROGUNAVAIL, -: 209: "RPC: Program unavailable" }, -: 210: { RPC_PROGVERSMISMATCH, -: 211: "RPC: Program/version mismatch" }, -: 212: { RPC_PROCUNAVAIL, -: 213: "RPC: Procedure unavailable" }, -: 214: { RPC_CANTDECODEARGS, -: 215: "RPC: Server can't decode arguments" }, -: 216: { RPC_SYSTEMERROR, -: 217: "RPC: Remote system error" }, -: 218: { RPC_UNKNOWNHOST, -: 219: "RPC: Unknown host" }, -: 220: { RPC_UNKNOWNPROTO, -: 221: "RPC: Unknown protocol" }, -: 222: { RPC_PMAPFAILURE, -: 223: "RPC: Port mapper failure" }, -: 224: { RPC_PROGNOTREGISTERED, -: 225: "RPC: Program not registered"}, -: 226: { RPC_FAILED, -: 227: "RPC: Failed (unspecified error)"} -: 228:}; -: 229: -: 230: -: 231:/* -: 232: * This interface for use by clntrpc -: 233: */ -: 234:char * 12: 235:clnt_sperrno(enum clnt_stat stat) -: 236:{ -: 237: unsigned int i; -: 238: 12: 239: for (i = 0; i < sizeof(rpc_errlist)/sizeof(struct rpc_errtab); i++) { 12: 240: if (rpc_errlist[i].status == stat) { 12: 241: return (rpc_errlist[i].message); -: 242: } -: 243: } #####: 244: return ("RPC: (unknown error code)"); -: 245:} -: 246: -: 247:void #####: 248:clnt_perrno(enum clnt_stat num) -: 249:{ #####: 250: (void) fprintf(stderr,"%s",clnt_sperrno(num)); #####: 251:} -: 252: -: 253: -: 254:char * #####: 255:clnt_spcreateerror(char *s) -: 256:{ #####: 257: char *str = get_buf(); -: 258: char *strend; -: 259: #####: 260: if (str == 0) #####: 261: return(0); #####: 262: strend = str+BUFSIZ; #####: 263: (void) snprintf(str, strend-str, "%s: ", s); #####: 264: str[BUFSIZ - 1] = '\0'; #####: 265: (void) strncat(str, clnt_sperrno(rpc_createerr.cf_stat), BUFSIZ - 1); #####: 266: switch (rpc_createerr.cf_stat) { -: 267: case RPC_PMAPFAILURE: #####: 268: (void) strncat(str, " - ", BUFSIZ - 1 - strlen(str)); #####: 269: (void) strncat(str, #####: 270: clnt_sperrno(rpc_createerr.cf_error.re_status), -: 271: BUFSIZ - 1 - strlen(str)); #####: 272: break; -: 273: -: 274: case RPC_SYSTEMERROR: #####: 275: (void) strncat(str, " - ", BUFSIZ - 1 - strlen(str)); -: 276: { #####: 277: const char *m = strerror(rpc_createerr.cf_error.re_errno); #####: 278: if (m) #####: 279: (void) strncat(str, m, BUFSIZ - 1 - strlen(str)); -: 280: else #####: 281: (void) snprintf(&str[strlen(str)], BUFSIZ - strlen(str), -: 282: "Error %d", -: 283: rpc_createerr.cf_error.re_errno); -: 284: } -: 285: break; -: 286: -: 287: case RPC_CANTSEND: -: 288: case RPC_CANTDECODERES: -: 289: case RPC_CANTENCODEARGS: -: 290: case RPC_SUCCESS: -: 291: case RPC_UNKNOWNPROTO: -: 292: case RPC_PROGNOTREGISTERED: -: 293: case RPC_FAILED: -: 294: case RPC_UNKNOWNHOST: -: 295: case RPC_CANTDECODEARGS: -: 296: case RPC_PROCUNAVAIL: -: 297: case RPC_PROGVERSMISMATCH: -: 298: case RPC_PROGUNAVAIL: -: 299: case RPC_AUTHERROR: -: 300: case RPC_VERSMISMATCH: -: 301: case RPC_TIMEDOUT: -: 302: case RPC_CANTRECV: -: 303: default: -: 304: break; -: 305: } #####: 306: (void) strncat(str, "\n", BUFSIZ - 1 - strlen(str)); #####: 307: return (str); -: 308:} -: 309: -: 310:void #####: 311:clnt_pcreateerror(char *s) -: 312:{ #####: 313: (void) fprintf(stderr,"%s",clnt_spcreateerror(s)); #####: 314:} -: 315: -: 316:struct auth_errtab { -: 317: enum auth_stat status; -: 318: char *message; -: 319:}; -: 320: -: 321:static struct auth_errtab auth_errlist[] = { -: 322: { AUTH_OK, -: 323: "Authentication OK" }, -: 324: { AUTH_BADCRED, -: 325: "Invalid client credential" }, -: 326: { AUTH_REJECTEDCRED, -: 327: "Server rejected credential" }, -: 328: { AUTH_BADVERF, -: 329: "Invalid client verifier" }, -: 330: { AUTH_REJECTEDVERF, -: 331: "Server rejected verifier" }, -: 332: { AUTH_TOOWEAK, -: 333: "Client credential too weak" }, -: 334: { AUTH_INVALIDRESP, -: 335: "Invalid server verifier" }, -: 336: { AUTH_FAILED, -: 337: "Failed (unspecified error)" }, -: 338:}; -: 339: -: 340:static char * #####: 341:auth_errmsg(enum auth_stat stat) -: 342:{ -: 343: unsigned int i; -: 344: #####: 345: for (i = 0; i < sizeof(auth_errlist)/sizeof(struct auth_errtab); i++) { #####: 346: if (auth_errlist[i].status == stat) { #####: 347: return(auth_errlist[i].message); -: 348: } -: 349: } #####: 350: return(NULL); -: 351:}