--- rpms/e-smith-tinydns/sme9/e-smith-tinydns-2.4.0_add_hostname_following_dhcpdleases_hostname.patch 2015/01/17 18:48:40 1.6 +++ rpms/e-smith-tinydns/sme9/e-smith-tinydns-2.4.0_add_hostname_following_dhcpdleases_hostname.patch 2015/01/27 23:35:57 1.7 @@ -1,6 +1,6 @@ -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-17 18:02:35.489764844 +0100 +diff -Nur e-smith-tinydns-2.4.0.old2388/createlinks e-smith-tinydns-2.4.0.bz2388/createlinks +--- e-smith-tinydns-2.4.0.old2388/createlinks 2015-01-27 19:31:32.953849658 +0100 ++++ e-smith-tinydns-2.4.0.bz2388/createlinks 2015-01-27 20:23:29.080882560 +0100 @@ -26,3 +26,19 @@ service_link_enhanced("tinydns", "K65", "6"); service_link_enhanced("tinydns", "K65", "0"); @@ -21,43 +21,54 @@ diff -Nur e-smith-tinydns-2.4.0/createli + service_link_enhanced("dhcp-dns", "K65", "0"); + service_link_enhanced("dhcp-dns", "K65", "1"); + 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-16 20:02:12.050969025 +0100 +diff -Nur e-smith-tinydns-2.4.0.old2388/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.old2388/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-27 20:30:30.481143377 +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-16 20:02:12.050969025 +0100 ++disabled +diff -Nur e-smith-tinydns-2.4.0.old2388/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.old2388/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-27 20:23:29.075882144 +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-17 19:45:33.892642388 +0100 -@@ -0,0 +1,107 @@ +diff -Nur e-smith-tinydns-2.4.0.old2388/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.old2388/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-28 00:28:30.792458726 +0100 +@@ -0,0 +1,128 @@ +{ + use strict; + use warnings; + use esmith::Logger; + use esmith::ConfigDB; ++ use esmith::HostsDB; + # 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"); ++ my $DB = esmith::ConfigDB->open_ro or die ("Unable to open configuration database"); ++ my $hosts = esmith::HostsDB->open_ro or die ("Unable to open Host database"); + -+ #we start a hash for name because we don't want several same names & ip ++ #test if the service is enabled return if not ++ my $dhcpdns = $DB->get_prop('dhcp-dns','status') || 'disabled'; ++ return '' if $dhcpdns ne 'enabled'; ++ ++ #we start a hash for name & ip + my %allocated_name = (); + my %allocated_ip_dhcplease = (); + ++ #start a hash of all hosts ++ my @hosts = $hosts->keys; ++ my %hostsdb; ++ @hostsdb{@hosts} = (); ++ + # copy of dhcpd.leases file to /tmp because working directly on the original + # is not a good idea + 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 ++ #we want to write in log + sub log2messages + { + my $message = shift; @@ -125,9 +136,20 @@ 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" unless ($name eq $servername); -+ log2messages("The hostname of this server ($servername) is already in use with a different IP address in /var/lib/dhcpd/dhcpd.leases") -+ if ($name eq $servername); ++ ++ # verify if dhcp client name is not used in host DB ++ if (! exists $hostsdb{"$name\.$localdomain"}) ++ { ++ $OUT .= "=$name.$localdomain:$ip:$ttl:$endtai\n" unless (($name eq $servername) || ($name !~ /^[a-zA-Z0-9][a-zA-Z0-9-]*$/)); ++ log2messages("The hostname of this server ($servername) is already in use with a different IP address in /var/lib/dhcpd/dhcpd.leases") ++ if ($name eq $servername); ++ log2messages("The hostname of the dhcp client ($name) has illegal characters in /var/lib/dhcpd/dhcpd.leases") ++ if ($name !~ /^[a-zA-Z0-9][a-zA-Z0-9-]*$/); ++ } ++ else ++ { ++ log2messages("The hostname of the dhcp client ($name) is already used in the hosts database"); ++ } + } + + $allocated_ip_dhcplease{$ip} = 1; @@ -141,14 +163,17 @@ diff -Nur e-smith-tinydns-2.4.0/root/etc + 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-17 18:06:32.318810671 +0100 -@@ -0,0 +1,45 @@ +diff -Nur e-smith-tinydns-2.4.0.old2388/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.old2388/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-28 00:24:48.209462754 +0100 +@@ -0,0 +1,49 @@ +#!/usr/bin/perl +use strict; +use warnings; ++use esmith::ConfigDB; ++ ++my $DB = esmith::ConfigDB->open_ro or die ("Unable to open configuration database"); ++my $dhcpdns = $DB->get_prop('dhcp-dns','status') || 'disabled'; + +my $lease_file = "/var/lib/dhcpd/dhcpd.leases"; + @@ -158,7 +183,7 @@ 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 ++#we want to write in log +sub log2messages + { + my $message = shift; @@ -169,7 +194,7 @@ diff -Nur e-smith-tinydns-2.4.0/root/var + +########################################################################### +# Main Loop -+while (1) { ++while ($dhcpdns eq 'enabled') { + + # check the file's last updated time, if it's been changed, update + # the DNS and save the modified time. This will ALWAYS run once - on @@ -191,9 +216,9 @@ diff -Nur e-smith-tinydns-2.4.0/root/var + +} # end main +########################################################################### -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-16 20:02:12.055969339 +0100 +diff -Nur e-smith-tinydns-2.4.0.old2388/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.old2388/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-27 20:23:29.079882477 +0100 @@ -0,0 +1,4 @@ +#!/bin/sh +