--- rpms/e-smith-tinydns/sme9/e-smith-tinydns-2.4.0_add_hostname_following_dhcpdleases_hostname.patch 2015/01/12 20:59:17 1.4 +++ rpms/e-smith-tinydns/sme9/e-smith-tinydns-2.4.0_add_hostname_following_dhcpdleases_hostname.patch 2015/01/17 18:17:09 1.5 @@ -1,7 +1,7 @@ diff -Nur e-smith-tinydns-2.4.0/createlinks e-smith-tinydns-2.4.0.bz2388/createlinks --- e-smith-tinydns-2.4.0/createlinks 2006-03-14 23:01:42.000000000 +0100 -+++ e-smith-tinydns-2.4.0.bz2388/createlinks 2015-01-09 22:18:42.489639249 +0100 -@@ -26,3 +26,24 @@ ++++ e-smith-tinydns-2.4.0.bz2388/createlinks 2015-01-17 18:02:35.489764844 +0100 +@@ -26,3 +26,19 @@ service_link_enhanced("tinydns", "K65", "6"); service_link_enhanced("tinydns", "K65", "0"); service_link_enhanced("tinydns", "K65", "1"); @@ -10,13 +10,8 @@ diff -Nur e-smith-tinydns-2.4.0/createli + for my $event (qw( dhcp-dns )) + { + # services to launch on event -+ safe_symlink("restart", "root/etc/e-smith/events/$event/services2adjust/dnscache"); ++ safe_symlink("sigusr1", "root/etc/e-smith/events/$event/services2adjust/dnscache"); + safe_symlink("sigusr1", "root/etc/e-smith/events/$event/services2adjust/tinydns"); -+ safe_symlink("restart", "root/etc/e-smith/events/$event/services2adjust/dhcpd"); -+ safe_symlink("restart", "root/etc/e-smith/events/$event/services2adjust/dhcp-dns"); -+ -+ # Template to event -+ templates2events("/var/service/tinydns/root/data", $event); + } + +#creation of dhcp-dns service @@ -28,30 +23,49 @@ diff -Nur e-smith-tinydns-2.4.0/createli + safe_symlink("/var/service/dhcp-dns/", "root/service/dhcp-dns"); diff -Nur e-smith-tinydns-2.4.0/root/etc/e-smith/db/configuration/defaults/dhcp-dns/status e-smith-tinydns-2.4.0.bz2388/root/etc/e-smith/db/configuration/defaults/dhcp-dns/status --- e-smith-tinydns-2.4.0/root/etc/e-smith/db/configuration/defaults/dhcp-dns/status 1970-01-01 01:00:00.000000000 +0100 -+++ e-smith-tinydns-2.4.0.bz2388/root/etc/e-smith/db/configuration/defaults/dhcp-dns/status 2015-01-08 13:33:30.870973725 +0100 ++++ e-smith-tinydns-2.4.0.bz2388/root/etc/e-smith/db/configuration/defaults/dhcp-dns/status 2015-01-16 20:02:12.050969025 +0100 @@ -0,0 +1 @@ +enabled diff -Nur e-smith-tinydns-2.4.0/root/etc/e-smith/db/configuration/defaults/dhcp-dns/type e-smith-tinydns-2.4.0.bz2388/root/etc/e-smith/db/configuration/defaults/dhcp-dns/type --- e-smith-tinydns-2.4.0/root/etc/e-smith/db/configuration/defaults/dhcp-dns/type 1970-01-01 01:00:00.000000000 +0100 -+++ e-smith-tinydns-2.4.0.bz2388/root/etc/e-smith/db/configuration/defaults/dhcp-dns/type 2015-01-08 13:33:30.870973725 +0100 ++++ e-smith-tinydns-2.4.0.bz2388/root/etc/e-smith/db/configuration/defaults/dhcp-dns/type 2015-01-16 20:02:12.050969025 +0100 @@ -0,0 +1 @@ +service diff -Nur e-smith-tinydns-2.4.0/root/etc/e-smith/templates/var/service/tinydns/root/data/65dhcpARecords e-smith-tinydns-2.4.0.bz2388/root/etc/e-smith/templates/var/service/tinydns/root/data/65dhcpARecords --- e-smith-tinydns-2.4.0/root/etc/e-smith/templates/var/service/tinydns/root/data/65dhcpARecords 1970-01-01 01:00:00.000000000 +0100 -+++ e-smith-tinydns-2.4.0.bz2388/root/etc/e-smith/templates/var/service/tinydns/root/data/65dhcpARecords 2015-01-09 22:09:02.149175482 +0100 -@@ -0,0 +1,76 @@ ++++ e-smith-tinydns-2.4.0.bz2388/root/etc/e-smith/templates/var/service/tinydns/root/data/65dhcpARecords 2015-01-17 19:02:21.779342484 +0100 +@@ -0,0 +1,107 @@ +{ -+ # we need perl-Date-Manip to convert to a unix timestamp -+ use Date::Manip qw /UnixDate/; -+ ++ use strict; ++ use warnings; ++ use esmith::Logger; ++ use esmith::ConfigDB; + # we need perl-Time-TAI64 for timestamp conversion + use Time::TAI64 qw /unixtai64/; ++ # we need perl-Date-Manip to convert to a unix timestamp ++ use Date::Manip qw /UnixDate/; ++ use File::Copy; ++ ++ my $DB = esmith::ConfigDB->open_ro or die ("cannot open configuration database"); ++ ++ #we start a hash for name because we don't want several same names & ip ++ my %allocated_name = (); ++ my %allocated_ip_dhcplease = (); + + # copy of dhcpd.leases file to /tmp because working directly on the original + # is not a good idea -+ use File::Copy; -+ copy('/var/lib/dhcpd/dhcpd.leases', '/tmp/tmpdhcpd.leases') -+ or die ("Error dhcp-dns Service : Can't copy the /var/lib/dhcpd/dhcpd.leases"); ++ copy("/var/lib/dhcpd/dhcpd.leases","/tmp/tmpdhcpd.leases") ++ or die ("Error dhcp-dns Service : Unable to copy the /var/lib/dhcpd/dhcpd.leases"); ++ ++ #we create a fonction because we want to write in log ++ sub log2messages ++ { ++ my $message = shift; ++ tie *FH, 'esmith::Logger'; ++ print FH "$message"; ++ close FH; ++ } ++ + + #Text::DHCPparse forked because it doesn't allow to retrieve the end of lease + #Only the start is found by the leaseparse of DHCPparse.pm s/starts/ends @@ -84,19 +98,23 @@ diff -Nur e-smith-tinydns-2.4.0/root/etc +} + + # now we parse the leases -+ $return = leaseparse('/tmp/tmpdhcpd.leases'); -+ -+ # variable with local domain value (default is mycompamy.local) -+ my $localdomain = get_local_domainname; ++ my $return = leaseparse('/tmp/tmpdhcpd.leases'); ++ my ($ip,$time,$mac,$name); ++ ++ # variable with local domain value (default is mycompamy.local) and retrieve the server name ++ my $localdomain = $DB->get_value('DomainName') or die ("Unable retrieve the DomainName property"); ++ my $servername = $DB->get_value('SystemName') or die ("Unable retrieve the SystemName property"); + + $OUT .= "# A records for dhcp hosts in $localdomain\n"; + + foreach (keys %$return) { + ($ip, $time, $mac, $name) = unpack("A17 A21 A19 A30", $return->{$_}); -+ # when the dhcp lease is over $name is empty .. we want only non empty one -+ if ( $name ne "" ) { -+ # we skip also ips already allocated -+ unless (exists $allocated_ips{$ip}) ++ ++ # when the dhcp lease is over $name is empty .. we want only non empty one ++ if ( $name ne "" ) ++ { ++ # we skip also ips & names already allocated ++ unless (exists $allocated_ip_dhcplease{$ip} || exists $allocated_name{$name}) + { + # Convert lease end time to the format expected as + # see: http://cr.yp.to/djbdns/tinydns-data.html @@ -107,20 +125,30 @@ diff -Nur e-smith-tinydns-2.4.0/root/etc + # Determine TTL + my $ttl = ''; + $ttl = 0 unless ($ts <= time); -+ $OUT .= "=$name.$localdomain:$ip:$ttl:$endtai\n"; ++ $OUT .= "=$name.$localdomain:$ip:$ttl:$endtai\n" unless ($name eq $servername); ++ log2messages("The hostname of this server ($servername) is used with different IP in /var/lib/dhcpd/dhcpd.leases") ++ if ($name eq $servername); + } -+ $allocated_ips{$ip} = 1; ++ ++ $allocated_ip_dhcplease{$ip} = 1; ++ $allocated_name{$name} ++; ++ ++ log2messages("The hostname \"$name\" is duplicated with different IP in /var/lib/dhcpd/dhcpd.leases") ++ if ($allocated_name{$name} >1); + } + } + # remove the temp file -+ system ("rm -f /tmp/tmpdhcpd.leases") ==0 -+ or die ("Error dhcp-dns Service : Can't rm the /tmp/tmpdhcpd.leases"); ++ unlink "/tmp/tmpdhcpd.leases" ++ or log2messages("Error dhcp-dns Service : Unable to remove the /tmp/tmpdhcpd.leases"); +} ++ diff -Nur e-smith-tinydns-2.4.0/root/var/service/dhcp-dns/dhcp-dns e-smith-tinydns-2.4.0.bz2388/root/var/service/dhcp-dns/dhcp-dns --- e-smith-tinydns-2.4.0/root/var/service/dhcp-dns/dhcp-dns 1970-01-01 01:00:00.000000000 +0100 -+++ e-smith-tinydns-2.4.0.bz2388/root/var/service/dhcp-dns/dhcp-dns 2015-01-09 22:22:32.389241240 +0100 -@@ -0,0 +1,38 @@ ++++ e-smith-tinydns-2.4.0.bz2388/root/var/service/dhcp-dns/dhcp-dns 2015-01-17 18:06:32.318810671 +0100 +@@ -0,0 +1,45 @@ +#!/usr/bin/perl ++use strict; ++use warnings; + +my $lease_file = "/var/lib/dhcpd/dhcpd.leases"; + @@ -130,6 +158,15 @@ diff -Nur e-smith-tinydns-2.4.0/root/var +# seconds to wait +my $update_freq = 30; + ++#we create a function because we want to write in log ++sub log2messages ++ { ++ my $message = shift; ++ tie *FH, 'esmith::Logger'; ++ print FH "$message"; ++ close FH; ++ } ++ +########################################################################### +# Main Loop +while (1) { @@ -142,15 +179,11 @@ diff -Nur e-smith-tinydns-2.4.0/root/var + if ($stats[9] > $modtime) { + + $modtime = $stats[9]; -+ system ("expand-template /var/service/tinydns/root/data") ==0 -+ or warn ("Error service dhcp-dns : can't do expand-template /var/service/tinydns/root/data"); -+ + system ("/usr/bin/sv 1 /service/tinydns") ==0 -+ or warn ("Error service dhcp-dns : can't do sv 1 /service/tinydns"); ++ or log2messages('Error service dhcp-dns : Unable to restart /service/tinydns'); + + system ("/usr/bin/sv 1 /service/dnscache") ==0 -+ or warn ("Error service dhcp-dns : can't do sv 1 /service/dnscache"); -+ ++ or log2messages('Error service dhcp-dns : Unable to do restart /service/dnscache'); + } + + # wait till next check time @@ -160,7 +193,7 @@ diff -Nur e-smith-tinydns-2.4.0/root/var +########################################################################### diff -Nur e-smith-tinydns-2.4.0/root/var/service/dhcp-dns/run e-smith-tinydns-2.4.0.bz2388/root/var/service/dhcp-dns/run --- e-smith-tinydns-2.4.0/root/var/service/dhcp-dns/run 1970-01-01 01:00:00.000000000 +0100 -+++ e-smith-tinydns-2.4.0.bz2388/root/var/service/dhcp-dns/run 2015-01-08 13:33:30.871973834 +0100 ++++ e-smith-tinydns-2.4.0.bz2388/root/var/service/dhcp-dns/run 2015-01-16 20:02:12.055969339 +0100 @@ -0,0 +1,4 @@ +#!/bin/sh +