Path: blob/main/crypto/krb5/src/include/gssrpc/svc.h
34907 views
/* @(#)svc.h 2.2 88/07/29 4.0 RPCSRC; from 1.20 88/02/08 SMI */1/*2* Copyright (c) 2010, Oracle America, Inc.3*4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions are met:8*9* * Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* * Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in14* the documentation and/or other materials provided with the15* distribution.16*17* * Neither the name of the "Oracle America, Inc." nor the names of18* its contributors may be used to endorse or promote products19* derived from this software without specific prior written permission.20*21* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS22* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED23* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A24* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT25* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,26* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED27* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR28* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF29* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING30* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS31* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.32*/3334/*35* svc.h, Server-side remote procedure call interface.36*/3738#ifndef GSSRPC_SVC_H39#define GSSRPC_SVC_H4041#include <gssrpc/svc_auth.h>4243GSSRPC__BEGIN_DECLS44/*45* This interface must manage two items concerning remote procedure calling:46*47* 1) An arbitrary number of transport connections upon which rpc requests48* are received. The two most notable transports are TCP and UDP; they are49* created and registered by routines in svc_tcp.c and svc_udp.c, respectively;50* they in turn call xprt_register and xprt_unregister.51*52* 2) An arbitrary number of locally registered services. Services are53* described by the following four data: program number, version number,54* "service dispatch" function, a transport handle, and a boolean that55* indicates whether or not the exported program should be registered with a56* local binder service; if true the program's number and version and the57* port number from the transport handle are registered with the binder.58* These data are registered with the rpc svc system via svc_register.59*60* A service's dispatch function is called whenever an rpc request comes in61* on a transport. The request's program and version numbers must match62* those of the registered service. The dispatch function is passed two63* parameters, struct svc_req * and SVCXPRT *, defined below.64*/6566enum xprt_stat {67XPRT_DIED,68XPRT_MOREREQS,69XPRT_IDLE70};7172/*73* Server side transport handle74*/75typedef struct SVCXPRT {76#ifdef _WIN3277SOCKET xp_sock;78#else79int xp_sock;80#endif81u_short xp_port; /* associated port number */82struct xp_ops {83/* receive incoming requests */84bool_t (*xp_recv)(struct SVCXPRT *, struct rpc_msg *);85/* get transport status */86enum xprt_stat (*xp_stat)(struct SVCXPRT *);87/* get arguments */88bool_t (*xp_getargs)(struct SVCXPRT *, xdrproc_t,89void *);90/* send reply */91bool_t (*xp_reply)(struct SVCXPRT *,92struct rpc_msg *);93/* free mem allocated for args */94bool_t (*xp_freeargs)(struct SVCXPRT *, xdrproc_t,95void *);96/* destroy this struct */97void (*xp_destroy)(struct SVCXPRT *);98} *xp_ops;99int xp_addrlen; /* length of remote address */100struct sockaddr_in xp_raddr; /* remote address */101struct opaque_auth xp_verf; /* raw response verifier */102SVCAUTH *xp_auth; /* auth flavor of current req */103void *xp_p1; /* private */104void *xp_p2; /* private */105int xp_laddrlen; /* length of local address */106struct sockaddr_in xp_laddr; /* local address */107} SVCXPRT;108109/*110* Approved way of getting address of caller111*/112#define svc_getcaller(x) (&(x)->xp_raddr)113114/*115* Operations defined on an SVCXPRT handle116*117* SVCXPRT *xprt;118* struct rpc_msg *msg;119* xdrproc_t xargs;120* caddr_t argsp;121*/122#define SVC_RECV(xprt, msg) \123(*(xprt)->xp_ops->xp_recv)((xprt), (msg))124#define svc_recv(xprt, msg) \125(*(xprt)->xp_ops->xp_recv)((xprt), (msg))126127#define SVC_STAT(xprt) \128(*(xprt)->xp_ops->xp_stat)(xprt)129#define svc_stat(xprt) \130(*(xprt)->xp_ops->xp_stat)(xprt)131132#define SVC_GETARGS(xprt, xargs, argsp) \133(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))134#define svc_getargs(xprt, xargs, argsp) \135(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))136137#define SVC_GETARGS_REQ(xprt, req, xargs, argsp) \138(*(xprt)->xp_ops->xp_getargs_req)((xprt), (req), (xargs), (argsp))139#define svc_getargs_req(xprt, req, xargs, argsp) \140(*(xprt)->xp_ops->xp_getargs_req)((xprt), (req), (xargs), (argsp))141142#define SVC_REPLY(xprt, msg) \143(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))144#define svc_reply(xprt, msg) \145(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))146147#define SVC_REPLY_REQ(xprt, req, msg) \148(*(xprt)->xp_ops->xp_reply_req) ((xprt), (req), (msg))149#define svc_reply_req(xprt, msg) \150(*(xprt)->xp_ops->xp_reply_req) ((xprt), (req), (msg))151152#define SVC_FREEARGS(xprt, xargs, argsp) \153(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))154#define svc_freeargs(xprt, xargs, argsp) \155(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))156157#define SVC_DESTROY(xprt) \158(*(xprt)->xp_ops->xp_destroy)(xprt)159#define svc_destroy(xprt) \160(*(xprt)->xp_ops->xp_destroy)(xprt)161162163/*164* Service request165*/166struct svc_req {167rpcprog_t rq_prog; /* service program number */168rpcvers_t rq_vers; /* service protocol version */169rpcproc_t rq_proc; /* the desired procedure */170struct opaque_auth rq_cred; /* raw creds from the wire */171void * rq_clntcred; /* read only cooked client cred */172void * rq_svccred; /* read only svc cred/context */173void * rq_clntname; /* read only client name */174SVCXPRT *rq_xprt; /* associated transport */175/* The request's auth flavor *should* be here, but the svc_req */176/* isn't passed around everywhere it is necessary. The */177/* transport *is* passed around, so the auth flavor it stored */178/* there. This means that the transport must be single */179/* threaded, but other parts of SunRPC already require that. */180/*SVCAUTH *rq_auth; associated auth flavor */181};182183184/*185* Service registration186*187* svc_register(xprt, prog, vers, dispatch, protocol)188* SVCXPRT *xprt;189* rpcprog_t prog;190* rpcvers_t vers;191* void (*dispatch)();192* int protocol; like IPPROTO_TCP or _UDP; zero means do not register193*194* registerrpc(prog, vers, proc, routine, inproc, outproc)195* returns 0 upon success, -1 if error.196*/197extern bool_t svc_register(SVCXPRT *, rpcprog_t, rpcvers_t,198void (*)(struct svc_req *, SVCXPRT *), int);199200extern int registerrpc(rpcprog_t, rpcvers_t, rpcproc_t,201char *(*)(void *),202xdrproc_t, xdrproc_t);203204/*205* Service un-registration206*207* svc_unregister(prog, vers)208* rpcprog_t prog;209* rpcvers_t vers;210*/211extern void svc_unregister(rpcprog_t, rpcvers_t);212213/*214* Transport registration.215*216* xprt_register(xprt)217* SVCXPRT *xprt;218*/219extern void xprt_register(SVCXPRT *);220221/*222* Transport un-register223*224* xprt_unregister(xprt)225* SVCXPRT *xprt;226*/227extern void xprt_unregister(SVCXPRT *);228229230/*231* When the service routine is called, it must first check to see if232* it knows about the procedure; if not, it should call svcerr_noproc233* and return. If so, it should deserialize its arguments via234* SVC_GETARGS or the new SVC_GETARGS_REQ (both defined above). If235* the deserialization does not work, svcerr_decode should be called236* followed by a return. Successful decoding of the arguments should237* be followed the execution of the procedure's code and a call to238* svc_sendreply or the new svc_sendreply_req.239*240* Also, if the service refuses to execute the procedure due to too-241* weak authentication parameters, svcerr_weakauth should be called.242* Note: do not confuse access-control failure with weak authentication!243*244* NB: In pure implementations of rpc, the caller always waits for a reply245* msg. This message is sent when svc_sendreply is called.246* Therefore pure service implementations should always call247* svc_sendreply even if the function logically returns void; use248* xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows249* for the abuse of pure rpc via batched calling or pipelining. In the250* case of a batched call, svc_sendreply should NOT be called since251* this would send a return message, which is what batching tries to avoid.252* It is the service/protocol writer's responsibility to know which calls are253* batched and which are not. Warning: responding to batch calls may254* deadlock the caller and server processes!255*/256257extern bool_t svc_sendreply(SVCXPRT *, xdrproc_t, caddr_t);258extern void svcerr_decode(SVCXPRT *);259extern void svcerr_weakauth(SVCXPRT *);260extern void svcerr_noproc(SVCXPRT *);261extern void svcerr_progvers(SVCXPRT *, rpcvers_t, rpcvers_t);262extern void svcerr_auth(SVCXPRT *, enum auth_stat);263extern void svcerr_noprog(SVCXPRT *);264extern void svcerr_systemerr(SVCXPRT *);265266/*267* Lowest level dispatching -OR- who owns this process anyway.268* Somebody has to wait for incoming requests and then call the correct269* service routine. The routine svc_run does infinite waiting; i.e.,270* svc_run never returns.271* Since another (co-existant) package may wish to selectively wait for272* incoming calls or other events outside of the rpc architecture, the273* routine svc_getreq is provided. It must be passed readfds, the274* "in-place" results of a select system call (see select, section 2).275*/276277/*278* Global keeper of rpc service descriptors in use279* dynamic; must be inspected before each call to select280*/281extern int svc_maxfd;282#ifdef FD_SETSIZE283extern fd_set svc_fdset;284/* RENAMED */285#define gssrpc_svc_fds gsssrpc_svc_fdset.fds_bits[0] /* compatibility */286#else287extern int svc_fds;288#endif /* def FD_SETSIZE */289extern int svc_maxfd;290291extern void svc_getreq(int);292#ifdef FD_SETSIZE293extern void svc_getreqset(fd_set *);/* takes fdset instead of int */294#else295extern void svc_getreqset(int *);296#endif297extern void svc_run(void); /* never returns */298299/*300* Socket to use on svcxxx_create call to get default socket301*/302#define RPC_ANYSOCK -1303304/*305* These are the existing service side transport implementations306*/307308/*309* Memory based rpc for testing and timing.310*/311extern SVCXPRT *svcraw_create(void);312313/*314* Udp based rpc.315*/316extern SVCXPRT *svcudp_create(int);317extern SVCXPRT *svcudp_bufcreate(int, u_int, u_int);318extern int svcudp_enablecache(SVCXPRT *, uint32_t);319320/*321* Tcp based rpc.322*/323extern SVCXPRT *svctcp_create(int, u_int, u_int);324325/*326* Like svtcp_create(), except the routine takes any *open* UNIX file327* descriptor as its first input.328*/329extern SVCXPRT *svcfd_create(int, u_int, u_int);330331/* XXX add auth_gsapi_log_*? */332333GSSRPC__END_DECLS334335#endif /* !defined(GSSRPC_SVC_H) */336337338