clnt_perror.c 6.5 KB

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