Home | History | Annotate | Line # | Download | only in rpc
svc.h revision 1.3
      1  1.1  deraadt /*
      2  1.1  deraadt  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
      3  1.1  deraadt  * unrestricted use provided that this legend is included on all tape
      4  1.1  deraadt  * media and as a part of the software program in whole or part.  Users
      5  1.1  deraadt  * may copy or modify Sun RPC without charge, but are not authorized
      6  1.1  deraadt  * to license or distribute it to anyone else except as part of a product or
      7  1.1  deraadt  * program developed by the user.
      8  1.1  deraadt  *
      9  1.1  deraadt  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
     10  1.1  deraadt  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
     11  1.1  deraadt  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
     12  1.1  deraadt  *
     13  1.1  deraadt  * Sun RPC is provided with no support and without any obligation on the
     14  1.1  deraadt  * part of Sun Microsystems, Inc. to assist in its use, correction,
     15  1.1  deraadt  * modification or enhancement.
     16  1.1  deraadt  *
     17  1.1  deraadt  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
     18  1.1  deraadt  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
     19  1.1  deraadt  * OR ANY PART THEREOF.
     20  1.1  deraadt  *
     21  1.1  deraadt  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
     22  1.1  deraadt  * or profits or other special, indirect and consequential damages, even if
     23  1.1  deraadt  * Sun has been advised of the possibility of such damages.
     24  1.1  deraadt  *
     25  1.1  deraadt  * Sun Microsystems, Inc.
     26  1.1  deraadt  * 2550 Garcia Avenue
     27  1.1  deraadt  * Mountain View, California  94043
     28  1.3  mycroft  *
     29  1.3  mycroft  *	from: @(#)svc.h 1.20 88/02/08 SMI
     30  1.3  mycroft  *	from: @(#)svc.h	2.2 88/07/29 4.0 RPCSRC
     31  1.3  mycroft  *	$Id: svc.h,v 1.3 1993/08/01 18:45:52 mycroft Exp $
     32  1.1  deraadt  */
     33  1.1  deraadt 
     34  1.1  deraadt /*
     35  1.1  deraadt  * svc.h, Server-side remote procedure call interface.
     36  1.1  deraadt  *
     37  1.1  deraadt  * Copyright (C) 1984, Sun Microsystems, Inc.
     38  1.1  deraadt  */
     39  1.1  deraadt 
     40  1.2   brezak #ifndef _RPC_SVC_H
     41  1.2   brezak #define _RPC_SVC_H
     42  1.2   brezak #include <sys/cdefs.h>
     43  1.1  deraadt 
     44  1.1  deraadt /*
     45  1.1  deraadt  * This interface must manage two items concerning remote procedure calling:
     46  1.1  deraadt  *
     47  1.1  deraadt  * 1) An arbitrary number of transport connections upon which rpc requests
     48  1.1  deraadt  * are received.  The two most notable transports are TCP and UDP;  they are
     49  1.1  deraadt  * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
     50  1.1  deraadt  * they in turn call xprt_register and xprt_unregister.
     51  1.1  deraadt  *
     52  1.1  deraadt  * 2) An arbitrary number of locally registered services.  Services are
     53  1.1  deraadt  * described by the following four data: program number, version number,
     54  1.1  deraadt  * "service dispatch" function, a transport handle, and a boolean that
     55  1.1  deraadt  * indicates whether or not the exported program should be registered with a
     56  1.1  deraadt  * local binder service;  if true the program's number and version and the
     57  1.1  deraadt  * port number from the transport handle are registered with the binder.
     58  1.1  deraadt  * These data are registered with the rpc svc system via svc_register.
     59  1.1  deraadt  *
     60  1.1  deraadt  * A service's dispatch function is called whenever an rpc request comes in
     61  1.1  deraadt  * on a transport.  The request's program and version numbers must match
     62  1.1  deraadt  * those of the registered service.  The dispatch function is passed two
     63  1.1  deraadt  * parameters, struct svc_req * and SVCXPRT *, defined below.
     64  1.1  deraadt  */
     65  1.1  deraadt 
     66  1.1  deraadt enum xprt_stat {
     67  1.1  deraadt 	XPRT_DIED,
     68  1.1  deraadt 	XPRT_MOREREQS,
     69  1.1  deraadt 	XPRT_IDLE
     70  1.1  deraadt };
     71  1.1  deraadt 
     72  1.1  deraadt /*
     73  1.1  deraadt  * Server side transport handle
     74  1.1  deraadt  */
     75  1.1  deraadt typedef struct {
     76  1.1  deraadt 	int		xp_sock;
     77  1.1  deraadt 	u_short		xp_port;	 /* associated port number */
     78  1.1  deraadt 	struct xp_ops {
     79  1.1  deraadt 	    bool_t	(*xp_recv)();	 /* receive incomming requests */
     80  1.1  deraadt 	    enum xprt_stat (*xp_stat)(); /* get transport status */
     81  1.1  deraadt 	    bool_t	(*xp_getargs)(); /* get arguments */
     82  1.1  deraadt 	    bool_t	(*xp_reply)();	 /* send reply */
     83  1.1  deraadt 	    bool_t	(*xp_freeargs)();/* free mem allocated for args */
     84  1.1  deraadt 	    void	(*xp_destroy)(); /* destroy this struct */
     85  1.1  deraadt 	} *xp_ops;
     86  1.1  deraadt 	int		xp_addrlen;	 /* length of remote address */
     87  1.1  deraadt 	struct sockaddr_in xp_raddr;	 /* remote address */
     88  1.1  deraadt 	struct opaque_auth xp_verf;	 /* raw response verifier */
     89  1.1  deraadt 	caddr_t		xp_p1;		 /* private */
     90  1.1  deraadt 	caddr_t		xp_p2;		 /* private */
     91  1.1  deraadt } SVCXPRT;
     92  1.1  deraadt 
     93  1.1  deraadt /*
     94  1.1  deraadt  *  Approved way of getting address of caller
     95  1.1  deraadt  */
     96  1.1  deraadt #define svc_getcaller(x) (&(x)->xp_raddr)
     97  1.1  deraadt 
     98  1.1  deraadt /*
     99  1.1  deraadt  * Operations defined on an SVCXPRT handle
    100  1.1  deraadt  *
    101  1.1  deraadt  * SVCXPRT		*xprt;
    102  1.1  deraadt  * struct rpc_msg	*msg;
    103  1.1  deraadt  * xdrproc_t		 xargs;
    104  1.1  deraadt  * caddr_t		 argsp;
    105  1.1  deraadt  */
    106  1.1  deraadt #define SVC_RECV(xprt, msg)				\
    107  1.1  deraadt 	(*(xprt)->xp_ops->xp_recv)((xprt), (msg))
    108  1.1  deraadt #define svc_recv(xprt, msg)				\
    109  1.1  deraadt 	(*(xprt)->xp_ops->xp_recv)((xprt), (msg))
    110  1.1  deraadt 
    111  1.1  deraadt #define SVC_STAT(xprt)					\
    112  1.1  deraadt 	(*(xprt)->xp_ops->xp_stat)(xprt)
    113  1.1  deraadt #define svc_stat(xprt)					\
    114  1.1  deraadt 	(*(xprt)->xp_ops->xp_stat)(xprt)
    115  1.1  deraadt 
    116  1.1  deraadt #define SVC_GETARGS(xprt, xargs, argsp)			\
    117  1.1  deraadt 	(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
    118  1.1  deraadt #define svc_getargs(xprt, xargs, argsp)			\
    119  1.1  deraadt 	(*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
    120  1.1  deraadt 
    121  1.1  deraadt #define SVC_REPLY(xprt, msg)				\
    122  1.1  deraadt 	(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
    123  1.1  deraadt #define svc_reply(xprt, msg)				\
    124  1.1  deraadt 	(*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
    125  1.1  deraadt 
    126  1.1  deraadt #define SVC_FREEARGS(xprt, xargs, argsp)		\
    127  1.1  deraadt 	(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
    128  1.1  deraadt #define svc_freeargs(xprt, xargs, argsp)		\
    129  1.1  deraadt 	(*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
    130  1.1  deraadt 
    131  1.1  deraadt #define SVC_DESTROY(xprt)				\
    132  1.1  deraadt 	(*(xprt)->xp_ops->xp_destroy)(xprt)
    133  1.1  deraadt #define svc_destroy(xprt)				\
    134  1.1  deraadt 	(*(xprt)->xp_ops->xp_destroy)(xprt)
    135  1.1  deraadt 
    136  1.1  deraadt 
    137  1.1  deraadt /*
    138  1.1  deraadt  * Service request
    139  1.1  deraadt  */
    140  1.1  deraadt struct svc_req {
    141  1.1  deraadt 	u_long		rq_prog;	/* service program number */
    142  1.1  deraadt 	u_long		rq_vers;	/* service protocol version */
    143  1.1  deraadt 	u_long		rq_proc;	/* the desired procedure */
    144  1.1  deraadt 	struct opaque_auth rq_cred;	/* raw creds from the wire */
    145  1.1  deraadt 	caddr_t		rq_clntcred;	/* read only cooked cred */
    146  1.1  deraadt 	SVCXPRT	*rq_xprt;		/* associated transport */
    147  1.1  deraadt };
    148  1.1  deraadt 
    149  1.1  deraadt 
    150  1.1  deraadt /*
    151  1.1  deraadt  * Service registration
    152  1.1  deraadt  *
    153  1.1  deraadt  * svc_register(xprt, prog, vers, dispatch, protocol)
    154  1.1  deraadt  *	SVCXPRT *xprt;
    155  1.1  deraadt  *	u_long prog;
    156  1.1  deraadt  *	u_long vers;
    157  1.1  deraadt  *	void (*dispatch)();
    158  1.1  deraadt  *	int protocol;  /* like TCP or UDP, zero means do not register
    159  1.1  deraadt  */
    160  1.2   brezak __BEGIN_DECLS
    161  1.2   brezak extern bool_t	svc_register __P((SVCXPRT *, u_long, u_long, void (*)(), int));
    162  1.2   brezak __END_DECLS
    163  1.1  deraadt 
    164  1.1  deraadt /*
    165  1.1  deraadt  * Service un-registration
    166  1.1  deraadt  *
    167  1.1  deraadt  * svc_unregister(prog, vers)
    168  1.1  deraadt  *	u_long prog;
    169  1.1  deraadt  *	u_long vers;
    170  1.1  deraadt  */
    171  1.2   brezak __BEGIN_DECLS
    172  1.2   brezak extern void	svc_unregister __P((u_long, u_long));
    173  1.2   brezak __END_DECLS
    174  1.1  deraadt 
    175  1.1  deraadt /*
    176  1.1  deraadt  * Transport registration.
    177  1.1  deraadt  *
    178  1.1  deraadt  * xprt_register(xprt)
    179  1.1  deraadt  *	SVCXPRT *xprt;
    180  1.1  deraadt  */
    181  1.2   brezak __BEGIN_DECLS
    182  1.2   brezak extern void	xprt_register	__P((SVCXPRT *));
    183  1.2   brezak __END_DECLS
    184  1.1  deraadt 
    185  1.1  deraadt /*
    186  1.1  deraadt  * Transport un-register
    187  1.1  deraadt  *
    188  1.1  deraadt  * xprt_unregister(xprt)
    189  1.1  deraadt  *	SVCXPRT *xprt;
    190  1.1  deraadt  */
    191  1.2   brezak __BEGIN_DECLS
    192  1.2   brezak extern void	xprt_unregister	__P((SVCXPRT *));
    193  1.2   brezak __END_DECLS
    194  1.1  deraadt 
    195  1.1  deraadt 
    196  1.1  deraadt 
    197  1.1  deraadt 
    198  1.1  deraadt /*
    199  1.1  deraadt  * When the service routine is called, it must first check to see if it
    200  1.1  deraadt  * knows about the procedure;  if not, it should call svcerr_noproc
    201  1.1  deraadt  * and return.  If so, it should deserialize its arguments via
    202  1.1  deraadt  * SVC_GETARGS (defined above).  If the deserialization does not work,
    203  1.1  deraadt  * svcerr_decode should be called followed by a return.  Successful
    204  1.1  deraadt  * decoding of the arguments should be followed the execution of the
    205  1.1  deraadt  * procedure's code and a call to svc_sendreply.
    206  1.1  deraadt  *
    207  1.1  deraadt  * Also, if the service refuses to execute the procedure due to too-
    208  1.1  deraadt  * weak authentication parameters, svcerr_weakauth should be called.
    209  1.1  deraadt  * Note: do not confuse access-control failure with weak authentication!
    210  1.1  deraadt  *
    211  1.1  deraadt  * NB: In pure implementations of rpc, the caller always waits for a reply
    212  1.1  deraadt  * msg.  This message is sent when svc_sendreply is called.
    213  1.1  deraadt  * Therefore pure service implementations should always call
    214  1.1  deraadt  * svc_sendreply even if the function logically returns void;  use
    215  1.1  deraadt  * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
    216  1.1  deraadt  * for the abuse of pure rpc via batched calling or pipelining.  In the
    217  1.1  deraadt  * case of a batched call, svc_sendreply should NOT be called since
    218  1.1  deraadt  * this would send a return message, which is what batching tries to avoid.
    219  1.1  deraadt  * It is the service/protocol writer's responsibility to know which calls are
    220  1.1  deraadt  * batched and which are not.  Warning: responding to batch calls may
    221  1.1  deraadt  * deadlock the caller and server processes!
    222  1.1  deraadt  */
    223  1.1  deraadt 
    224  1.2   brezak __BEGIN_DECLS
    225  1.2   brezak extern bool_t	svc_sendreply	__P((SVCXPRT *, xdrproc_t, char *));
    226  1.2   brezak extern void	svcerr_decode	__P((SVCXPRT *));
    227  1.2   brezak extern void	svcerr_weakauth	__P((SVCXPRT *));
    228  1.2   brezak extern void	svcerr_noproc	__P((SVCXPRT *));
    229  1.2   brezak extern void	svcerr_progvers	__P((SVCXPRT *, u_long, u_long));
    230  1.2   brezak extern void	svcerr_auth	__P((SVCXPRT *, enum auth_stat));
    231  1.2   brezak extern void	svcerr_noprog	__P((SVCXPRT *));
    232  1.2   brezak extern void	svcerr_systemerr __P((SVCXPRT *));
    233  1.2   brezak __END_DECLS
    234  1.1  deraadt 
    235  1.1  deraadt /*
    236  1.1  deraadt  * Lowest level dispatching -OR- who owns this process anyway.
    237  1.1  deraadt  * Somebody has to wait for incoming requests and then call the correct
    238  1.1  deraadt  * service routine.  The routine svc_run does infinite waiting; i.e.,
    239  1.1  deraadt  * svc_run never returns.
    240  1.1  deraadt  * Since another (co-existant) package may wish to selectively wait for
    241  1.1  deraadt  * incoming calls or other events outside of the rpc architecture, the
    242  1.1  deraadt  * routine svc_getreq is provided.  It must be passed readfds, the
    243  1.1  deraadt  * "in-place" results of a select system call (see select, section 2).
    244  1.1  deraadt  */
    245  1.1  deraadt 
    246  1.1  deraadt /*
    247  1.1  deraadt  * Global keeper of rpc service descriptors in use
    248  1.1  deraadt  * dynamic; must be inspected before each call to select
    249  1.1  deraadt  */
    250  1.1  deraadt #ifdef FD_SETSIZE
    251  1.1  deraadt extern fd_set svc_fdset;
    252  1.1  deraadt #define svc_fds svc_fdset.fds_bits[0]	/* compatibility */
    253  1.1  deraadt #else
    254  1.1  deraadt extern int svc_fds;
    255  1.1  deraadt #endif /* def FD_SETSIZE */
    256  1.1  deraadt 
    257  1.1  deraadt /*
    258  1.1  deraadt  * a small program implemented by the svc_rpc implementation itself;
    259  1.1  deraadt  * also see clnt.h for protocol numbers.
    260  1.1  deraadt  */
    261  1.1  deraadt extern void rpctest_service();
    262  1.1  deraadt 
    263  1.2   brezak __BEGIN_DECLS
    264  1.2   brezak extern void	svc_getreq	__P((int));
    265  1.2   brezak extern void	svc_getreqset	__P((fd_set *));
    266  1.2   brezak extern void	svc_run		__P((void));
    267  1.2   brezak __END_DECLS
    268  1.1  deraadt 
    269  1.1  deraadt /*
    270  1.1  deraadt  * Socket to use on svcxxx_create call to get default socket
    271  1.1  deraadt  */
    272  1.1  deraadt #define	RPC_ANYSOCK	-1
    273  1.1  deraadt 
    274  1.1  deraadt /*
    275  1.1  deraadt  * These are the existing service side transport implementations
    276  1.1  deraadt  */
    277  1.1  deraadt 
    278  1.1  deraadt /*
    279  1.1  deraadt  * Memory based rpc for testing and timing.
    280  1.1  deraadt  */
    281  1.2   brezak __BEGIN_DECLS
    282  1.2   brezak extern SVCXPRT *svcraw_create __P((void));
    283  1.2   brezak __END_DECLS
    284  1.1  deraadt 
    285  1.2   brezak 
    286  1.1  deraadt /*
    287  1.1  deraadt  * Udp based rpc.
    288  1.1  deraadt  */
    289  1.2   brezak __BEGIN_DECLS
    290  1.2   brezak extern SVCXPRT *svcudp_create __P((int));
    291  1.2   brezak extern SVCXPRT *svcudp_bufcreate __P((int, u_int, u_int));
    292  1.2   brezak __END_DECLS
    293  1.2   brezak 
    294  1.1  deraadt 
    295  1.1  deraadt /*
    296  1.1  deraadt  * Tcp based rpc.
    297  1.1  deraadt  */
    298  1.2   brezak __BEGIN_DECLS
    299  1.2   brezak extern SVCXPRT *svctcp_create __P((int, u_int, u_int));
    300  1.2   brezak __END_DECLS
    301  1.1  deraadt 
    302  1.2   brezak #endif /* !_RPC_SVC_H */
    303