Add support for globbing when matching the host name in the
bootparams(5) file, a'la Solaris. This is extremely useful for configuring Jumpstart servers. From Dan Mercer <dmercer@zembu.com>.
This commit is contained in:
parent
445d18ed28
commit
c1b4b34401
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: bootparamd.c,v 1.33 2000/06/14 11:15:58 tron Exp $ */
|
||||
/* $NetBSD: bootparamd.c,v 1.34 2000/06/28 01:30:56 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* This code is not copyright, and is placed in the public domain.
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: bootparamd.c,v 1.33 2000/06/14 11:15:58 tron Exp $");
|
||||
__RCSID("$NetBSD: bootparamd.c,v 1.34 2000/06/28 01:30:56 thorpej Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -19,9 +19,11 @@ __RCSID("$NetBSD: bootparamd.c,v 1.33 2000/06/14 11:15:58 tron Exp $");
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
#include <fnmatch.h>
|
||||
#include <netdb.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@ -306,7 +308,7 @@ lookup_bootparam(client, client_canonical, id, server, path)
|
||||
static int ypbuflen = 0;
|
||||
#endif
|
||||
static char buf[BUFSIZ];
|
||||
char *bp, *word = NULL;
|
||||
char *canon = NULL, *bp, *word = NULL;
|
||||
size_t idlen = id == NULL ? 0 : strlen(id);
|
||||
int contin = 0;
|
||||
int found = 0;
|
||||
@ -348,9 +350,29 @@ lookup_bootparam(client, client_canonical, id, server, path)
|
||||
#endif
|
||||
if (debug)
|
||||
warnx("match %s with %s", word, client);
|
||||
|
||||
#define HASGLOB(str) \
|
||||
(strchr(str, '*') != NULL || \
|
||||
strchr(str, '?') != NULL || \
|
||||
strchr(str, '[') != NULL || \
|
||||
strchr(str, ']') != NULL)
|
||||
|
||||
/* See if this line's client is the one we are
|
||||
* looking for */
|
||||
if (strcasecmp(word, client) != 0) {
|
||||
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 {
|
||||
/*
|
||||
* If it didn't match, try getting the
|
||||
* canonical host name of the client
|
||||
@ -358,7 +380,7 @@ lookup_bootparam(client, client_canonical, id, server, path)
|
||||
* the client we are looking for
|
||||
*/
|
||||
struct hostent *hp = gethostbyname(word);
|
||||
if (hp == NULL ) {
|
||||
if (hp == NULL) {
|
||||
if (debug)
|
||||
warnx(
|
||||
"Unknown bootparams host %s", word);
|
||||
@ -367,9 +389,18 @@ lookup_bootparam(client, client_canonical, id, server, path)
|
||||
"Unknown bootparams host %s", word);
|
||||
continue;
|
||||
}
|
||||
if (strcasecmp(hp->h_name, client))
|
||||
continue;
|
||||
if (fnmatch(word, hp->h_name,
|
||||
FNM_CASEFOLD) == 0) {
|
||||
/* See above. */
|
||||
if (HASGLOB(word))
|
||||
canon = hp->h_name;
|
||||
else
|
||||
canon = word;
|
||||
}
|
||||
}
|
||||
|
||||
#undef HASGLOB
|
||||
|
||||
contin *= -1;
|
||||
break;
|
||||
case 1:
|
||||
@ -377,8 +408,9 @@ lookup_bootparam(client, client_canonical, id, server, path)
|
||||
break;
|
||||
}
|
||||
|
||||
assert(canon != NULL);
|
||||
if (client_canonical)
|
||||
strncpy(client_canonical, word, MAX_MACHINE_NAME);
|
||||
strncpy(client_canonical, canon, MAX_MACHINE_NAME);
|
||||
|
||||
/* We have found a line for CLIENT */
|
||||
if (id == NULL) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: bootparams.5,v 1.8 1999/04/06 04:54:21 cgd Exp $
|
||||
.\" $NetBSD: bootparams.5,v 1.9 2000/06/28 01:30:56 thorpej Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1994 Gordon W. Ross
|
||||
.\" All rights reserved.
|
||||
@ -44,15 +44,17 @@ Each client supported by this server must have an entry in the
|
||||
file containing the servers and pathnames for its
|
||||
.Pa root ,
|
||||
area. It may optionally contain
|
||||
.Pa swap
|
||||
and
|
||||
.Pa dump
|
||||
areas.
|
||||
.Pa swap ,
|
||||
.Pa dump ,
|
||||
and other entry types.
|
||||
.Pp
|
||||
Each line in the file
|
||||
(other than comment lines that begin with a #)
|
||||
specifies the client name followed by the pathnames that
|
||||
the client may request by their logical names.
|
||||
the client may request by their logical names. Names
|
||||
are matched in a case-insensitive fashion, and may also
|
||||
be wildcarded using shell-style globbing characters.
|
||||
.Pp
|
||||
The components of the line are delimited with blank or tab,
|
||||
and may be continued onto multiple lines with a backslash.
|
||||
.Pp
|
||||
@ -71,6 +73,20 @@ and pathname
|
||||
as the response to its
|
||||
.Tn RPC
|
||||
request.
|
||||
.Pp
|
||||
.Bd -literal -offset indent
|
||||
netra[1-5]www* root=server:/export/jumpstart/netra_www
|
||||
.Ed
|
||||
.Pp
|
||||
When any client with a name matching the pattern "netra[1-5]www*"
|
||||
requests the pathname for its logical "root" it will be given server
|
||||
.Dq Pa "server"
|
||||
and pathname
|
||||
.Dq Pa "/export/jumpstart/netra_www"
|
||||
as the response to its
|
||||
.Tn RPC
|
||||
request. As this example implies, this is useful for setting up
|
||||
Jumpstart servers for Sun clients.
|
||||
.Sh NOTES
|
||||
The server does not default to the localhost, and must be filled in.
|
||||
.Sh FILES
|
||||
|
Loading…
Reference in New Issue
Block a user