From 70de0abf48ea2d832e3445406155b521792b6d13 Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Mon, 30 Dec 1996 13:59:41 +0000 Subject: First commit of a series of cleanups for the libc rpc code which has been suffering a bad case neglect for the last few years. - Add full prototypes, including to function pointers. - Make the wire protocols 64-bit type safe, eg: 32 bit quantities are int32_t, not long. The orginal rpc code was implemented when an int could be 16 bits. Obtained from: a diff of FreeBSD vs. OpenBSD/NetBSD rpc code. --- include/rpc/auth.h | 27 ++++++++++++++------- include/rpc/clnt.h | 41 +++++++++++++++++++++----------- include/rpc/pmap_clnt.h | 5 ++-- include/rpc/rpc.h | 6 ++++- include/rpc/rpc_msg.h | 20 ++++++++-------- include/rpc/svc.h | 49 +++++++++++++++++++++++++------------- include/rpc/types.h | 10 +++----- include/rpc/xdr.h | 63 ++++++++++++++++++++++++++++++------------------- 8 files changed, 137 insertions(+), 84 deletions(-) (limited to 'include/rpc') diff --git a/include/rpc/auth.h b/include/rpc/auth.h index b979ffb101ea..0b87af498a0e 100644 --- a/include/rpc/auth.h +++ b/include/rpc/auth.h @@ -28,7 +28,7 @@ * * from: @(#)auth.h 1.17 88/02/08 SMI * from: @(#)auth.h 2.3 88/08/07 4.0 RPCSRC - * $Id: auth.h,v 1.4 1996/01/30 23:31:35 mpp Exp $ + * $Id: auth.h,v 1.5 1996/01/31 08:02:11 hsu Exp $ */ /* @@ -88,21 +88,29 @@ struct opaque_auth { caddr_t oa_base; /* address of more auth stuff */ u_int oa_length; /* not to exceed MAX_AUTH_BYTES */ }; +__BEGIN_DECLS +bool_t xdr_opaque_auth(XDR *xdrs, struct opaque_auth *ap); +__END_DECLS /* * Auth handle, interface to client side authenticators. */ -typedef struct { +typedef struct __rpc_auth { struct opaque_auth ah_cred; struct opaque_auth ah_verf; union des_block ah_key; struct auth_ops { - void (*ah_nextverf)(); - int (*ah_marshal)(); /* nextverf & serialize */ - int (*ah_validate)(); /* validate verifier */ - int (*ah_refresh)(); /* refresh credentials */ - void (*ah_destroy)(); /* destroy this structure */ + void (*ah_nextverf) __P((struct __rpc_auth *)); + /* nextverf & serialize */ + int (*ah_marshal) __P((struct __rpc_auth *, XDR *)); + /* validate verifier */ + int (*ah_validate) __P((struct __rpc_auth *, + struct opaque_auth *)); + /* refresh credentials */ + int (*ah_refresh) __P((struct __rpc_auth *)); + /* destroy this structure */ + void (*ah_destroy) __P((struct __rpc_auth *)); } *ah_ops; caddr_t ah_private; } AUTH; @@ -144,7 +152,6 @@ typedef struct { extern struct opaque_auth _null_auth; - /* * These are the various implementations of client side authenticators. */ @@ -159,10 +166,12 @@ extern struct opaque_auth _null_auth; * int *aup_gids; */ __BEGIN_DECLS +struct sockaddr_in; extern AUTH *authunix_create __P((char *, int, int, int, int *)); extern AUTH *authunix_create_default __P((void)); extern AUTH *authnone_create __P((void)); -extern AUTH *authdes_create(); +extern AUTH *authdes_create __P((char *, u_int, + struct sockaddr_in *, des_block *)); __END_DECLS #define AUTH_NONE 0 /* no authentication */ diff --git a/include/rpc/clnt.h b/include/rpc/clnt.h index d464d6076205..69d18f19d6bf 100644 --- a/include/rpc/clnt.h +++ b/include/rpc/clnt.h @@ -28,7 +28,7 @@ * * from: @(#)clnt.h 1.31 88/02/08 SMI * from: @(#)clnt.h 2.1 88/07/29 4.0 RPCSRC - * $Id: clnt.h,v 1.3 1995/05/30 04:55:14 rgrimes Exp $ + * $Id: clnt.h,v 1.4 1996/01/30 23:31:48 mpp Exp $ */ /* @@ -94,12 +94,12 @@ struct rpc_err { int RE_errno; /* related system error */ enum auth_stat RE_why; /* why the auth error occurred */ struct { - u_long low; /* lowest verion supported */ - u_long high; /* highest verion supported */ + u_int32_t low; /* lowest verion supported */ + u_int32_t high; /* highest verion supported */ } RE_vers; struct { /* maybe meaningful if RPC_FAILED */ - long s1; - long s2; + int32_t s1; + int32_t s2; } RE_lb; /* life boot & debugging only */ } ru; #define re_errno ru.RE_errno @@ -114,15 +114,26 @@ struct rpc_err { * Created by individual implementations, see e.g. rpc_udp.c. * Client is responsible for initializing auth, see e.g. auth_none.c. */ -typedef struct { +typedef struct __rpc_client { AUTH *cl_auth; /* authenticator */ struct clnt_ops { - enum clnt_stat (*cl_call)(); /* call remote procedure */ - void (*cl_abort)(); /* abort a call */ - void (*cl_geterr)(); /* get specific error code */ - bool_t (*cl_freeres)(); /* frees results */ - void (*cl_destroy)();/* destroy this structure */ - bool_t (*cl_control)();/* the ioctl() of rpc */ + /* call remote procedure */ + enum clnt_stat (*cl_call) __P((struct __rpc_client *, + u_long, xdrproc_t, caddr_t, xdrproc_t, + caddr_t, struct timeval)); + /* abort a call */ + void (*cl_abort) __P((struct __rpc_client *)); + /* get specific error code */ + void (*cl_geterr) __P((struct __rpc_client *, + struct rpc_err *)); + /* frees results */ + bool_t (*cl_freeres) __P((struct __rpc_client *, + xdrproc_t, caddr_t)); + /* destroy this structure */ + void (*cl_destroy) __P((struct __rpc_client *)); + /* the ioctl() of rpc */ + bool_t (*cl_control) __P((struct __rpc_client *, u_int, + void *)); } *cl_ops; caddr_t cl_private; /* private stuff */ } CLIENT; @@ -147,9 +158,11 @@ typedef struct { * struct timeval timeout; */ #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \ - ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs)) + ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, (caddr_t)argsp, \ + xres, (caddr_t)resp, secs)) #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \ - ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs)) + ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, (caddr_t)argsp, \ + xres, (caddr_t)resp, secs)) /* * void diff --git a/include/rpc/pmap_clnt.h b/include/rpc/pmap_clnt.h index 39f6f4467a20..76778d62a66c 100644 --- a/include/rpc/pmap_clnt.h +++ b/include/rpc/pmap_clnt.h @@ -28,7 +28,7 @@ * * from: @(#)pmap_clnt.h 1.11 88/02/08 SMI * from: @(#)pmap_clnt.h 2.1 88/07/29 4.0 RPCSRC - * $Id: pmap_clnt.h,v 1.3 1995/05/30 04:55:16 rgrimes Exp $ + * $Id: pmap_clnt.h,v 1.4 1996/01/30 23:31:59 mpp Exp $ */ /* @@ -76,7 +76,8 @@ extern enum clnt_stat pmap_rmtcall __P((struct sockaddr_in *, extern enum clnt_stat clnt_broadcast __P((u_long, u_long, u_long, xdrproc_t, char *, xdrproc_t, char *, - bool_t (*)())); + bool_t (*) __P((caddr_t, + struct sockaddr_in *)))); extern u_short pmap_getport __P((struct sockaddr_in *, u_long, u_long, u_int)); __END_DECLS diff --git a/include/rpc/rpc.h b/include/rpc/rpc.h index dbdfc1562531..63070dd2734a 100644 --- a/include/rpc/rpc.h +++ b/include/rpc/rpc.h @@ -28,7 +28,7 @@ * * from: @(#)rpc.h 1.9 88/02/08 SMI * from: @(#)rpc.h 2.4 89/07/11 4.0 RPCSRC - * $Id: rpc.h,v 1.4 1995/05/30 04:55:23 rgrimes Exp $ + * $Id: rpc.h,v 1.5 1996/01/30 23:32:20 mpp Exp $ */ /* @@ -84,8 +84,12 @@ __BEGIN_DECLS extern struct rpcent *getrpcbyname __P((char *)); extern struct rpcent *getrpcbynumber __P((int)); extern struct rpcent *getrpcent __P((void)); +extern int getrpcport __P((char *host, int prognum, int versnum, int proto)); extern void setrpcent __P((int)); extern void endrpcent __P((void)); + +extern int bindresvport __P((int, struct sockaddr_in *)); +extern int get_myaddress __P((struct sockaddr_in *)); __END_DECLS #endif /* !_RPC_RPC_H */ diff --git a/include/rpc/rpc_msg.h b/include/rpc/rpc_msg.h index 43103bd2da31..8fd342550cb4 100644 --- a/include/rpc/rpc_msg.h +++ b/include/rpc/rpc_msg.h @@ -28,7 +28,7 @@ * * from: @(#)rpc_msg.h 1.7 86/07/16 SMI * from: @(#)rpc_msg.h 2.1 88/07/29 4.0 RPCSRC - * $Id: rpc_msg.h,v 1.4 1995/05/30 04:55:25 rgrimes Exp $ + * $Id: rpc_msg.h,v 1.5 1996/01/30 23:32:24 mpp Exp $ */ /* @@ -88,8 +88,8 @@ struct accepted_reply { enum accept_stat ar_stat; union { struct { - u_long low; - u_long high; + u_int32_t low; + u_int32_t high; } AR_versions; struct { caddr_t where; @@ -108,8 +108,8 @@ struct rejected_reply { enum reject_stat rj_stat; union { struct { - u_long low; - u_long high; + u_int32_t low; + u_int32_t high; } RJ_versions; enum auth_stat RJ_why; /* why authentication did not work */ } ru; @@ -134,10 +134,10 @@ struct reply_body { * Body of an rpc request call. */ struct call_body { - u_long cb_rpcvers; /* must be equal to two */ - u_long cb_prog; - u_long cb_vers; - u_long cb_proc; + u_int32_t cb_rpcvers; /* must be equal to two */ + u_int32_t cb_prog; + u_int32_t cb_vers; + u_int32_t cb_proc; struct opaque_auth cb_cred; struct opaque_auth cb_verf; /* protocol specific - provided by client */ }; @@ -146,7 +146,7 @@ struct call_body { * The rpc message */ struct rpc_msg { - u_long rm_xid; + u_int32_t rm_xid; enum msg_type rm_direction; union { struct call_body RM_cmb; diff --git a/include/rpc/svc.h b/include/rpc/svc.h index 05bec14129c4..fea27f640dc0 100644 --- a/include/rpc/svc.h +++ b/include/rpc/svc.h @@ -28,7 +28,7 @@ * * from: @(#)svc.h 1.20 88/02/08 SMI * from: @(#)svc.h 2.2 88/07/29 4.0 RPCSRC - * $Id: svc.h,v 1.4 1995/05/30 04:55:28 rgrimes Exp $ + * $Id: svc.h,v 1.5 1996/01/30 23:32:29 mpp Exp $ */ /* @@ -72,16 +72,26 @@ enum xprt_stat { /* * Server side transport handle */ -typedef struct { +typedef struct __rpc_svcxprt { int xp_sock; u_short xp_port; /* associated port number */ struct xp_ops { - bool_t (*xp_recv)(); /* receive incoming requests */ - enum xprt_stat (*xp_stat)(); /* get transport status */ - bool_t (*xp_getargs)(); /* get arguments */ - bool_t (*xp_reply)(); /* send reply */ - bool_t (*xp_freeargs)();/* free mem allocated for args */ - void (*xp_destroy)(); /* destroy this struct */ + /* receive incoming requests */ + bool_t (*xp_recv) __P((struct __rpc_svcxprt *, + struct rpc_msg *)); + /* get transport status */ + enum xprt_stat (*xp_stat) __P((struct __rpc_svcxprt *)); + /* get arguments */ + bool_t (*xp_getargs) __P((struct __rpc_svcxprt *, xdrproc_t, + caddr_t)); + /* send reply */ + bool_t (*xp_reply) __P((struct __rpc_svcxprt *, + struct rpc_msg *)); + /* free mem allocated for args */ + bool_t (*xp_freeargs) __P((struct __rpc_svcxprt *, xdrproc_t, + caddr_t)); + /* destroy this struct */ + void (*xp_destroy) __P((struct __rpc_svcxprt *)); } *xp_ops; int xp_addrlen; /* length of remote address */ struct sockaddr_in xp_raddr; /* remote address */ @@ -138,9 +148,9 @@ typedef struct { * Service request */ struct svc_req { - u_long rq_prog; /* service program number */ - u_long rq_vers; /* service protocol version */ - u_long rq_proc; /* the desired procedure */ + u_int32_t rq_prog; /* service program number */ + u_int32_t rq_vers; /* service protocol version */ + u_int32_t rq_proc; /* the desired procedure */ struct opaque_auth rq_cred; /* raw creds from the wire */ caddr_t rq_clntcred; /* read only cooked cred */ SVCXPRT *rq_xprt; /* associated transport */ @@ -155,10 +165,11 @@ struct svc_req { * u_long prog; * u_long vers; * void (*dispatch)(); - * int protocol; // like TCP or UDP, zero means do not register + * int protocol; (like TCP or UDP, zero means do not register) */ __BEGIN_DECLS -extern bool_t svc_register __P((SVCXPRT *, u_long, u_long, void (*)(), int)); +extern bool_t svc_register __P((SVCXPRT *, u_long, u_long, + void (*) __P((struct svc_req *, SVCXPRT *)), int)); __END_DECLS /* @@ -247,12 +258,9 @@ __END_DECLS * Global keeper of rpc service descriptors in use * dynamic; must be inspected before each call to select */ -#ifdef FD_SETSIZE +extern int svc_maxfd; extern fd_set svc_fdset; #define svc_fds svc_fdset.fds_bits[0] /* compatibility */ -#else -extern int svc_fds; -#endif /* def FD_SETSIZE */ /* * a small program implemented by the svc_rpc implementation itself; @@ -299,4 +307,11 @@ __BEGIN_DECLS extern SVCXPRT *svctcp_create __P((int, u_int, u_int)); __END_DECLS +/* + * Fd based rpc. + */ +__BEGIN_DECLS +extern SVCXPRT *svcfd_create __P((int, u_int, u_int)); +__END_DECLS + #endif /* !_RPC_SVC_H */ diff --git a/include/rpc/types.h b/include/rpc/types.h index dd8b3fbd3f7e..631705121b5f 100644 --- a/include/rpc/types.h +++ b/include/rpc/types.h @@ -28,7 +28,7 @@ * * from: @(#)types.h 1.18 87/07/24 SMI * from: @(#)types.h 2.3 88/08/15 4.0 RPCSRC - * $Id: types.h,v 1.3 1995/05/30 04:55:35 rgrimes Exp $ + * $Id: types.h,v 1.4 1996/01/30 23:32:39 mpp Exp $ */ /* @@ -37,8 +37,8 @@ #ifndef _RPC_TYPES_H #define _RPC_TYPES_H -#define bool_t int -#define enum_t int +#define bool_t int32_t +#define enum_t int32_t #define __dontcare__ -1 #ifndef FALSE @@ -59,8 +59,4 @@ #endif #include -#ifndef INADDR_LOOPBACK -#define INADDR_LOOPBACK (u_long)0x7F000001 -#endif - #endif /* !_RPC_TYPES_H */ diff --git a/include/rpc/xdr.h b/include/rpc/xdr.h index 59fbbbff6098..3bfa7c3b6cad 100644 --- a/include/rpc/xdr.h +++ b/include/rpc/xdr.h @@ -28,7 +28,7 @@ * * from: @(#)xdr.h 1.19 87/04/22 SMI * from: @(#)xdr.h 2.2 88/07/29 4.0 RPCSRC - * $Id: xdr.h,v 1.3 1995/05/30 04:55:38 rgrimes Exp $ + * $Id: xdr.h,v 1.4 1996/01/30 23:32:45 mpp Exp $ */ /* @@ -89,34 +89,31 @@ enum xdr_op { #define RNDUP(x) ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \ * BYTES_PER_XDR_UNIT) -/* - * A xdrproc_t exists for each data type which is to be encoded or decoded. - * - * The second argument to the xdrproc_t is a pointer to an opaque pointer. - * The opaque pointer generally points to a structure of the data type - * to be decoded. If this pointer is 0, then the type routines should - * allocate dynamic storage of the appropriate size and return it. - * bool_t (*xdrproc_t)(XDR *, caddr_t *); - */ -typedef bool_t (*xdrproc_t)(); - /* * The XDR handle. * Contains operation which is being applied to the stream, * an operations vector for the particular implementation (e.g. see xdr_mem.c), * and two private fields for the use of the particular implementation. */ -typedef struct { +typedef struct __rpc_xdr { enum xdr_op x_op; /* operation; fast additional param */ struct xdr_ops { - bool_t (*x_getlong)(); /* get a long from underlying stream */ - bool_t (*x_putlong)(); /* put a long to " */ - bool_t (*x_getbytes)();/* get some bytes from " */ - bool_t (*x_putbytes)();/* put some bytes to " */ - u_int (*x_getpostn)();/* returns bytes off from beginning */ - bool_t (*x_setpostn)();/* lets you reposition the stream */ - long * (*x_inline)(); /* buf quick ptr to buffered data */ - void (*x_destroy)(); /* free privates of this xdr_stream */ + /* get a long from underlying stream */ + bool_t (*x_getlong) __P((struct __rpc_xdr *, long *)); + /* put a long to underlying stream */ + bool_t (*x_putlong) __P((struct __rpc_xdr *, long *)); + /* get some bytes from underlying stream */ + bool_t (*x_getbytes) __P((struct __rpc_xdr *, caddr_t, u_int)); + /* put some bytes to underlying stream */ + bool_t (*x_putbytes) __P((struct __rpc_xdr *, caddr_t, u_int)); + /* returns bytes off from beginning */ + u_int (*x_getpostn) __P((struct __rpc_xdr *)); + /* lets you reposition the stream */ + bool_t (*x_setpostn) __P((struct __rpc_xdr *, u_int)); + /* buf quick ptr to buffered data */ + int32_t *(*x_inline) __P((struct __rpc_xdr *, u_int)); + /* free privates of this xdr_stream */ + void (*x_destroy) __P((struct __rpc_xdr *)); } *x_ops; caddr_t x_public; /* users' data */ caddr_t x_private; /* pointer to private data */ @@ -124,6 +121,18 @@ typedef struct { int x_handy; /* extra private word */ } XDR; +/* + * A xdrproc_t exists for each data type which is to be encoded or decoded. + * + * The second argument to the xdrproc_t is a pointer to an opaque pointer. + * The opaque pointer generally points to a structure of the data type + * to be decoded. If this pointer is 0, then the type routines should + * allocate dynamic storage of the appropriate size and return it. + * + * XXX can't actually prototype it, because some take three args!!! + */ +typedef bool_t (*xdrproc_t) __P((/* XDR *, void *, u_int */)); + /* * Operations defined on a XDR handle * @@ -232,6 +241,10 @@ extern bool_t xdr_long __P((XDR *, long *)); extern bool_t xdr_u_long __P((XDR *, u_long *)); extern bool_t xdr_short __P((XDR *, short *)); extern bool_t xdr_u_short __P((XDR *, u_short *)); +extern bool_t xdr_int16_t __P((XDR *, int16_t *)); +extern bool_t xdr_u_int16_t __P((XDR *, u_int16_t *)); +extern bool_t xdr_int32_t __P((XDR *, int32_t *)); +extern bool_t xdr_u_int32_t __P((XDR *, u_int32_t *)); extern bool_t xdr_bool __P((XDR *, bool_t *)); extern bool_t xdr_enum __P((XDR *, enum_t *)); extern bool_t xdr_array __P((XDR *, char **, u_int *, u_int, u_int, xdrproc_t)); @@ -240,7 +253,7 @@ extern bool_t xdr_opaque __P((XDR *, caddr_t, u_int)); extern bool_t xdr_string __P((XDR *, char **, u_int)); extern bool_t xdr_union __P((XDR *, enum_t *, char *, struct xdr_discrim *, xdrproc_t)); extern bool_t xdr_char __P((XDR *, char *)); -extern bool_t xdr_u_char __P((XDR *, char *)); +extern bool_t xdr_u_char __P((XDR *, u_char *)); extern bool_t xdr_vector __P((XDR *, char *, u_int, u_int, xdrproc_t)); extern bool_t xdr_float __P((XDR *, float *)); extern bool_t xdr_double __P((XDR *, double *)); @@ -260,7 +273,7 @@ struct netobj { char *n_bytes; }; typedef struct netobj netobj; -extern bool_t xdr_netobj(); +extern bool_t xdr_netobj __P((XDR *, struct netobj *)); /* * These are the public routines for the various implementations of @@ -276,7 +289,9 @@ extern void xdrstdio_create __P((XDR *, FILE *, enum xdr_op)); #endif /* XDR pseudo records for tcp */ -extern void xdrrec_create __P((XDR *, u_int, u_int, char *, int (*)(), int (*)())); +extern void xdrrec_create __P((XDR *, u_int, u_int, char *, + int (*) __P((caddr_t, caddr_t, int)), + int (*) __P((caddr_t, caddr_t, int)))); /* make end of xdr record */ extern bool_t xdrrec_endofrecord __P((XDR *, int)); -- cgit v1.2.3