svc.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /* @(#)svc.h 2.2 88/07/29 4.0 RPCSRC; from 1.20 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. * svc.h, Server-side remote procedure call interface.
  36. */
  37. #ifndef GSSRPC_SVC_H
  38. #define GSSRPC_SVC_H
  39. #include <gssrpc/svc_auth.h>
  40. GSSRPC__BEGIN_DECLS
  41. /*
  42. * This interface must manage two items concerning remote procedure calling:
  43. *
  44. * 1) An arbitrary number of transport connections upon which rpc requests
  45. * are received. The two most notable transports are TCP and UDP; they are
  46. * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
  47. * they in turn call xprt_register and xprt_unregister.
  48. *
  49. * 2) An arbitrary number of locally registered services. Services are
  50. * described by the following four data: program number, version number,
  51. * "service dispatch" function, a transport handle, and a boolean that
  52. * indicates whether or not the exported program should be registered with a
  53. * local binder service; if true the program's number and version and the
  54. * port number from the transport handle are registered with the binder.
  55. * These data are registered with the rpc svc system via svc_register.
  56. *
  57. * A service's dispatch function is called whenever an rpc request comes in
  58. * on a transport. The request's program and version numbers must match
  59. * those of the registered service. The dispatch function is passed two
  60. * parameters, struct svc_req * and SVCXPRT *, defined below.
  61. */
  62. enum xprt_stat {
  63. XPRT_DIED,
  64. XPRT_MOREREQS,
  65. XPRT_IDLE
  66. };
  67. /*
  68. * Server side transport handle
  69. */
  70. typedef struct SVCXPRT {
  71. #ifdef _WIN32
  72. SOCKET xp_sock;
  73. #else
  74. int xp_sock;
  75. #endif
  76. u_short xp_port; /* associated port number */
  77. struct xp_ops {
  78. /* receive incomming requests */
  79. bool_t (*xp_recv)(struct SVCXPRT *, struct rpc_msg *);
  80. /* get transport status */
  81. enum xprt_stat (*xp_stat)(struct SVCXPRT *);
  82. /* get arguments */
  83. bool_t (*xp_getargs)(struct SVCXPRT *, xdrproc_t,
  84. void *);
  85. /* send reply */
  86. bool_t (*xp_reply)(struct SVCXPRT *,
  87. struct rpc_msg *);
  88. /* free mem allocated for args */
  89. bool_t (*xp_freeargs)(struct SVCXPRT *, xdrproc_t,
  90. void *);
  91. /* destroy this struct */
  92. void (*xp_destroy)(struct SVCXPRT *);
  93. } *xp_ops;
  94. int xp_addrlen; /* length of remote address */
  95. struct sockaddr_in xp_raddr; /* remote address */
  96. struct opaque_auth xp_verf; /* raw response verifier */
  97. SVCAUTH *xp_auth; /* auth flavor of current req */
  98. void *xp_p1; /* private */
  99. void *xp_p2; /* private */
  100. int xp_laddrlen; /* lenght of local address */
  101. struct sockaddr_in xp_laddr; /* local address */
  102. } SVCXPRT;
  103. /*
  104. * Approved way of getting address of caller
  105. */
  106. #define svc_getcaller(x) (&(x)->xp_raddr)
  107. /*
  108. * Operations defined on an SVCXPRT handle
  109. *
  110. * SVCXPRT *xprt;
  111. * struct rpc_msg *msg;
  112. * xdrproc_t xargs;
  113. * caddr_t argsp;
  114. */
  115. #define SVC_RECV(xprt, msg) \
  116. (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  117. #define svc_recv(xprt, msg) \
  118. (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  119. #define SVC_STAT(xprt) \
  120. (*(xprt)->xp_ops->xp_stat)(xprt)
  121. #define svc_stat(xprt) \
  122. (*(xprt)->xp_ops->xp_stat)(xprt)
  123. #define SVC_GETARGS(xprt, xargs, argsp) \
  124. (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  125. #define svc_getargs(xprt, xargs, argsp) \
  126. (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  127. #define SVC_GETARGS_REQ(xprt, req, xargs, argsp) \
  128. (*(xprt)->xp_ops->xp_getargs_req)((xprt), (req), (xargs), (argsp))
  129. #define svc_getargs_req(xprt, req, xargs, argsp) \
  130. (*(xprt)->xp_ops->xp_getargs_req)((xprt), (req), (xargs), (argsp))
  131. #define SVC_REPLY(xprt, msg) \
  132. (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  133. #define svc_reply(xprt, msg) \
  134. (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  135. #define SVC_REPLY_REQ(xprt, req, msg) \
  136. (*(xprt)->xp_ops->xp_reply_req) ((xprt), (req), (msg))
  137. #define svc_reply_req(xprt, msg) \
  138. (*(xprt)->xp_ops->xp_reply_req) ((xprt), (req), (msg))
  139. #define SVC_FREEARGS(xprt, xargs, argsp) \
  140. (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  141. #define svc_freeargs(xprt, xargs, argsp) \
  142. (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  143. #define SVC_DESTROY(xprt) \
  144. (*(xprt)->xp_ops->xp_destroy)(xprt)
  145. #define svc_destroy(xprt) \
  146. (*(xprt)->xp_ops->xp_destroy)(xprt)
  147. /*
  148. * Service request
  149. */
  150. struct svc_req {
  151. rpcprog_t rq_prog; /* service program number */
  152. rpcvers_t rq_vers; /* service protocol version */
  153. rpcproc_t rq_proc; /* the desired procedure */
  154. struct opaque_auth rq_cred; /* raw creds from the wire */
  155. void * rq_clntcred; /* read only cooked client cred */
  156. void * rq_svccred; /* read only svc cred/context */
  157. void * rq_clntname; /* read only client name */
  158. SVCXPRT *rq_xprt; /* associated transport */
  159. /* The request's auth flavor *should* be here, but the svc_req */
  160. /* isn't passed around everywhere it is necessary. The */
  161. /* transport *is* passed around, so the auth flavor it stored */
  162. /* there. This means that the transport must be single */
  163. /* threaded, but other parts of SunRPC already require that. */
  164. /*SVCAUTH *rq_auth; associated auth flavor */
  165. };
  166. /*
  167. * Service registration
  168. *
  169. * svc_register(xprt, prog, vers, dispatch, protocol)
  170. * SVCXPRT *xprt;
  171. * rpcprog_t prog;
  172. * rpcvers_t vers;
  173. * void (*dispatch)();
  174. * int protocol; like IPPROTO_TCP or _UDP; zero means do not register
  175. *
  176. * registerrpc(prog, vers, proc, routine, inproc, outproc)
  177. * returns 0 upon success, -1 if error.
  178. */
  179. extern bool_t svc_register(SVCXPRT *, rpcprog_t, rpcvers_t,
  180. void (*)(struct svc_req *, SVCXPRT *), int);
  181. extern int registerrpc(rpcprog_t, rpcvers_t, rpcproc_t,
  182. char *(*)(void *),
  183. xdrproc_t, xdrproc_t);
  184. /*
  185. * Service un-registration
  186. *
  187. * svc_unregister(prog, vers)
  188. * rpcprog_t prog;
  189. * rpcvers_t vers;
  190. */
  191. extern void svc_unregister(rpcprog_t, rpcvers_t);
  192. /*
  193. * Transport registration.
  194. *
  195. * xprt_register(xprt)
  196. * SVCXPRT *xprt;
  197. */
  198. extern void xprt_register(SVCXPRT *);
  199. /*
  200. * Transport un-register
  201. *
  202. * xprt_unregister(xprt)
  203. * SVCXPRT *xprt;
  204. */
  205. extern void xprt_unregister(SVCXPRT *);
  206. /*
  207. * When the service routine is called, it must first check to see if
  208. * it knows about the procedure; if not, it should call svcerr_noproc
  209. * and return. If so, it should deserialize its arguments via
  210. * SVC_GETARGS or the new SVC_GETARGS_REQ (both defined above). If
  211. * the deserialization does not work, svcerr_decode should be called
  212. * followed by a return. Successful decoding of the arguments should
  213. * be followed the execution of the procedure's code and a call to
  214. * svc_sendreply or the new svc_sendreply_req.
  215. *
  216. * Also, if the service refuses to execute the procedure due to too-
  217. * weak authentication parameters, svcerr_weakauth should be called.
  218. * Note: do not confuse access-control failure with weak authentication!
  219. *
  220. * NB: In pure implementations of rpc, the caller always waits for a reply
  221. * msg. This message is sent when svc_sendreply is called.
  222. * Therefore pure service implementations should always call
  223. * svc_sendreply even if the function logically returns void; use
  224. * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows
  225. * for the abuse of pure rpc via batched calling or pipelining. In the
  226. * case of a batched call, svc_sendreply should NOT be called since
  227. * this would send a return message, which is what batching tries to avoid.
  228. * It is the service/protocol writer's responsibility to know which calls are
  229. * batched and which are not. Warning: responding to batch calls may
  230. * deadlock the caller and server processes!
  231. */
  232. extern bool_t svc_sendreply(SVCXPRT *, xdrproc_t, caddr_t);
  233. extern void svcerr_decode(SVCXPRT *);
  234. extern void svcerr_weakauth(SVCXPRT *);
  235. extern void svcerr_noproc(SVCXPRT *);
  236. extern void svcerr_progvers(SVCXPRT *, rpcvers_t, rpcvers_t);
  237. extern void svcerr_auth(SVCXPRT *, enum auth_stat);
  238. extern void svcerr_noprog(SVCXPRT *);
  239. extern void svcerr_systemerr(SVCXPRT *);
  240. /*
  241. * Lowest level dispatching -OR- who owns this process anyway.
  242. * Somebody has to wait for incoming requests and then call the correct
  243. * service routine. The routine svc_run does infinite waiting; i.e.,
  244. * svc_run never returns.
  245. * Since another (co-existant) package may wish to selectively wait for
  246. * incoming calls or other events outside of the rpc architecture, the
  247. * routine svc_getreq is provided. It must be passed readfds, the
  248. * "in-place" results of a select system call (see select, section 2).
  249. */
  250. /*
  251. * Global keeper of rpc service descriptors in use
  252. * dynamic; must be inspected before each call to select
  253. */
  254. extern int svc_maxfd;
  255. #ifdef FD_SETSIZE
  256. extern fd_set svc_fdset;
  257. /* RENAMED */
  258. #define gssrpc_svc_fds gsssrpc_svc_fdset.fds_bits[0] /* compatibility */
  259. #else
  260. extern int svc_fds;
  261. #endif /* def FD_SETSIZE */
  262. extern int svc_maxfd;
  263. /*
  264. * a small program implemented by the svc_rpc implementation itself;
  265. * also see clnt.h for protocol numbers.
  266. */
  267. extern void rpctest_service();
  268. extern void svc_getreq(int);
  269. #ifdef FD_SETSIZE
  270. extern void svc_getreqset(fd_set *);/* takes fdset instead of int */
  271. extern void svc_getreqset2(fd_set *, int);
  272. #else
  273. extern void svc_getreqset(int *);
  274. #endif
  275. extern void svc_run(void); /* never returns */
  276. /*
  277. * Socket to use on svcxxx_create call to get default socket
  278. */
  279. #define RPC_ANYSOCK -1
  280. /*
  281. * These are the existing service side transport implementations
  282. */
  283. /*
  284. * Memory based rpc for testing and timing.
  285. */
  286. extern SVCXPRT *svcraw_create(void);
  287. /*
  288. * Udp based rpc.
  289. */
  290. extern SVCXPRT *svcudp_create(int);
  291. extern SVCXPRT *svcudp_bufcreate(int, u_int, u_int);
  292. extern int svcudp_enablecache(SVCXPRT *, uint32_t);
  293. /*
  294. * Tcp based rpc.
  295. */
  296. extern SVCXPRT *svctcp_create(int, u_int, u_int);
  297. /*
  298. * Like svtcp_create(), except the routine takes any *open* UNIX file
  299. * descriptor as its first input.
  300. */
  301. extern SVCXPRT *svcfd_create(int, u_int, u_int);
  302. /* XXX add auth_gsapi_log_*? */
  303. GSSRPC__END_DECLS
  304. #endif /* !defined(GSSRPC_SVC_H) */