rpc.c revision 199767f8919635c4928607450d9e0abb932109ce
/* $NetBSD: rpc.c,v 1.18 1998/01/23 19:27:45 thorpej Exp $ */
/*
* Copyright (c) 1992 Regents of the University of California.
* All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#) Header: rpc.c,v 1.12 93/09/28 08:31:56 leres Exp (LBL)
*/
__FBSDID("$FreeBSD$");
/*
* RPC functions used by NFS and bootparams.
* Note that bootparams requires the ability to find out the
* address of the server from which its response has come.
* buffer space provided by the caller. (See rpc_fromaddr)
*/
#include <netinet/in_systm.h>
#include <string.h>
#include "rpcv2.h"
#include "stand.h"
#include "net.h"
#include "netif.h"
#include "rpc.h"
struct auth_info {
};
struct auth_unix {
};
struct rpc_call {
};
struct rpc_reply {
union {
struct {
} rpu_rok;
} rp_u;
};
/* Local forwards */
int rpc_xid;
/*
* Make a rpc call; return length of answer
* Note: Caller must leave room for headers.
*/
{
n_long x;
int port; /* host order */
#ifdef RPC_DEBUG
if (debug)
printf("rpc_call: prog=0x%x vers=%d proc=%d\n",
#endif
if (port == -1)
return (-1);
/*
* Prepend authorization stuff and headers.
* Note, must prepend things in reverse order.
*/
/* Auth verifier is always auth_null */
#if 1
/* Auth credentials: always auth unix (as root) */
#else
/* Auth credentials: always auth_null (XXX OK?) */
#endif
/* RPC call structure. */
rpc_xid++;
/* Make room for the rpc_reply header. */
#ifdef RPC_DEBUG
if (debug)
#endif
if (cc == -1)
return (-1);
return (-1);
}
/*
* Check the RPC reply status.
* The xid, dir, astatus were already checked.
*/
if (x != 0) {
#ifdef RPC_DEBUG
if (debug)
printf("callrpc: reply auth != NULL\n");
#endif
return(-1);
}
if (x != 0) {
printf("callrpc: error = %ld\n", (long)x);
return(-1);
}
}
/*
* Returns true if packet is the one we're waiting for.
* This just checks the XID, direction, acceptance.
* Remaining checks are done by callrpc
*/
static ssize_t
{
ssize_t n;
int x;
errno = 0;
#ifdef RPC_DEBUG
if (debug)
#endif
if (n <= (4 * 4))
return -1;
if (x != rpc_xid) {
#ifdef RPC_DEBUG
if (debug)
#endif
return -1;
}
if (x != RPC_REPLY) {
#ifdef RPC_DEBUG
if (debug)
printf("recvrpc: rp_direction %d != REPLY\n", x);
#endif
return -1;
}
if (x != RPC_MSGACCEPTED) {
return -1;
}
/* Return data count (thus indicating success) */
return (n);
}
/*
* Given a pointer to a reply just received,
*/
void
{
struct hackhdr {
/* Tail of IP header: just IP addresses */
/* UDP header: */
/* RPC reply header: */
} *hhdr;
}
/*
* RPC Portmapper cache
*/
int rpc_pmap_num;
struct pmap_list {
int port; /* host order */
/*
* return port number in host order, or -1.
* arguments are:
* addr .. server, net order.
* prog .. host order.
* vers .. host order.
*/
int
{
{
}
}
return (-1);
}
/*
* arguments are:
* addr .. server, net order.
* prog .. host order.
* vers .. host order.
* port .. host order.
*/
void
{
/* Don't overflow cache... */
if (rpc_pmap_num >= PMAP_NUM) {
/* ... just re-use the last entry. */
#ifdef RPC_DEBUG
printf("rpc_pmap_putcache: cache overflow\n");
#endif
}
rpc_pmap_num++;
/* Cache answer */
}
/*
* Request a port number from the port mapper.
* Returns the port in host order.
* prog and vers are host order.
*/
int
{
struct args {
} *args;
struct res {
} *res;
struct {
struct args d;
} sdata;
struct {
struct res d;
} rdata;
int port;
#ifdef RPC_DEBUG
if (debug)
#endif
/* This one is fixed forever. */
goto out;
}
/* Try for cached answer first */
if (port != -1)
goto out;
return (-1);
}
out:
#ifdef RPC_DEBUG
if (debug)
#endif
return (port);
}