Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/rpc.bootparamd Add support for globbing when matchi...



details:   https://anonhg.NetBSD.org/src/rev/137079a5edab
branches:  trunk
changeset: 493964:137079a5edab
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Wed Jun 28 01:30:56 2000 +0000

description:
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@localhost>.

diffstat:

 usr.sbin/rpc.bootparamd/bootparamd.c |  48 ++++++++++++++++++++++++++++++------
 usr.sbin/rpc.bootparamd/bootparams.5 |  28 ++++++++++++++++----
 2 files changed, 62 insertions(+), 14 deletions(-)

diffs (164 lines):

diff -r b945b894d857 -r 137079a5edab usr.sbin/rpc.bootparamd/bootparamd.c
--- a/usr.sbin/rpc.bootparamd/bootparamd.c      Wed Jun 28 01:13:35 2000 +0000
+++ b/usr.sbin/rpc.bootparamd/bootparamd.c      Wed Jun 28 01:30:56 2000 +0000
@@ -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 @@
 #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 @@
        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 @@
 #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 @@
                                 * 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 @@
                                            "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 @@
                        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) {
diff -r b945b894d857 -r 137079a5edab usr.sbin/rpc.bootparamd/bootparams.5
--- a/usr.sbin/rpc.bootparamd/bootparams.5      Wed Jun 28 01:13:35 2000 +0000
+++ b/usr.sbin/rpc.bootparamd/bootparams.5      Wed Jun 28 01:30:56 2000 +0000
@@ -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 @@
 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 @@
 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



Home | Main Index | Thread Index | Old Index