summaryrefslogtreecommitdiffstats
path: root/lib/libc/rpc/rpc_prot.c
diff options
context:
space:
mode:
authoralfred <alfred@FreeBSD.org>2001-03-19 12:50:13 +0000
committeralfred <alfred@FreeBSD.org>2001-03-19 12:50:13 +0000
commitf67e4a8fc7fc95c74bd6c09d3453200de47faea5 (patch)
tree98b613188d263fdcef5f2d020e5e8c374db1f5b6 /lib/libc/rpc/rpc_prot.c
parent6f24d923a7fa9d1679753d77cc982ec72c22a197 (diff)
downloadFreeBSD-src-f67e4a8fc7fc95c74bd6c09d3453200de47faea5.zip
FreeBSD-src-f67e4a8fc7fc95c74bd6c09d3453200de47faea5.tar.gz
Bring in a hybrid of SunSoft's transport-independent RPC (TI-RPC) and
associated changes that had to happen to make this possible as well as bugs fixed along the way. Bring in required TLI library routines to support this. Since we don't support TLI we've essentially copied what NetBSD has done, adding a thin layer to emulate direct the TLI calls into BSD socket calls. This is mostly from Sun's tirpc release that was made in 1994, however some fixes were backported from the 1999 release (supposedly only made available after this porting effort was underway). The submitter has agreed to continue on and bring us up to the 1999 release. Several key features are introduced with this update: Client calls are thread safe. (1999 code has server side thread safe) Updated, a more modern interface. Many userland updates were done to bring the code up to par with the recent RPC API. There is an update to the pthreads library, a function pthread_main_np() was added to emulate a function of Sun's threads library. While we're at it, bring in NetBSD's lockd, it's been far too long of a wait. New rpcbind(8) replaces portmap(8) (supporting communication over an authenticated Unix-domain socket, and by default only allowing set and unset requests over that channel). It's much more secure than the old portmapper. Umount(8), mountd(8), mount_nfs(8), nfsd(8) have also been upgraded to support TI-RPC and to support IPV6. Umount(8) is also fixed to unmount pathnames longer than 80 chars, which are currently truncated by the Kernel statfs structure. Submitted by: Martin Blapp <mb@imp.ch> Manpage review: ru Secure RPC implemented by: wpaul
Diffstat (limited to 'lib/libc/rpc/rpc_prot.c')
-rw-r--r--lib/libc/rpc/rpc_prot.c140
1 files changed, 99 insertions, 41 deletions
diff --git a/lib/libc/rpc/rpc_prot.c b/lib/libc/rpc/rpc_prot.c
index 940a29d..4dbfe19 100644
--- a/lib/libc/rpc/rpc_prot.c
+++ b/lib/libc/rpc/rpc_prot.c
@@ -1,3 +1,5 @@
+/* $NetBSD: rpc_prot.c,v 1.16 2000/06/02 23:11:13 fvdl Exp $ */
+
/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
@@ -27,9 +29,10 @@
* Mountain View, California 94043
*/
+#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-/*static char *sccsid = "from: @(#)rpc_prot.c 1.36 87/08/11 Copyr 1984 Sun Micro";*/
-/*static char *sccsid = "from: @(#)rpc_prot.c 2.3 88/08/07 4.0 RPCSRC";*/
+static char *sccsid = "@(#)rpc_prot.c 1.36 87/08/11 Copyr 1984 Sun Micro";
+static char *sccsid = "@(#)rpc_prot.c 2.3 88/08/07 4.0 RPCSRC";
static char *rcsid = "$FreeBSD$";
#endif
@@ -46,13 +49,20 @@ static char *rcsid = "$FreeBSD$";
* routines are also in this program.
*/
+#include "namespace.h"
#include <sys/param.h>
+#include <assert.h>
+
#include <rpc/rpc.h>
+#include "un-namespace.h"
+
+static void accepted __P((enum accept_stat, struct rpc_err *));
+static void rejected __P((enum reject_stat, struct rpc_err *));
/* * * * * * * * * * * * * * XDR Authentication * * * * * * * * * * * */
-struct opaque_auth _null_auth;
+extern struct opaque_auth _null_auth;
/*
* XDR an opaque authentication struct
@@ -60,10 +70,13 @@ struct opaque_auth _null_auth;
*/
bool_t
xdr_opaque_auth(xdrs, ap)
- register XDR *xdrs;
- register struct opaque_auth *ap;
+ XDR *xdrs;
+ struct opaque_auth *ap;
{
+ assert(xdrs != NULL);
+ assert(ap != NULL);
+
if (xdr_enum(xdrs, &(ap->oa_flavor)))
return (xdr_bytes(xdrs, &ap->oa_base,
&ap->oa_length, MAX_AUTH_BYTES));
@@ -75,10 +88,14 @@ xdr_opaque_auth(xdrs, ap)
*/
bool_t
xdr_des_block(xdrs, blkp)
- register XDR *xdrs;
- register des_block *blkp;
+ XDR *xdrs;
+ des_block *blkp;
{
- return (xdr_opaque(xdrs, (caddr_t)blkp, sizeof(des_block)));
+
+ assert(xdrs != NULL);
+ assert(blkp != NULL);
+
+ return (xdr_opaque(xdrs, (caddr_t)(void *)blkp, sizeof(des_block)));
}
/* * * * * * * * * * * * * * XDR RPC MESSAGE * * * * * * * * * * * * * * * */
@@ -88,10 +105,13 @@ xdr_des_block(xdrs, blkp)
*/
bool_t
xdr_accepted_reply(xdrs, ar)
- register XDR *xdrs;
- register struct accepted_reply *ar;
+ XDR *xdrs;
+ struct accepted_reply *ar;
{
+ assert(xdrs != NULL);
+ assert(ar != NULL);
+
/* personalized union, rather than calling xdr_union */
if (! xdr_opaque_auth(xdrs, &(ar->ar_verf)))
return (FALSE);
@@ -106,7 +126,11 @@ xdr_accepted_reply(xdrs, ar)
if (! xdr_u_int32_t(xdrs, &(ar->ar_vers.low)))
return (FALSE);
return (xdr_u_int32_t(xdrs, &(ar->ar_vers.high)));
- default:
+
+ case GARBAGE_ARGS:
+ case SYSTEM_ERR:
+ case PROC_UNAVAIL:
+ case PROG_UNAVAIL:
break;
}
return (TRUE); /* TRUE => open ended set of problems */
@@ -115,12 +139,15 @@ xdr_accepted_reply(xdrs, ar)
/*
* XDR the MSG_DENIED part of a reply message union
*/
-bool_t
+bool_t
xdr_rejected_reply(xdrs, rr)
- register XDR *xdrs;
- register struct rejected_reply *rr;
+ XDR *xdrs;
+ struct rejected_reply *rr;
{
+ assert(xdrs != NULL);
+ assert(rr != NULL);
+
/* personalized union, rather than calling xdr_union */
if (! xdr_enum(xdrs, (enum_t *)&(rr->rj_stat)))
return (FALSE);
@@ -134,12 +161,14 @@ xdr_rejected_reply(xdrs, rr)
case AUTH_ERROR:
return (xdr_enum(xdrs, (enum_t *)&(rr->rj_why)));
}
+ /* NOTREACHED */
+ assert(0);
return (FALSE);
}
-static struct xdr_discrim reply_dscrm[3] = {
- { (int)MSG_ACCEPTED, xdr_accepted_reply },
- { (int)MSG_DENIED, xdr_rejected_reply },
+static const struct xdr_discrim reply_dscrm[3] = {
+ { (int)MSG_ACCEPTED, (xdrproc_t)xdr_accepted_reply },
+ { (int)MSG_DENIED, (xdrproc_t)xdr_rejected_reply },
{ __dontcare__, NULL_xdrproc_t } };
/*
@@ -147,15 +176,19 @@ static struct xdr_discrim reply_dscrm[3] = {
*/
bool_t
xdr_replymsg(xdrs, rmsg)
- register XDR *xdrs;
- register struct rpc_msg *rmsg;
+ XDR *xdrs;
+ struct rpc_msg *rmsg;
{
+ assert(xdrs != NULL);
+ assert(rmsg != NULL);
+
if (
- xdr_u_int32_t(xdrs, &(rmsg->rm_xid)) &&
+ xdr_u_int32_t(xdrs, &(rmsg->rm_xid)) &&
xdr_enum(xdrs, (enum_t *)&(rmsg->rm_direction)) &&
(rmsg->rm_direction == REPLY) )
return (xdr_union(xdrs, (enum_t *)&(rmsg->rm_reply.rp_stat),
- (caddr_t)&(rmsg->rm_reply.ru), reply_dscrm, NULL_xdrproc_t));
+ (caddr_t)(void *)&(rmsg->rm_reply.ru), reply_dscrm,
+ NULL_xdrproc_t));
return (FALSE);
}
@@ -167,10 +200,13 @@ xdr_replymsg(xdrs, rmsg)
*/
bool_t
xdr_callhdr(xdrs, cmsg)
- register XDR *xdrs;
- register struct rpc_msg *cmsg;
+ XDR *xdrs;
+ struct rpc_msg *cmsg;
{
+ assert(xdrs != NULL);
+ assert(cmsg != NULL);
+
cmsg->rm_direction = CALL;
cmsg->rm_call.cb_rpcvers = RPC_MSG_VERSION;
if (
@@ -179,7 +215,7 @@ xdr_callhdr(xdrs, cmsg)
xdr_enum(xdrs, (enum_t *)&(cmsg->rm_direction)) &&
xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_prog)) )
- return (xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)));
+ return (xdr_u_int32_t(xdrs, &(cmsg->rm_call.cb_vers)));
return (FALSE);
}
@@ -187,10 +223,12 @@ xdr_callhdr(xdrs, cmsg)
static void
accepted(acpt_stat, error)
- register enum accept_stat acpt_stat;
- register struct rpc_err *error;
+ enum accept_stat acpt_stat;
+ struct rpc_err *error;
{
+ assert(error != NULL);
+
switch (acpt_stat) {
case PROG_UNAVAIL:
@@ -217,34 +255,35 @@ accepted(acpt_stat, error)
error->re_status = RPC_SUCCESS;
return;
}
+ /* NOTREACHED */
/* something's wrong, but we don't know what ... */
error->re_status = RPC_FAILED;
- error->re_lb.s1 = (long)MSG_ACCEPTED;
- error->re_lb.s2 = (long)acpt_stat;
+ error->re_lb.s1 = (int32_t)MSG_ACCEPTED;
+ error->re_lb.s2 = (int32_t)acpt_stat;
}
-static void
+static void
rejected(rjct_stat, error)
- register enum reject_stat rjct_stat;
- register struct rpc_err *error;
+ enum reject_stat rjct_stat;
+ struct rpc_err *error;
{
- switch (rjct_stat) {
+ assert(error != NULL);
- case RPC_VERSMISMATCH:
+ switch (rjct_stat) {
+ case RPC_MISMATCH:
error->re_status = RPC_VERSMISMATCH;
return;
case AUTH_ERROR:
error->re_status = RPC_AUTHERROR;
return;
- default:
- break;
}
/* something's wrong, but we don't know what ... */
+ /* NOTREACHED */
error->re_status = RPC_FAILED;
- error->re_lb.s1 = (long)MSG_DENIED;
- error->re_lb.s2 = (long)rjct_stat;
+ error->re_lb.s1 = (int32_t)MSG_DENIED;
+ error->re_lb.s2 = (int32_t)rjct_stat;
}
/*
@@ -252,10 +291,13 @@ rejected(rjct_stat, error)
*/
void
_seterr_reply(msg, error)
- register struct rpc_msg *msg;
- register struct rpc_err *error;
+ struct rpc_msg *msg;
+ struct rpc_err *error;
{
+ assert(msg != NULL);
+ assert(error != NULL);
+
/* optimized for normal, SUCCESSful case */
switch (msg->rm_reply.rp_stat) {
@@ -263,7 +305,7 @@ _seterr_reply(msg, error)
if (msg->acpted_rply.ar_stat == SUCCESS) {
error->re_status = RPC_SUCCESS;
return;
- };
+ }
accepted(msg->acpted_rply.ar_stat, error);
break;
@@ -273,7 +315,7 @@ _seterr_reply(msg, error)
default:
error->re_status = RPC_FAILED;
- error->re_lb.s1 = (long)(msg->rm_reply.rp_stat);
+ error->re_lb.s1 = (int32_t)(msg->rm_reply.rp_stat);
break;
}
switch (error->re_status) {
@@ -291,6 +333,22 @@ _seterr_reply(msg, error)
error->re_vers.low = msg->acpted_rply.ar_vers.low;
error->re_vers.high = msg->acpted_rply.ar_vers.high;
break;
+
+ case RPC_FAILED:
+ case RPC_SUCCESS:
+ case RPC_PROGNOTREGISTERED:
+ case RPC_PMAPFAILURE:
+ case RPC_UNKNOWNPROTO:
+ case RPC_UNKNOWNHOST:
+ case RPC_SYSTEMERROR:
+ case RPC_CANTDECODEARGS:
+ case RPC_PROCUNAVAIL:
+ case RPC_PROGUNAVAIL:
+ case RPC_TIMEDOUT:
+ case RPC_CANTRECV:
+ case RPC_CANTSEND:
+ case RPC_CANTDECODERES:
+ case RPC_CANTENCODEARGS:
default:
break;
}
OpenPOWER on IntegriCloud