clnt_perror.c 6.5 KB

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