autodns-dhcp-0.8/0000775000000000000000000000000012006471413010640 5ustar autodns-dhcp-0.8/autodns-dhcp.conf0000664000000000000000000000055612006471413014106 0ustar # edit these for your own system # this conf file is 'required()' into perl scripts so # perl syntax applies. $DOMAIN="__DOMAIN__"; $DDNSHOME="/var/lib/autodns-dhcp"; $NSUPDATE="/usr/bin/nsupdate"; $DHCPDCONF="/etc/dhcp/dhcpd.conf"; $DHCPDINIT="/etc/init.d/isc-dhcp-server"; $DHCPDPID="/var/run/dhcp-server/dhcpd.pid"; $DHCPDLEASES="/var/lib/dhcp/dhcpd.leases"; autodns-dhcp-0.8/Makefile0000664000000000000000000000042110763051166012304 0ustar #! /usr/bin/make -f SCRIPTS=autodns-dhcp_cron autodns-dhcp_ddns CONF=autodns-dhcp.conf MANP=autodns-dhcp_cron.1 autodns-dhcp_ddns.1 all: install: $(SCRIPTS) install $(SCRIPTS) $(DESTDIR)/usr/sbin/ cp $(CONF) $(DESTDIR)/etc/ cp $(MANP) $(DESTDIR)/usr/share/man/man1/ autodns-dhcp-0.8/autodns-dhcp_ddns.10000664000000000000000000000144610763047706014344 0ustar .TH autodns-dhcp_ddns 1 .SH NAME autodns-dhcp_ddns \- the script that updates the dns and settles the dhcp stuff .SH SYNOPSIS .B INTERNAL .br .SH DESCRIPTION .B autodns-dhcp_ddns is the script that updates the dns data, it also settles the information given dinamically on the dhcp server configuration, so that things become static instead of dynamic. It does this by creating the update instructions for nsupdate and BIND, and writing host entries with the name, MAC and IP addresses on the dhcp configuration. This script is called from autodns-dhcp_cron, and should not be called directly, if the user wants to force any updates, he should call autodns-dhcp_cron and not autodns-dhcp_ddns directly. .PP .SS FILES .nf /etc/autodns-dhcp.conf /usr/share/doc/autodns-dhcp/* /var/lib/autodns-dhcp/* .fi autodns-dhcp-0.8/autodns-dhcp_cron.10000664000000000000000000000137210763050367014350 0ustar .TH autodns-dhcp_cron 1 .SH NAME autodns-dhcp_cron \- a cron script to check for changes to the dhcp.leases file .SH SYNOPSIS .B autodns-dhcp_cron .br .SH DESCRIPTION .B autodns-dhcp_cron is a cron script to check for changes to the dhcp.leases file, it calls autodns-dhcp_ddns whenever there are changes, so that the changes are updated on the dns server and also settled on the dhcp configuration. Also, it reloads dhcp server configuration whenever it has been changed. This is done periodically from the cron as stated on the cron file for the package, however it can also be called by hand whenever the administrator may want to. .PP .SS FILES .nf /etc/cron.d/autodns-dhcp /etc/autodns-dhcp.conf /usr/share/doc/autodns-dhcp/* /var/lib/autodns-dhcp/* .fi autodns-dhcp-0.8/autodns-dhcp_ddns0000775000000000000000000002132410771550453014202 0ustar #!/usr/bin/perl # # autodns-dhcp_ddns # The procedure here is simple. # If a record has been added since the last change, delte any previous # mentions and add a new record. This can lead to expired records but this # should not be a problem. # # Copyright (C) 1999 Stephen Carville # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # use inverse time functions use Time::Local; use strict; use Socket; my $DEBUG = 0; my $version="0.7"; # these are the only valid character for a machine name -- used in checkname() my $NAMECHARS="[a-zA-Z0-9\\-]"; # define the extra filters to apply for machine names -- in checkname() # these filters allow for extra name filtering if needed. For example, this # filter only allows "legitimate" names into my employers's DNS #my $CYPFILTER="cy(pci|pca|hpr|sun)t\\d{2}|\\d{3}"; # these are the active filters -- set this to "" if you don't need any extra # filters. my(@filters)=(""); # filter for a bogus ethernet address (look for seven octets :-) #my $ETHER="\\w\\w:\\w\\w:\\w\\w:\\w\\w:\\w\\w:\\w\\w:\\w\\w"; # lets try filtering on the first two octets of the bogus address this may # cause a legitimate address to choke but all the info I can find indicates # the 52:41 sequence has never been issued to any manufacturer my $ETHER="\^52:41:"; # nsupdate command strings my $IFEXIST="prereq yxdomain"; my $IFNOTEXIST="prereq nxdomain"; my $ADD="update add"; my $DELETE="update delete"; # use a default time to live of one hour my $TTL="3600"; my $LEASE_TEMP="dhcpd.leases.last"; # my $UPDATE="nsupdate.data"; my (%newip,%newmac,%newname,$hostname,$hostip,$hard); my ($nowtime,$lastime,$ip,$linea); my ($home,$dhcpdleases,$update,$dhcpup,$dhcpdleases_temp,$domain,$dhcpdconf); my (@ddnscommand,@OUTPUT,@SALIDA); my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, $blksize,$blocks); # get the program environment variables $home = $ENV{DDNSHOME}; $dhcpdleases = $ENV{DHCPDLEASES}; $update = $ENV{UPDATE}; $dhcpdleases_temp = $ENV{DHCPDLEASES_TEMP}; $dhcpdconf = $ENV{DHCPDCONF}; $domain = $ENV{DNS_DOMAIN}; $dhcpup = $ENV{DHCPUP}; # get the current GMT $nowtime=time(); # get last update time; if (-e "$home/$LEASE_TEMP") { ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, $blksize,$blocks)=stat("$home/$LEASE_TEMP"); $lastime=$mtime; } else { $lastime=0; } # now copy the dhcpd.leases file over to DDNSHOME system "/bin/cp", $dhcpdleases, $dhcpdleases_temp; # get the new data # I have changed this to two global hashes: # newip is indexed by IP and contains the last MAC asociated with that IP # newmac is indexed by MAC and contains the last IP and the name for that MAC load_new_data($nowtime,$lastime); unless (open OUTPUT, ">$update") { print STDERR "Unable to open $update\n"; die; } unless (open SALIDA, ">$dhcpup") { print STDERR "Unable to open $dhcpup\n"; die; } unless (open ENTRADA, "<$dhcpdconf") { print STDERR "Unable to open $dhcpdconf\n"; die; } if ($DEBUG == 1) { *OUTPUT=*STDERR; } # We parse the dhcpd.conf file getting the already fixed parameters to make # sure a MAC doesn't get two IPs and fixed IPs aren't asigned again. # I know this can only happen in a few cases, but this has gotta be strong. while () { if (/host.+hardware ethernet (.+); fixed-address (.+);.+/) { delete $newmac{$1}; delete $newip{$2}; } } seek(ENTRADA,0,0); # now do the adds #For each of the found ips (sorted numerically) foreach $ip (sort ipcomp keys (%newip)) { #Get the mac for the ip we'll work with $hard=$newip{$ip}; #For that mac, get it's IP and the host name ($hostip,$hostname) = split(/ /,$newmac{$hard}); #Do not add the host if the IP doesn't match the one we were asking for unless ($hostip eq $ip) { next; } #Do not add the host if the name is not valid acording to our criteria unless (checkname($hostname)) { next; } #Do not add the host if the name already exists on dns if (gethostbyname("$hostname.$domain.")) { next; } #Check if we had added the same name on this round (only add the first one) if ( $newname{$hostname} ) { next; } #Mark the name so that we don't add the name more than once $newname{$hostname} = 1; @ddnscommand=add_record($hostname,$ip); while (($linea=) ne "range $ip;\n") { print SALIDA $linea } print SALIDA "host $hostname {hardware ethernet $hard; fixed-address $ip;}\n"; print OUTPUT @ddnscommand; } while ($linea=) { print SALIDA $linea } close SALIDA; close ENTRADA; # # check an ethernet id # Windows will try to grab multiple addresses. I can't stop DHCP from # granting them but I can make sure only addresses granted to valid # ethernet addresses get into the DNS # sub checkethid { my ($ether)=@_; if ($ether =~m/$ETHER/) { return 1; } return 0; } # # check a name to see if it is a valid name # first check the name is FQDN valid then does it fit our # internal naming policy. I may add an exception list here later. # sub checkname { my ($name)=@_; my (@array,$letter,$filter); @array=split(//,$name); foreach $letter(@array) { unless ($letter=~m/$NAMECHARS/) { return 0; } } foreach $filter (@filters) { unless ($name=~m/$filter/) { return 0; } } return 1; } # # add a record # sub add_record { my ($machine,$address) = @_; my ($xaddress,@c,$arpa); # get reverse lookup for the new address $arpa=get_arpa($address); # add the new forward record push @c, "$ADD $machine.$domain $TTL IN A $address\n\n"; # add the new reverse record push @c, "$ADD $arpa $TTL IN PTR $machine.$domain\n\n"; return @c; } # # get the reverse lookup value for an address # sub get_arpa { my ($address) = @_; my ($arpa,$a,$b,$c,$d); ($a,$b,$c,$d) = split /\./, $address; $arpa = "$d.$c.$b.$a.in-addr.arpa"; return $arpa; } # # load the current dhcpd.leases file # here we look at the hostname, the lease start time and the lease end time. # if a hostname does not exist, there will be no entry made in DNS. sub load_new_data{ my ($nowtime,$lastime)=@_; my(@DATA,$hn,$ip,$startime,$endtime,@date,@time,@a,$hard,$bogus); unless (open DATA,"$dhcpdleases_temp") { print STDERR "autodns-dhcp_ddns $version: can't open $dhcpdleases_temp\n"; die; } # set the bogus ethernet id flag to 0 $bogus=0; # parse each line in the file while () { # get rid of semicolons and quote marks $_=~s/\"//g; $_=~s/\;//g; @a=split(" ",$_); # get IP address if ($a[0] eq "lease") { # start of a new entry so reset bogus $bogus=0; $ip= $a[1]; } # get the starting GMT for the lease if ($a[0] eq "starts") { @date=split("/",$a[2]); @time=split(":",$a[3]); $startime=timegm($time[2],$time[1],$time[0],$date[2],$date[1]-1,$date[0]); } # get the ending GMT for the lease if ($a[0] eq "ends") { @date=split("/",$a[2]); @time=split(":",$a[3]); $endtime=timegm($time[2],$time[1],$time[0],$date[2],$date[1]-1,$date[0]); } # check if the Ethernet address is legit. Some Win boxen will request # multiple addresses using bogus ethernet id's (yuck!) if ($a[0] eq "hardware") { # if it is a bogus address go to the next entry if (checkethid($hard=$a[2])) { $bogus=$a[2]; next; } } # since dhcpd adds new leases to the end of the file, it is assumed that # a later entry is the most likely to be correct. Therefore just overwrite # any duplicate hostnames found if ($a[0] eq "client-hostname") { $hn=lc($a[1]); # is this lease new and valid? (is it worthwhile here to check for bogosity?) if ($startime > $lastime && $endtime > $nowtime) { unless ($bogus) { $newip{$ip} = $hard; $newmac{$hard} = "$ip $hn"; } } # if the lease is not valid and not bogus we remove the posible valid leases # that had been assigned before. else { unless ($bogus) { delete $newip{$ip}; delete $newmac{$hard}; } } } } close DATA; } sub ipcomp { my @ip1 = split(/\./,$a); my @ip2 = split(/\./,$b); my $ip1n = (((($ip1[0]*256)+$ip1[1])*256)+$ip1[2])*256+$ip1[3]; my $ip2n = (((($ip2[0]*256)+$ip2[1])*256)+$ip2[2])*256+$ip2[3]; return ($ip1n <=> $ip2n); } autodns-dhcp-0.8/README0000664000000000000000000001500310763051055011523 0ustar Automatic DNS with dhcp By Santiago García Mantiñán (C) 2007, distributed under GPL 2.0 Well, this is based on Stephen Carville's dhcp-dns scripts to do dynamic DNS using ISC's dhcp, but this is no dynamic DNS, it is an static DNS wich is updated automatically. Also, I'm using the patches Craig Sanders did when packaging it for debian. To both of them, thank you for giving me the job half done. What this scripts do, or at least intend to do, is automatically put into DNS any machine with a well formed name that gets a new lease from the dhcp server. Also, once the host is put into DNS, they settle on the dhcp configuration the IP it was given by the server, so that next time the machine boots it gets the same IP. As a consequence of this, the time on wich a client can get more than one lease gets reduced to the time elapsed between two runs of the scripts (by default 1 minute), and also, the time he can have more than one IP if it gets more than one IP, is reduced to the lease time. Afterwards he will be given just one IP and only one, and it will allways be the same. This is based on machine's MAC address, so... well, you know, if this address is changed, then all that I have just said are lies. The contents are more or less the same ones as on the original package: autodns-dhcp_cron: script to check for changes to the dhcp.leases file. autodns-dhcp_ddns: the script that does the actual work of creating the update instructions for nsupdate and BIND, it also is responsible for settling the name, MAC address and IP on the dhcp conf. I have not included Stephen's ddnsupdate.pl as I personally think that the standard nsupdate should be used if someone has to manually touch the dns. ------------------------ Setting up this package. ------------------------ This comes from Graig's patches for the Stephen Carville's scripts: In what now is /etc/autodns-dhcp.conf, the domain defaults to: $DOMAIN='__DOMAIN__' until changed, the scripts will exit immediately without doing anything. You need to configure this before autodns-dhcp will work. you also need to configure dhcp and bind as detailed below. ----------------------------------------- Setting up DHCP to use with this scripts. ----------------------------------------- The scripts want the dhcpd to contain a one line range __IP__; line per each IP that a host can be given. Also they spect this ranges to be sorted incrementally. For example, If we want to give away range 192.168.1.15-192.168.1.254 of the class C network 192.168.1.0 then we write for example: subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.15; range 192.168.1.16; range 192.168.1.17; range 192.168.1.18; ... range 192.168.1.251; range 192.168.1.252; range 192.168.1.253; range 192.168.1.254; } This range lines can be easily generated with something like this: perl -e 'for ($i=15;$i<255;$i++){print "range 192.168.1.$i;\n"}' ----------------------------------------- Setting up BIND to allow dynamic updates. ----------------------------------------- To use dynamic DNS, you must have your named.conf set up to allow it. This is accomplished by using the allow-update directive in your named.conf file. For example: zone "high-g.prv" { type master; file "local.db"; allow-update {192.168.1.10;}; }; zone "1.168.192.in-addr.arpa" { type master; file "192.168.1.db"; allow-update {192.168.1.10;}; }; The address in the braces is the address of the computer that is allowed to update the running named dynamically, at least the machine running the dhcp-server and this scripts should be listed there. It is very important that every zone you want to update dynamically have the allow-update directive. A common mistake is to allow updates in the forward lookup zone (A records) but forget to add the allow-update directive to the reverse lookup zone (PTR records) ---------------------------------------------------------------------------- Well, now the story... I'm a member of the G.P.U.L. (Grupo de Programadores y Usuarios de Linux) translated to english this is: Group of Programmers and Users of Linux, our LUG here in A Coruña, I'm also a member of A.M.I.G.A. (Asociación da Modidade Informática Galega de A Coruña). As a member of AMIGA I like DemoScene parties, and as a member of GPUL I like Linux, so what I do is, with the help of the other members, build software and hardware solutions mainly for our own party, the Arroutada Party, even though now it seems that we are being called from some others to help with the network or just organice the Linux contests there. I don't have to tell you that people has a nice time there. Well, on last Arroutada I tried dhcp version 3.0 beta with DDNS and it didn't work as well as I supposed it would do, so when we were contacted to give a solution for the XuventudeGalicia.Net, I tried the last beta of version 3 and still didn't work as I wanted it to, mainly because of the new one lease per client option, so I took a look at Stephen's scripts and saw that I could get a nice thing done with a few modifications. The modifications I wanted was to achieve something like the new one lease per client option, or the closest to this I could get, and also I didn't want people coming to be able to overwrite other people's machine name or even organization's machine name, and this was allowed on Stephen's original scripts. When thinking of all this, I thought that for administrative purposes it was better if there were no chances at all that one could change his IP, so I settled all of them. Well, after changing all this at home and after doing the tests with a couple of clients, we came to the party, and of course it broke. When you are organicing a party, you don't sleep too much, if you sleep, that is, so, your mind is not too clear. That's why after a time I called up Roberto Suarez Soto, to explain him how it all worked and see if he could help me debug the scripts, and we found the bug (sort wasn't meant for sorting IP numbers), so we started fixing the stuff, and it worked on our little script for testing, but when we took it to the server it failed :-( That's were Rik van Riel, who was at the party to to give a talk on memory management, showed up, and after looking at our code without finding the problem, just when I had found the problem (we were all quite sleepy), he proposed a diferent aproach wich was correct. And that's the hole story of how this was rewritten. Of course I'd like to thank Rik and Roberto, for helping me when I was totally switched off ;-) autodns-dhcp-0.8/debian/0000775000000000000000000000000012006470505012063 5ustar autodns-dhcp-0.8/debian/postrm0000664000000000000000000000045207071455624013346 0ustar #! /bin/sh set -e case "$1" in purge) rm -rf /var/lib/autodns-dhcp/ || true ;; remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) ;; *) echo "postrm called with unknown argument \`$1'" >&2 exit 0 esac #DEBHELPER# exit 0autodns-dhcp-0.8/debian/rules0000775000000000000000000000254110763052213013145 0ustar #!/usr/bin/make -f #-*- makefile -*- # Made with the aid of dh_make, by Craig Small # Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess. # Some lines taken from debmake, by Christoph Lameter. # Uncomment this to turn on verbose mode. export DH_VERBOSE=1 build: build-stamp build-stamp: dh_testdir # Add here commands to compile the package. $(MAKE) touch build-stamp clean: dh_testdir dh_testroot rm -f build-stamp install-stamp # Add here commands to clean up after the build process. dh_clean install: install-stamp install-stamp: build-stamp dh_testdir dh_testroot dh_clean -k dh_installdirs $(MAKE) install DESTDIR=`pwd`/debian/autodns-dhcp touch install-stamp # Build architecture-independent files here. binary-indep: build install # dh_testversion dh_testdir dh_testroot dh_installdocs # dh_installexamples # dh_installmenu # dh_installemacsen # dh_installinit dh_installcron # dh_installmanpages # dh_undocumented dh_installchangelogs dh_compress dh_fixperms dh_installdeb dh_shlibdeps dh_gencontrol dh_md5sums dh_builddeb binary-arch: build install source diff: @echo >&2 'source and diff are obsolete - use dpkg-source -b'; false binary: binary-indep binary-arch .PHONY: build clean binary-indep binary-arch binary autodns-dhcp-0.8/debian/dirs0000664000000000000000000000006507071451744012762 0ustar var/lib/autodns-dhcp usr/share/man/man1 usr/sbin etc autodns-dhcp-0.8/debian/postinst0000664000000000000000000000072507071453151013701 0ustar #! /bin/sh set -e case "$1" in configure) echo echo Remember that before using autodns-dhcp you must configure echo the dhcp and bind servers as well as the package itself. echo To know how to do this have a look at the documentation of echo the package at /usr/share/doc/autodns-dhcp/ ;; abort-upgrade|abort-remove|abort-deconfigure) ;; *) echo "postinst called with unknown argument \$1'" >&2 exit 0 ;; esac #DEBHELPER# exit 0 autodns-dhcp-0.8/debian/changelog0000664000000000000000000000546012006470505013742 0ustar autodns-dhcp (0.8ubuntu1) quantal; urgency=low * Switch Depends: to isc-dhcp-server following dhcp3-server to isc-dhcp-server transition. * Switch paths to follow new location of configuration files. -- Andy Whitcroft Tue, 31 Jul 2012 14:08:26 +0100 autodns-dhcp (0.8) unstable; urgency=low * Fix a bug that allowed a DOS caused by adding twice the same name on the dhcp config file. -- Santiago Garcia Mantinan Sun, 23 Mar 2008 22:52:58 +0100 autodns-dhcp (0.7) unstable; urgency=low * Change the names of the scripts to comply with Policy Manual section 10.4. * Update it to work with dhcp v3 by default by moving a lot of the hardcoded stuff to the config file and updating this (v2 should still work adjusting the default config). Closes: #220487. * Fix the path for nsupdate on the config file. Closes: #452203. * Fix the restart of the dhcp daemon. * Remove the ndc stuff as ndc is no longer available on bind9 and rndc doesn't implement restart. Besides, doing a restart just to update the zones doesn't seem worth it, and one can do it by hand whenever he feels the need. -- Santiago Garcia Mantinan Wed, 27 Feb 2008 18:34:50 +0100 autodns-dhcp (0.6) unstable; urgency=low * Untaint PATH, thanks to Brett Cundal. Closes: #198688. -- Santiago Garcia Mantinan Thu, 14 Aug 2003 20:40:22 +0200 autodns-dhcp (0.5) unstable; urgency=low * Little change to avoid asigning addresses no longer used. * Avoid the output of /etc/init.d/dhcp on the cron tasks. * Fix the path to dhcp.leases to comply with the new dhcp. Closes: #176417. -- Santiago Garcia Mantinan Sat, 29 Mar 2003 16:26:16 +0100 autodns-dhcp (0.4) unstable; urgency=low * Include a fix for the problem with nsupdate. I have not been able to repruduce the problem, so I can't confirm that it works ok. I've been told by John Cooper that it works, however if anybody still has problems with DNS not being updated, please report them. Closes: #128147. -- Santiago Garcia Mantinan Sat, 19 Jan 2002 20:49:40 +0100 autodns-dhcp (0.3) unstable; urgency=low * Fix dependencies, as nsupdate is now on dnsutils. * Updated the hole package a bit. -- Santiago Garcia Mantinan Fri, 28 Dec 2001 11:13:01 +0100 autodns-dhcp (0.2) unstable; urgency=low * Fixed the sorting bug we found at the party. -- Santiago Garcia Mantinan Sat, 1 Apr 2000 16:45:05 +2000 autodns-dhcp (0.1) unstable; urgency=low * Based on v0.50 of Stephen Carville's original scripts written for the XuventudeGalicia.Net and the Arroutada Party. -- Santiago Garcia Mantinan Sat, 1 Apr 2000 16:45:05 +2000 Local variables: mode: debian-changelog End: autodns-dhcp-0.8/debian/docs0000664000000000000000000000000707071410434012734 0ustar README autodns-dhcp-0.8/debian/copyright0000664000000000000000000000110707413042643014021 0ustar This package was written and packaged by Santiago Garcia Mantinan , it is heavily based on version 0.50 of the dhcp-dns package Copyright 1999 by Stephen Carville licensed under The Gnu Public License V2 or later packaged by Craig Sanders . This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. see /usr/share/common-licenses/GPL for details autodns-dhcp-0.8/debian/compat0000664000000000000000000000000210763046303013264 0ustar 5 autodns-dhcp-0.8/debian/cron.d0000664000000000000000000000022210763050223013164 0ustar # # Regular cron jobs for the autodns-dhcp package # */1 * * * * root /usr/bin/test -x /usr/sbin/autodns-dhcp_cron && /usr/sbin/autodns-dhcp_cron autodns-dhcp-0.8/debian/control0000664000000000000000000000124412006470505013467 0ustar Source: autodns-dhcp Section: net Priority: extra Maintainer: Ubuntu Developers XSBC-Original-Maintainer: Santiago Garcia Mantinan Build-Depends: debhelper (>=5.0.0) Standards-Version: 3.7.3 Package: autodns-dhcp Architecture: all Depends: bind9 | bind, dnsutils, perl | perl5, isc-dhcp-server | dhcp Conflicts: dhcp-dns Description: Automatic DNS updates for DHCP autodns-dhcp uses bind's dynamic update features to update a zonefile with hostnames from the dhcp leases file, this is done just once for each hostname as the IP, MAC address and name are settled on the dhcp configuration to have an static zone. autodns-dhcp-0.8/autodns-dhcp_cron0000775000000000000000000000455310772024771014220 0ustar #!/usr/bin/perl -T # this script checks is the current version of /etc/dhcpd.leases is more # current than the version stored in DDNSHOME. If so, autodns-dhcp_ddns # is called to create the ndupdate data file. Then nsupdate is called to # notify BIND of the changes. use strict; require '/etc/autodns-dhcp.conf' ; exit 0 if ($main::DOMAIN eq "__DOMAIN__") ; # Untaint PATH $ENV{PATH} = ''; my $UPDATE="$main::DDNSHOME/nsupdate.data"; my $DHCPUP="$main::DDNSHOME/dhcpd.conf.new"; my $DHCPDLEASES_TEMP="$main::DDNSHOME/dhcpd.leases.last"; my $LOCKFILE="$main::DDNSHOME/lock"; my $DHCPDCONF="$main::DHCPDCONF"; my $DHCPDPID="$main::DHCPDPID"; my $DHCPDINIT="$main::DHCPDINIT"; my $DDNS="/usr/sbin/autodns-dhcp_ddns"; my($ref,$data); my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks); # get timestamp on leases file ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, $blksize,$blocks)=stat($main::DHCPDLEASES); $data=$mtime; # get timestamp on saved file ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, $blksize,$blocks)=stat($DHCPDLEASES_TEMP); $ref=$mtime; if ($ref >= $data) { exit 0; } # are we locked? (JIC :-) if (-e "$LOCKFILE") { exit 0; } # ok lock us up system "/bin/touch", $LOCKFILE; $ENV{DDNSHOME}=$main::DDNSHOME; $ENV{DHCPDLEASES}=$main::DHCPDLEASES; $ENV{DHCPDCONF}=$main::DHCPDCONF; $ENV{UPDATE}=$UPDATE; $ENV{DHCPDLEASES_TEMP}=$DHCPDLEASES_TEMP; $ENV{DNS_DOMAIN}=$main::DOMAIN; $ENV{DHCPUP}=$DHCPUP; # call autodns-dhcp_ddns system "/usr/bin/perl", $DDNS; ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, $blksize,$blocks)=stat($UPDATE); # now call nsupdate to notify BIND if ( $size > 0 && ! system $main::NSUPDATE,$UPDATE) { ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, $blksize,$blocks)=stat($DHCPUP); $data=$size; ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime, $blksize,$blocks)=stat($DHCPDCONF); if ($data > $size) { system "/bin/cp",$DHCPUP,$DHCPDCONF; $ENV{'PATH'} = '/sbin:/bin'; system "/sbin/start-stop-daemon --stop --quiet --pidfile $DHCPDPID --retry 5 >/dev/null"; system "$DHCPDINIT start >/dev/null"; } else { print STDERR "$data $size"; print STDERR "Error creating the new dhcpd configuration.\n"; } } # unlock the process system "/bin/rm", $LOCKFILE;