5 * C. Stone. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer,
12 * verbatim and that no modifications are made prior to this
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY C. STONE ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL C STONE OR HIS BODILY PARASITES BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE BY THE VOICES IN YOUR HEAD BEFOREHAND.
32 #include "sysinstall.h"
37 dhcpParseLeases(char *file, char *hostname, char *domain, char *nameserver,
38 char *ipaddr, char *gateway, char *netmask)
41 char optbuf[1024], *optname = NULL;
46 enum { P_NOSTMT, P_NOSTMT1, P_STMT, P_STMTLINE } state;
48 if ((fp = fopen(file, "r")) == NULL) {
49 msgDebug("error opening file %s: %s\n", file, strerror(errno));
54 while (fscanf(fp, "%1023s", tempbuf) > 0) {
58 if (!strncasecmp(tempbuf, "lease", 5)) {
69 if (tempbuf[0] != '{') {
70 msgWarn("dhcpParseLeases: '{' expected");
78 if (!strncasecmp("option", tempbuf, 6))
80 if (tempbuf[0] == '}') {
87 if (tempbuf[0] == ';') { /* play it safe */
91 if ((tptr = (char *)strchr(tempbuf, ';')) && (*(tptr + 1) == 0)) {
95 if (!isalnum(tempbuf[0])) {
96 msgWarn("dhcpParseLeases: bad option");
102 optname = strdup(tempbuf);
112 if (tempbuf[0] == ';') {
116 if ((tptr = (char *)strchr(tempbuf, ';')) && (*(tptr + 1) == 0)) {
120 if (tempbuf[0] == '"') {
121 if (sscanf(tempbuf, "\"%[^\" ]\"", optbuf) < 1) {
122 msgWarn("dhcpParseLeases: bad option value");
128 strcpy(optbuf, tempbuf);
130 if (!strcasecmp("host-name", optname)) {
131 strcpy(hostname, optbuf);
132 } else if (!strcasecmp("domain-name", optname)) {
133 strcpy(domain, optbuf);
134 } else if (!strcasecmp("fixed-address", optname)) {
135 strcpy(ipaddr, optbuf);
136 } else if (!strcasecmp("routers", optname)) {
137 if((tptr = (char *)strchr(optbuf, ',')))
139 strcpy(gateway, optbuf);
140 } else if (!strcasecmp("subnet-mask", optname)) {
141 strcpy(netmask, optbuf);
142 } else if (!strcasecmp("domain-name-servers", optname)) {
143 /* <jkh> ...one value per property */
144 if((tptr = (char *)strchr(optbuf, ',')))
146 strcpy(nameserver, optbuf);