This is an updated patch that fix more problems.

dhcpd version detection was assuming that the version number started with a V. 
on centos6, dhcpd V4 has no more "V" in its version. This patch fixes this 
detection method as well. This will work for all passed and future version that 
match \d+(\.\d+)* numbering scheme

ifconfig was called without setting LC_ALL=C thus on FR system as example, inet 
addr is rendered "inet adr" and thus the addr with 2 "d" won't match.

finaly, we do not hang on unconfigured interfaces.



________________________________
De : LAHAYE Olivier
Date d'envoi : mercredi 27 juin 2012 15:18
À : oscar-devel@lists.sourceforge.net
Objet : [Oscar-devel] mkdhcpconf unconfigured interfaces patch


Here is a patch on mkdhcpconf that prevent mkdhcpconf to fail when trying to 
parse and handle an unconfigured network interface.


Index: pkgsrc/systeminstaller-oscar/trunk/bin/mkdhcpconf
===================================================================
--- pkgsrc/systeminstaller-oscar/trunk/bin/mkdhcpconf	(révision 9443)
+++ pkgsrc/systeminstaller-oscar/trunk/bin/mkdhcpconf	(copie de travail)
@@ -163,11 +163,15 @@
 foreach my $int (@INTS) {
 	unless (($int eq "lo") || ($int =~ /:\d+$/) || ($int eq $config->interface)) {
 		my ($ip,$bcast,$mask) = find_internal_ip($int);
-		$mask ||= "255.255.255.0"; # ensure non-null mask
-		my $block = new Net::Netmask ($ip,$mask);
-		my $net = $block->base();
-		print OUTFILE "\n# This entry ignores requests on $int...\n";
-		print OUTFILE "subnet $net netmask $mask {\n\tnot authoritative;\n}\n";
+		if ( $ip =~ /^(?:\s|\t)*$/ ) { # interface not configured ($ip is empty string)
+			print OUTFILE "\n# Interface $int is not configured\n";
+		} else {
+			$mask ||= "255.255.255.0"; # ensure non-null mask
+			my $block = new Net::Netmask ($ip,$mask);
+			my $net = $block->base();
+			print OUTFILE "\n# This entry ignores requests on $int...\n";
+			print OUTFILE "subnet $net netmask $mask {\n\tnot authoritative;\n}\n";
+		}
 	}
 }
 close(OUTFILE);
@@ -204,7 +208,7 @@
 		print OUTFILE "option option-143 \"9000\"; # Also for flamethrower\n";
 	}
 	if ($dhcpdver >= 3) {
-		print OUTFILE "ddns-update-style none; # For dhpcd version 3\n";
+		print OUTFILE "ddns-update-style none; # For dhpcd version 3 and higher\n";
 	}
 	print OUTFILE "\n";
 
@@ -230,7 +234,7 @@
 sub dhcpd_version {
         # Gets the version number of dhcpd.
         my $vstring=`/usr/sbin/dhcpd --version 2>&1`;
-        my ($stuff,$version)=split(/-V/,$vstring);
+	my ($version) = ($vstring =~ /\d+(?:\.\d+)+/g); # handles dhcp-V3.x and dhcp-4.x formats (no V).
         my ($major,$minor)=split(/\./,$version);
         return $major;
 } # dhcpd_version        
@@ -238,7 +242,7 @@
 sub find_internal_ip {
     my $interface = shift;
     # normally I hate sub processes, but for this I make an exception
-    my $string = qx/\/sbin\/ifconfig $interface | grep inet/;
+    my $string = qx/LC_ALL=C \/sbin\/ifconfig $interface | grep inet/;
 
     if($string =~ /addr:([\d\.]+).*cast:([\d\.]+).*ask:([\d\.]+)/) {
         return $1,$2,$3;
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Oscar-devel mailing list
Oscar-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oscar-devel

Reply via email to