clnt.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /* @(#)clnt.h 2.1 88/07/29 4.0 RPCSRC; from 1.31 88/02/08 SMI*/
  2. /*
  3. * Copyright (c) 2010, Oracle America, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. *
  13. * * Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. *
  18. * * Neither the name of the "Oracle America, Inc." nor the names of
  19. * its contributors may be used to endorse or promote products
  20. * derived from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  24. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  25. * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  26. * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  27. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  28. * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  31. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. /*
  35. * clnt.h - Client side remote procedure call interface.
  36. */
  37. #ifndef GSSRPC_CLNT_H
  38. #define GSSRPC_CLNT_H
  39. GSSRPC__BEGIN_DECLS
  40. /*
  41. * Rpc calls return an enum clnt_stat. This should be looked at more,
  42. * since each implementation is required to live with this (implementation
  43. * independent) list of errors.
  44. */
  45. enum clnt_stat {
  46. RPC_SUCCESS=0, /* call succeeded */
  47. /*
  48. * local errors
  49. */
  50. RPC_CANTENCODEARGS=1, /* can't encode arguments */
  51. RPC_CANTDECODERES=2, /* can't decode results */
  52. RPC_CANTSEND=3, /* failure in sending call */
  53. RPC_CANTRECV=4, /* failure in receiving result */
  54. RPC_TIMEDOUT=5, /* call timed out */
  55. /*
  56. * remote errors
  57. */
  58. RPC_VERSMISMATCH=6, /* rpc versions not compatible */
  59. RPC_AUTHERROR=7, /* authentication error */
  60. RPC_PROGUNAVAIL=8, /* program not available */
  61. RPC_PROGVERSMISMATCH=9, /* program version mismatched */
  62. RPC_PROCUNAVAIL=10, /* procedure unavailable */
  63. RPC_CANTDECODEARGS=11, /* decode arguments error */
  64. RPC_SYSTEMERROR=12, /* generic "other problem" */
  65. /*
  66. * callrpc & clnt_create errors
  67. */
  68. RPC_UNKNOWNHOST=13, /* unknown host name */
  69. RPC_UNKNOWNPROTO=17, /* unknown protocol */
  70. /*
  71. * _ create errors
  72. */
  73. RPC_PMAPFAILURE=14, /* the pmapper failed in its call */
  74. RPC_PROGNOTREGISTERED=15, /* remote program is not registered */
  75. /*
  76. * unspecified error
  77. */
  78. RPC_FAILED=16
  79. };
  80. /*
  81. * Error info.
  82. */
  83. struct rpc_err {
  84. enum clnt_stat re_status;
  85. union {
  86. int RE_errno; /* realated system error */
  87. enum auth_stat RE_why; /* why the auth error occurred */
  88. struct {
  89. rpcvers_t low; /* lowest version supported */
  90. rpcvers_t high; /* highest version supported */
  91. } RE_vers;
  92. struct { /* maybe meaningful if RPC_FAILED */
  93. int32_t s1;
  94. int32_t s2;
  95. } RE_lb; /* life boot & debugging only */
  96. } ru;
  97. #define re_errno ru.RE_errno
  98. #define re_why ru.RE_why
  99. #define re_vers ru.RE_vers
  100. #define re_lb ru.RE_lb
  101. };
  102. /*
  103. * Client rpc handle.
  104. * Created by individual implementations, see e.g. rpc_udp.c.
  105. * Client is responsible for initializing auth, see e.g. auth_none.c.
  106. */
  107. typedef struct CLIENT {
  108. AUTH *cl_auth; /* authenticator */
  109. struct clnt_ops {
  110. /* call remote procedure */
  111. enum clnt_stat (*cl_call)(struct CLIENT *,
  112. rpcproc_t, xdrproc_t, void *,
  113. xdrproc_t, void *,
  114. struct timeval);
  115. /* abort a call */
  116. void (*cl_abort)(struct CLIENT *);
  117. /* get specific error code */
  118. void (*cl_geterr)(struct CLIENT *,
  119. struct rpc_err *);
  120. /* frees results */
  121. bool_t (*cl_freeres)(struct CLIENT *,
  122. xdrproc_t, void *);
  123. /* destroy this structure */
  124. void (*cl_destroy)(struct CLIENT *);
  125. /* the ioctl() of rpc */
  126. /* XXX CITI makes 2nd arg take u_int */
  127. bool_t (*cl_control)(struct CLIENT *, int,
  128. void *);
  129. } *cl_ops;
  130. void *cl_private; /* private stuff */
  131. } CLIENT;
  132. /*
  133. * client side rpc interface ops
  134. *
  135. * Parameter types are:
  136. *
  137. */
  138. /*
  139. * enum clnt_stat
  140. * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
  141. * CLIENT *rh;
  142. * rpcproc_t proc;
  143. * xdrproc_t xargs;
  144. * caddr_t argsp;
  145. * xdrproc_t xres;
  146. * caddr_t resp;
  147. * struct timeval timeout;
  148. */
  149. #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
  150. ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  151. #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
  152. ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  153. /*
  154. * void
  155. * CLNT_ABORT(rh);
  156. * CLIENT *rh;
  157. */
  158. #define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh))
  159. #define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh))
  160. /*
  161. * struct rpc_err
  162. * CLNT_GETERR(rh);
  163. * CLIENT *rh;
  164. */
  165. #define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  166. #define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  167. /*
  168. * bool_t
  169. * CLNT_FREERES(rh, xres, resp);
  170. * CLIENT *rh;
  171. * xdrproc_t xres;
  172. * caddr_t resp;
  173. */
  174. #define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  175. #define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  176. /*
  177. * bool_t
  178. * CLNT_CONTROL(cl, request, info)
  179. * CLIENT *cl;
  180. * u_int request;
  181. * char *info;
  182. */
  183. #define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  184. #define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  185. /*
  186. * control operations that apply to both udp and tcp transports
  187. */
  188. #define CLSET_TIMEOUT 1 /* set timeout (timeval) */
  189. #define CLGET_TIMEOUT 2 /* get timeout (timeval) */
  190. #define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */
  191. /*
  192. * udp only control operations
  193. */
  194. #define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */
  195. #define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */
  196. /*
  197. * new control operations
  198. */
  199. #define CLGET_LOCAL_ADDR 6 /* get local address (sockaddr, getsockname)*/
  200. /*
  201. * void
  202. * CLNT_DESTROY(rh);
  203. * CLIENT *rh;
  204. */
  205. #define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
  206. #define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
  207. /*
  208. * RPCTEST is a test program which is accessible on every rpc
  209. * transport/port. It is used for testing, performance evaluation,
  210. * and network administration.
  211. */
  212. #define RPCTEST_PROGRAM ((rpcprog_t)1)
  213. #define RPCTEST_VERSION ((rpcvers_t)1)
  214. #define RPCTEST_NULL_PROC ((rpcproc_t)2)
  215. #define RPCTEST_NULL_BATCH_PROC ((rpcproc_t)3)
  216. /*
  217. * By convention, procedure 0 takes null arguments and returns them
  218. */
  219. #define NULLPROC ((rpcproc_t)0)
  220. /*
  221. * Below are the client handle creation routines for the various
  222. * implementations of client side rpc. They can return NULL if a
  223. * creation failure occurs.
  224. */
  225. /*
  226. * Memory based rpc (for speed check and testing)
  227. * CLIENT *
  228. * clntraw_create(prog, vers)
  229. * rpcprog_t prog;
  230. * rpcvers_t vers;
  231. */
  232. extern CLIENT *clntraw_create(rpcprog_t, rpcvers_t);
  233. /*
  234. * Generic client creation routine. Supported protocols are "udp" and "tcp"
  235. */
  236. extern CLIENT *clnt_create(char *, rpcprog_t, rpcvers_t, char *);
  237. /*
  238. * TCP based rpc
  239. * CLIENT *
  240. * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
  241. * struct sockaddr_in *raddr;
  242. * rpcprog_t prog;
  243. * rpcvers_t version;
  244. * int *sockp;
  245. * u_int sendsz;
  246. * u_int recvsz;
  247. */
  248. extern CLIENT *clnttcp_create(struct sockaddr_in *, rpcprog_t, rpcvers_t,
  249. int *, u_int, u_int);
  250. /*
  251. * UDP based rpc.
  252. * CLIENT *
  253. * clntudp_create(raddr, program, version, wait, sockp)
  254. * struct sockaddr_in *raddr;
  255. * rpcprog_t program;
  256. * rpcvers_t version;
  257. * struct timeval wait;
  258. * int *sockp;
  259. *
  260. * Same as above, but you specify max packet sizes.
  261. * CLIENT *
  262. * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
  263. * struct sockaddr_in *raddr;
  264. * rpcprog_t program;
  265. * rpcvers_t version;
  266. * struct timeval wait;
  267. * int *sockp;
  268. * u_int sendsz;
  269. * u_int recvsz;
  270. */
  271. extern CLIENT *clntudp_create(struct sockaddr_in *, rpcprog_t,
  272. rpcvers_t, struct timeval, int *);
  273. extern CLIENT *clntudp_bufcreate(struct sockaddr_in *, rpcprog_t,
  274. rpcvers_t, struct timeval, int *,
  275. u_int, u_int);
  276. /*
  277. * Print why creation failed
  278. */
  279. void clnt_pcreateerror(char *); /* stderr */
  280. char *clnt_spcreateerror(char *); /* string */
  281. /*
  282. * Like clnt_perror(), but is more verbose in its output
  283. */
  284. void clnt_perrno(enum clnt_stat); /* stderr */
  285. /*
  286. * Print an English error message, given the client error code
  287. */
  288. void clnt_perror(CLIENT *, char *); /* stderr */
  289. char *clnt_sperror(CLIENT *, char *); /* string */
  290. /*
  291. * If a creation fails, the following allows the user to figure out why.
  292. */
  293. struct rpc_createerr {
  294. enum clnt_stat cf_stat;
  295. struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
  296. };
  297. extern struct rpc_createerr rpc_createerr;
  298. /*
  299. * Copy error message to buffer.
  300. */
  301. char *clnt_sperrno(enum clnt_stat num); /* string */
  302. #define UDPMSGSIZE 8800 /* rpc imposed limit on udp msg size */
  303. #define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */
  304. GSSRPC__END_DECLS
  305. #endif /* !defined(GSSRPC_CLNT_H) */