Source-Changes-HG archive

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

[src/netbsd-1-5]: src/usr.sbin/rpc.bootparamd Pull up rev. 1.34:



details:   https://anonhg.NetBSD.org/src/rev/17e19e5f68e0
branches:  netbsd-1-5
changeset: 488393:17e19e5f68e0
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon Jul 03 22:30:56 2000 +0000

description:
Pull up rev. 1.34:
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 ++++++++++++++++++++++++++++++------
 1 files changed, 40 insertions(+), 8 deletions(-)

diffs (111 lines):

diff -r 472d6fa60120 -r 17e19e5f68e0 usr.sbin/rpc.bootparamd/bootparamd.c
--- a/usr.sbin/rpc.bootparamd/bootparamd.c      Mon Jul 03 22:30:13 2000 +0000
+++ b/usr.sbin/rpc.bootparamd/bootparamd.c      Mon Jul 03 22: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.33.2.1 2000/07/03 22: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.33.2.1 2000/07/03 22: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) {



Home | Main Index | Thread Index | Old Index