diff --unified --recursive --new-file pump-0.7.2/Makefile pump-0.7.2gm1/Makefile --- pump-0.7.2/Makefile Tue Sep 7 13:35:35 1999 +++ pump-0.7.2gm1/Makefile Wed Sep 22 19:34:16 1999 @@ -1,6 +1,7 @@ SBINPATH = $(RPM_BUILD_ROOT)/sbin USRSBINPATH = $(RPM_BUILD_ROOT)/usr/sbin MAN8PATH = $(RPM_BUILD_ROOT)/usr/man/man8 +PUMPDIR = $(RPM_BUILD_ROOT)/etc/pump CFLAGS = -Wall -g $(RPM_OPT_FLAGS) -D__STANDALONE__ -DVERSION=\"$(VERSION)\" LOADLIBES = -lpopt -lresolv @@ -32,6 +33,10 @@ install -m 755 -s netconfig $(USRSBINPATH)/netconfig install -m 755 -s pump $(SBINPATH)/pump install -m 644 pump.8 $(MAN8PATH) + install -m 755 -d $(PUMPDIR) + install -m 644 pump.conf $(PUMPDIR)/pump.conf + install -m 755 scripts/pumpscript.pl $(PUMPDIR)/pumpscript.pl + install -m 755 scripts/fancydns.pl $(PUMPDIR)/fancydns.pl create-archive: tag-archive @rm -rf /tmp/pump diff --unified --recursive --new-file pump-0.7.2/config.c pump-0.7.2gm1/config.c --- pump-0.7.2/config.c Sat Aug 7 15:15:19 1999 +++ pump-0.7.2gm1/config.c Wed Sep 22 18:57:27 1999 @@ -40,6 +40,7 @@ continue; } else if (*start == '#') { next = strchr(start, '\n') + 1; + continue; } end = strchr(start, '\n'); @@ -159,6 +160,9 @@ */ override->searchPath = strdup(argv[0]); free(argv); + } else if (!strcmp(start, "setupscript")) { + /* Same comment as above re: memory leak */ + override->setupScript = strdup(rest); } else if (!strcmp(start, "nodns")) { if (*rest) { parseError(*lineNum, "unexpected argument to nodns directive"); diff --unified --recursive --new-file pump-0.7.2/dhcp.c pump-0.7.2gm1/dhcp.c --- pump-0.7.2/dhcp.c Sat Aug 7 15:15:19 1999 +++ pump-0.7.2gm1/dhcp.c Wed Sep 22 15:55:06 1999 @@ -1137,5 +1137,6 @@ strcpy(override->intf.device, "MASTER"); override->timeout = DEFAULT_TIMEOUT; override->numRetries = DEFAULT_NUM_RETRIES; + override->setupScript = ""; } diff --unified --recursive --new-file pump-0.7.2/pump.8 pump-0.7.2gm1/pump.8 --- pump-0.7.2/pump.8 Sat Aug 14 10:35:31 1999 +++ pump-0.7.2gm1/pump.8 Wed Sep 22 18:47:12 1999 @@ -120,6 +120,12 @@ \fBtimeout\fR \fIcount\fR Don't let any one step of the DHCP process take more then \fIcount\fR seconds. +.TP +\fBsetupscript\fR \fIfilename\fR +Don't configure anything directly; instead, determine the configuration +and send it as a series of tag=value pairs to the named script. See the +sample scripts supplied with pump for more information. + .SH BUGS Probably limited to Ethernet, might work on PLIP, probably not ARCnet and Token Ring. The configuration file should let you do more diff --unified --recursive --new-file pump-0.7.2/pump.c pump-0.7.2gm1/pump.c --- pump-0.7.2/pump.c Sat Aug 7 15:15:19 1999 +++ pump-0.7.2gm1/pump.c Wed Sep 22 18:46:43 1999 @@ -225,6 +225,49 @@ } } +void runSetupScript(struct pumpNetIntf * intf, + struct pumpOverrideInfo * override) +{ + FILE *ss; + char *cmd; + int i; + + cmd = malloc(strlen(override->setupScript)+14); + strcpy(cmd,override->setupScript); + strcat(cmd," &> /var/null"); + ss = popen(cmd, "w"); + free(cmd); + if (ss == NULL) { + syslog(LOG_ERR, "cannot execute script $s", override->setupScript); + return; + } + + fprintf(ss, "dev=%s\n", intf->device); + fprintf(ss, "ip=%s\n", inet_ntoa(intf->ip)); + fprintf(ss, "netmask=%s\n", inet_ntoa(intf->netmask)); + fprintf(ss, "broadcast=%s\n", inet_ntoa(intf->broadcast)); + fprintf(ss, "network=%s\n", inet_ntoa(intf->network)); + fprintf(ss, "gateway=%s\n", inet_ntoa(intf->gateway)); + fprintf(ss, "bootserver=%s\n", inet_ntoa(intf->bootServer)); + if (intf->bootFile) + fprintf(ss, "bootfile=%s\n", intf->bootFile); + if (intf->hostname) + fprintf(ss, "hostname=%s\n", intf->hostname); + if (intf->domain) + fprintf(ss, "domain=%s\n", intf->domain); + fprintf(ss, "numdns=%d\n", intf->numDns); + for (i=0; i < intf->numDns; i++) { + fprintf(ss, "dns%d=%s\n", i, inet_ntoa(intf->dnsServers[i])); + } + fflush(ss); + + syslog(LOG_INFO, "configured interface %s using script %s", + intf->device, override->setupScript); + + pclose(ss); + +} + static void runDaemon(int sock, char * configFile) { int conn; struct sockaddr_un addr; @@ -302,15 +345,24 @@ intf + numInterfaces, o)) { cmd.u.result = 1; } else { - pumpSetupInterface(intf); - syslog(LOG_INFO, "configured interface %s", intf->device); + if (o->setupScript[0] == 0) { - if (intf->set & PUMP_NETINFO_HAS_GATEWAY) { - pumpSetupDefaultGateway(&intf->gateway); - } + pumpSetupInterface(intf); + + syslog(LOG_INFO, "configured interface %s", intf->device); + + if (intf->set & PUMP_NETINFO_HAS_GATEWAY) { + pumpSetupDefaultGateway(&intf->gateway); + } - setupDns(intf, o); + setupDns(intf, o); + + } else { + + runSetupScript(intf, o); + + } cmd.u.result = 0; numInterfaces++; @@ -509,13 +561,13 @@ int killDaemon = 0; int release = 0, renew = 0, status = 0, lookupHostname = 0; struct command cmd, response; - char * configFile = "/etc/pump.conf"; + char * configFile = "/etc/pump/pump.conf"; struct pumpOverrideInfo * overrides; int cont; struct poptOption options[] = { { "config-file", 'c', POPT_ARG_STRING, &configFile, 0, N_("Configuration file to use instead of " - "/etc/pump.conf") }, + "/etc/pump/pump.conf") }, { "hostname", 'h', POPT_ARG_STRING, &hostname, 0, N_("Hostname to request"), N_("hostname") }, { "interface", 'i', POPT_ARG_STRING, &device, 0, diff --unified --recursive --new-file pump-0.7.2/pump.conf pump-0.7.2gm1/pump.conf --- pump-0.7.2/pump.conf Wed Dec 31 19:00:00 1969 +++ pump-0.7.2gm1/pump.conf Wed Sep 22 18:48:30 1999 @@ -0,0 +1,3 @@ +# Un-comment the following line to make pump set up its network config via +# a Perl script, for cases where the default behavior is not what you want +#setupscript /etc/pump/pumpscript.pl diff --unified --recursive --new-file pump-0.7.2/pump.h pump-0.7.2gm1/pump.h --- pump-0.7.2/pump.h Sat Aug 7 15:15:19 1999 +++ pump-0.7.2gm1/pump.h Wed Sep 22 14:51:48 1999 @@ -46,6 +46,7 @@ struct pumpOverrideInfo { struct pumpNetIntf intf; char * searchPath; + char * setupScript; int flags; int numRetries; int timeout; diff --unified --recursive --new-file pump-0.7.2/scripts/fancydns.pl pump-0.7.2gm1/scripts/fancydns.pl --- pump-0.7.2/scripts/fancydns.pl Wed Dec 31 19:00:00 1969 +++ pump-0.7.2gm1/scripts/fancydns.pl Wed Sep 22 18:51:50 1999 @@ -0,0 +1,146 @@ +#!/usr/bin/perl + +########################################################################## +# +# fancydns.pl - September 22, 1999 - Graham Mainwaring +# +# This is an example script intended to be called from pump when an +# interface receives its DHCP configuration. In addition to doing the +# normal stuff you would expect, this script updates a local named +# instance and sets its forwarders to point to the DNS servers given +# by DHCP, yet leaves /etc/resolv.conf pointing at the local server. +# This might be useful if you are running a local caching nameserver, +# yet want to take advantage of on-site DNS servers wherever you are. +# +# Note that for this script to work, you must be running BIND 8 using +# named.conf (not named.boot), and your named.conf must have an options +# section that commences with a line containing just "options {", ends +# with a line containing just "};", and the forwarders directive must +# be all on one line like this: "forwarders { 1.2.3.4; 5.6.7.8; };". +# +########################################################################## + +use Sys::Syslog; + +sub logerr($) { + openlog('pumpd', 'cons,pid', 'daemon'); + syslog('err', $_[0]); + closelog(); +} + +sub errexit($) { + logerr($_[0]); + die $_[0]; +} + +while (<>) { + chop; + ($tag,$value)=split(/\=/); + $tag=lc($tag); + if ($tag eq "dev") { $dev = $value } + elsif ($tag eq "ip") { $ip = $value } + elsif ($tag eq "netmask") { $netmask = $value } + elsif ($tag eq "broadcast") { $broadcast = $value } + elsif ($tag eq "network") { $network = $value } + elsif ($tag eq "gateway") { $gateway = $value } + elsif ($tag eq "hostname") { $hostname = $value } + elsif ($tag eq "domain") { $domain = $value } + elsif ($tag =~ /dns[0-9]/) { $dns[$#dns+1] = $value } +} + +if (defined $dev && defined $ip && defined $netmask && defined $broadcast) { + system "/sbin/ifconfig $dev $ip netmask $netmask broadcast $broadcast"; +} else { + errexit("did not get enough information to configure interface"); +} + +if (defined $gateway) { + system "/sbin/route del default"; + system "/sbin/route add default gw $gateway"; +} else { + logerr("did not get a default gateway"); +} + +if (defined $hostname) { + system "/bin/hostname $hostname"; +} + +open RESOLV, "/etc/resolv.conf"; +while () { + chop; + ($key,$value)=split(/\s/); + $key = lc($key); + if ($key eq "nameserver") { + $old_nameserver=$value; + } elsif ($key eq "domain") { + $old_domain=$value; + } elsif ($key eq "search") { + $old_search=$value; + } else { + $resolv[$#resolv+1]=$_; + } +} +close RESOLV; + +open RESOLV, ">/etc/resolv.conf"; +if (defined $old_nameserver) { + print RESOLV "nameserver $old_nameserver\n"; +} elsif ($#dns >= 0) { + print RESOLV "nameserver "; + foreach $dns (@dns) { + print RESOLV "$dns "; + } + print RESOLV "\n"; +} +if (defined $domain) { + print RESOLV "domain $domain\n"; +} elsif (defined $old_domain) { + print RESOLV "domain $old_domain\n"; +} +if (defined $old_search) { + print RESOLV "search $old_search\n"; +} +foreach $resolv (@resolv) { + print RESOLV "$resolv\n"; +} +close RESOLV; + +open NAMED, "/etc/named.conf"; +while () { + chop; + $named[$#named+1] = $_; +} +close NAMED; + +sub write_forwarders () +{ + $looking=0; + print NAMED " forwarders { "; + foreach $dns (@dns) { + print NAMED "$dns; "; + } + print NAMED "};\n"; +} + +$looking=0; +open NAMED, ">/etc/named.conf"; +foreach $named (@named) { + if ($looking == 1) { + if (lc($named) =~ /forwarders/) { + write_forwarders(); + } elsif ($named =~ /^\s*\}\;\s*$/) { + write_forwarders(); + print NAMED "$named\n"; + } else { + print NAMED "$named\n"; + } + } else { + if (lc($named) =~ /options \{/) { + $looking=1; + } + print NAMED "$named\n"; + } +} +close NAMED; + +system("/usr/bin/killall -HUP named"); diff --unified --recursive --new-file pump-0.7.2/scripts/pumpscript.pl pump-0.7.2gm1/scripts/pumpscript.pl --- pump-0.7.2/scripts/pumpscript.pl Wed Dec 31 19:00:00 1969 +++ pump-0.7.2gm1/scripts/pumpscript.pl Wed Sep 22 17:18:23 1999 @@ -0,0 +1,75 @@ +#!/usr/bin/perl + +########################################################################## +# +# pumpscript.pl - September 22, 1999 - Graham Mainwaring +# +# This is an example script intended to be called from pump when an +# interface receives its DHCP configuration. It is passed a series of +# key=value pairs on stdin, which contain the information that pump +# was able to gather from the DHCP server. It is not guaranteed that +# any particular item will necessarily be available. The script must +# also silently ignore any unknown items that arrive. Note that there +# is no reason to ever use this script exactly as it is given here; +# if all you want is default behavior, just use pump's built-in +# routines. This scripting capability is intended for people who +# want to customize the behavior of what happens when you get your +# dhcp information, for whatever bizarre purpose. +# +########################################################################## + +use Sys::Syslog; + +sub logerr($) { + openlog('pumpd', 'cons,pid', 'daemon'); + syslog('err', $_[0]); + closelog(); +} + +sub errexit($) { + logerr($_[0]); + die $_[0]; +} + +while (<>) { + chop; + ($tag,$value)=split(/\=/); + $tag=lc($tag); + if ($tag eq "dev") { $dev = $value } + elsif ($tag eq "ip") { $ip = $value } + elsif ($tag eq "netmask") { $netmask = $value } + elsif ($tag eq "broadcast") { $broadcast = $value } + elsif ($tag eq "network") { $network = $value } + elsif ($tag eq "gateway") { $gateway = $value } + elsif ($tag eq "hostname") { $hostname = $value } + elsif ($tag eq "domain") { $domain = $value } + elsif ($tag =~ /dns[0-9]/) { $dns[$#dns+1] = $value } +} + +if (defined $dev && defined $ip && defined $netmask && defined $broadcast) { + system "/sbin/ifconfig $dev $ip netmask $netmask broadcast $broadcast"; +} else { + errexit("did not get enough information to configure interface"); +} + +if (defined $gateway) { + system "/sbin/route del default"; + system "/sbin/route add default gw $gateway"; +} else { + logerr("did not get a default gateway"); +} + +if (defined $hostname) { + system "/bin/hostname $hostname"; +} + +if ($#dns >= 0) { + open RESOLV, ">/etc/resolv.conf"; + if ($domain ne "") { print RESOLV "domain $domain\n"; } + print RESOLV "nameserver "; + foreach $dns (@dns) { + print RESOLV "$dns "; + } + print RESOLV "\n"; + close RESOLV; +} diff --unified --recursive --new-file pump-0.7.2/scripts/setup.in pump-0.7.2gm1/scripts/setup.in --- pump-0.7.2/scripts/setup.in Wed Dec 31 19:00:00 1969 +++ pump-0.7.2gm1/scripts/setup.in Wed Sep 22 16:48:16 1999 @@ -0,0 +1,8 @@ +dev=eth0 +ip=10.0.1.60 +netmask=255.255.0.0 +broadcast=10.0.255.255 +gateway=10.0.0.1 +hostname=motivator +domain=int.magellanlabs.com +dns0=10.0.0.201