/* $NetBSD: bootparam.c,v 1.11 1997/06/26 19:11:32 drochner Exp $ */
/*
* Copyright (c) 1995 Gordon W. Ross
* All rights reserved.
*
* 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
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* 4. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Gordon W. Ross
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
__FBSDID("$FreeBSD$");
/*
*/
#include <netinet/in_systm.h>
#include <string.h>
#include "rpcv2.h"
#include "stand.h"
#include "net.h"
#include "netif.h"
#include "rpc.h"
#include "bootparam.h"
#ifdef DEBUG_RPC
#else
#define RPC_PRINTF(a)
#endif
/*
* RPC definitions for bootparamd
*/
/*
* Inet address in RPC messages
* (Note, really four ints, NOT chars. Blech.)
*/
struct xdr_inaddr {
};
/*
* Given client IP address, get:
* client name (hostname)
* domain name (domainname)
* gateway address
*
* The hostname and domainname are set here for convenience.
*
* Note - bpsin is initialized to the broadcast address,
* and will be replaced with the bootparam server address
* after this call is complete. Have to use PMAP_PROC_CALL
* to make sure we get responses only from a servers that
* know about us (don't want to broadcast a getport call).
*/
int
int sockfd;
{
/* RPC structures for PMAPPROC_CALLIT */
struct args {
} *args;
struct repl {
/* encapsulated data here */
} *repl;
struct {
struct args d;
} sdata;
struct {
struct repl d;
} rdata;
struct iodesc *d;
int len, x;
if (!(d = socktodesc(sockfd))) {
return (-1);
}
/*
* Build request args for PMAPPROC_CALLIT.
*/
/*
* append encapsulated data (client IP address)
*/
return (-1);
/* rpc_call will set d->destport */
if (len < 8) {
printf("bootparamd: 'whoami' call failed\n");
return (-1);
}
/* Save bootparam server address (from IP header). */
/*
* Note that bp_server_port is now 111 due to the
* indirect call (using PMAPPROC_CALLIT), so get the
* actual port number from the reply data.
*/
RPC_PRINTF(("bp_whoami: server at %s:%d\n",
/* We have just done a portmap call, so cache the portnum. */
(int)ntohs(bp_server_port));
/*
*/
if (len < x) {
return (-1);
}
/* client name */
RPC_PRINTF(("bp_whoami: bad hostname\n"));
return (-1);
}
/* domain name */
RPC_PRINTF(("bp_whoami: bad domainname\n"));
return (-1);
}
/* gateway address */
RPC_PRINTF(("bp_whoami: bad gateway\n"));
return (-1);
}
/* success */
return(0);
}
/*
* Given client name and file "key", get:
* server name
* server IP address
* server pathname
*/
int
int sockfd;
char *key;
char *pathname;
{
struct {
n_long d[64];
} sdata;
struct {
n_long d[128];
} rdata;
/* misc... */
struct iodesc *d;
if (!(d = socktodesc(sockfd))) {
return (-1);
}
/*
* Build request message.
*/
/* client name (hostname) */
RPC_PRINTF(("bp_getfile: bad client\n"));
return (-1);
}
/* key name (root or swap) */
RPC_PRINTF(("bp_getfile: bad key\n"));
return (-1);
}
d->destip = bp_server_addr;
/* rpc_call will set d->destport */
if (rlen < 4) {
RPC_PRINTF(("bp_getfile: short reply\n"));
return (-1);
}
/*
* Parse result message.
*/
/* server name */
RPC_PRINTF(("bp_getfile: bad server name\n"));
return (-1);
}
RPC_PRINTF(("bp_getfile: bad server addr\n"));
return (-1);
}
/* server pathname */
RPC_PRINTF(("bp_getfile: bad server path\n"));
return (-1);
}
/* success */
return(0);
}
/*
* eXternal Data Representation routines.
* (but with non-standard args...)
*/
int
char **pkt;
char *str;
int len;
{
char *datap;
/* The data will be int aligned. */
return (0);
}
int
char **pkt;
char *str;
int *len_p; /* bufsize - 1 */
{
char *datap;
/* The data will be int aligned. */
return (0);
}
int
char **pkt;
{
union {
n_long l; /* network order */
u_char c[4];
} uia;
/* The data will be int aligned. */
/*
* Note: the htonl() calls below DO NOT
* imply that uia.l is in host order.
* In fact this needs it in net order.
*/
return (0);
}
int
char **pkt;
{
union {
n_long l; /* network order */
u_char c[4];
} uia;
/* The data will be int aligned. */
RPC_PRINTF(("xdr_inaddr_decode: bad addrtype=%d\n",
return(-1);
}
/*
* Note: the ntohl() calls below DO NOT
* imply that uia.l is in host order.
* In fact this needs it in net order.
*/
return (0);
}