2 * Copyright (c) 1988, 1992 The University of Utah and the Center
3 * for Software Science (CSS).
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * the Center for Software Science of the University of Utah Computer
9 * Science Department. CSS requests users of this software to return
10 * to css-dist@cs.utah.edu any improvements that they make and grant
11 * CSS redistribution rights.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement:
23 * This product includes software developed by the University of
24 * California, Berkeley and its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 * from: @(#)parseconf.c 8.1 (Berkeley) 6/4/93
43 * From: Utah Hdr: parseconf.c 3.1 92/07/06
44 * Author: Jeff Forys, University of Utah CSS
49 static const char sccsid[] = "@(#)parseconf.c 8.1 (Berkeley) 6/4/93";
51 static const char rcsid[] =
55 #include <sys/param.h>
70 ** ParseConfig -- parse the config file into linked list of clients.
76 ** 1 on success, 0 otherwise.
79 ** - Linked list of clients will be (re)allocated.
82 ** - GetBootFiles() must be called before this routine
83 ** to create a linked list of default boot files.
94 int omask, linecnt = 0;
96 if (BootAny) /* ignore config file */
99 FreeClients(); /* delete old list of clients */
101 if ((fp = fopen(ConfigFile, "r")) == NULL) {
102 syslog(LOG_ERR, "ParseConfig: can't open config file (%s)",
108 * We've got to block SIGHUP to prevent reconfiguration while
109 * dealing with the linked list of Clients. This can be done
110 * when actually linking the new client into the list, but
111 * this could have unexpected results if the server was HUP'd
112 * whilst reconfiguring. Hence, it is done here.
114 omask = sigblock(sigmask(SIGHUP));
117 * GETSTR positions `bcp' at the start of the current token,
118 * and null terminates it. `cp' is positioned at the start
119 * of the next token. spaces & commas are separators.
121 #define GETSTR while (isspace(*cp) || *cp == ',') cp++; \
123 while (*cp && *cp!=',' && !isspace(*cp)) cp++; \
124 if (*cp) *cp++ = '\0'
127 * For each line, parse it into a new CLIENT struct.
129 while (fgets(line, C_LINELEN, fp) != NULL) {
130 linecnt++; /* line counter */
132 if (*line == '\0' || *line == '#') /* ignore comment */
135 if ((cp = strchr(line,'#')) != NULL) /* trash comments */
138 cp = line; /* init `cp' */
139 GETSTR; /* get RMP addr */
140 if (bcp == cp) /* all delimiters */
144 * Get an RMP address from a string. Abort on failure.
146 if ((addr = ParseAddr(bcp)) == NULL) {
148 "ParseConfig: line %d: cant parse <%s>",
153 if ((client = NewClient(addr)) == NULL) /* alloc new client */
156 GETSTR; /* get first file */
159 * If no boot files are spec'd, use the default list.
160 * Otherwise, validate each file (`bcp') against the
161 * list of boot-able files.
164 if (bcp == cp) /* no files spec'd */
165 for (; i < C_MAXFILE && BootFiles[i] != NULL; i++)
166 client->files[i] = BootFiles[i];
170 * For each boot file spec'd, make sure it's
171 * in our list. If so, include a pointer to
172 * it in the CLIENT's list of boot files.
175 if (j==C_MAXFILE||BootFiles[j]==NULL) {
176 syslog(LOG_ERR, "ParseConfig: line %d: no boot file (%s)",
180 if (STREQN(BootFiles[j], bcp)) {
185 syslog(LOG_ERR, "ParseConfig: line %d: too many boot files (%s)",
190 GETSTR; /* get next file */
194 * Restricted list of boot files were spec'd,
195 * however, none of them were found. Since we
196 * apparently cant let them boot "just anything",
197 * the entire record is invalidated.
206 * Link this client into the linked list of clients.
207 * SIGHUP has already been blocked.
210 client->next = Clients;
214 (void) fclose(fp); /* close config file */
216 (void) sigsetmask(omask); /* reset signal mask */
218 return(1); /* return success */
222 ** ParseAddr -- Parse a string containing an RMP address.
224 ** This routine is fairly liberal at parsing an RMP address. The
225 ** address must contain 6 octets consisting of between 0 and 2 hex
226 ** chars (upper/lower case) separated by colons. If two colons are
227 ** together (e.g. "::", the octet between them is recorded as being
228 ** zero. Hence, the following addrs are all valid and parse to the
231 ** 08:00:09:00:66:ad 8::9:0:66:AD 8::9::66:aD
233 ** For clarity, an RMP address is really an Ethernet address, but
234 ** since the HP boot code uses IEEE 802.3, it's really an IEEE
235 ** 802.3 address. Of course, all of these are identical.
238 ** str - string representation of an RMP address.
241 ** pointer to a static array of RMP_ADDRLEN bytes.
247 ** - The return value points to a static buffer; it must
248 ** be copied if it's to be saved.
253 static u_int8_t addr[RMP_ADDRLEN];
258 memset((char *)&addr[0], 0, RMP_ADDRLEN); /* zero static buffer */
261 for (cp = str; *cp; cp++) {
263 * A colon (`:') must be used to delimit each octet.
266 if (++part == RMP_ADDRLEN) /* too many parts */
273 * Convert hex character to an integer.
278 i = (isupper(*cp)? tolower(*cp): *cp) - 'a' + 10;
279 if (i < 10 || i > 15) /* not a hex char */
284 if (subpart > 2) /* too many hex chars */
291 if (part != (RMP_ADDRLEN-1)) /* too few parts */
298 ** GetBootFiles -- record list of files in current (boot) directory.
304 ** Number of boot files on success, 0 on failure.
307 ** Strings in `BootFiles' are freed/allocated.
310 ** - After this routine is called, ParseConfig() must be
311 ** called to re-order it's list of boot file pointers.
322 * Free the current list of boot files.
324 for (i = 0; i < C_MAXFILE && BootFiles[i] != NULL; i++) {
325 FreeStr(BootFiles[i]);
330 * Open current directory to read boot file names.
332 if ((dfd = opendir(".")) == NULL) { /* open BootDir */
333 syslog(LOG_ERR, "GetBootFiles: can't open directory (%s)\n",
339 * Read each boot file name and allocate space for it in the
340 * list of boot files (BootFiles). All boot files read after
341 * C_MAXFILE will be ignored.
344 for (dp = readdir(dfd); dp != NULL; dp = readdir(dfd)) {
345 if (stat(dp->d_name, &statb) < 0 ||
346 (statb.st_mode & S_IFMT) != S_IFREG)
350 "GetBootFiles: too many boot files (%s ignored)",
352 else if ((BootFiles[i] = NewStr(dp->d_name)) != NULL)
356 (void) closedir(dfd); /* close BootDir */
358 if (i == 0) /* cant find any boot files */
359 syslog(LOG_ERR, "GetBootFiles: no boot files (%s)\n", BootDir);