diff options
author | jkh <jkh@FreeBSD.org> | 1999-07-19 10:06:18 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1999-07-19 10:06:18 +0000 |
commit | 362c174f0ecccf186bc683c9822722165abafe12 (patch) | |
tree | 4ebc1f90f19217af451b98a53337f7cdcbefa38e /release/sysinstall | |
parent | f3c07181e3a6a7579dac59ab5d7db8dda4765baa (diff) | |
download | FreeBSD-src-362c174f0ecccf186bc683c9822722165abafe12.zip FreeBSD-src-362c174f0ecccf186bc683c9822722165abafe12.tar.gz |
Another batch of fixes for dhcp support in sysinstall, now dragging
in some code from C. Stone to parse the lease information. This is still
a WIP and this commit is largely intended to allow others to sync up; the
dhclient code still only works when doing dhcp configuration post-install
and requires a bit more work on the boot floppy before it will truly
work in the minimal bootstrapping role.
Diffstat (limited to 'release/sysinstall')
-rw-r--r-- | release/sysinstall/Makefile | 12 | ||||
-rw-r--r-- | release/sysinstall/dhcp.c | 156 | ||||
-rw-r--r-- | release/sysinstall/sysinstall.h | 6 | ||||
-rw-r--r-- | release/sysinstall/system.c | 6 | ||||
-rw-r--r-- | release/sysinstall/tcpip.c | 142 |
5 files changed, 246 insertions, 76 deletions
diff --git a/release/sysinstall/Makefile b/release/sysinstall/Makefile index 20ce7ce..609ef7b 100644 --- a/release/sysinstall/Makefile +++ b/release/sysinstall/Makefile @@ -9,27 +9,23 @@ CLEANFILES+= keymap.tmp keymap.h pccard_conf.h .PATH: ${.CURDIR}/../disklabel ${.CURDIR}/../../usr.bin/cksum -SRCS= anonFTP.c cdrom.c command.c config.c devices.c kget.c \ +SRCS= anonFTP.c cdrom.c command.c config.c devices.c dhcp.c kget.c \ disks.c dispatch.c dist.c dmenu.c doc.c dos.c floppy.c \ ftp.c globals.c index.c install.c installUpgrade.c keymap.c \ label.c lndir.c main.c makedevs.c media.c menus.c misc.c mouse.c \ - msg.c network.c nfs.c options.c package.c pccard_conf.h pccard.c \ + msg.c network.c nfs.c options.c package.c pccard.c \ system.c tape.c tcpip.c termcap.c ufs.c user.c variable.c wizard.c \ - keymap.h + keymap.h pccard_conf.h CFLAGS+= -Wall -I${.CURDIR}/../../gnu/lib/libdialog -I${.OBJDIR} CFLAGS+= -I${.CURDIR}/../../sys -CFLAGS+= -DUC_PRIVATE -DKERN_NO_SYMBOLS PCCARD?= NO DPADD= ${LIBDIALOG} ${LIBNCURSES} ${LIBMYTINFO} ${LIBUTIL} ${LIBDISK} ${LIBFTPIO} LDADD= -ldialog -lncurses -lmytinfo -lutil -ldisk -lftpio -cleanconfig: - rm -f pccard_conf.h - -pccard_conf.h: cleanconfig +pccard_conf.h: .if ${PCCARD} == "YES" echo "#define PCCARD 1" > pccard_conf.h .else diff --git a/release/sysinstall/dhcp.c b/release/sysinstall/dhcp.c new file mode 100644 index 0000000..0cbdaa8 --- /dev/null +++ b/release/sysinstall/dhcp.c @@ -0,0 +1,156 @@ +/* + * $Id$ + * + * Copyright (c) 1999 + * C. Stone. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer, + * verbatim and that no modifications are made prior to this + * point in the file. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY C. STONE ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL C STONE OR HIS BODILY PARASITES BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE BY THE VOICES IN YOUR HEAD BEFOREHAND. + * + */ + +#include "sysinstall.h" + +#include <ctype.h> + +int +dhcpParseLeases(char *file, char *hostname, char *domain, char *nameserver, + char *ipaddr, char *gateway, char *netmask) +{ + char tempbuf[1024]; + char optbuf[1024], *optname = NULL; + char *tptr; + int endedflag = 0; + int leaseflag = 0; + FILE *fp; + enum { P_NOSTMT, P_NOSTMT1, P_STMT, P_STMTLINE } state; + + if ((fp = fopen(file, "r")) == NULL) { + msgDebug("error opening file %s: %s\n", file, strerror(errno)); + return -1; + } + + state = P_NOSTMT; + while (fscanf(fp, "%1023s", tempbuf) > 0) { + switch (state) { + case P_NOSTMT: + state = P_NOSTMT1; + if (!strncasecmp(tempbuf, "lease", 5)) { + if (!leaseflag) + leaseflag = 1; + else { + fclose(fp); + return 0; + } + } + break; + + case P_NOSTMT1: + if (tempbuf[0] != '{') { + msgWarn("dhcpParseLeases: '{' expected"); + fclose(fp); + return -1; + } + state = P_STMT; + break; + + case P_STMT: + if (!strncasecmp("option", tempbuf, 6)) + continue; + if (tempbuf[0] == '}') { + state = P_NOSTMT; + leaseflag = 0; + continue; + } + if (!leaseflag) + break; + if (tempbuf[0] == ';') { /* play it safe */ + state = P_STMT; + continue; + } + if ((tptr = (char *)strchr(tempbuf, ';')) && (*(tptr + 1) == 0)) { + *tptr = NULL; + endedflag = 1; + } + if (!isalnum(tempbuf[0])) { + msgWarn("dhcpParseLeases: bad option"); + fclose(fp); + return -1; + } + if (optname) + free(optname); + optname = strdup(tempbuf); + if (endedflag) { + state = P_STMT; + endedflag = 0; + continue; + } + state = P_STMTLINE; + break; + + case P_STMTLINE: + if (tempbuf[0] == ';') { + state = P_STMT; + continue; + } + if ((tptr = (char *)strchr(tempbuf, ';')) && (*(tptr + 1) == 0)) { + *tptr = NULL; + endedflag = 1; + } + if (tempbuf[0] == '"') { + if (sscanf(tempbuf, "\"%[^\" ]\"", optbuf) < 1) { + msgWarn("dhcpParseLeases: bad option value"); + fclose(fp); + return -1; + } + } + else + strcpy(optbuf, tempbuf); + + if (!strcasecmp("server-name", optname)) { + strcpy(hostname, optbuf); + } else if (!strcasecmp("domain-name", optname)) { + strcpy(domain, optbuf); + } else if (!strcasecmp("fixed-address", optname)) { + strcpy(ipaddr, optbuf); + } else if (!strcasecmp("routers", optname)) { + strcpy(gateway, optbuf); + } else if (!strcasecmp("subnet-mask", optname)) { + strcpy(netmask, optbuf); + } else if (!strcasecmp("domain-name-servers", optname)) { + /* <jkh> ...one value per property */ + if((tptr = (char *)strchr(optbuf, ','))) + *tptr = NULL; + strcpy(nameserver, optbuf); + } + if (endedflag) { + state = P_STMT; + endedflag = 0; + continue; + } + break; + } + } + fclose(fp); + return 0; +} diff --git a/release/sysinstall/sysinstall.h b/release/sysinstall/sysinstall.h index f10927d..0ed5308 100644 --- a/release/sysinstall/sysinstall.h +++ b/release/sysinstall/sysinstall.h @@ -4,7 +4,7 @@ * This is probably the last attempt in the `sysinstall' line, the next * generation being slated to essentially a complete rewrite. * - * $Id: sysinstall.h,v 1.169 1999/07/16 11:13:09 jkh Exp $ + * $Id: sysinstall.h,v 1.170 1999/07/18 10:18:06 jkh Exp $ * * Copyright (c) 1995 * Jordan Hubbard. All rights reserved. @@ -450,6 +450,10 @@ extern Boolean dummyInit(Device *dev); extern FILE *dummyGet(Device *dev, char *dist, Boolean probe); extern void dummyShutdown(Device *dev); +/* dhcp.c */ +extern int dhcpParseLeases(char *file, char *hostname, char *domain, char *nameserver, + char *ipaddr, char *gateway, char *netmask); + /* disks.c */ extern int diskPartitionEditor(dialogMenuItem *self); extern int diskPartitionWrite(dialogMenuItem *self); diff --git a/release/sysinstall/system.c b/release/sysinstall/system.c index 2f618c9..152ad36 100644 --- a/release/sysinstall/system.c +++ b/release/sysinstall/system.c @@ -4,7 +4,7 @@ * This is probably the last program in the `sysinstall' line - the next * generation being essentially a complete rewrite. * - * $Id: system.c,v 1.91 1999/02/15 00:49:33 jkh Exp $ + * $Id: system.c,v 1.92 1999/07/16 22:07:09 jkh Exp $ * * Jordan Hubbard * @@ -71,8 +71,6 @@ expand(char *fname) void systemInitialize(int argc, char **argv) { - int i; - signal(SIGINT, SIG_IGN); globalsInit(); @@ -351,7 +349,7 @@ systemCreateHoloshell(void) if (kill(ehs_pid, 0) == 0) { if (msgYesNo("There seems to be an emergency holographic shell\n" - "already running von VTY 4.\n" + "already running on VTY 4.\n\n" "Kill it and start a new one?")) return; diff --git a/release/sysinstall/tcpip.c b/release/sysinstall/tcpip.c index 67205b6..542f207 100644 --- a/release/sysinstall/tcpip.c +++ b/release/sysinstall/tcpip.c @@ -1,5 +1,5 @@ /* - * $Id: tcpip.c,v 1.81 1999/07/18 02:20:56 jkh Exp $ + * $Id: tcpip.c,v 1.82 1999/07/18 10:18:06 jkh Exp $ * * Copyright (c) 1995 * Gary J Palmer. All rights reserved. @@ -146,6 +146,55 @@ verifySettings(void) return 0; } +static void +dhcpGetInfo(Device *devp) +{ + /* If it fails, do it the old-fashioned way */ + if (dhcpParseLeases("/var/db/dhclient.leases", hostname, domainname, + nameserver, ipaddr, gateway, netmask) == -1) { + FILE *ifp; + char *cp, cmd[256], data[2048]; + int i = 0, j = 0; + + /* Bah, now we have to kludge getting the information from ifconfig */ + snprintf(cmd, sizeof cmd, "ifconfig %s", devp->name); + ifp = popen(cmd, "r"); + if (ifp) { + while ((j = fread(data + i, 1, 512, ifp)) > 0) + i += j; + fclose(ifp); + data[i] = 0; + if (isDebug()) + msgDebug("DHCP configured interface returns %s\n", data); + /* XXX This is gross as it assumes a certain ordering to + ifconfig's output! XXX */ + if ((cp = strstr(data, "inet")) != NULL) { + i = 0; + cp += 5; /* move over keyword */ + while (*cp != ' ') + ipaddr[i++] = *(cp++); + ipaddr[i] = '\0'; + if (!strncmp(++cp, "netmask", 7)) { + i = 0; + cp += 8; + while (*cp != ' ') + netmask[i++] = *(cp++); + netmask[i] = '\0'; + } + } + } + } + + /* If we didn't get a name server value, hunt for it in resolv.conf */ + if (!nameserver[0] && file_readable("/etc/resolv.conf")) + configEnvironmentResolv("/etc/resolv.conf"); + + /* See if we have a hostname and can derive one if not */ + if (!hostname[0] && ipaddr[0]) { + } + variable_set2(VAR_HOSTNAME, hostname, 1); +} + /* This is it - how to get TCP setup values */ int tcpOpenDialog(Device *devp) @@ -177,50 +226,14 @@ tcpOpenDialog(Device *devp) Mkdir("/tmp"); msgNotify("Scanning for DHCP servers..."); if (!vsystem("dhclient %s", devp->name)) { - FILE *ifp; - char cmd[256]; - if (isDebug()) msgDebug("Successful return from dhclient"); - snprintf(cmd, sizeof cmd, "ifconfig %s", devp->name); - ifp = popen(cmd, "r"); - if (ifp) { - char *cp, data[1024]; - int i = 0, j = 0; - - while ((j = fread(data + i, 1, 512, ifp)) > 0) - i += j; - fclose(ifp); - data[i] = 0; - if (isDebug()) - msgDebug("DHCP configured interface returns %s\n", data); - /* XXX This is gross as it assumes a certain ordering to - ifconfig's output! XXX */ - if ((cp = strstr(data, "inet")) != NULL) { - i = 0; - cp += 5; /* move over keyword */ - while (*cp != ' ') - ipaddr[i++] = *(cp++); - ipaddr[i] = '\0'; - if (!strncmp(++cp, "netmask", 7)) { - i = 0; - cp += 8; - while (*cp != ' ') - netmask[i++] = *(cp++); - netmask[i] = '\0'; - } - if (file_readable("/etc/resolv.conf")) - configEnvironmentResolv("/etc/resolv.conf"); - /* See if we have a hostname */ - if (!gethostname(data, sizeof data - 1) && data[0]) - variable_set2(VAR_HOSTNAME, data, 1); - use_dhcp = TRUE; - } - } + dhcpGetInfo(devp); + use_dhcp = TRUE; } else { if (isDebug()) - msgConfirm("Unsuccessful return from dhclient"); + msgDebug("Unsuccessful return from dhclient"); use_dhcp = FALSE; } } @@ -253,26 +266,26 @@ tcpOpenDialog(Device *devp) } /* Look up values already recorded with the system, or blank the string variables ready to accept some new data */ - tmp = variable_get(VAR_HOSTNAME); - if (tmp) - SAFE_STRCPY(hostname, tmp); - else - bzero(hostname, sizeof(hostname)); - tmp = variable_get(VAR_DOMAINNAME); - if (tmp) - SAFE_STRCPY(domainname, tmp); - else - bzero(domainname, sizeof(domainname)); - tmp = variable_get(VAR_GATEWAY); - if (tmp) - SAFE_STRCPY(gateway, tmp); - else - bzero(gateway, sizeof(gateway)); - tmp = variable_get(VAR_NAMESERVER); - if (tmp) - SAFE_STRCPY(nameserver, tmp); - else - bzero(nameserver, sizeof(nameserver)); + if (!hostname[0]) { + tmp = variable_get(VAR_HOSTNAME); + if (tmp) + SAFE_STRCPY(hostname, tmp); + } + if (!domainname[0]) { + tmp = variable_get(VAR_DOMAINNAME); + if (tmp) + SAFE_STRCPY(domainname, tmp); + } + if (!gateway[0]) { + tmp = variable_get(VAR_GATEWAY); + if (tmp) + SAFE_STRCPY(gateway, tmp); + } + if (!nameserver[0]) { + tmp = variable_get(VAR_NAMESERVER); + if (tmp) + SAFE_STRCPY(nameserver, tmp); + } save = savescr(); /* If non-interactive, jump straight over the dialog crap and into config section */ @@ -353,8 +366,10 @@ netconfig: char temp[512], ifn[255]; char *ifaces; - variable_set2(VAR_HOSTNAME, hostname, 1); - sethostname(hostname, strlen(hostname)); + if (hostname[0]) { + variable_set2(VAR_HOSTNAME, hostname, 1); + sethostname(hostname, strlen(hostname)); + } if (domainname[0]) variable_set2(VAR_DOMAINNAME, domainname, 0); if (gateway[0]) @@ -386,7 +401,8 @@ netconfig: } if (ipaddr[0]) variable_set2(VAR_IPADDR, ipaddr, 0); - configResolv(NULL); /* XXX this will do it on the MFS copy XXX */ + if (!use_dhcp) + configResolv(NULL); /* XXX this will do it on the MFS copy XXX */ ret = DITEM_SUCCESS; } else |