clnt_perror.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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[] =
  32. "@(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro";
  33. #endif
  34. /*
  35. * clnt_perror.c
  36. *
  37. * Copyright (C) 1984, Sun Microsystems, Inc.
  38. *
  39. */
  40. #include <stdio.h>
  41. #include <rpc/types.h>
  42. #include <rpc/auth.h>
  43. #include <rpc/clnt.h>
  44. extern char *sys_errlist[];
  45. static char *auth_errmsg();
  46. extern char *strcpy();
  47. static char *buf;
  48. static char *_buf()
  49. {
  50. if (buf == 0)
  51. buf = (char *) malloc(256);
  52. return (buf);
  53. }
  54. /*
  55. * Print reply error info
  56. */
  57. char *clnt_sperror(rpch, s)
  58. CLIENT *rpch;
  59. char *s;
  60. {
  61. #if 0
  62. struct rpc_err e;
  63. void clnt_perrno();
  64. char *err;
  65. char *str = _buf();
  66. char *strstart = str;
  67. if (str == 0)
  68. return (0);
  69. CLNT_GETERR(rpch, &e);
  70. (void) sprintf(str, "%s: ", s);
  71. str += strlen(str);
  72. (void) strcpy(str, clnt_sperrno(e.re_status));
  73. str += strlen(str);
  74. switch (e.re_status) {
  75. case RPC_SUCCESS:
  76. case RPC_CANTENCODEARGS:
  77. case RPC_CANTDECODERES:
  78. case RPC_TIMEDOUT:
  79. case RPC_PROGUNAVAIL:
  80. case RPC_PROCUNAVAIL:
  81. case RPC_CANTDECODEARGS:
  82. case RPC_SYSTEMERROR:
  83. case RPC_UNKNOWNHOST:
  84. case RPC_UNKNOWNPROTO:
  85. case RPC_PMAPFAILURE:
  86. case RPC_PROGNOTREGISTERED:
  87. case RPC_FAILED:
  88. break;
  89. case RPC_CANTSEND:
  90. case RPC_CANTRECV:
  91. (void) sprintf(str, "; errno = %s", sys_errlist[e.re_errno]);
  92. str += strlen(str);
  93. break;
  94. case RPC_VERSMISMATCH:
  95. (void) sprintf(str,
  96. "; low version = %lu, high version = %lu",
  97. e.re_vers.low, e.re_vers.high);
  98. str += strlen(str);
  99. break;
  100. case RPC_AUTHERROR:
  101. err = auth_errmsg(e.re_why);
  102. (void) sprintf(str, "; why = ");
  103. str += strlen(str);
  104. if (err != NULL) {
  105. (void) sprintf(str, "%s", err);
  106. } else {
  107. (void) sprintf(str,
  108. "(unknown authentication error - %d)",
  109. (int) e.re_why);
  110. }
  111. str += strlen(str);
  112. break;
  113. case RPC_PROGVERSMISMATCH:
  114. (void) sprintf(str,
  115. "; low version = %lu, high version = %lu",
  116. e.re_vers.low, e.re_vers.high);
  117. str += strlen(str);
  118. break;
  119. default: /* unknown */
  120. (void) sprintf(str,
  121. "; s1 = %lu, s2 = %lu", e.re_lb.s1, e.re_lb.s2);
  122. str += strlen(str);
  123. break;
  124. }
  125. (void) sprintf(str, "\n");
  126. return (strstart);
  127. #endif
  128. }
  129. void clnt_perror(rpch, s)
  130. CLIENT *rpch;
  131. char *s;
  132. {
  133. (void) fprintf(stderr, "%s", clnt_sperror(rpch, s));
  134. }
  135. struct rpc_errtab {
  136. enum clnt_stat status;
  137. char *message;
  138. };
  139. #if 0
  140. static struct rpc_errtab rpc_errlist[] = {
  141. {RPC_SUCCESS,
  142. "RPC: Success"},
  143. {RPC_CANTENCODEARGS,
  144. "RPC: Can't encode arguments"},
  145. {RPC_CANTDECODERES,
  146. "RPC: Can't decode result"},
  147. {RPC_CANTSEND,
  148. "RPC: Unable to send"},
  149. {RPC_CANTRECV,
  150. "RPC: Unable to receive"},
  151. {RPC_TIMEDOUT,
  152. "RPC: Timed out"},
  153. {RPC_VERSMISMATCH,
  154. "RPC: Incompatible versions of RPC"},
  155. {RPC_AUTHERROR,
  156. "RPC: Authentication error"},
  157. {RPC_PROGUNAVAIL,
  158. "RPC: Program unavailable"},
  159. {RPC_PROGVERSMISMATCH,
  160. "RPC: Program/version mismatch"},
  161. {RPC_PROCUNAVAIL,
  162. "RPC: Procedure unavailable"},
  163. {RPC_CANTDECODEARGS,
  164. "RPC: Server can't decode arguments"},
  165. {RPC_SYSTEMERROR,
  166. "RPC: Remote system error"},
  167. {RPC_UNKNOWNHOST,
  168. "RPC: Unknown host"},
  169. {RPC_UNKNOWNPROTO,
  170. "RPC: Unknown protocol"},
  171. {RPC_PMAPFAILURE,
  172. "RPC: Port mapper failure"},
  173. {RPC_PROGNOTREGISTERED,
  174. "RPC: Program not registered"},
  175. {RPC_FAILED,
  176. "RPC: Failed (unspecified error)"}
  177. };
  178. #endif
  179. /*
  180. * This interface for use by clntrpc
  181. */
  182. char *clnt_sperrno(stat)
  183. enum clnt_stat stat;
  184. {
  185. #if 0
  186. int i;
  187. for (i = 0; i < sizeof(rpc_errlist) / sizeof(struct rpc_errtab); i++) {
  188. if (rpc_errlist[i].status == stat) {
  189. return (rpc_errlist[i].message);
  190. }
  191. }
  192. #endif
  193. return ("RPC: (unknown error code)");
  194. }
  195. void clnt_perrno(num)
  196. enum clnt_stat num;
  197. {
  198. (void) fprintf(stderr, "%s", clnt_sperrno(num));
  199. }
  200. char *clnt_spcreateerror(s)
  201. char *s;
  202. {
  203. #if 0
  204. extern int sys_nerr;
  205. extern char *sys_errlist[];
  206. char *str = _buf();
  207. if (str == 0)
  208. return (0);
  209. (void) sprintf(str, "%s: ", s);
  210. (void) strcat(str, clnt_sperrno(rpc_createerr.cf_stat));
  211. switch (rpc_createerr.cf_stat) {
  212. case RPC_PMAPFAILURE:
  213. (void) strcat(str, " - ");
  214. (void) strcat(str, clnt_sperrno(rpc_createerr.cf_error.re_status));
  215. break;
  216. case RPC_SYSTEMERROR:
  217. (void) strcat(str, " - ");
  218. if (rpc_createerr.cf_error.re_errno > 0
  219. && rpc_createerr.cf_error.re_errno < sys_nerr)
  220. (void) strcat(str,
  221. sys_errlist[rpc_createerr.cf_error.re_errno]);
  222. else
  223. (void) sprintf(&str[strlen(str)], "Error %d",
  224. rpc_createerr.cf_error.re_errno);
  225. break;
  226. }
  227. (void) strcat(str, "\n");
  228. return (str);
  229. #endif
  230. }
  231. void clnt_pcreateerror(s)
  232. char *s;
  233. {
  234. (void) fprintf(stderr, "%s", clnt_spcreateerror(s));
  235. }
  236. struct auth_errtab {
  237. enum auth_stat status;
  238. char *message;
  239. };
  240. static struct auth_errtab auth_errlist[] = {
  241. {AUTH_OK,
  242. "Authentication OK"},
  243. {AUTH_BADCRED,
  244. "Invalid client credential"},
  245. {AUTH_REJECTEDCRED,
  246. "Server rejected credential"},
  247. {AUTH_BADVERF,
  248. "Invalid client verifier"},
  249. {AUTH_REJECTEDVERF,
  250. "Server rejected verifier"},
  251. {AUTH_TOOWEAK,
  252. "Client credential too weak"},
  253. {AUTH_INVALIDRESP,
  254. "Invalid server verifier"},
  255. {AUTH_FAILED,
  256. "Failed (unspecified error)"},
  257. };
  258. static char *auth_errmsg(stat)
  259. enum auth_stat stat;
  260. {
  261. int i;
  262. for (i = 0; i < sizeof(auth_errlist) / sizeof(struct auth_errtab); i++) {
  263. if (auth_errlist[i].status == stat) {
  264. return (auth_errlist[i].message);
  265. }
  266. }
  267. return (NULL);
  268. }