2004-09-07 17:20:39 +04:00
|
|
|
/* $NetBSD: bootparamd.c,v 1.43 2004/09/07 13:20:40 jrf Exp $ */
|
1996-08-31 00:03:54 +04:00
|
|
|
|
1994-01-08 16:22:03 +03:00
|
|
|
/*
|
|
|
|
* This code is not copyright, and is placed in the public domain.
|
|
|
|
* Feel free to use and modify. Please send modifications and/or
|
|
|
|
* suggestions + bug fixes to Klas Heggemann <klas@nada.kth.se>
|
1994-01-10 17:04:44 +03:00
|
|
|
*
|
1994-01-08 16:22:03 +03:00
|
|
|
* Various small changes by Theo de Raadt <deraadt@fsa.ca>
|
1994-01-10 17:04:44 +03:00
|
|
|
* Parser rewritten (adding YP support) by Roland McGrath <roland@frob.com>
|
1994-01-08 16:22:03 +03:00
|
|
|
*/
|
|
|
|
|
1997-07-28 10:03:54 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
2004-09-07 17:20:39 +04:00
|
|
|
__RCSID("$NetBSD: bootparamd.c,v 1.43 2004/09/07 13:20:40 jrf Exp $");
|
1997-07-28 10:03:54 +04:00
|
|
|
#endif
|
|
|
|
|
1994-01-08 16:22:03 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/socket.h>
|
1996-12-08 16:44:26 +03:00
|
|
|
|
2000-06-28 05:30:56 +04:00
|
|
|
#include <assert.h>
|
1994-01-08 16:22:03 +03:00
|
|
|
#include <ctype.h>
|
1999-08-23 05:09:42 +04:00
|
|
|
#include <errno.h>
|
1996-12-08 16:44:26 +03:00
|
|
|
#include <err.h>
|
2000-06-28 05:30:56 +04:00
|
|
|
#include <fnmatch.h>
|
1996-12-08 16:44:26 +03:00
|
|
|
#include <netdb.h>
|
1997-07-28 10:03:54 +04:00
|
|
|
#include <stdlib.h>
|
1996-12-08 16:44:26 +03:00
|
|
|
#include <stdio.h>
|
1994-01-10 17:04:44 +03:00
|
|
|
#include <string.h>
|
1996-12-08 16:44:26 +03:00
|
|
|
#include <syslog.h>
|
1997-07-28 10:03:54 +04:00
|
|
|
#include <unistd.h>
|
1999-06-06 06:38:00 +04:00
|
|
|
#include <util.h>
|
2000-04-14 16:14:40 +04:00
|
|
|
#include <ifaddrs.h>
|
1996-12-08 16:44:26 +03:00
|
|
|
|
2000-04-27 13:48:59 +04:00
|
|
|
#include <net/if.h>
|
|
|
|
|
1996-12-08 16:44:26 +03:00
|
|
|
#include <netinet/in.h>
|
1996-10-14 23:28:09 +04:00
|
|
|
#include <arpa/inet.h>
|
1996-12-08 16:44:26 +03:00
|
|
|
|
|
|
|
#include <rpc/rpc.h>
|
1997-07-28 10:03:54 +04:00
|
|
|
#include <rpc/pmap_clnt.h>
|
1996-12-08 16:44:26 +03:00
|
|
|
#include <rpcsvc/bootparam_prot.h>
|
Split the notion of building Hesiod, Kerberos, S/key, and YP
infrastructure and using that infrastructure in programs.
* MKHESIOD, MKKERBEROS, MKSKEY, and MKYP control building
of the infratsructure (libraries, support programs, etc.)
* USE_HESIOD, USE_KERBEROS, USE_SKEY, and USE_YP control
building of support for using the corresponding API
in various libraries/programs that can use it.
As discussed on tech-toolchain.
2002-03-22 21:10:19 +03:00
|
|
|
#ifdef YP
|
1997-07-28 10:03:54 +04:00
|
|
|
#include <rpcsvc/ypclnt.h>
|
Split the notion of building Hesiod, Kerberos, S/key, and YP
infrastructure and using that infrastructure in programs.
* MKHESIOD, MKKERBEROS, MKSKEY, and MKYP control building
of the infratsructure (libraries, support programs, etc.)
* USE_HESIOD, USE_KERBEROS, USE_SKEY, and USE_YP control
building of support for using the corresponding API
in various libraries/programs that can use it.
As discussed on tech-toolchain.
2002-03-22 21:10:19 +03:00
|
|
|
#endif
|
1996-12-08 16:44:26 +03:00
|
|
|
|
1994-01-10 17:04:44 +03:00
|
|
|
#include "pathnames.h"
|
1994-01-08 16:22:03 +03:00
|
|
|
|
|
|
|
#define MAXLEN 800
|
|
|
|
|
|
|
|
static char hostname[MAX_MACHINE_NAME];
|
|
|
|
static char askname[MAX_MACHINE_NAME];
|
|
|
|
static char domain_name[MAX_MACHINE_NAME];
|
|
|
|
|
1995-06-24 19:03:49 +04:00
|
|
|
extern void bootparamprog_1 __P((struct svc_req *, SVCXPRT *));
|
1994-01-08 16:22:03 +03:00
|
|
|
|
1995-06-24 19:03:49 +04:00
|
|
|
int _rpcsvcdirty = 0;
|
|
|
|
int _rpcpmstart = 0;
|
1994-01-08 16:22:03 +03:00
|
|
|
int debug = 0;
|
|
|
|
int dolog = 0;
|
1997-07-28 10:03:54 +04:00
|
|
|
struct in_addr route_addr;
|
1994-01-08 16:22:03 +03:00
|
|
|
struct sockaddr_in my_addr;
|
1994-01-10 17:04:44 +03:00
|
|
|
char *bootpfile = _PATH_BOOTPARAMS;
|
2003-06-26 09:38:45 +04:00
|
|
|
char *iface = NULL;
|
1994-01-08 16:22:03 +03:00
|
|
|
|
1997-07-28 10:03:54 +04:00
|
|
|
int main __P((int, char *[]));
|
|
|
|
int lookup_bootparam __P((char *, char *, char *, char **, char **));
|
|
|
|
void usage __P((void));
|
2000-04-14 16:14:40 +04:00
|
|
|
static int get_localaddr __P((const char *, struct sockaddr_in *));
|
1994-01-08 16:22:03 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ever familiar
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
1997-07-28 10:03:54 +04:00
|
|
|
char *argv[];
|
1994-01-08 16:22:03 +03:00
|
|
|
{
|
|
|
|
SVCXPRT *transp;
|
|
|
|
struct hostent *he;
|
|
|
|
struct stat buf;
|
1996-03-31 03:53:51 +04:00
|
|
|
int c;
|
1994-01-08 16:22:03 +03:00
|
|
|
|
2003-06-26 09:38:45 +04:00
|
|
|
while ((c = getopt(argc, argv, "di:sr:f:")) != -1)
|
1994-01-08 16:22:03 +03:00
|
|
|
switch (c) {
|
|
|
|
case 'd':
|
|
|
|
debug = 1;
|
|
|
|
break;
|
2003-06-26 09:38:45 +04:00
|
|
|
case 'i':
|
|
|
|
iface = optarg;
|
|
|
|
break;
|
1994-01-08 16:22:03 +03:00
|
|
|
case 'r':
|
|
|
|
if (isdigit(*optarg)) {
|
1997-07-28 10:03:54 +04:00
|
|
|
if (inet_aton(optarg, &route_addr) != 0)
|
|
|
|
break;
|
1994-01-08 16:22:03 +03:00
|
|
|
}
|
|
|
|
he = gethostbyname(optarg);
|
1997-07-28 10:03:54 +04:00
|
|
|
if (he == 0) {
|
1997-09-08 06:21:52 +04:00
|
|
|
warnx("no such host: %s", optarg);
|
1994-01-08 16:22:03 +03:00
|
|
|
usage();
|
|
|
|
}
|
1997-10-18 15:27:49 +04:00
|
|
|
memmove(&route_addr.s_addr, he->h_addr, he->h_length);
|
1994-01-08 16:22:03 +03:00
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
bootpfile = optarg;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
dolog = 1;
|
|
|
|
#ifndef LOG_DAEMON
|
2001-01-11 04:43:25 +03:00
|
|
|
openlog("rpc.bootparamd", 0, 0);
|
1994-01-08 16:22:03 +03:00
|
|
|
#else
|
2001-01-11 04:43:25 +03:00
|
|
|
openlog("rpc.bootparamd", 0, LOG_DAEMON);
|
1994-01-08 16:22:03 +03:00
|
|
|
setlogmask(LOG_UPTO(LOG_NOTICE));
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
1996-12-08 16:44:26 +03:00
|
|
|
if (stat(bootpfile, &buf))
|
|
|
|
err(1, "%s", bootpfile);
|
|
|
|
|
1997-07-28 10:03:54 +04:00
|
|
|
if (route_addr.s_addr == 0) {
|
2000-04-14 16:14:40 +04:00
|
|
|
if (get_localaddr(NULL, &my_addr) != 0)
|
|
|
|
errx(1, "router address not found");
|
1997-07-28 10:03:54 +04:00
|
|
|
route_addr.s_addr = my_addr.sin_addr.s_addr;
|
1994-01-08 16:22:03 +03:00
|
|
|
}
|
1996-12-08 16:44:26 +03:00
|
|
|
if (!debug) {
|
|
|
|
if (daemon(0, 0))
|
|
|
|
err(1, "can't detach from terminal");
|
|
|
|
}
|
1999-06-06 06:38:00 +04:00
|
|
|
pidfile(NULL);
|
1994-01-08 16:22:03 +03:00
|
|
|
|
|
|
|
(void) pmap_unset(BOOTPARAMPROG, BOOTPARAMVERS);
|
|
|
|
|
|
|
|
transp = svcudp_create(RPC_ANYSOCK);
|
1996-12-08 16:44:26 +03:00
|
|
|
if (transp == NULL)
|
|
|
|
errx(1, "can't create udp service");
|
|
|
|
|
|
|
|
if (!svc_register(transp, BOOTPARAMPROG, BOOTPARAMVERS, bootparamprog_1,
|
|
|
|
IPPROTO_UDP))
|
2000-06-14 15:15:58 +04:00
|
|
|
/*
|
|
|
|
* Do NOT change the "%u" in the format string below to "%lu". If your
|
|
|
|
* build fails update the "rpcgen" program and use "make cleandir" and
|
|
|
|
* "make includes" in "src/lib/librpcsvc" afterwards.
|
|
|
|
*/
|
2000-06-14 10:54:20 +04:00
|
|
|
errx(1, "unable to register BOOTPARAMPROG version %u, udp",
|
1994-01-08 16:22:03 +03:00
|
|
|
BOOTPARAMVERS);
|
1996-12-08 16:44:26 +03:00
|
|
|
|
1994-01-08 16:22:03 +03:00
|
|
|
svc_run();
|
1996-12-08 16:44:26 +03:00
|
|
|
errx(1, "svc_run returned");
|
1994-01-08 16:22:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bp_whoami_res *
|
1995-06-24 19:03:49 +04:00
|
|
|
bootparamproc_whoami_1_svc(whoami, rqstp)
|
1994-01-08 16:22:03 +03:00
|
|
|
bp_whoami_arg *whoami;
|
1995-06-24 19:03:49 +04:00
|
|
|
struct svc_req *rqstp;
|
1994-01-08 16:22:03 +03:00
|
|
|
{
|
|
|
|
static bp_whoami_res res;
|
1996-10-14 23:28:09 +04:00
|
|
|
struct hostent *he;
|
1999-03-25 01:01:38 +03:00
|
|
|
struct in_addr haddr;
|
1999-08-23 05:09:42 +04:00
|
|
|
int e;
|
1994-01-10 17:04:44 +03:00
|
|
|
|
1994-01-08 16:22:03 +03:00
|
|
|
if (debug)
|
1997-09-08 06:21:52 +04:00
|
|
|
warnx("whoami got question for %d.%d.%d.%d",
|
1994-01-08 16:22:03 +03:00
|
|
|
255 & whoami->client_address.bp_address_u.ip_addr.net,
|
|
|
|
255 & whoami->client_address.bp_address_u.ip_addr.host,
|
|
|
|
255 & whoami->client_address.bp_address_u.ip_addr.lh,
|
|
|
|
255 & whoami->client_address.bp_address_u.ip_addr.impno);
|
|
|
|
if (dolog)
|
1997-09-08 06:21:52 +04:00
|
|
|
syslog(LOG_NOTICE, "whoami got question for %d.%d.%d.%d",
|
1994-01-08 16:22:03 +03:00
|
|
|
255 & whoami->client_address.bp_address_u.ip_addr.net,
|
|
|
|
255 & whoami->client_address.bp_address_u.ip_addr.host,
|
|
|
|
255 & whoami->client_address.bp_address_u.ip_addr.lh,
|
|
|
|
255 & whoami->client_address.bp_address_u.ip_addr.impno);
|
|
|
|
|
1997-10-18 15:27:49 +04:00
|
|
|
memmove((char *) &haddr,
|
|
|
|
(char *) &whoami->client_address.bp_address_u.ip_addr,
|
|
|
|
sizeof(haddr));
|
1994-01-08 16:22:03 +03:00
|
|
|
he = gethostbyaddr((char *) &haddr, sizeof(haddr), AF_INET);
|
1997-09-23 11:28:29 +04:00
|
|
|
if (he) {
|
2004-09-07 17:20:39 +04:00
|
|
|
(void)strlcpy(askname, he->h_name, sizeof(askname));
|
1997-09-23 11:28:29 +04:00
|
|
|
} else {
|
2004-09-07 17:20:39 +04:00
|
|
|
(void)strlcpy(askname, inet_ntoa(haddr), sizeof(askname));
|
1996-10-14 23:28:09 +04:00
|
|
|
}
|
1994-01-08 16:22:03 +03:00
|
|
|
|
|
|
|
if (debug)
|
1997-09-08 06:21:52 +04:00
|
|
|
warnx("This is host %s", askname);
|
1994-01-08 16:22:03 +03:00
|
|
|
if (dolog)
|
1997-09-08 06:21:52 +04:00
|
|
|
syslog(LOG_NOTICE, "This is host %s", askname);
|
1994-01-08 16:22:03 +03:00
|
|
|
|
1999-08-23 05:09:42 +04:00
|
|
|
if ((e = lookup_bootparam(askname, hostname, NULL, NULL, NULL)) == 0) {
|
1994-01-08 16:22:03 +03:00
|
|
|
res.client_name = hostname;
|
|
|
|
getdomainname(domain_name, MAX_MACHINE_NAME);
|
|
|
|
res.domain_name = domain_name;
|
|
|
|
|
|
|
|
if (res.router_address.address_type != IP_ADDR_TYPE) {
|
|
|
|
res.router_address.address_type = IP_ADDR_TYPE;
|
1997-10-18 15:27:49 +04:00
|
|
|
memmove(&res.router_address.bp_address_u.ip_addr,
|
|
|
|
&route_addr.s_addr,4);
|
1994-01-08 16:22:03 +03:00
|
|
|
}
|
|
|
|
if (debug)
|
1997-09-08 06:21:52 +04:00
|
|
|
warnx("Returning %s %s %d.%d.%d.%d",
|
1994-01-08 16:22:03 +03:00
|
|
|
res.client_name, res.domain_name,
|
|
|
|
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,
|
1997-09-23 11:28:29 +04:00
|
|
|
255 &res.router_address.bp_address_u.ip_addr.impno);
|
1994-01-08 16:22:03 +03:00
|
|
|
if (dolog)
|
1997-09-08 06:21:52 +04:00
|
|
|
syslog(LOG_NOTICE, "Returning %s %s %d.%d.%d.%d",
|
1994-01-08 16:22:03 +03:00
|
|
|
res.client_name, res.domain_name,
|
|
|
|
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,
|
1997-09-23 11:28:29 +04:00
|
|
|
255 &res.router_address.bp_address_u.ip_addr.impno);
|
1994-01-08 16:22:03 +03:00
|
|
|
|
|
|
|
return (&res);
|
|
|
|
}
|
1999-08-23 05:09:42 +04:00
|
|
|
errno = e;
|
1994-01-08 16:22:03 +03:00
|
|
|
if (debug)
|
1999-08-23 05:09:42 +04:00
|
|
|
warn("whoami failed");
|
1994-01-08 16:22:03 +03:00
|
|
|
if (dolog)
|
1999-08-23 05:09:42 +04:00
|
|
|
syslog(LOG_NOTICE, "whoami failed %m");
|
1994-01-08 16:22:03 +03:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bp_getfile_res *
|
1995-06-24 19:03:49 +04:00
|
|
|
bootparamproc_getfile_1_svc(getfile, rqstp)
|
1994-01-08 16:22:03 +03:00
|
|
|
bp_getfile_arg *getfile;
|
1995-06-24 19:03:49 +04:00
|
|
|
struct svc_req *rqstp;
|
1994-01-08 16:22:03 +03:00
|
|
|
{
|
|
|
|
static bp_getfile_res res;
|
1996-10-14 23:28:09 +04:00
|
|
|
struct hostent *he;
|
1994-01-10 17:04:44 +03:00
|
|
|
int err;
|
1994-01-08 16:22:03 +03:00
|
|
|
|
|
|
|
if (debug)
|
1997-09-08 06:21:52 +04:00
|
|
|
warnx("getfile got question for \"%s\" and file \"%s\"",
|
1994-01-08 16:22:03 +03:00
|
|
|
getfile->client_name, getfile->file_id);
|
|
|
|
|
|
|
|
if (dolog)
|
1997-09-08 06:21:52 +04:00
|
|
|
syslog(LOG_NOTICE,
|
|
|
|
"getfile got question for \"%s\" and file \"%s\"",
|
1994-01-08 16:22:03 +03:00
|
|
|
getfile->client_name, getfile->file_id);
|
|
|
|
|
|
|
|
he = NULL;
|
|
|
|
he = gethostbyname(getfile->client_name);
|
2001-04-11 10:21:49 +04:00
|
|
|
if (!he) {
|
|
|
|
if (debug)
|
|
|
|
warnx("getfile can't resolve client %s",
|
|
|
|
getfile->client_name);
|
|
|
|
if (dolog)
|
|
|
|
syslog(LOG_NOTICE, "getfile can't resolve client %s",
|
|
|
|
getfile->client_name);
|
|
|
|
return (NULL);
|
|
|
|
}
|
1994-01-08 16:22:03 +03:00
|
|
|
|
2004-09-07 17:20:39 +04:00
|
|
|
(void)strlcpy(askname, he->h_name, sizeof(askname));
|
1994-01-10 17:04:44 +03:00
|
|
|
err = lookup_bootparam(askname, NULL, getfile->file_id,
|
|
|
|
&res.server_name, &res.server_path);
|
|
|
|
if (err == 0) {
|
|
|
|
he = gethostbyname(res.server_name);
|
2001-04-11 10:21:49 +04:00
|
|
|
if (!he) {
|
|
|
|
if (debug)
|
|
|
|
warnx("getfile can't resolve server %s for %s",
|
|
|
|
res.server_name, getfile->client_name);
|
|
|
|
if (dolog)
|
|
|
|
syslog(LOG_NOTICE,
|
|
|
|
"getfile can't resolve server %s for %s",
|
|
|
|
res.server_name, getfile->client_name);
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
}
|
1997-10-18 15:27:49 +04:00
|
|
|
memmove(&res.server_address.bp_address_u.ip_addr,
|
|
|
|
he->h_addr, 4);
|
1994-01-10 17:04:44 +03:00
|
|
|
res.server_address.address_type = IP_ADDR_TYPE;
|
|
|
|
} else if (err == ENOENT && !strcmp(getfile->file_id, "dump")) {
|
|
|
|
/* Special for dump, answer with null strings. */
|
|
|
|
res.server_name[0] = '\0';
|
|
|
|
res.server_path[0] = '\0';
|
1997-10-18 15:27:49 +04:00
|
|
|
memset(&res.server_address.bp_address_u.ip_addr, 0, 4);
|
1994-01-10 17:04:44 +03:00
|
|
|
} else {
|
1994-01-08 16:22:03 +03:00
|
|
|
if (debug)
|
2001-04-11 10:21:49 +04:00
|
|
|
warnx("getfile lookup failed for %s",
|
1994-01-10 17:04:44 +03:00
|
|
|
getfile->client_name);
|
1994-01-08 16:22:03 +03:00
|
|
|
if (dolog)
|
|
|
|
syslog(LOG_NOTICE,
|
2001-04-11 10:21:49 +04:00
|
|
|
"getfile lookup failed for %s",
|
|
|
|
getfile->client_name);
|
1994-01-10 17:04:44 +03:00
|
|
|
return (NULL);
|
1994-01-08 16:22:03 +03:00
|
|
|
}
|
1994-01-10 17:04:44 +03:00
|
|
|
|
1994-01-08 16:22:03 +03:00
|
|
|
if (debug)
|
1996-12-08 16:44:26 +03:00
|
|
|
warnx(
|
1997-09-08 06:21:52 +04:00
|
|
|
"returning server:%s path:%s address: %d.%d.%d.%d",
|
1994-01-10 17:04:44 +03:00
|
|
|
res.server_name, res.server_path,
|
|
|
|
255 & res.server_address.bp_address_u.ip_addr.net,
|
|
|
|
255 & res.server_address.bp_address_u.ip_addr.host,
|
|
|
|
255 & res.server_address.bp_address_u.ip_addr.lh,
|
|
|
|
255 & res.server_address.bp_address_u.ip_addr.impno);
|
1994-01-08 16:22:03 +03:00
|
|
|
if (dolog)
|
|
|
|
syslog(LOG_NOTICE,
|
1997-09-08 06:21:52 +04:00
|
|
|
"returning server:%s path:%s address: %d.%d.%d.%d",
|
1994-01-10 17:04:44 +03:00
|
|
|
res.server_name, res.server_path,
|
|
|
|
255 & res.server_address.bp_address_u.ip_addr.net,
|
|
|
|
255 & res.server_address.bp_address_u.ip_addr.host,
|
|
|
|
255 & res.server_address.bp_address_u.ip_addr.lh,
|
|
|
|
255 & res.server_address.bp_address_u.ip_addr.impno);
|
|
|
|
return (&res);
|
1994-01-08 16:22:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-01-10 17:04:44 +03:00
|
|
|
int
|
|
|
|
lookup_bootparam(client, client_canonical, id, server, path)
|
|
|
|
char *client;
|
|
|
|
char *client_canonical;
|
|
|
|
char *id;
|
|
|
|
char **server;
|
|
|
|
char **path;
|
1994-01-08 16:22:03 +03:00
|
|
|
{
|
1994-01-10 17:04:44 +03:00
|
|
|
FILE *f = fopen(bootpfile, "r");
|
|
|
|
#ifdef YP
|
|
|
|
static char *ypbuf = NULL;
|
|
|
|
static int ypbuflen = 0;
|
|
|
|
#endif
|
|
|
|
static char buf[BUFSIZ];
|
2000-06-28 05:30:56 +04:00
|
|
|
char *canon = NULL, *bp, *word = NULL;
|
1994-01-10 17:04:44 +03:00
|
|
|
size_t idlen = id == NULL ? 0 : strlen(id);
|
|
|
|
int contin = 0;
|
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
if (f == NULL)
|
|
|
|
return EINVAL; /* ? */
|
|
|
|
|
|
|
|
while (fgets(buf, sizeof buf, f)) {
|
|
|
|
int wascontin = contin;
|
|
|
|
contin = buf[strlen(buf) - 2] == '\\';
|
|
|
|
bp = buf + strspn(buf, " \t\n");
|
|
|
|
|
|
|
|
switch (wascontin) {
|
|
|
|
case -1:
|
|
|
|
/* Continuation of uninteresting line */
|
|
|
|
contin *= -1;
|
|
|
|
continue;
|
|
|
|
case 0:
|
|
|
|
/* New line */
|
|
|
|
contin *= -1;
|
|
|
|
if (*bp == '#')
|
|
|
|
continue;
|
|
|
|
if ((word = strsep(&bp, " \t\n")) == NULL)
|
|
|
|
continue;
|
|
|
|
#ifdef YP
|
|
|
|
/* A + in the file means try YP now */
|
|
|
|
if (!strcmp(word, "+")) {
|
|
|
|
char *ypdom;
|
|
|
|
|
|
|
|
if (yp_get_default_domain(&ypdom) ||
|
|
|
|
yp_match(ypdom, "bootparams", client,
|
|
|
|
strlen(client), &ypbuf, &ypbuflen))
|
|
|
|
continue;
|
|
|
|
bp = ypbuf;
|
|
|
|
word = client;
|
|
|
|
contin *= -1;
|
|
|
|
break;
|
1994-01-08 16:22:03 +03:00
|
|
|
}
|
1994-01-10 17:04:44 +03:00
|
|
|
#endif
|
1999-08-23 05:09:42 +04:00
|
|
|
if (debug)
|
|
|
|
warnx("match %s with %s", word, client);
|
2000-06-28 05:30:56 +04:00
|
|
|
|
|
|
|
#define HASGLOB(str) \
|
|
|
|
(strchr(str, '*') != NULL || \
|
|
|
|
strchr(str, '?') != NULL || \
|
|
|
|
strchr(str, '[') != NULL || \
|
|
|
|
strchr(str, ']') != NULL)
|
|
|
|
|
1994-01-10 17:04:44 +03:00
|
|
|
/* See if this line's client is the one we are
|
|
|
|
* looking for */
|
2000-06-28 05:30:56 +04:00
|
|
|
if (fnmatch(word, client, FNM_CASEFOLD) == 0) {
|
|
|
|
/*
|
|
|
|
* Match. The token may be globbed, we
|
|
|
|
* can't just return that as the canonical
|
|
|
|
* name. Check to see if the token has any
|
|
|
|
* globbing characters in it (*, ?, [, ]).
|
|
|
|
* If so, just return the name we already
|
|
|
|
* have. Otherwise, return the token.
|
|
|
|
*/
|
|
|
|
if (HASGLOB(word))
|
|
|
|
canon = client;
|
|
|
|
else
|
|
|
|
canon = word;
|
|
|
|
} else {
|
2000-07-20 10:21:51 +04:00
|
|
|
struct hostent *hp;
|
1994-01-10 17:04:44 +03:00
|
|
|
/*
|
|
|
|
* If it didn't match, try getting the
|
|
|
|
* canonical host name of the client
|
2000-07-20 10:21:51 +04:00
|
|
|
* on this line, if it's not a glob,
|
|
|
|
* and comparing it to the client we
|
|
|
|
* are looking up.
|
1994-01-10 17:04:44 +03:00
|
|
|
*/
|
2000-07-20 10:21:51 +04:00
|
|
|
if (HASGLOB(word)) {
|
|
|
|
if (debug)
|
|
|
|
warnx("Skipping non-match: %s",
|
|
|
|
word);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((hp = gethostbyname(word)) == NULL) {
|
1999-04-26 06:35:17 +04:00
|
|
|
if (debug)
|
|
|
|
warnx(
|
2000-07-20 10:21:51 +04:00
|
|
|
"Unknown bootparams host %s",
|
|
|
|
word);
|
1999-04-26 06:35:17 +04:00
|
|
|
if (dolog)
|
|
|
|
syslog(LOG_NOTICE,
|
2000-07-20 10:21:51 +04:00
|
|
|
"Unknown bootparams host %s",
|
|
|
|
word);
|
1999-04-26 06:35:17 +04:00
|
|
|
continue;
|
|
|
|
}
|
2000-07-20 10:21:51 +04:00
|
|
|
if (strcasecmp(hp->h_name, client) != 0)
|
2000-07-04 12:18:44 +04:00
|
|
|
continue;
|
2000-07-20 10:21:51 +04:00
|
|
|
canon = hp->h_name;
|
1994-01-10 17:04:44 +03:00
|
|
|
}
|
2000-06-28 05:30:56 +04:00
|
|
|
|
|
|
|
#undef HASGLOB
|
|
|
|
|
1994-01-10 17:04:44 +03:00
|
|
|
contin *= -1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/* Continued line we want to parse below */
|
1994-01-08 16:22:03 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-06-28 05:30:56 +04:00
|
|
|
assert(canon != NULL);
|
1994-01-10 17:04:44 +03:00
|
|
|
if (client_canonical)
|
2000-06-28 05:30:56 +04:00
|
|
|
strncpy(client_canonical, canon, MAX_MACHINE_NAME);
|
1994-01-10 17:04:44 +03:00
|
|
|
|
|
|
|
/* We have found a line for CLIENT */
|
1994-11-29 18:03:13 +03:00
|
|
|
if (id == NULL) {
|
|
|
|
(void) fclose(f);
|
1994-01-10 17:04:44 +03:00
|
|
|
return 0;
|
1994-11-29 18:03:13 +03:00
|
|
|
}
|
1994-01-10 17:04:44 +03:00
|
|
|
|
|
|
|
/* Look for a value for the parameter named by ID */
|
|
|
|
while ((word = strsep(&bp, " \t\n")) != NULL) {
|
|
|
|
if (!strncmp(word, id, idlen) && word[idlen] == '=') {
|
|
|
|
/* We have found the entry we want */
|
|
|
|
*server = &word[idlen + 1];
|
|
|
|
*path = strchr(*server, ':');
|
|
|
|
if (*path == NULL)
|
|
|
|
/* Malformed entry */
|
|
|
|
continue;
|
|
|
|
*(*path)++ = '\0';
|
|
|
|
(void) fclose(f);
|
|
|
|
return 0;
|
1994-01-08 16:22:03 +03:00
|
|
|
}
|
|
|
|
}
|
1994-01-10 17:04:44 +03:00
|
|
|
|
|
|
|
found = 1;
|
1994-01-08 16:22:03 +03:00
|
|
|
}
|
1994-01-10 17:04:44 +03:00
|
|
|
|
|
|
|
(void) fclose(f);
|
|
|
|
return found ? ENOENT : EPERM;
|
1994-01-08 16:22:03 +03:00
|
|
|
}
|
1997-07-28 10:03:54 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
2003-12-25 22:01:35 +03:00
|
|
|
"usage: %s [-ds] [-i interface] [-r router] [-f bootparamsfile]\n",
|
2001-02-20 02:22:40 +03:00
|
|
|
getprogname());
|
1997-07-28 10:03:54 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
2000-04-14 16:14:40 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
get_localaddr(ifname, sin)
|
|
|
|
const char *ifname;
|
|
|
|
struct sockaddr_in *sin;
|
|
|
|
{
|
|
|
|
struct ifaddrs *ifap, *ifa;
|
|
|
|
|
|
|
|
if (getifaddrs(&ifap) != 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
|
|
|
if (ifname && strcmp(ifname, ifa->ifa_name) != 0)
|
|
|
|
continue;
|
|
|
|
if (ifa->ifa_addr->sa_family != AF_INET)
|
|
|
|
continue;
|
|
|
|
if (ifa->ifa_addr->sa_len != sizeof(*sin))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* no loopback please */
|
|
|
|
#ifdef IFF_LOOPBACK
|
|
|
|
if (ifa->ifa_flags & IFF_LOOPBACK)
|
|
|
|
continue;
|
|
|
|
#else
|
2000-04-27 13:48:59 +04:00
|
|
|
if (strncmp(ifa->ifa_name, "lo", 2) == 0 &&
|
|
|
|
(isdigit(ifa->ifa_name[2]) || ifa->ifa_name[2] == '\0'))
|
2000-04-14 16:14:40 +04:00
|
|
|
continue;
|
|
|
|
#endif
|
|
|
|
|
2003-06-26 09:38:45 +04:00
|
|
|
if (!iface || strcmp(ifa->ifa_name, iface) == 0)
|
|
|
|
;
|
|
|
|
else
|
|
|
|
continue;
|
2000-04-14 16:14:40 +04:00
|
|
|
|
|
|
|
/* candidate found */
|
|
|
|
memcpy(sin, ifa->ifa_addr, ifa->ifa_addr->sa_len);
|
|
|
|
freeifaddrs(ifap);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no candidate */
|
|
|
|
freeifaddrs(ifap);
|
|
|
|
return -1;
|
|
|
|
}
|