clnt_perror.c 6.3 KB

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