1995-02-26 23:40:53 +00:00
|
|
|
/*
|
|
|
|
|
1995-05-30 03:57:47 +00:00
|
|
|
This code is not copyright, and is placed in the public domain. Feel free to
|
1995-02-26 23:40:53 +00:00
|
|
|
use and modify. Please send modifications and/or suggestions + bug fixes to
|
|
|
|
|
|
|
|
Klas Heggemann <klas@nada.kth.se>
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
1997-09-04 11:50:37 +00:00
|
|
|
#ifndef lint
|
|
|
|
static const char rcsid[] =
|
1999-08-28 01:35:59 +00:00
|
|
|
"$FreeBSD$";
|
1997-09-04 11:50:37 +00:00
|
|
|
#endif /* not lint */
|
1995-02-26 23:40:53 +00:00
|
|
|
|
|
|
|
#include "bootparam_prot.h"
|
|
|
|
#include <rpc/rpc.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
1998-06-12 14:39:00 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
1997-09-04 11:50:37 +00:00
|
|
|
#include <err.h>
|
1995-02-26 23:40:53 +00:00
|
|
|
#include <netdb.h>
|
2003-06-20 04:54:27 +00:00
|
|
|
#include <stdlib.h>
|
1995-02-26 23:40:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* #define bp_address_u bp_address */
|
|
|
|
#include <stdio.h>
|
1997-09-04 11:50:37 +00:00
|
|
|
#include <string.h>
|
1995-02-26 23:40:53 +00:00
|
|
|
|
|
|
|
int broadcast;
|
|
|
|
|
|
|
|
char cln[MAX_MACHINE_NAME+1];
|
|
|
|
char dmn[MAX_MACHINE_NAME+1];
|
|
|
|
char path[MAX_PATH_LEN+1];
|
2007-11-07 10:53:41 +00:00
|
|
|
static void usage(void);
|
|
|
|
int printgetfile(bp_getfile_res *);
|
|
|
|
int printwhoami(bp_whoami_res *);
|
1995-02-26 23:40:53 +00:00
|
|
|
|
2017-08-17 20:37:01 +00:00
|
|
|
static bool_t
|
|
|
|
eachres_whoami(bp_whoami_res *resultp, struct sockaddr_in *raddr)
|
1995-02-26 23:40:53 +00:00
|
|
|
{
|
|
|
|
struct hostent *he;
|
|
|
|
|
|
|
|
he = gethostbyaddr((char *)&raddr->sin_addr.s_addr,4,AF_INET);
|
|
|
|
printf("%s answered:\n", he ? he->h_name : inet_ntoa(raddr->sin_addr));
|
|
|
|
printwhoami(resultp);
|
|
|
|
printf("\n");
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2017-08-17 20:37:01 +00:00
|
|
|
static bool_t
|
|
|
|
eachres_getfile(bp_getfile_res *resultp, struct sockaddr_in *raddr)
|
1995-02-26 23:40:53 +00:00
|
|
|
{
|
|
|
|
struct hostent *he;
|
|
|
|
|
|
|
|
he = gethostbyaddr((char *)&raddr->sin_addr.s_addr,4,AF_INET);
|
|
|
|
printf("%s answered:\n", he ? he->h_name : inet_ntoa(raddr->sin_addr));
|
|
|
|
printgetfile(resultp);
|
|
|
|
printf("\n");
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-09-04 11:50:37 +00:00
|
|
|
int
|
2017-08-17 20:37:01 +00:00
|
|
|
main(int argc, char **argv)
|
1995-02-26 23:40:53 +00:00
|
|
|
{
|
|
|
|
char *server;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-02-26 23:40:53 +00:00
|
|
|
bp_whoami_arg whoami_arg;
|
|
|
|
bp_whoami_res *whoami_res, stat_whoami_res;
|
|
|
|
bp_getfile_arg getfile_arg;
|
|
|
|
bp_getfile_res *getfile_res, stat_getfile_res;
|
|
|
|
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-02-26 23:40:53 +00:00
|
|
|
long the_inet_addr;
|
|
|
|
CLIENT *clnt;
|
|
|
|
|
|
|
|
stat_whoami_res.client_name = cln;
|
|
|
|
stat_whoami_res.domain_name = dmn;
|
|
|
|
|
|
|
|
stat_getfile_res.server_name = cln;
|
|
|
|
stat_getfile_res.server_path = path;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1997-09-04 11:50:37 +00:00
|
|
|
if (argc < 3)
|
|
|
|
usage();
|
1995-02-26 23:40:53 +00:00
|
|
|
|
|
|
|
server = argv[1];
|
|
|
|
if ( ! strcmp(server , "all") ) broadcast = 1;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-02-26 23:40:53 +00:00
|
|
|
if ( ! broadcast ) {
|
|
|
|
clnt = clnt_create(server,BOOTPARAMPROG, BOOTPARAMVERS, "udp");
|
2003-06-20 04:54:27 +00:00
|
|
|
if ( clnt == NULL )
|
|
|
|
errx(1, "could not contact bootparam server on host %s", server);
|
1995-05-30 03:57:47 +00:00
|
|
|
}
|
1995-02-26 23:40:53 +00:00
|
|
|
|
|
|
|
switch (argc) {
|
|
|
|
case 3:
|
|
|
|
whoami_arg.client_address.address_type = IP_ADDR_TYPE;
|
|
|
|
the_inet_addr = inet_addr(argv[2]);
|
2013-10-15 07:37:30 +00:00
|
|
|
if ( the_inet_addr == INADDR_NONE)
|
1997-09-04 11:50:37 +00:00
|
|
|
errx(2, "bogus addr %s", argv[2]);
|
1995-02-26 23:40:53 +00:00
|
|
|
bcopy(&the_inet_addr,&whoami_arg.client_address.bp_address_u.ip_addr,4);
|
|
|
|
|
|
|
|
if (! broadcast ) {
|
|
|
|
whoami_res = bootparamproc_whoami_1(&whoami_arg, clnt);
|
|
|
|
printf("Whoami returning:\n");
|
|
|
|
if (printwhoami(whoami_res)) {
|
1997-09-04 11:50:37 +00:00
|
|
|
errx(1, "bad answer returned from server %s", server);
|
1995-02-26 23:40:53 +00:00
|
|
|
} else
|
|
|
|
exit(0);
|
|
|
|
} else {
|
2012-01-20 01:39:26 +00:00
|
|
|
(void)clnt_broadcast(BOOTPARAMPROG, BOOTPARAMVERS,
|
1995-02-26 23:40:53 +00:00
|
|
|
BOOTPARAMPROC_WHOAMI,
|
2003-06-20 04:54:27 +00:00
|
|
|
(xdrproc_t)xdr_bp_whoami_arg,
|
|
|
|
(char *)&whoami_arg,
|
|
|
|
(xdrproc_t)xdr_bp_whoami_res,
|
|
|
|
(char *)&stat_whoami_res,
|
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
2001-03-19 12:50:13 +00:00
|
|
|
(resultproc_t)eachres_whoami);
|
1995-02-26 23:40:53 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
|
|
getfile_arg.client_name = argv[2];
|
|
|
|
getfile_arg.file_id = argv[3];
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-02-26 23:40:53 +00:00
|
|
|
if (! broadcast ) {
|
|
|
|
getfile_res = bootparamproc_getfile_1(&getfile_arg,clnt);
|
|
|
|
printf("getfile returning:\n");
|
|
|
|
if (printgetfile(getfile_res)) {
|
1997-09-04 11:50:37 +00:00
|
|
|
errx(1, "bad answer returned from server %s", server);
|
1995-02-26 23:40:53 +00:00
|
|
|
} else
|
1995-05-30 03:57:47 +00:00
|
|
|
exit(0);
|
1995-02-26 23:40:53 +00:00
|
|
|
} else {
|
2012-01-20 01:39:26 +00:00
|
|
|
(void)clnt_broadcast(BOOTPARAMPROG, BOOTPARAMVERS,
|
1995-02-26 23:40:53 +00:00
|
|
|
BOOTPARAMPROC_GETFILE,
|
2003-06-20 04:54:27 +00:00
|
|
|
(xdrproc_t)xdr_bp_getfile_arg,
|
|
|
|
(char *)&getfile_arg,
|
|
|
|
(xdrproc_t)xdr_bp_getfile_res,
|
|
|
|
(char *)&stat_getfile_res,
|
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
2001-03-19 12:50:13 +00:00
|
|
|
(resultproc_t)eachres_getfile);
|
1995-02-26 23:40:53 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-02-26 23:40:53 +00:00
|
|
|
default:
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1997-09-04 11:50:37 +00:00
|
|
|
usage();
|
1995-02-26 23:40:53 +00:00
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-02-26 23:40:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-09-04 11:50:37 +00:00
|
|
|
static void
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"usage: callbootd server procnum (IP-addr | host fileid)\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1997-09-04 11:50:37 +00:00
|
|
|
int
|
|
|
|
printwhoami(res)
|
1995-02-26 23:40:53 +00:00
|
|
|
bp_whoami_res *res;
|
|
|
|
{
|
|
|
|
if ( res) {
|
|
|
|
printf("client_name:\t%s\ndomain_name:\t%s\n",
|
|
|
|
res->client_name, res->domain_name);
|
|
|
|
printf("router:\t%d.%d.%d.%d\n",
|
|
|
|
255 & res->router_address.bp_address_u.ip_addr.net,
|
|
|
|
255 & res->router_address.bp_address_u.ip_addr.host,
|
|
|
|
255 & res->router_address.bp_address_u.ip_addr.lh,
|
|
|
|
255 & res->router_address.bp_address_u.ip_addr.impno);
|
|
|
|
return(0);
|
|
|
|
} else {
|
1997-09-04 11:50:37 +00:00
|
|
|
warnx("null answer!!!");
|
1995-02-26 23:40:53 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
}
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-02-26 23:40:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
printgetfile(res)
|
|
|
|
bp_getfile_res *res;
|
|
|
|
{
|
|
|
|
if (res) {
|
|
|
|
printf("server_name:\t%s\nserver_address:\t%s\npath:\t%s\n",
|
1995-05-30 03:57:47 +00:00
|
|
|
res->server_name,
|
1998-06-12 14:39:00 +00:00
|
|
|
inet_ntoa(*(struct in_addr *)&res->server_address.bp_address_u.ip_addr),
|
1995-02-26 23:40:53 +00:00
|
|
|
res->server_path);
|
|
|
|
return(0);
|
|
|
|
} else {
|
1997-09-04 11:50:37 +00:00
|
|
|
warnx("null answer!!!");
|
1995-02-26 23:40:53 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
}
|