clnt_perror.c 6.6 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. #if 0
  48. static char *buf;
  49. static char *_buf()
  50. {
  51. if (buf == 0)
  52. buf = (char *) malloc(256);
  53. return (buf);
  54. }
  55. #endif
  56. /*
  57. * Print reply error info
  58. */
  59. char *clnt_sperror __P ((CLIENT *rpch, const 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. return (0);
  129. }
  130. void clnt_perror __P ((CLIENT *rpch, const char *s))
  131. {
  132. (void) fprintf(stderr, "%s", clnt_sperror(rpch, s));
  133. }
  134. struct rpc_errtab {
  135. enum clnt_stat status;
  136. char *message;
  137. };
  138. #if 0
  139. static struct rpc_errtab rpc_errlist[] = {
  140. {RPC_SUCCESS,
  141. "RPC: Success"},
  142. {RPC_CANTENCODEARGS,
  143. "RPC: Can't encode arguments"},
  144. {RPC_CANTDECODERES,
  145. "RPC: Can't decode result"},
  146. {RPC_CANTSEND,
  147. "RPC: Unable to send"},
  148. {RPC_CANTRECV,
  149. "RPC: Unable to receive"},
  150. {RPC_TIMEDOUT,
  151. "RPC: Timed out"},
  152. {RPC_VERSMISMATCH,
  153. "RPC: Incompatible versions of RPC"},
  154. {RPC_AUTHERROR,
  155. "RPC: Authentication error"},
  156. {RPC_PROGUNAVAIL,
  157. "RPC: Program unavailable"},
  158. {RPC_PROGVERSMISMATCH,
  159. "RPC: Program/version mismatch"},
  160. {RPC_PROCUNAVAIL,
  161. "RPC: Procedure unavailable"},
  162. {RPC_CANTDECODEARGS,
  163. "RPC: Server can't decode arguments"},
  164. {RPC_SYSTEMERROR,
  165. "RPC: Remote system error"},
  166. {RPC_UNKNOWNHOST,
  167. "RPC: Unknown host"},
  168. {RPC_UNKNOWNPROTO,
  169. "RPC: Unknown protocol"},
  170. {RPC_PMAPFAILURE,
  171. "RPC: Port mapper failure"},
  172. {RPC_PROGNOTREGISTERED,
  173. "RPC: Program not registered"},
  174. {RPC_FAILED,
  175. "RPC: Failed (unspecified error)"}
  176. };
  177. #endif
  178. /*
  179. * This interface for use by clntrpc
  180. */
  181. char *clnt_sperrno(stat)
  182. enum clnt_stat stat;
  183. {
  184. #if 0
  185. int i;
  186. for (i = 0; i < sizeof(rpc_errlist) / sizeof(struct rpc_errtab); i++) {
  187. if (rpc_errlist[i].status == stat) {
  188. return (rpc_errlist[i].message);
  189. }
  190. }
  191. #endif
  192. return ("RPC: (unknown error code)");
  193. }
  194. void clnt_perrno(num)
  195. enum clnt_stat num;
  196. {
  197. (void) fprintf(stderr, "%s", clnt_sperrno(num));
  198. }
  199. char *clnt_spcreateerror __P ((__const char *s))
  200. {
  201. #if 0
  202. extern int sys_nerr;
  203. extern char *sys_errlist[];
  204. char *str = _buf();
  205. if (str == 0)
  206. return (0);
  207. (void) sprintf(str, "%s: ", s);
  208. (void) strcat(str, clnt_sperrno(rpc_createerr.cf_stat));
  209. switch (rpc_createerr.cf_stat) {
  210. case RPC_PMAPFAILURE:
  211. (void) strcat(str, " - ");
  212. (void) strcat(str, clnt_sperrno(rpc_createerr.cf_error.re_status));
  213. break;
  214. case RPC_SYSTEMERROR:
  215. (void) strcat(str, " - ");
  216. if (rpc_createerr.cf_error.re_errno > 0
  217. && rpc_createerr.cf_error.re_errno < sys_nerr)
  218. (void) strcat(str,
  219. sys_errlist[rpc_createerr.cf_error.re_errno]);
  220. else
  221. (void) sprintf(&str[strlen(str)], "Error %d",
  222. rpc_createerr.cf_error.re_errno);
  223. break;
  224. }
  225. (void) strcat(str, "\n");
  226. return (str);
  227. #endif
  228. return(0);
  229. }
  230. extern void clnt_pcreateerror __P ((__const char *s))
  231. {
  232. (void) fprintf(stderr, "%s", clnt_spcreateerror(s));
  233. }
  234. struct auth_errtab {
  235. enum auth_stat status;
  236. char *message;
  237. };
  238. #if 0
  239. static struct auth_errtab auth_errlist[] = {
  240. {AUTH_OK,
  241. "Authentication OK"},
  242. {AUTH_BADCRED,
  243. "Invalid client credential"},
  244. {AUTH_REJECTEDCRED,
  245. "Server rejected credential"},
  246. {AUTH_BADVERF,
  247. "Invalid client verifier"},
  248. {AUTH_REJECTEDVERF,
  249. "Server rejected verifier"},
  250. {AUTH_TOOWEAK,
  251. "Client credential too weak"},
  252. {AUTH_INVALIDRESP,
  253. "Invalid server verifier"},
  254. {AUTH_FAILED,
  255. "Failed (unspecified error)"},
  256. };
  257. static char *auth_errmsg(stat)
  258. enum auth_stat stat;
  259. {
  260. int i;
  261. for (i = 0; i < sizeof(auth_errlist) / sizeof(struct auth_errtab); i++) {
  262. if (auth_errlist[i].status == stat) {
  263. return (auth_errlist[i].message);
  264. }
  265. }
  266. return (NULL);
  267. }
  268. #endif