home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / d / libc / libc-4.6 / libc-4 / libc-linux / rpc / clnt_perror.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-30  |  8.0 KB  |  383 lines

  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. /*
  35.  * clnt_perror.c
  36.  *
  37.  * Copyright (C) 1984, Sun Microsystems, Inc.
  38.  *
  39.  */
  40. #include <stdio.h>
  41. #include <errno.h>
  42.  
  43. #include <rpc/rpc.h>
  44.  
  45. #ifdef __STDC__
  46. #include <stdlib.h>
  47. #endif
  48.  
  49. #ifdef __linux__
  50. #include <string.h>
  51. #else
  52. extern char *sys_errlist[];
  53. extern char *sprintf();
  54. extern char *strcpy();
  55. #endif
  56. static char *auth_errmsg();
  57. #if NLS
  58. #include "nl_types.h"
  59. #endif
  60.  
  61. static char *buf;
  62.  
  63. static char *
  64. _buf()
  65. {
  66.  
  67.     if (buf == 0)
  68.         buf = (char *)malloc(256);
  69.     return (buf);
  70. }
  71.  
  72. /*
  73.  * Print reply error info
  74.  */
  75. char *
  76. clnt_sperror(rpch, s)
  77.     CLIENT *rpch;
  78.     __const char *s;
  79. {
  80.     struct rpc_err e;
  81.     void clnt_perrno();
  82.     char *err;
  83.     char *str = _buf();
  84.     char *strstart = str;
  85.  
  86.     if (str == 0)
  87.         return (0);
  88.     CLNT_GETERR(rpch, &e);
  89.  
  90.     (void) sprintf(str, "%s: ", s);  
  91.     str += strlen(str);
  92.  
  93.     (void) strcpy(str, clnt_sperrno(e.re_status));  
  94.     str += strlen(str);
  95.  
  96. #if NLS
  97.     libc_nls_init();
  98. #endif
  99.  
  100.     switch (e.re_status) {
  101.     case RPC_SUCCESS:
  102.     case RPC_CANTENCODEARGS:
  103.     case RPC_CANTDECODERES:
  104.     case RPC_TIMEDOUT:     
  105.     case RPC_PROGUNAVAIL:
  106.     case RPC_PROCUNAVAIL:
  107.     case RPC_CANTDECODEARGS:
  108.     case RPC_SYSTEMERROR:
  109.     case RPC_UNKNOWNHOST:
  110.     case RPC_UNKNOWNPROTO:
  111.     case RPC_PMAPFAILURE:
  112.     case RPC_PROGNOTREGISTERED:
  113.     case RPC_FAILED:
  114.         break;
  115.  
  116.     case RPC_CANTSEND:
  117.     case RPC_CANTRECV:
  118.         (void) sprintf(str,
  119. #if NLS
  120.                    catgets(_libc_cat, ClntMiscSet, ClntMiscErrno,
  121.                        "; errno = %s"),
  122. #else
  123.                    "; errno = %s",
  124. #endif
  125.  
  126. #if NLS
  127.             catgets(_libc_cat, ErrorListSet, e.re_errno+1,
  128.             sys_errlist[e.re_errno]));
  129. #else
  130.             sys_errlist[e.re_errno]); 
  131. #endif
  132.         str += strlen(str);
  133.         break;
  134.  
  135.     case RPC_VERSMISMATCH:
  136.         (void) sprintf(str,
  137. #if NLS
  138.                catgets(_libc_cat, ClntMiscSet, ClntMiscLowHigh,
  139.                    "; low version = %lu, high version = %lu"), 
  140. #else
  141.             "; low version = %lu, high version = %lu", 
  142. #endif
  143.             e.re_vers.low, e.re_vers.high);
  144.         str += strlen(str);
  145.         break;
  146.  
  147.     case RPC_AUTHERROR:
  148.         err = auth_errmsg(e.re_why);
  149.         (void) sprintf(str,
  150. #if NLS
  151.                    catgets(_libc_cat, ClntMiscSet, ClntMiscWhy,
  152.                        "; why = "));
  153. #else
  154.                    "; why = ");
  155. #endif
  156.         str += strlen(str);
  157.         if (err != NULL) {
  158.             (void) sprintf(str, "%s",err);
  159.         } else {
  160.             (void) sprintf(str,
  161. #if NLS
  162.                 catgets (_libc_cat, ClntMiscSet, ClntMiscUnknownAuth,
  163.                      "(unknown authentication error - %d)"),
  164. #else
  165.                 "(unknown authentication error - %d)",
  166. #endif
  167.                 (int) e.re_why);
  168.         }
  169.         str += strlen(str);
  170.         break;
  171.  
  172.     case RPC_PROGVERSMISMATCH:
  173.         (void) sprintf(str, 
  174. #if NLS
  175.                catgets(_libc_cat, ClntMiscSet, ClntMiscLowHigh,
  176.                    "; low version = %lu, high version = %lu"), 
  177. #else
  178.             "; low version = %lu, high version = %lu", 
  179. #endif
  180.             e.re_vers.low, e.re_vers.high);
  181.         str += strlen(str);
  182.         break;
  183.  
  184.     default:    /* unknown */
  185.         (void) sprintf(str, 
  186.             "; s1 = %lu, s2 = %lu", 
  187.             e.re_lb.s1, e.re_lb.s2);
  188.         str += strlen(str);
  189.         break;
  190.     }
  191.     (void) sprintf(str, "\n");
  192.     return(strstart) ;
  193. }
  194.  
  195. void
  196. clnt_perror(rpch, s)
  197.     CLIENT *rpch;
  198.     __const char *s;
  199. {
  200.     (void) fprintf(stderr,"%s",clnt_sperror(rpch,s));
  201. }
  202.  
  203.  
  204. struct rpc_errtab {
  205.     enum clnt_stat status;
  206.     char *message;
  207. };
  208.  
  209. static struct rpc_errtab  rpc_errlist[] = {
  210.     { RPC_SUCCESS, 
  211.         "RPC: Success" }, 
  212.     { RPC_CANTENCODEARGS, 
  213.         "RPC: Can't encode arguments" },
  214.     { RPC_CANTDECODERES, 
  215.         "RPC: Can't decode result" },
  216.     { RPC_CANTSEND, 
  217.         "RPC: Unable to send" },
  218.     { RPC_CANTRECV, 
  219.         "RPC: Unable to receive" },
  220.     { RPC_TIMEDOUT, 
  221.         "RPC: Timed out" },
  222.     { RPC_VERSMISMATCH, 
  223.         "RPC: Incompatible versions of RPC" },
  224.     { RPC_AUTHERROR, 
  225.         "RPC: Authentication error" },
  226.     { RPC_PROGUNAVAIL, 
  227.         "RPC: Program unavailable" },
  228.     { RPC_PROGVERSMISMATCH, 
  229.         "RPC: Program/version mismatch" },
  230.     { RPC_PROCUNAVAIL, 
  231.         "RPC: Procedure unavailable" },
  232.     { RPC_CANTDECODEARGS, 
  233.         "RPC: Server can't decode arguments" },
  234.     { RPC_SYSTEMERROR, 
  235.         "RPC: Remote system error" },
  236.     { RPC_UNKNOWNHOST, 
  237.         "RPC: Unknown host" },
  238.     { RPC_UNKNOWNPROTO,
  239.         "RPC: Unknown protocol" },
  240.     { RPC_PMAPFAILURE, 
  241.         "RPC: Port mapper failure" },
  242.     { RPC_PROGNOTREGISTERED, 
  243.         "RPC: Program not registered"},
  244.     { RPC_FAILED, 
  245.         "RPC: Failed (unspecified error)"}
  246. };
  247.  
  248.  
  249. /*
  250.  * This interface for use by clntrpc
  251.  */
  252. char *
  253. clnt_sperrno(stat)
  254.     enum clnt_stat stat;
  255. {
  256.     int i;
  257.  
  258. #if NLS
  259.     libc_nls_init();
  260. #endif
  261.     for (i = 0; i < sizeof(rpc_errlist)/sizeof(struct rpc_errtab); i++) {
  262.         if (rpc_errlist[i].status == stat) {
  263. #if NLS
  264.             return catgets(_libc_cat, RpcErrListSet, stat+1, rpc_errlist[i].message);
  265. #else
  266.             return (rpc_errlist[i].message);
  267. #endif
  268.         }
  269.     }
  270. #if NLS
  271.     return catgets(_libc_cat, RpcErrListSet, RpcErrListUnknown,
  272.             "RPC: (unknown error code)");
  273. #else
  274.     return ("RPC: (unknown error code)");
  275. #endif
  276. }
  277.  
  278. void
  279. clnt_perrno(num)
  280.     enum clnt_stat num;
  281. {
  282.     (void) fprintf(stderr,"%s",clnt_sperrno(num));
  283. }
  284.  
  285.  
  286. char *
  287. clnt_spcreateerror(s)
  288.     __const char *s;
  289. {
  290. #ifndef __linux__
  291.     extern int sys_nerr;
  292.     extern char *sys_errlist[];
  293. #endif
  294.     char *str = _buf();
  295.  
  296.     if (str == 0)
  297.         return(0);
  298. #if NLS
  299.     libc_nls_init();
  300. #endif
  301.     (void) sprintf(str, "%s: ", s);
  302.     (void) strcat(str, clnt_sperrno(rpc_createerr.cf_stat));
  303.     switch (rpc_createerr.cf_stat) {
  304.     case RPC_PMAPFAILURE:
  305.         (void) strcat(str, " - ");
  306.         (void) strcat(str,
  307.             clnt_sperrno(rpc_createerr.cf_error.re_status));
  308.         break;
  309.  
  310.     case RPC_SYSTEMERROR:
  311.         (void) strcat(str, " - ");
  312.         if (rpc_createerr.cf_error.re_errno > 0
  313.             && rpc_createerr.cf_error.re_errno < sys_nerr)
  314.             (void) strcat(str,
  315. #if NLS
  316.             catgets(_libc_cat, ErrorListSet,
  317.                 rpc_createerr.cf_error.re_errno+1,
  318.                 sys_errlist[rpc_createerr.cf_error.re_errno]));
  319. #else
  320.                 sys_errlist[rpc_createerr.cf_error.re_errno]);
  321. #endif
  322.         else
  323.             (void) sprintf(&str[strlen(str)], "Error %d",
  324.                 rpc_createerr.cf_error.re_errno);
  325.         break;
  326.     }
  327.     (void) strcat(str, "\n");
  328.     return (str);
  329. }
  330.  
  331. void
  332. clnt_pcreateerror(s)
  333.     __const char *s;
  334. {
  335.     (void) fprintf(stderr,"%s",clnt_spcreateerror(s));
  336. }
  337.  
  338. struct auth_errtab {
  339.     enum auth_stat status;    
  340.     char *message;
  341. };
  342.  
  343. static struct auth_errtab auth_errlist[] = {
  344.     { AUTH_OK,
  345.         "Authentication OK" },
  346.     { AUTH_BADCRED,
  347.         "Invalid client credential" },
  348.     { AUTH_REJECTEDCRED,
  349.         "Server rejected credential" },
  350.     { AUTH_BADVERF,
  351.         "Invalid client verifier" },
  352.     { AUTH_REJECTEDVERF,
  353.         "Server rejected verifier" },
  354.     { AUTH_TOOWEAK,
  355.         "Client credential too weak" },
  356.     { AUTH_INVALIDRESP,
  357.         "Invalid server verifier" },
  358.     { AUTH_FAILED,
  359.         "Failed (unspecified error)" },
  360. };
  361.  
  362. static char *
  363. auth_errmsg(stat)
  364.     enum auth_stat stat;
  365. {
  366.     int i;
  367.  
  368. #if NLS
  369.     libc_nls_init();
  370. #endif
  371.     for (i = 0; i < sizeof(auth_errlist)/sizeof(struct auth_errtab); i++) {
  372.         if (auth_errlist[i].status == stat) {
  373. #if NLS
  374.             return catgets(_libc_cat, AuthListSet, i+1,
  375.                        auth_errlist[i].message);
  376. #else
  377.             return(auth_errlist[i].message);
  378. #endif
  379.         }
  380.     }
  381.     return(NULL);
  382. }
  383.