pf-tools commit: r803 [ccaillet-guest] - in /branches/next-gen: debian/changelog lib/PFTools/Disk.pm lib/PFTools/Host.pm lib/PFTools/Net.pm lib/PFTools/Parser.pm lib/PFTools/Update.pm lib/PFTools/Utils.pm

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Thu Aug 5 14:37:43 UTC 2010


Author: ccaillet-guest
Date: Thu Aug  5 14:37:26 2010
New Revision: 803

URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=803
Log:
  - rewrite all functions $FUNCTIONS and $DEPENDS
  - adding a wrapper which is exported for other packages instead of
  $FUNCTIONS and $DEPENDS

Modified:
    branches/next-gen/debian/changelog
    branches/next-gen/lib/PFTools/Disk.pm
    branches/next-gen/lib/PFTools/Host.pm
    branches/next-gen/lib/PFTools/Net.pm
    branches/next-gen/lib/PFTools/Parser.pm
    branches/next-gen/lib/PFTools/Update.pm
    branches/next-gen/lib/PFTools/Utils.pm

Modified: branches/next-gen/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/debian/changelog?rev=803&op=diff
==============================================================================
--- branches/next-gen/debian/changelog (original)
+++ branches/next-gen/debian/changelog Thu Aug  5 14:37:26 2010
@@ -49,6 +49,9 @@
   * lib/PFTools/Update.pm
     - using new packages Parser.pm et Logger.pm
     - removing cvs part which are moved to lib/PFTools/VCS.pm
+    - rewrite all functions $FUNCTIONS and $DEPENDS
+    - adding a wrapper which is exported for other packages instead of
+    $FUNCTIONS and $DEPENDS
   * lib/PFTools/Utils.pm
     - new library for handling functions used by scripts, filters, and tools
   * lib/PFTools/VCS.pm
@@ -86,7 +89,7 @@
   useless and deprecated
   * tools/Display_IP_list : rewrite of dumpiplist.pl
 
- -- Christophe Caillet <totof at mithrandir>  Thu, 05 Aug 2010 09:44:10 +0200
+ -- Christophe Caillet <tof at sitadelle.com>  Thu, 05 Aug 2010 16:36:03 +0200
 
 pf-tools (0.34.0-0WIP) unstable; urgency=low
 

Modified: branches/next-gen/lib/PFTools/Disk.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Disk.pm?rev=803&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Disk.pm (original)
+++ branches/next-gen/lib/PFTools/Disk.pm Thu Aug  5 14:37:26 2010
@@ -27,10 +27,25 @@
 our @ISA = ( 'Exporter' ) ;
 
 our @EXPORT = qw(
-	$DEBUG
+	Build_structure_from_fstab
+	Build_fstab_from_structure
 );
 
 our @EXPORT_OK = qw();
+
+use PFTools::Logger;
+
+######################################
+### Constants
+
+my @FSTAB_FIELDS_ORDER = (
+	'source',
+	'dest',
+	'fstype',
+	'options',
+	'dump',
+	'pass'
+);
 
 #
 # Global(s) var(s)
@@ -55,12 +70,12 @@
 if ( $DEBUG ) { $VERBOSE = 1 ; }
 
 # Checking if all commands vars exists
-foreach my $cmd ( $MDADM, $MKFS, $SFDISK, $FDISK, $HALT, $ECHO ) {
-	if ( ! -e $cmd ) {
-		warn "Command ".$cmd." doesn't exist\n" if ( $VERBOSE ) ;
-		exit 1 ;
-	}
-}
+# foreach my $cmd ( $MDADM, $MKFS, $SFDISK, $FDISK, $HALT, $ECHO ) {
+# 	if ( ! -e $cmd ) {
+# 		warn "Command ".$cmd." doesn't exist\n" if ( $VERBOSE ) ;
+# 		exit 1 ;
+# 	}
+# }
 
 ### /proc definitions for different files
 my $PROC_PART		= '/proc/partitions' ;
@@ -87,6 +102,56 @@
 #
 # Misc functions
 #
+
+sub Build_structure_from_fstab ($) {
+	my ( $fstab_file ) = @_;
+	my $struct = {};
+
+	if ( ! open ( FSTAB, $fstab_file ) ) {
+		Warn ( $CODE->{'OPEN'}, "Unable to open /etc/fstab" );
+		return undef;
+	}
+	my @current_fstab = <FSTAB>;
+	close ( FSTAB );
+
+	print join @current_fstab;
+	foreach my $line ( @current_fstab ) {
+		# Skip comments
+		next if ( $line =~ /^#/ );
+		 # Removing trailing spaces
+		$line =~ s/^\s*//;
+		$line =~ s/\s*$//;
+		my ( $src_mnt, $mnt_pt, $type, $opt_mnt, $dump, $pass ) = split ( /\s+/, $line );
+		push ( @{$struct->{'__mnt_order'}}, $mnt_pt );
+		$struct->{$mnt_pt} = {
+			'source'	=> $src_mnt,
+			'dest'		=> $mnt_pt,
+			'fstype'	=> $type,
+			'options'	=> join ( ',', sort split ( ',', $opt_mnt ) ),
+			'dump'		=> $dump,
+			'pass'		=> $pass
+		}
+	}
+	return $struct;
+}
+
+sub Build_fstab_from_structure ($) {
+	my ( $struct ) = @_;
+	my $fstab = [];
+
+	push ( @{$fstab}, "###################################################" );
+	push ( @{$fstab}, "# Fstab generated by Build_fstab_from_structure" );
+	push ( @{$fstab}, "#\n" );
+	foreach my $entry ( @{$struct->{'__mnt_order'}} ) {
+		my @line;
+		foreach my $field ( @FSTAB_FIELDS_ORDER ) {
+			push ( @line, $struct->{$entry}->{$field} );
+		}
+		push ( @{$fstab}, join ( "\t", @line ) );
+	}
+	push ( @{$fstab}, "" );
+	return $fstab
+}
 
 sub Exec_cmd ($;$) {
 	my ( $cmd, $msg ) = @_ ;
@@ -658,4 +723,4 @@
 	}
 }
 
-1;
+1;

Modified: branches/next-gen/lib/PFTools/Host.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Host.pm?rev=803&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Host.pm (original)
+++ branches/next-gen/lib/PFTools/Host.pm Thu Aug  5 14:37:26 2010
@@ -42,11 +42,6 @@
 use PFTools::Logger;
 use PFTools::Net;
 use Data::Dumper;
-
-#########################################################################
-# Prototypes : needed by recursive calls
-
-sub Resolv_hostname_from_GLOBAL ($$;$$);
 
 #########################################################################
 #

Modified: branches/next-gen/lib/PFTools/Net.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Net.pm?rev=803&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Net.pm (original)
+++ branches/next-gen/lib/PFTools/Net.pm Thu Aug  5 14:37:26 2010
@@ -35,6 +35,8 @@
 	Add_zone
 	Get_site_list
 	Get_netblock_from_vlan
+	Resolv_hostname_from_DNS
+	Resolv_hostname_from_GLOBAL
 );
 
 our @EXPORT_OK = qw();
@@ -50,6 +52,11 @@
 use Data::Dumper;
 #$Data::Dumper::Sortkeys = 1;
 #$Data::Dumper::Useperl = 1;
+
+##############################################################
+### Prototypes
+
+sub Resolv_hostname_from_GLOBAL ($$$$$);
 
 #########################################################################
 ### Rewrite with new syntax
@@ -312,4 +319,61 @@
 	}
 }
 
+sub Resolv_hostname_from_GLOBAL ($$$$$) {
+	my ( $hostname, $global_config, $site, $zone, $hosttype ) = @_;
+	my $resolved = [];
+
+	$hostname						=~ /^([^.]+)(\.([^.]+))?$/;
+	my ( $hostshort, $hostvlan )	= ( $1, $3 );
+	my $zone_part 					= $global_config->{'ZONE'}->{'BY_NAME'}->{$zone}->{'BY_SITE'}->{$site};
+	if ( $hostname =~ /^(network|netmask|broadcast|gateway)/ ) {
+		return undef if ( $hostvlan && ! defined $zone_part->{$hostvlan} );
+		my ( $type, $field ) = split ( /\s+/, $zone_part->{$hostvlan}->{$hostshort} );
+		push ( @{$resolved}, $field );
+	}
+	else {
+		foreach my $entry ( keys %{$zone_part->{$hosttype}} ) {
+			next if ( $entry !~ /^$hostname$/ );
+			my @fields;
+			if ( ref ( $zone_part->{$hosttype}->{$entry} ) eq 'ARRAY' ) {
+				@fields = @{$zone_part->{$hosttype}->{$entry}}
+			}
+			else {
+				@fields = ( $zone_part->{$hosttype}->{$entry} );
+			}
+			foreach my $line ( @fields ) {
+				my ( $type, $field ) = split ( /\s+/, $line );
+				if ( $type eq 'A' ) {
+					push ( @{$resolved}, $field );
+				}
+				elsif ( $type eq 'CNAME' ) {
+					my $cname_resolved = Resolv_hostname_from_GLOBAL ( $field, $global_config, $site, $zone, $hosttype );
+					push ( @{$resolved}, @{$cname_resolved} );
+				}
+			}
+		}
+	}
+	return $resolved;
+}
+
+sub Resolv_hostname_from_DNS ($) {
+	my ( $hostname ) = @_;
+	my $resolved = [];
+
+	my $res   = Net::DNS::Resolver->new;
+	my $query = $res->search( $hostname );
+
+	if ($query) {
+		foreach my $rr ( $query->answer ) {
+			next unless $rr->type eq "A";
+			push ( @{$resolved}, $rr->address );
+		}
+	} else {
+		Warn ( $CODE->{'BIND_QUERY'},
+			"Query failed: ".$res->errorstring );
+		return undef;
+	}
+	return $resolved;
+}
+
 1;

Modified: branches/next-gen/lib/PFTools/Parser.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Parser.pm?rev=803&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Parser.pm (original)
+++ branches/next-gen/lib/PFTools/Parser.pm Thu Aug  5 14:37:26 2010
@@ -87,6 +87,8 @@
     }
     return ($str);
 }
+
+my $PFTOOLS_VARS = {};
 
 sub Parser_pftools ($$) {
     my ( $fic_conf, $substdestvars ) = @_;

Modified: branches/next-gen/lib/PFTools/Update.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Update.pm?rev=803&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Update.pm (original)
+++ branches/next-gen/lib/PFTools/Update.pm Thu Aug  5 14:37:26 2010
@@ -43,6 +43,8 @@
 use File::Copy;
 use PFTools::Logger;
 use PFTools::Parser;
+use PFTools::Net;
+use PFTools::Host;
 use PFTools::Packages;
 
 use Fcntl ':mode';
@@ -102,8 +104,8 @@
 	}
 	my ( $dev, $ino, $mode, $nlink, $uid, $gid, @others ) = stat($dest);
 	if ( $type eq 'chown' ) {
-		my $newuid = getpwnam ($owner);
-		my $newgid = getgrnam ($group);
+		my $newuid = getpwnam ($right1);
+		my $newgid = getgrnam ($right2);
 		if (
 			( defined($uid) && $uid == $newuid )
 			&& ( defined($gid) && $gid == $newgid )
@@ -113,13 +115,10 @@
 		return ! chown ( $newuid, $newgid, $dest );
 	}
 	elsif ( $type eq 'chmod' ) {
-		if ( defined($mode) && ( $mode & 07777 ) == $newmode ) {
+		if ( defined($mode) && ( $mode & 07777 ) == $right1 ) {
 			return 0;
 		}
-		return ! chmod ( $newmode, $dest );
-	}
-	else {
-		return 1
+		return ! chmod ( $right1, $dest );
 	}
 } 
 
@@ -161,8 +160,9 @@
 sub Do_moveold ($$) {
     my ( $dest, $options ) = @_;
 
+	my $pf_config = Init_PF_CONFIG ();
 	if ( -e $dest ) {
-		my $old = $CVS_OLD_DIR . "/" . $dest . "." . $STARTTIME;
+		my $old = $pf_config->{'path'}->{'checkout_dir'} . "/old/" . $dest . "." . $STARTTIME;
 		if ( $options->{'verbose'} ) {
 			Log( "(moving old to " . $old . ")" );
 		}
@@ -176,8 +176,8 @@
 sub Do_chownmod ($$$) {
 	my ( $ref_section, $dest, $options ) = @_;
 
-	$owner = defined( $ref_section->{'owner'} ) ? $ref_section->{'owner'} : $DEFAULT_OWNER;
-	$group = defined( $ref_section->{'group'} ) ? $ref_section->{'group'} : $DEFAULT_GROUP;
+	my $owner = defined( $ref_section->{'owner'} ) ? $ref_section->{'owner'} : $DEFAULT_OWNER;
+	my $group = defined( $ref_section->{'group'} ) ? $ref_section->{'group'} : $DEFAULT_GROUP;
 
 	if ( fullchown( $owner, $group, $dest, $options ) ) {
 		Warn( $CODE->{'OPEN'},
@@ -186,7 +186,7 @@
 		return 1;
 	}
 
-	$mode = defined( $ref_section->{'mode'} )
+	my $mode = defined( $ref_section->{'mode'} )
 		? $ref_section->{'mode'}
 		: ( ( -d $dest ) ? $DEFAULT_DIRMODE : $DEFAULT_MODE );
 	$mode =~ s/^[^0]/0$&/;
@@ -242,8 +242,8 @@
     }
 }
 
-sub Do_on_noaction {
-	my ( $ref_section, $options ) = @_;
+sub Do_on_noaction ($$$) {
+	my ( $ref_section, $options, $hash_subst ) = @_;
 
 	if ( ! $options->{'simul'}
 		&& defined ( $ref_section->{'on_noaction'} )
@@ -269,6 +269,7 @@
 	my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
 	my ( $source, $tmp, $cmp );
 
+	my $diff = 0;
 	$hash_subst->{'SECTIONNAME'} = $dest;
 	if ( $ref_section->{'source'} =~ /\s/ ) {
 		$source = Get_tmp_dest ($dest).".merged";
@@ -288,7 +289,7 @@
 		}
 	}
 	else {
-		$source = Get_source( Subst_vars( $ref_section->{'source'} ), $hash_subst );
+		$source = Get_source( Subst_vars( $ref_section->{'source'}, $hash_subst ), $hash_subst );
 	}
 
 	$hash_subst->{'SOURCE'}			= $source;
@@ -368,7 +369,7 @@
 		$dest = $newdest;
 	}
 
-	my $status = Get_pkg_status ( $pkg_type, $dest ) ;
+	my $status = Get_pkg_status ( $options->{'pkg_type'}, $dest ) ;
 	if ( ! defined $status ) {
 		Warn ( $CODE->{'OPEN'}, "Unable to retrieve status for package ".$dest ) ;
 		return 1;
@@ -381,7 +382,7 @@
 		Do_on_config( $ref_section, $options, $hash_subst ) && return 1;
 		Do_before_change( $ref_section, $options, $hash_subst ) && return 1;
 		if ( !$options->{'simul'} ) {
-			if ( ! Purge_pkg ( $pkg_type, $dest ) ) {
+			if ( ! Purge_pkg ( $options->{'pkg_type'}, $dest ) ) {
 				Warn ( $CODE->{'OPEN'}, "An error occured during purge for package ".$dest ) ;
 				return 1 ;
 			}
@@ -408,10 +409,10 @@
     my ( $ref_section, $dest, $options ) = @_;
 
     $options->{'pkg_type'} = 'deb' if ( ! defined $options->{'pkg_type'} ) ;
-    if ( aptupdate( $pkg_type ) ) {
+    if ( aptupdate( $options->{'pkg_type'} ) ) {
 		return 1;
 	}
-	my $deps = Get_pkg_depends ( $pkg_type, $dest ) ;
+	my $deps = Get_pkg_depends ( $options->{'pkg_type'}, $dest ) ;
 	if ( ! defined $deps ) {
 		Warn ( $CODE->{'OPEN'}, "Unable to get depends for package ".$dest ) ;
 		return 1;
@@ -421,7 +422,7 @@
 	}
 };
 
-$FUNCTIONS{'apt-get'} = sub ($$$$$) {
+$FUNCTIONS{'apt-get'} = sub ($$$$) {
     my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
 
     $options->{'pkg_type'} = 'deb' if ( ! defined $options->{'pkg_type'} ) ;
@@ -444,8 +445,8 @@
 		}
 		$dest = $newdest;
 	}
-	aptupdate( $pkg_type );
-	( $installed_version, $available_version, $specified_version ) = Get_pkg_policy ( $pkg_type, $dest, $ref_section->{'version'} ) ;
+	aptupdate( $options->{'pkg_type'} );
+	( $installed_version, $available_version, $specified_version ) = Get_pkg_policy ( $options->{'pkg_type'}, $dest, $ref_section->{'version'} ) ;
 	if ( ! defined ( $available_version ) ) {
 		Warn( $CODE->{'OPEN'}, "Package ".$dest." is unavailable" );
 		return 1;
@@ -455,7 +456,7 @@
 		return 1;
 	}
 	if ( defined $installed_version ) {
-		my $compare = Cmp_pkg_version ( $pkg_type, $dest, $installed_version, $available_version ) ;
+		my $compare = Cmp_pkg_version ( $options->{'pkg_type'}, $dest, $installed_version, $available_version ) ;
 		$install++ if ( defined $compare && $compare < 0 );
 	}
 
@@ -471,27 +472,39 @@
 			);
 		}
 		if ( defined( $ref_section->{'delay'} ) && ! $options->{'noaction'} ) {
-			$HOSTNAME =~ /\d+$/;
+			$hash_subst->{'HOSTNAME'} =~ /\d+$/;
 			if ( $& ne "" ) {
 				sleep( 120 * $& );
 			}
 		}
-		if ( !$options->{'simul'} && defined( $ref_section->{'debconf'} ) ) {
-			my $DEB;
-			my $conf;
-			my $pkg;
-			Debconf::Db->load;
-			foreach $conf ( keys %{ $ref_section->{'debconf'} } ) {
-				($pkg) = split( m:/:, $conf );
-				if ( !$DEB->{$pkg} ) {
-					$DEB->{$pkg} = 1;
-					Debconf::Template->load( $TEMPLATES . "/" . $pkg, $pkg );
+		if ( ! $options->{'simul'} ) {
+			my $debconf = 0;
+			my $debconf_vars = {};
+			foreach my $key ( keys %{$ref_section} ) {
+				next if ( $key !~ /^debconf/ );
+				$debconf = 1;
+				$key =~ /^debconf\.(.*)$/;
+				$debconf_vars->{$1} = $ref_section->{$key};
+			}
+			if ( $debconf ) {
+				my $DEB;
+				my $conf;
+				my $pkg;
+				my $pf_config	= Init_PF_CONFIG ();
+				my $vcs_tpl_dir	= $pf_config->{'path'}->{'checkout_dir'}.'/TEMPLATES';
+				Debconf::Db->load;
+				foreach $conf ( keys %{ $ref_section->{'debconf'} } ) {
+					($pkg) = split( m:/:, $conf );
+					if ( !$DEB->{$pkg} ) {
+						$DEB->{$pkg} = 1;
+						Debconf::Template->load( $vcs_tpl_dir."/".$pkg, $pkg );
+					}
+					Debconf::ConfModule->command_set( $conf,
+					$ref_section->{'debconf'}->{$conf} );
+					Debconf::ConfModule->command_fset( $conf, "seen", "true" );
 				}
-				Debconf::ConfModule->command_set( $conf,
-				$ref_section->{'debconf'}->{$conf} );
-				Debconf::ConfModule->command_fset( $conf, "seen", "true" );
-			}
-			Debconf::Db->save;
+				Debconf::Db->save;
+			}
 		}
 		Do_on_config( $ref_section, $options, $hash_subst ) && return 1;
 		Do_before_change( $ref_section, $options, $hash_subst ) && return 1;
@@ -503,7 +516,7 @@
 			$install = '';
 		}
 		if ( !$options->{'simul'} ) {
-			if ( ! Install_pkg ( $pkg_type, $dest, $ref_section->{'version'} ) ) {
+			if ( ! Install_pkg ( $options->{'pkg_type'}, $dest, $ref_section->{'version'} ) ) {
 				Warn( $CODE->{'OPEN'}, "Unable to install ".$dest ) ;
 				return 1;
 			}
@@ -526,9 +539,35 @@
 sub __Get_ip_host_from_GLOBAL ($$) {
 	my ( $host, $global_config ) = @_;
 
-	my $ip = $host;
+	my $ip							= $host;
+	my $zone						= Get_zone_from_hostname ( $host, $global_config );
+	if ( ! defined $zone ) {
+		Warn ( "Unable to retrieve zone for hostname ".$host );
+		return undef;
+	}
+	$ip								=~ s/\.$zone$//;
+	$host							=~ /^([^.]+)(\.([^.]+))?$/;
+	my ( $hostshort, $hostvlan )	= ( $1, $3 );
+	my $hosttype					= Get_hosttype_from_hostname ( $hostshort, $global_config );
+	if ( ! defined $hosttype ) {
+		Warn ( "Unable to retrieve hosttype for hostname ".$host );
+		return undef;
+	}
+	my $site_list					= Get_site_from_hostname ( $hostshort, $global_config );
+	my $site;
+	if ( ! defined $site_list ) {
+		Warn ( $CODE->{'UNDEF_KEY'}, "Unable to retrieve site for hostname ".$host );
+		return undef;
+	}
+	elsif ( scalar @{$site_list} > 1 ) {
+		Warn ( $CODE->{'UNDEF_KEY'}, "Multiple site for hostname ".$host );
+		return undef;
+	}
+	else {
+		$site = shift @{$site_list};
+	}
 	if ( ! isipaddr ( $host ) ) {
-		my $resolved = Resolv_hostname_from_GLOBAL ( $host, $global_config );
+		my $resolved = Resolv_hostname_from_GLOBAL ( $host, $global_config, $zone, $site, $hosttype );
 		if ( ! defined $resolved ) {
 			Warn ( $CODE->{'RESOLV'}, "Unknown host ".$host );
 			return undef;
@@ -544,793 +583,439 @@
 	return $ip
 }
 
+sub __Resolve_fstab_entry ($) {
+	my ( $param ) = @_;
+
+	my $pf_config	= Init_PF_CONFIG ();
+	my $fs_entry	= $param->{'fs_entry'}; 
+	if ( $fs_entry->{'fstype'} =~ /^$pf_config->{'regex'}->{'network_fstype'}$/ ) {
+		foreach my $key ( 'source', 'options' ) {
+			my $value = ( $key eq 'options' )
+				? $fs_entry->{$key} || $DEFAULT_OPTIONS
+				: $fs_entry->{$key};
+			my $val_addr = $value;
+			$val_addr =~ ( $key eq 'options' )
+				? s/^(.*,)?ip=([^,]+)(,.*)?$/$2/
+				: s/^([^:]+):(.+)$/$1/;
+			my $val_ip	= __Get_ip_host_from_GLOBAL ( $val_addr, $param->{'global_config'} ) if ( $val_addr );
+			return 1 if ( ! defined $val_ip );
+			$value =~ ( $key eq 'options' )
+				? s/^(.*,)?ip=([^,]+)(,.*)?$/$1ip=$val_ip$3/
+				: s/^([^:]+):(.+)$/$val_ip:$2/;
+			$fs_entry->{$key}	= $value;
+		}
+	}
+	return 0;
+}
+
+sub __Build_fstab_entry_from_config {
+	my ( $param ) = @_;
+	
+	my $fs_entry = $param->{'ref_section'};
+	$fs_entry->{'dest'}		= $param->{'dest'};
+	foreach my $key ( 'source', 'options' ) {
+		$fs_entry->{$key}	= Subst_vars ( $fs_entry->{$key}, $param->{'subst'} );
+	}
+	my $resolve_param = {
+		'fs_entry'		=> $fs_entry,
+		'global_config'	=> $param->{'global_config'}
+	};
+	if ( __Resolve_fstab_entry ( $resolve_param ) ) {
+		return undef;
+	};
+	return $fs_entry;
+}
+
 $FUNCTIONS{'addmount'} = sub ($$$$$) {
 	my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
 
-	$hash->{'SECTIONNAME'} = $dest;
+	$hash_subst->{'SECTIONNAME'} = $dest;
 	# Source
-	my $source		= Subst_vars( $ref_section->{'source'}, $hash_subst );
-    my $src_addr	= $source;
-	# Checking for network file system
-    $src_addr		=~ s/^([^:]+):(.+)$/$1/;    # NFS
-    if ( defined ( $sourceaddr ) ) {
-		my $src_ip = __Get_ip_host_from_GLOBAL ( $src_addr, $global_config );
-		return 1 if ( ! defined $src_ip );
-		$source =~ s/^([^:]+):(.+)$/$src_ip:$2/;
-	}
-    $hash_subst->{'SOURCE'} = $source;
-	# Mount option(s)
-    my $mnt_opts = $ref_section->{'options'} || $DEFAULT_OPTIONS;
-	$mnt_opts =~ /^(.*,)?ip=([^,]+)(,.*)?$/;
-	my $opts_addr = $2;
-	my $opts_ip = __Get_ip_host_from_GLOBAL ( $opts_addr, $global_config ) if ( $opts_addr );
-	return 1 if ( ! defined $opts_ip );
-	$mnt_opts =~ s/^(.*,)?ip=([^,]+)(,.*)?$/$opts_ip/;
-	$hash_subst->{'OPTIONS'}	= join ( ',', sort split ( ',', $mount_opts ) );
-	# FS type
-	$fstype 					= $ref_section->{'fstype'} || $DEFAULT_FSTYPE;
-	$hash_subst->{'FSTYPE'}		= $fstype;
-
-	if ( ! open( FSTAB, "< /etc/fstab" ) ) {
-		Warn ( $CODE->{'OPEN'}, "Unable to open /etc/fstab" );
+	my $add_mount	= __Build_fstab_entry_from_config (
+		{
+			'dest'			=> $dest,
+			'global_config'	=> $global_config,
+			'ref_section'	=> $ref_section
+		}
+	);
+	return 1 if ( ! defined $add_mount );
+	$hash_subst->{'SOURCE'}		= $add_mount->{'source'};
+	$hash_subst->{'OPTIONS'}	= join ( ',', sort split ( ',', $add_mount->{'options'} ) );
+	$hash_subst->{'FSTYPE'}		= $ref_section->{'fstype'} || $DEFAULT_FSTYPE;
+
+	my $current_fstab = Build_structure_from_fstab ( "/etc/fstab" );
+	if ( ! defined $current_fstab ) {
+		Warn ( $CODE->{'UNDEF_KEY'}, "Unable to build fstab structure from file /etc/fstab" );
+		return undef;
+	}
+	my $current_proc = Build_structure_from_fstab ( "/proc/mounts" );
+	if ( ! defined $current_fstab ) {
+		Warn ( $CODE->{'UNDEF_KEY'}, "Unable to build fstab structure from file /etc/fstab" );
+		return undef;
+	}
+	my $addfstab = 0;
+	if ( ! defined $current_fstab->{$dest} ) {
+		$current_fstab->{$dest} = $add_mount;
+		$addfstab = 1;
+	}
+	else {
+		foreach my $key ( 'source', 'dest', 'fstype', 'options' ) {
+			$addfstab = 1 if ( $add_mount->{$key} ne $current_fstab->{$dest}->{$key} );
+		}
+	}
+	
+	my $addproc = 0;
+	if ( ! defined $current_proc->{$dest} ) {
+		$addproc = 1;
+	}
+	else {
+		my $fs_proc = $current_proc->{$dest};
+		foreach my $key ( 'source', 'dest', 'fstype', 'options' ) {
+			if ( $key eq 'options' ) {
+				$addproc = 1 if ( $add_mount->{$key} ne $current_fstab->{$dest}->{$key} );
+			}
+			else {
+				$addproc = 1 if ( $add_mount->{$key} ne $current_proc->{$dest}->{$key} );
+			}
+		}
+	}
+
+	if ( $addfstab || $addproc || ! -d $dest ) {
+		if ( $options->{'verbose'} || $options->{'simul'} ) {
+			Log("(action needed)");
+		}
+		Do_on_config( $ref_section, $options, $hash_subst ) && return 1;
+		Do_before_change( $ref_section, $options, $hash_subst ) && return 1;
+		if ( ! -d $dest && $dest ne 'none' ) {
+			if ( ! defined ( $FUNCTIONS{'mkdir'} ) ) {
+				Warn( $CODE->{'OPEN'}, "Function mkdir is needed by addmount" );
+				return 1;
+			}
+			$FUNCTIONS{'mkdir'}->( $ref_section, $dest, $options, $hash_subst );
+		}
+		if ( $addfstab ) {
+			my $tmp = Get_tmp_dest("/etc/fstab");
+			unless ( open ( NEWFSTAB, ">".$tmp ) ) {
+				Warn( $CODE->{'OPEN'}, "Impossible de creer " . $tmp );
+				return 1;
+			}
+			$current_fstab->{$dest} = $add_mount;
+			my $new_fstab = Build_fstab_from_structure ( $current_fstab );
+			print NEWFSTAB join ( "", @{$new_fstab} );
+			close ( NEWFSTAB );
+			if ( $options->{'diff'} ) {
+				deferredlogsystem( "diff -uN '/etc/fstab' '" . $tmp . "'" );
+			}
+			if ( ! $options->{'simul'} ) {
+				if ( ! move ( $tmp, "/etc/fstab" ) ) {
+					Warn( $CODE->{'OPEN'}, "Unable to move new fstab ".$tmp." to /etc/fstab" ); 
+					return 1;
+				}
+			}
+		}
+		if ( $addproc ) {
+			if ( $options->{'diff'} ) {
+				foreach my $key ( 'source', 'dest', 'fstype', 'options' ) {
+					my $value = $current_proc->{$dest}->{$key} || '?';
+					if ( $key eq 'options' ) {
+						Log ( $key." ".$value." -> ".$add_mount->{$key} ) if ( $current_fstab->{$dest}->{$key} ne $add_mount->{$key} );
+					}
+					else {
+						Log ( $key." ".$value." -> ".$add_mount->{$key} ) if ( $value ne $add_mount->{$key} );
+					}
+				}
+			}
+			if ( ! $options->{'simul'} && ! $options->{'noaction'} ) {
+				# Unmounting fs
+				my $remount = 1;
+				foreach my $key ( 'source', 'dest', 'fstype' ) {
+					$remount = 0 if ( $add_mount->{$key} ne $current_proc->{$dest}->{$key} );
+				}
+				if ( $remount ) {
+					my $cmd = "mount -o 'remount,".$add_mount->{'options'}."' '".$dest."'";
+					if ( deferredlogsystem( $cmd ) ) {
+						Warn( $CODE->{'OPEN'},
+							"Unable to remount ".$dest." with options ".$add_mount->{'options'} ); 
+						return 1;
+					}
+				}
+				else {
+					my $umount = ( $add_mount->{'source'} ne $current_proc->{$dest}->{'source'} )
+						? $current_proc->{$dest}->{'source'}
+						: $add_mount->{'source'};
+					if ( deferredlogsystem( "umount '".$umount."'" ) ) {
+						Warn ( $CODE->{'OPEN'}, "Unable to unmount ".$umount );
+						return 1;
+					}
+					my $mount_cmd = "mount -t '".$add_mount->{'fstype'}."' - o '".$add_mount->{'options'}."' '"
+						.$add_mount->{'source'}."' '".$add_mount->{'dest'}."'";
+					if ( deferredlogsystem ( $mount_cmd ) ) {
+						Warn ( $CODE->{'EXEC'}, "Unable to mount ".$dest." with command ".$mount_cmd );
+						return 1;
+					}
+				}
+			}
+		}
+		Do_after_change( $ref_section, $options, $hash_subst ) && return 1;
+		Do_on_noaction( $ref_section, $options, $hash_subst ) && return 1;
+    }
+    return 0;
+};
+
+$FUNCTIONS{'ignore'} = sub ($$$$$) {
+	my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
+
+	return 0;
+};
+
+$DEPENDS{'addlink'} = sub ($$$) {
+	my ( $ref_section, $dest, $options ) = @_;
+
+	while ( $dest ne "/" && $dest ne "." ) {
+		$ref_section->{'depends'} .= " " . dirname($dest);
+		$dest = dirname($dest);
+	}
+};
+
+$FUNCTIONS{'addlink'} = sub ($$$$$) {
+	my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
+
+	$hash_subst->{'SECTIONNAME'} = $dest;
+	my $source = Subst_vars( $ref_section->{'source'}, $hash_subst );
+	while ( $source ne "/" && $source ne "." ) {
+		$ref_section->{'depends'} .= " " . dirname($source);
+		$source = dirname($source);
+	}
+	if ( ! -l $dest || ( -l $dest && readlink($dest) ne $source ) ) {
+		if ( $options->{'verbose'} || $options->{'simul'} ) {
+			Log("(action needed)");
+		}
+		if ( $options->{'diff'} ) {
+			if ( -l $dest ) {
+				Log( "( readlink = " . readlink($dest) . ")" );
+			}
+			else {
+				Log( "( !-l " . $dest . ")" );
+			}
+		}
+		Do_on_config( $ref_section, $options, $hash_subst ) && return 1;
+		Do_before_change( $ref_section, $options, $hash_subst ) && return 1;
+		if ( ! $options->{'simul'} ) {
+			Do_moveold( $dest, $options );
+			if ( Mk_dest_dir ( $dest ) || ln_sfn( $source, $dest ) ) {
+				Warn( $CODE->{'OPEN'},
+					"Impossible de lier " . $dest . " a " . $source );
+				return 1;
+			}
+		}
+		Do_after_change( $ref_section, $options, $hash_subst ) && return 1;
+		Do_on_noaction( $ref_section, $options, $hash_subst ) && return 1;
+	}
+	return 0;
+};
+
+$DEPENDS{'createfile'} = sub ($$$) {
+	my ( $ref_section, $dest, $options ) = @_;
+
+	while ( $dest ne "/" && $dest ne "." ) {
+		$ref_section->{'depends'} .= " " . dirname($dest);
+		$dest = dirname($dest);
+	}
+};
+
+$FUNCTIONS{'createfile'} = sub ($$$$$) {
+	my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
+
+    my $cmp = 0;
+    $hash_subst->{'SECTIONNAME'} = $dest;
+    if ( ! defined $ref_section->{'source'} ) {
+		if ( ! -f $dest ) {
+			$cmp = 1;
+			if ( $options->{'verbose'} || $options->{'simul'} ) {
+				Log("(action needed)");
+			}
+			Do_on_config( $ref_section, $options, $hash_subst ) && return 1;
+			Do_before_change( $ref_section, $options, $hash_subst ) && return 1;
+			if ( ! $options->{'simul'} ) {
+				if ( deferredlogsystem ( "/usr/bin/touch '" . $dest . "'" ) ) {
+					Warn( $CODE->{'OPEN'}, "Unable to create empty file ".$dest );
+					return 1;
+				}
+			}
+		}
+    }
+    else {
+		my $source = Get_source( Subst_vars( $ref_section->{'source'}, $hash_subst ) );
+		$hash_subst->{'SOURCE'} = $source;
+		my $tmp = Get_tmp_dest ( $dest );
+		$hash_subst->{'DESTINATION'} = $tmp;
+		if ( ! -f $source ) {
+			Warn( $CODE->{'OPEN'}, "Unable to open source ".$source );
+			return 1;
+		}
+		if ( defined( $ref_section->{'filter'} ) ) {
+			my $filter = Subst_vars ( $ref_section->{'filter'}, $hash_subst );
+			if ( deferredlogsystem ( $filter ) ) {
+				Warn( $CODE->{'OPEN'}, "Unable to apply filter ".$filter );
+				return 1;
+			}
+		}
+		else {
+			if ( ! copy ( $source, $tmp ) ) {
+				Warn( $CODE->{'OPEN'},
+					"Unable to copy ".$source." to ".$tmp );
+				return 1;
+			}
+		}
+		if ( ! -f $tmp ) {
+			Warn( $CODE->{'OPEN'}, "Unable top open file ".$tmp );
+			return 1;
+		}
+		if ( !-f $dest ) {
+			$cmp = 1;
+			if ( $options->{'verbose'} || $options->{'simul'} ) {
+				Log("(action needed)");
+			}
+			Do_on_config( $ref_section, $options, $hash_subst ) && return 1;
+			Do_before_change( $ref_section, $options, $hash_subst ) && return 1;
+			if ( !$options->{'simul'} ) {
+				if ( ! copy ( $source, $dest ) ) {
+					Warn( $CODE->{'OPEN'},
+						"Unable to create file ".$dest." from source ".$source );
+						return 1;
+				}
+			}
+		}
+	}
+	Do_chownmod ( $ref_section, $dest, $options );
+	if ( $cmp ) {
+		Do_after_change( $ref_section, $options, $hash_subst ) && return 1;
+		Do_on_noaction( $ref_section, $options, $hash_subst ) && return 1;
+	}
+	return 0;
+};
+
+$DEPENDS{'mkdir'} = sub ($$$) {
+	my ( $ref_section, $dest, $options ) = @_;
+
+	while ( $dest ne "/" && $dest ne "." ) {
+		$ref_section->{'depends'} .= " " . dirname($dest);
+		$dest = dirname($dest);
+	}
+};
+
+$FUNCTIONS{'mkdir'} = sub ($$$$$) {
+	my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
+
+	my $cmp = 0;
+
+	$hash_subst->{'SECTIONNAME'} = $dest;
+    if ( ! -d $dest ) {
+		$cmp = 1;
+		if ( $options->{'verbose'} || $options->{'simul'} ) {
+			Log("(action needed)");
+		}
+		Do_on_config( $ref_section, $options, $hash_subst ) && return 1;
+		Do_before_change( $ref_section, $options, $hash_subst ) && return 1;
+		if ( !$options->{'simul'} ) {
+			Do_moveold( $dest, $options );
+			if ( deferredlogsystem( "/bin/mkdir -p '" . $dest . "'" ) ) {
+				Warn( $CODE->{'OPEN'},
+					"Unable to create directory ".$dest );
+				return 1;
+			}
+		}
+	}
+	Do_chownmod( $ref_section, $dest, $options );
+	if ( $cmp ) {
+		Do_after_change( $ref_section, $options, $hash_subst ) && return 1;
+		Do_on_noaction( $ref_section, $options, $hash_subst ) && return 1;
+	}
+	return 0;
+};
+
+$FUNCTIONS{'removefile'} = sub ($$$$$) {
+	my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
+
+	my $cmp = 0;
+	if ( ! -f $dest ) {
+		Warn( $CODE->{'OPEN'},
+			"Destination ".$dest. " MUST BE a file" );
 		return 1;
 	}
-	my @current_fstab = <FSTAB>;
-	close ( FSTAB );
-
-
-    while (<FSTAB>) {
-		next if ( /^#/ );
-		s/^\s*//; s/\s*$//; # Removing trailing spaces
-		# <file system> <mount point>   <type>  <options>       <dump>  <pass>
-		my ( $fs, $mnt_pt, $type, $opt_mnt, $dump, $pass ) = split ( /\s+/, $_)
-		$fs =~ /^([^:]+):(.+)$/; my $fs_addr = $1;
-		if ( defined $fs_addr && ! isipaddr ( $fs_addr ) ) {
-			my $resolv_fs = Resolv_hostname_from_GLOBAL ( $fs_addr, $global_config ) if ( $fs_addr && ! isipaddr( $fs_addr) );
-			if ( ! defined $resolv_fs ) {
-				Warn ( $CODE->{'RESOLV'}, "Unknown host ".$fs_addr );
-				return 1;
-			}
-			elsif ( scalar @{$resolv_fs} > 1 ) {
-				Warn ( $CODE->{'RESOLV'}, "Multiple response for ".$fs_addr." : unable to choose the right one" );
-				return 1;
-			}
-			else {
-				my $opts_ip = shift @{$resolv_opts};
-				$mount_opts =~ s/^(.*,)?ip=([^,]+)(,.*)?$/$opts_ip/;
-			}
-		}
-	if (
-		m/^[ 	]*([^ 	]+)[ 	]+([^ 	]+)[ 	]+([^ 	]+)[ 	]+([^ 	]+)[ 	]+([^ 	]+)[ 	]+([^ 	]+)/
-	) {
-		
-		my $resolved1 = $1;
-		{
-			my $oldsourceaddr = $1;
-			$oldsourceaddr =~ s/^([^:]+):(.+)$/$1/;    # NFS
-			if ( defined($oldsourceaddr) && !isipaddr($oldsourceaddr) ) {
-				if ( !defined($Z) ) {
-				$Z = Init_lib_net(
-					Get_source("GLOBAL:private-network") );
-				}
-				my $oldsourceip = Resolv( $oldsourceaddr, $Z );
-				if ( defined($oldsourceip) && $oldsourceip ne "" ) {
-				$resolved1 =~ s/^([^:]+):(.+)$/$oldsourceip:$2/;
-				}
-			}
-		}
-
-	    my $resolved4 = $4;
-	    {
-		my $oldoptsaddr = $4;
-		$oldoptsaddr =~ s/^(.*,)?ip=([^,]+)(,.*)?$/$2/;
-		if ( defined($oldoptsaddr) && !isipaddr($oldoptsaddr) ) {
-		    if ( !defined($Z) ) {
-			$Z = Init_lib_net(
-			    Get_source("GLOBAL:private-network") );
-		    }
-		    my $oldoptsip = Resolv( $oldoptsaddr, $Z );
-		    if ( defined($oldoptsip) && $oldoptsip ne "" ) {
-			$resolved4
-			    =~ s/^(.*,)?ip=([^,]+)(,.*)?$/$1ip=$oldoptsip$3/;
-		    }
-		}
-	    }
-
-	    if ( $1 eq $source && $source ne "none" ) {
-		$olddest = $2;
-	    }
-	    if ( $2 eq $dest ) {
-		$oldsource = $1;
-	    }
-
-	    if ( $resolved1 eq $source && $2 eq $dest ) {
-		$oldfstype       = $3;
-		$oldopts         = $4;
-		$oldopts         = join( ',', sort split( ',', $oldopts ) );
-		$oldresolvedopts = $resolved4;
-		$oldresolvedopts
-		    = join( ',', sort split( ',', $oldresolvedopts ) );
-	    }
-	}
-    }
-    close(FSTAB);
-
-    $addmountfstab = 1;
-    if (   defined($oldsource)
-	&& $oldsource eq $source
-	&& defined($olddest)
-	&& $olddest eq $dest
-	&& defined($oldfstype)
-	&& $oldfstype eq $fstype
-	&& defined($oldopts)
-	&& $oldopts eq $sortedopts
-	&& defined($oldresolvedopts)
-	&& $oldresolvedopts eq $sortedopts )
-    {
-	$addmountfstab = 0;
-    }
-
-    if ( !$options->{'noaction'} ) {
-	if ( !open( MOUNTS, "< /proc/mounts" ) ) {
-	    Warn( $CODE->{'OPEN'}, "Impossible de lire /proc/mounts" );
-	}
-	else {
-	    while (<MOUNTS>) {
-		if (m/^([^ 	]+)[ 	]+([^ 	]+)[ 	]+([^ 	]+)[ 	]+([^ 	]+)[ 	]+([^ 	]+)[ 	]+([^ 	]+)/
-		    )
-		{
-		    my $resolved1 = $1;
-		    {
-			my $oldmsourceaddr = $1;
-			$oldmsourceaddr =~ s/^([^:]+):(.+)$/$1/;    # NFS
-			if ( defined($oldmsourceaddr)
-			    && !isipaddr($oldmsourceaddr) )
-			{
-			    if ( !defined($Z) ) {
-				$Z = Init_lib_net(
-				    Get_source("GLOBAL:private-network") );
-			    }
-			    my $oldmsourceip = Resolv( $oldmsourceaddr, $Z );
-			    if ( defined($oldmsourceip)
-				&& $oldmsourceip ne "" )
-			    {
-				$resolved1
-				    =~ s/^([^:]+):(.+)$/$oldmsourceip:$2/;
-			    }
-			}
-		    }
-
-		    if ( $resolved1 eq $source && $source ne "none" ) {
-			$oldmdest = $2;
-		    }
-		    if ( $2 eq $dest ) {
-			$oldmsource         = $1;
-			$oldmresolvedsource = $resolved1;
-		    }
-
-		    if ( $resolved1 eq $source && $2 eq $dest ) {
-			$oldmfstype = $3;
-			$oldmopts   = $4;
-			$oldmopts = join( ',', sort split( ',', $oldmopts ) );
-		    }
-		}
-	    }
-	    close(MOUNTS);
-
-	    #todo, parsing options, utilisation de celles de fstab
-	    $addmountmounts = 1;
-	    if (   defined($oldmresolvedsource)
-		&& $oldmresolvedsource eq $source
-		&& defined($oldmdest)
-		&& $oldmdest eq $dest
-		&& defined($oldmfstype)
-		&& $oldmfstype eq $fstype
-		&& defined($oldresolvedopts)
-		&& $oldresolvedopts eq $sortedopts )
-	    {
-		$addmountmounts = 0;
-	    }
-	}
-    }
-
-    if ( $addmountfstab || $addmountmounts || !-d $dest ) {
-
-	if ( $options->{'verbose'} || $options->{'simul'} ) {
-	    Log("(action needed)");
-	}
-
-	Do_on_config( $ref_section, $options ) && return 1;
-
-	Do_before_change( $ref_section, $options ) && return 1;
-
-	if ( !-d $dest && $dest ne 'none' ) {
-	    if ( !defined( $FUNCTIONS{'mkdir'} ) ) {
-		Warn( $CODE->{'OPEN'}, "Fonction mkdir necessaire pour addmount" );
+	if ( -f $dest ) {
+		$cmp = 1;
+		if ( $options->{'verbose'} || $options->{'simul'} ) {
+			Log("(action needed)");
+		}
+		Do_on_config( $ref_section, $options, $hash_subst ) && return 1;
+		Do_before_change( $ref_section, $options, $hash_subst ) && return 1;
+		if ( !$options->{'simul'} ) {
+			Do_moveold ( $dest, $options );
+		}
+	}
+	if ( $cmp ) {
+		Do_after_change( $ref_section, $options, $hash_subst ) && return 1;
+		Do_on_noaction( $ref_section, $options, $hash_subst ) && return 1;
+	}
+	return 0;
+};
+
+$FUNCTIONS{'removedir'} = sub ($$$$$) {
+    my ( $ref_section, $dest, $options, $hash_subst, $global_config ) = @_;
+
+    my $cmp = 0;
+	if ( -e $dest && !-d $dest ) {
+		Warn( $CODE->{'OPEN'},
+			"Destination ".$dest." MUST BE a directory" );
 		return 1;
-	    }
-	    $FUNCTIONS{'mkdir'}->( $ref_section, $dest, $options );
-	}
-
-	if ($addmountfstab) {
-	    my $tmp = Get_tmp_dest("/etc/fstab");
-
-	    if ( !open( FSTAB, "< /etc/fstab" ) ) {
-		Warn( $CODE->{'OPEN'}, "Impossible de lire /etc/fstab" );
-		return 1;
-	    }
-
-	    if ( !open( NEWFSTAB, "> " . $tmp ) ) {
-		Warn( $CODE->{'OPEN'}, "Impossible de creer " . $tmp );
-		return 1;
-	    }
-
-	    while (<FSTAB>) {
-		my $line = $_;
-		if (   defined($oldsource)
-		    && $oldsource ne $source
-		    && $line =~ m|^[ 	]*$oldsource[ 	]+| )
-		{
-		    Warn( $CODE->{'OPEN'},
-			      "Suppression de la source "
-			    . $oldsource
-			    . " de fstab" );
-		}
-		elsif (defined($olddest)
-		    && $olddest ne $dest
-		    && $line =~ m|^[ 	]*[^ 	]+[ 	]+$olddest[ 	]+| )
-		{
-		    Warn( $CODE->{'OPEN'},
-			      "Suppression de la destination " 
-			    . $olddest
-			    . " de fstab" );
-		}
-		elsif (defined($oldfstype)
-		    && $oldfstype ne $fstype
-		    && $line =~ m|^[ 	]*$source+[ 	]+$dest[ 	]+| )
-		{
-		    Warn( $CODE->{'OPEN'},
-			      "Suppression du mauvais type "
-			    . $oldfstype
-			    . " pour "
-			    . $source
-			    . " de fstab" );
-		}
-		elsif (defined($oldopts)
-		    && $oldopts ne $opts
-		    && $line =~ m|^[ 	]*$source+[ 	]+$dest[ 	]+| )
-		{
-		    Warn( $CODE->{'OPEN'},
-			      "Suppression des mauvaises options " 
-			    . $oldopts
-			    . " pour "
-			    . $source
-			    . " de fstab" );
-		}
-		else {
-		    print NEWFSTAB $line;
-		}
-	    }
-	    print NEWFSTAB $source . "	" . $dest . "	" . $fstype . "	" . $opts
-		. "	0 0\n";
-	    close(NEWFSTAB);
-	    close(FSTAB);
-
-	    if ( $options->{'diff'} ) {
-		deferredlogsystem( "diff -uN '/etc/fstab' '" . $tmp . "'" );
-	    }
-
-	    if ( !$options->{'simul'} ) {
-		if ( system( "cat '" . $tmp . "' > /etc/fstab" ) ) {
-		    Warn( $CODE->{'OPEN'},
-			      "Impossible de recopier " 
-			    . $tmp
-			    . " dans /etc/fstab" );
-		    return 1;
-		}
-	    }
-	}
-
-	if ($addmountmounts) {
-
-	    if ( $options->{'diff'} ) {
-		if ((   ( defined $oldmresolvedsource )
-			? $oldmresolvedsource
-			: '?'
-		    ) ne $source
-		    )
-		{
-		    Log("src "
-			    . (
-			    ( defined $oldmresolvedsource )
-			    ? $oldmresolvedsource
-			    : '?'
-			    )
-			    . " -> "
-			    . $source
-		    );
-		}
-		if ( ( ( defined $oldmdest ) ? $oldmdest : '?' ) ne $dest ) {
-		    Log(      "dst "
-			    . ( ( defined $oldmdest ) ? $oldmdest : '?' )
-			    . " -> "
-			    . $dest );
-		}
-		if ( ( ( defined $oldmfstype ) ? $oldmfstype : '?' ) ne
-		    $fstype )
-		{
-		    Log(      "fs  "
-			    . ( ( defined $oldmfstype ) ? $oldmfstype : '?' )
-			    . " -> "
-			    . $fstype );
-		}
-		if ( ( ( defined $oldresolvedopts ) ? $oldresolvedopts : '?' )
-		    ne $opts )
-		{
-		    Log("opt "
-			    . (
-			    ( defined $oldresolvedopts )
-			    ? $oldresolvedopts
-			    : '?'
-			    )
-			    . " -> "
-			    . $opts
-		    );
-		}
-	    }
-
-	    if ( !$options->{'simul'} && !$options->{'noaction'} ) {
-
-		if (   defined($oldmsource)
-		    && $oldmsource ne $source
-		    && ( !defined($oldmresolvedsource)
-			|| $oldmresolvedsource ne $source )
-		    )    # Pas la peine de remounter si le resolv est le meme
-		{
-		    if ( deferredlogsystem( "umount '" . $oldmsource . "'" ) )
-		    {
-			Warn( $CODE->{'OPEN'},
-			    "Impossible d'unmounter la source "
-				. $oldmsource );
-			return 1;
-		    }
-		}
-
-		if ( defined($oldmdest) && $oldmdest ne $dest ) {
-		    if ( deferredlogsystem( "umount '" . $oldmdest . "'" ) ) {
-			Warn( $CODE->{'OPEN'},
-			    "Impossible d'unmounter la destination "
-				. $oldmdest );
-			return 1;
-		    }
-		}
-
-		if ( defined($oldmfstype) && $oldmfstype ne $fstype ) {
-		    if ( deferredlogsystem( "umount '" . $dest . "'" ) ) {
-			Warn( $CODE->{'OPEN'},
-			    "Impossible d'unmounter la destination "
-				. $dest );
-			return 1;
-		    }
-		}
-
-		if (   defined($oldopts)
-		    && $oldopts ne $opts
-		    && defined($oldmfstype)
-		    && $oldmfstype eq $fstype )
-		{
-		    if (deferredlogsystem(
-			    "mount -o 'remount," . $opts . "' '" . $dest . "'"
-			)
-			)
-		    {
-			Warn( $CODE->{'OPEN'},
-			          "Impossible de remounter la destination " 
-				. $dest
-				. " avec les options "
-				. $opts );
-			return 1;
-		    }
-		}
-		else {
-
-		    if (deferredlogsystem(
-			          "mount -t '" 
-				. $fstype 
-				. "' -o '" 
-				. $opts . "' '"
-				. $source . "' '"
-				. $dest . "'"
-			)
-			)
-		    {
-			Warn( $CODE->{'OPEN'},
-			          "Impossible de mounter la source " 
-				. $source . " sur "
-				. $dest
-				. " de type "
-				. $fstype
-				. " avec les options "
-				. $opts );
-			return 1;
-		    }
-		}
-	    }
-	}
-
-	Do_after_change( $ref_section, $options ) && return 1;
-
-	Do_on_noaction( $ref_section, $options ) && return 1;
-    }
-
-    return 0;
-};
-
-$FUNCTIONS{'ignore'} = sub {
-    my ( $ref_section, $dest, $options ) = @_;
-
-    return 0;
-};
-
-$DEPENDS{'addlink'} = sub {
-    my ( $ref_section, $dest, $options ) = @_;
-    my $source = Subst_vars( $ref_section->{'source'} );
-
-    while ( $source ne '/' && $source ne '.' ) {
-	$ref_section->{'depends'} .= " " . dirname($source);
-	$source = dirname($source);
-    }
-    while ( $dest ne '/' && $dest ne '.' ) {
-	$ref_section->{'depends'} .= " " . dirname($dest);
-	$dest = dirname($dest);
-    }
-};
-
-$FUNCTIONS{'addlink'} = sub {
-    my ( $ref_section, $dest, $options ) = @_;
-
-    my $cmp = 0;
-
-    $SUBST{'SECTIONNAME'} = $dest;
-    if ( !defined( $ref_section->{'source'} ) ) {
-	Abort( $CODE->{'SYNTAX'}, "Source non definie pour " . $dest );
-    }
-    my $source = Subst_vars( $ref_section->{'source'} );
-
-    if ( !-l $dest || ( -l $dest && readlink($dest) ne $source ) ) {
-	$cmp = 1;
-
-	if ( $options->{'verbose'} || $options->{'simul'} ) {
-	    Log("(action needed)");
-	}
-
-	if ( $options->{'diff'} ) {
-	    if ( -l $dest ) {
-		Log( "( readlink = " . readlink($dest) . ")" );
-	    }
-	    else {
-		Log( "( !-l " . $dest . ")" );
-	    }
-	}
-
-	Do_on_config( $ref_section, $options ) && return 1;
-
-	Do_before_change( $ref_section, $options ) && return 1;
-
-	if ( !$options->{'simul'} ) {
-	    Do_moveold( $dest, $options );
-
-	    if ( Mk_dest_dir($dest) || ln_sfn( $source, $dest ) ) {
-		Warn( $CODE->{'OPEN'},
-		    "Impossible de lier " . $dest . " a " . $source );
-		return 1;
-	    }
-	}
-
-	Do_after_change( $ref_section, $options ) && return 1;
-
-	Do_on_noaction( $ref_section, $options ) && return 1;
-    }
-
-    return 0;
-};
-
-$DEPENDS{'createfile'} = sub {
-    my ( $ref_section, $dest, $options ) = @_;
-
-    while ( $dest ne '/' && $dest ne '.' ) {
-	$ref_section->{'depends'} .= " " . dirname($dest);
-	$dest = dirname($dest);
-    }
-};
-
-$FUNCTIONS{'createfile'} = sub {
-    my ( $ref_section, $dest, $options ) = @_;
-
-    my $cmp = 0;
-
-    $SUBST{'SECTIONNAME'} = $dest;
-    if ( !defined $ref_section->{'source'} ) {
-	if ( !-f $dest ) {
-	    $cmp = 1;
-
-	    if ( $options->{'verbose'} || $options->{'simul'} ) {
-		Log("(action needed)");
-	    }
-
-	    Do_on_config( $ref_section, $options ) && return 1;
-
-	    Do_before_change( $ref_section, $options ) && return 1;
-
-	    if ( !$options->{'simul'} ) {
-
-		#Do_moveold( $dest, $options );
-
-		if (deferredlogsystem(
-			"/usr/bin/touch -t 197901010000 '" . $dest . "'"
-		    )
-		    )
-		{
-		    Warn( $CODE->{'OPEN'},
-			"Impossible de creer le fichier " . $dest );
-		    return 1;
-		}
-	    }
-	}
-    }
-    else {
-	my $source;
-	my $tmp;
-
-	$source = Get_source( Subst_vars( $ref_section->{'source'} ) );
-	$SUBST{'SOURCE'} = $source;
-
-	$tmp = Get_tmp_dest($dest);
-	$SUBST{'DESTINATION'} = $tmp;
-
-	if ( !-f $source ) {
-	    Warn( $CODE->{'OPEN'}, "Impossible d'ouvrir " . $source );
-	    return 1;
-	}
-
-	if ( defined( $ref_section->{'filter'} ) ) {
-	    my $filter = Subst_vars( $ref_section->{'filter'} );
-	    if ( deferredlogsystem($filter) ) {
-		Warn( $CODE->{'OPEN'}, "Impossible d'appliquer " . $filter );
-		return 1;
-	    }
-	}
-	else {
-
-	    if (deferredlogsystem(
-		    "/bin/cp -a '" . $source . "' '" . $tmp . "'"
-		)
-		)
-	    {
-		Warn( $CODE->{'OPEN'},
-		    "Impossible de copier " . $source . " vers " . $tmp );
-		return 1;
-	    }
-	}
-
-	if ( !-f $tmp ) {
-	    Warn( $CODE->{'OPEN'}, "Impossible d'ouvrir " . $tmp );
-	    return 1;
-	}
-
-	if ( !-f $dest ) {
-	    $cmp = 1;
-
-	    if ( $options->{'verbose'} || $options->{'simul'} ) {
-		Log("(action needed)");
-	    }
-
-	    Do_on_config( $ref_section, $options ) && return 1;
-
-	    Do_before_change( $ref_section, $options ) && return 1;
-
-	    if ( !$options->{'simul'} ) {
-
-		#Do_moveold( $dest, $options );
-
-		if (deferredlogsystem(
-			"/bin/cp -a '" . $source . "' '" . $dest . "'"
-		    )
-		    )
-		{
-		    Warn( $CODE->{'OPEN'},
-			"Impossible de creer le fichier " . $dest );
-		    return 1;
-		}
-	    }
-	}
-    }
-
-    Do_chownmod( $ref_section, $dest, $options );
-
-    if ($cmp) {
-	Do_after_change( $ref_section, $options ) && return 1;
-
-	Do_on_noaction( $ref_section, $options ) && return 1;
-    }
-
-    return 0;
-};
-
-$DEPENDS{'mkdir'} = sub {
-    my ( $ref_section, $dest, $options ) = @_;
-
-    while ( $dest ne '/' && $dest ne '.' ) {
-	$ref_section->{'depends'} .= " " . dirname($dest);
-	$dest = dirname($dest);
-    }
-};
-
-$FUNCTIONS{'mkdir'} = sub {
-    my ( $ref_section, $dest, $options ) = @_;
-
-    my $cmp = 0;
-
-    $SUBST{'SECTIONNAME'} = $dest;
-    if ( !-d $dest ) {
-	$cmp = 1;
-
-	if ( $options->{'verbose'} || $options->{'simul'} ) {
-	    Log("(action needed)");
-	}
-
-	Do_on_config( $ref_section, $options ) && return 1;
-
-	Do_before_change( $ref_section, $options ) && return 1;
-
-	if ( !$options->{'simul'} ) {
-	    Do_moveold( $dest, $options );
-
-	    if ( deferredlogsystem( "/bin/mkdir -p '" . $dest . "'" ) ) {
-		Warn( $CODE->{'OPEN'},
-		    "Impossible de creer le repertoire " . $dest );
-		return 1;
-	    }
-	}
-    }
-
-    Do_chownmod( $ref_section, $dest, $options );
-
-    if ($cmp) {
-	Do_after_change( $ref_section, $options ) && return 1;
-
-	Do_on_noaction( $ref_section, $options ) && return 1;
-    }
-
-    return 0;
-};
-
-$FUNCTIONS{'removefile'} = sub {
-    my ( $ref_section, $dest, $options ) = @_;
-
-    my $cmp = 0;
-    if ( -d $dest ) {
-	Warn( $CODE->{'OPEN'},
-	    "La destination " . $dest . "doit etre un fichier!" );
-	return 1;
-    }
-    if ( -f $dest ) {
-	$cmp = 1;
-
-	if ( $options->{'verbose'} || $options->{'simul'} ) {
-	    Log("(action needed)");
-	}
-
-	Do_on_config( $ref_section, $options ) && return 1;
-
-	Do_before_change( $ref_section, $options ) && return 1;
-
-	if ( !$options->{'simul'} ) {
-
-	    Do_moveold( $dest, $options );
-
-	    # Pas besoin, move -> del
-	    #if (!unlink($dest) )
-	    #{
-	    #    Warn( $CODE->{'OPEN'},
-	    #        "Impossible d'effacer " . $dest );
-	    #    return;
-	    #}
-	}
-    }
-
-    # Mais bien sur
-    #Do_chownmod( $ref_section, $dest, $options );
-
-    if ($cmp) {
-	Do_after_change( $ref_section, $options ) && return 1;
-
-	Do_on_noaction( $ref_section, $options ) && return 1;
-    }
-
-    return 0;
-};
-
-$FUNCTIONS{'removedir'} = sub {
-    my ( $ref_section, $dest, $options ) = @_;
-
-    my $cmp = 0;
-    if ( -e $dest && !-d $dest ) {
-	Warn( $CODE->{'OPEN'},
-	    "La destination " . $dest . "doit etre un repertoire!" );
-	return 1;
-    }
-    if ( -d $dest ) {
-	$cmp = 1;
-
-	if ( $options->{'verbose'} || $options->{'simul'} ) {
-	    Log("(action needed)");
-	}
-
-	Do_on_config( $ref_section, $options ) && return 1;
-
-	Do_before_change( $ref_section, $options ) && return 1;
-
-	if ( !$options->{'simul'} ) {
-
-	    Do_moveold( $dest, $options );
-
-	    # Pas besoin, move -> del
-	    #if (!rmdir($dest) )
-	    #{
-	    #    Warn( $CODE->{'OPEN'},
-	    #        "Impossible d'effacer " . $dest );
-	    #    return;
-	    #}
-	}
-    }
-
-    # Mais bien sur
-    #Do_chownmod( $ref_section, $dest, $options );
-
-    if ($cmp) {
-	Do_after_change( $ref_section, $options ) && return 1;
-
-	Do_on_noaction( $ref_section, $options ) && return 1;
-    }
-
-    return 0;
-};
-
-sub Mk_dest_dir {
-    my ($dir) = @_;
-
-    $dir =~ s://:/:g;    # supprimer // sinon ca marche moins bien
-
-    $dir =~ s:/[^/]+/*$::;
-
-    # verif que pas un fichier a la place d'un rep au milieu du mkdir -p
-    my $dir2 = $dir;
-    while ( $dir2 ne "" && !-e $dir2 ) {
-	$dir2 =~ s:/[^/]+/*$::;
-    }
-    if ( $dir2 ne "" && -e $dir2 && !-d $dir2 ) {
-	unlink($dir2);
-    }
-
-    $dir && return system( "/bin/mkdir -p '" . $dir . "' >/dev/null 2>&1" );
-}
-
-sub Get_tmp_dest {
-    my ($dest) = @_;
-
-    my $tmp = $CVS_TMP_DIR . "/" . $dest;
-
-    Mk_dest_dir($tmp);
-
-    if ( -d $tmp ) {
-	rmdir($tmp);
-    }
-    elsif ( -e $tmp ) {
-	unlink($tmp);
-    }
-
-    return $tmp;
+	}
+	if ( -d $dest ) {
+		$cmp = 1;
+		if ( $options->{'verbose'} || $options->{'simul'} ) {
+			Log("(action needed)");
+		}
+		Do_on_config( $ref_section, $options, $hash_subst ) && return 1;
+		Do_before_change( $ref_section, $options, $hash_subst ) && return 1;
+		if ( !$options->{'simul'} ) {
+			Do_moveold( $dest, $options );
+		}
+	}
+	if ( $cmp ) {
+		Do_after_change( $ref_section, $options, $hash_subst ) && return 1;
+		Do_on_noaction( $ref_section, $options, $hash_subst ) && return 1;
+	}
+	return 0;
+};
+
+sub Mk_dest_dir ($) {
+	my ( $dir ) = @_;
+
+	$dir =~ s://:/:g;    # supprimer // sinon ca marche moins bien
+	$dir =~ s:/[^/]+/*$::;
+	my $dir2 = $dir;
+	while ( $dir2 ne "" && !-e $dir2 ) {
+		$dir2 =~ s:/[^/]+/*$::;
+	}
+	if ( $dir2 ne "" && -e $dir2 && !-d $dir2 ) {
+		unlink($dir2);
+	}
+	$dir && return system( "/bin/mkdir -p '" . $dir . "' >/dev/null 2>&1" );
+}
+
+sub Get_tmp_dest ($) {
+	my ( $dest ) = @_;
+
+	my $pf_config = Init_PF_CONFIG (); 
+	my $tmp = $pf_config->{'path'}->{'checkout_dir'} . "/tmp/" . $dest;
+	Mk_dest_dir ( $tmp );
+	if ( -d $tmp ) {
+		rmdir( $tmp );
+	}
+	elsif ( -e $tmp ) {
+		unlink ( $tmp );
+	}
+	return $tmp;
 }
 
 sub Get_depends_for_action ($$$$) {
@@ -1370,13 +1055,13 @@
 	$prio++;
 
 	# Third : Packaging infra and packages
-	return $prio if ( $section =~ m|^/etc/apt/| );
+	return $prio if ( $section =~ /^\/etc\/apt\// );
 	$prio++;
 	return $prio if ( $section eq "pf-tools" );
 	$prio++;
-	return $prio if ( $action eq 'dpkg-purge' );
+	return $prio if ( $action eq "dpkg-purge" );
     $prio++;
-    return $prio if ( $action eq 'apt-get' );
+    return $prio if ( $action eq "apt-get" );
     $prio++;
 
 	# Fourth : creations and adds for files and links

Modified: branches/next-gen/lib/PFTools/Utils.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Utils.pm?rev=803&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Utils.pm (original)
+++ branches/next-gen/lib/PFTools/Utils.pm Thu Aug  5 14:37:26 2010
@@ -69,8 +69,7 @@
 #########################################################################
 # Prototypes : needed by recursive calls
 
-sub Resolv_hostname_from_GLOBAL ($$;$$);
-sub __Do_updateloop ($$$);
+sub __Do_updateloop ($$$$$);
 
 #########################################################################
 # Functions
@@ -446,7 +445,7 @@
 	print OUTPUT "\n";
 	print OUTPUT "search ".$domain."\n";
 	foreach my $dns (@dns) {
-		my $resolved = Resolv_hostname_from_GLOBAL ( $dns, $global_config, $site );
+		my $resolved = Resolv ( 'cnf', $dns, $global_config, $site );
 		foreach my $ip ( @{$resolved} ) {
 			print OUTPUT "nameserver ".$ip."\n";
 		}
@@ -455,83 +454,38 @@
 	return 1;
 }
 
-sub Resolv_hostname_from_GLOBAL ($$;$$) {
-	my ( $hostname, $global_config, $site, $hosttype ) = @_;
-	my $resolved = [];
-
-	if ( ! defined $site ) {
-		my $ref_site_list = Get_site_from_hostname ( $hostname, $global_config );
-		if ( ! defined $ref_site_list ) {
-			Warn ( $CODE->{'UNDEF_KEY'},
-				"Hostname ".$hostname." is not defined into the global configuration" );
-			return undef;
-		}
-		elsif ( scalar @{$ref_site_list} > 1 ) {
-			Warn ( $CODE->{'DUPLICATE_VALUE'},
-				"Hostname ".$hostname." is defined into multiple sites : unable to choose the right one" );
-		}
-		else {
-			( $site ) = @{$ref_site_list};
-		}
-	}
-
-	my $zone						= Get_zone_from_hostname ( $hostname, $global_config, $site );
-	$hostname						=~ s/\.$zone$//;
-	$hostname						=~ /^([^.]+)(\.([^.]+))?$/;
-	my ( $hostshort, $hostvlan )	= ( $1, $3 );
-	my $zone_part 					= $global_config->{'ZONE'}->{'BY_NAME'}->{$zone}->{'BY_SITE'}->{$site};
-	if ( $hostname =~ /^(network|netmask|broadcast|gateway)/ && defined $hostvlan ) {
-		return undef if ( ! defined $zone_part->{$hostvlan} );
-		my ( $type, $field ) = split ( /\s+/, $zone_part->{$hostvlan}->{$hostshort} );
-		push ( @{$resolved}, $field );
-	}
-	else {
-		if ( ! defined $hosttype ) {
+sub Resolv ($$;$$$) {
+	my ( $type_resolve, $hostname, $global_config, $site, $hosttype ) = @_;
+	
+	if ( $type_resolve eq 'cnf' ) {
+		if ( ! defined $site ) {
+			my $ref_site_list = Get_site_from_hostname ( $hostname, $global_config );
+			if ( ! defined $ref_site_list ) {
+				Warn ( $CODE->{'UNDEF_KEY'},
+					"Hostname ".$hostname." is not defined into the global configuration" );
+				return undef;
+			}
+			elsif ( scalar @{$ref_site_list} > 1 ) {
+				Warn ( $CODE->{'DUPLICATE_VALUE'},
+					"Hostname ".$hostname." is defined into multiple sites : unable to choose the right one" );
+			}
+			else {
+				( $site ) = @{$ref_site_list};
+			}
+		}
+		my $zone						= Get_zone_from_hostname ( $hostname, $global_config, $site );
+		$hostname						=~ s/\.$zone$//;
+		$hostname						=~ /^([^.]+)(\.([^.]+))?$/;
+		my ( $hostshort, $hostvlan )	= ( $1, $3 );
+		if ( ! defined $hosttype && $hostname !~ /^(network|netmask|broadcast|gateway)/ ) {
 			$hosttype = Get_hosttype_from_hostname ( $hostshort, $global_config, $site );
 			return undef if ( ! defined $hosttype );
 		}
-		foreach my $entry ( keys %{$zone_part->{$hosttype}} ) {
-			next if ( $entry !~ /^$hostname$/ );
-			my @fields;
-			if ( ref ( $zone_part->{$hosttype}->{$entry} ) eq 'ARRAY' ) {
-				@fields = @{$zone_part->{$hosttype}->{$entry}}
-			}
-			else {
-				@fields = ( $zone_part->{$hosttype}->{$entry} );
-			}
-			foreach my $line ( @fields ) {
-				my ( $type, $field ) = split ( /\s+/, $line );
-				if ( $type eq 'A' ) {
-					push ( @{$resolved}, $field );
-				}
-				elsif ( $type eq 'CNAME' ) {
-					my $cname_resolved = Resolv_hostname_from_GLOBAL ( $field, $global_config, $site, $hosttype );
-					push ( @{$resolved}, @{$cname_resolved} );
-				}
-			}
-		}
-	}
-	return $resolved;
-}
-
-sub Resolv_hostname_from_DNS ($) {
-	my ( $hostname ) = @_;
-	my $resolved = [];
-
-	my $res   = Net::DNS::Resolver->new;
-	my $query = $res->search( $hostname );
-
-	if ($query) {
-		foreach my $rr ( $query->answer ) {
-			next unless $rr->type eq "A";
-			push ( @{$resolved}, $rr->address );
-		}
-	} else {
-		Warn ( $CODE->{'BIND_QUERY'},
-			"Query failed: ".$res->errorstring );
-		return undef;
-	}
-	return $resolved;
+		return Resolv_hostname_from_GLOBAL ( $hostname, $global_config, $site, $zone, $hosttype );
+	}
+	else {
+		return Resolv_hostname_from_DNS ( $hostname );
+	}
 }
 
 sub __Search_and_resolve_IP ($$$$$$$) {
@@ -552,9 +506,7 @@
 			my $match2 = $match;
 			$match2 =~ s/HOSTNAME/$hostname/;
 			$match2 =~ s/POPNAME/$hash_subst->{'POPNAME'}/g;
-			my $resolved = ( $type_resolve eq 'cnf' )
-				? Resolv_hostname_from_GLOBAL ( $match2, $global_config, $site )
-				: Resolv_hostname_from_DNS ( $match2 );
+			my $resolved = Resolv ( $type_resolve, $match2, $global_config, $site );
 			if ( scalar $resolved ) {
 				if ( $separator eq "DUPLICATE" ) {
 					my $templine = "";
@@ -927,11 +879,11 @@
 	return $interfaces;
 }
 
-sub __Do_updateloop ($$$$) {
-    my ( $host_config, $options, $hash_subst, @sortedkeys ) = @_;
+sub __Do_updateloop ($$$$$) {
+    my ( $host_config, $options, $hash_subst, $global_config, @sortedkeys ) = @_;
     my $errorcount = 0;
 
-    foreach $section (@sortedkeys) {
+    foreach my $section (@sortedkeys) {
 		if (   defined( $host_config->{$section} )
 			&& ! defined( $host_config->{$section}->{'doing'} )
 			&& ! defined( $host_config->{$section}->{'done'} )
@@ -943,7 +895,7 @@
 				my @depends;
 				my $d;
 				@dependsraw = split( /[ ,]+/, $host_config->{$section}->{'depends'} );
-				foreach $depend (@dependsraw) {
+				foreach my $depend (@dependsraw) {
 					if ( defined($depend) && $depend ne "" && defined( $host_config->{$depend} ) ) {
 						if ( $depend eq $section ) {
 							Warn ( $CODE->{'SYNTAX'},
@@ -961,11 +913,11 @@
 				}
 				if ( $#depends >= 0 ) {
 					Log ( "<".$section."> ".join( ' ', @depends ) );
-					$errorcount += __Do_updateloop( $host_config, $options, $hash_subst, @depends );
+					$errorcount += __Do_updateloop( $host_config, $options, $hash_subst, $global_config, @depends );
 				}
 			}
 			Log( "[".$section."]" );
-			if ( Exec_action ( $host_config->{$section}->{'action'}, $host_config->{$section}, $section, $options, $hash_subst ) ) {
+			if ( Exec_action ( $host_config->{$section}->{'action'}, $host_config->{$section}, $section, $options, $hash_subst, $global_config ) ) {
 				FlushLog();
 				$errorcount++;
 			}
@@ -980,6 +932,7 @@
 
 sub Do_update_from_GLOBAL ($$$$$$) {
 	my ( $hostname, $site, $options, $hash_subst, $global_config, $pf_config ) = @_;
+	my $errorcount = 0;
 
 	if ( ! VCS_Update ( $hostname, $pf_config, $options, $options->{'branche'} ) ) {
 		Abort ( $CODE->{'EXEC'},
@@ -997,10 +950,10 @@
 			"Unable to update configuration : update feature is deactivated in pf-tools configuration file" );
 	}
 
-	@sortedkeys = sort { Trie_dependances( $host_config, $a, $b ) } $host_config->{'__sections_order'} ;
+	my @sortedkeys = sort { Trie_dependances( $host_config, $a, $b ) } $host_config->{'__sections_order'} ;
 
 	$| = 1;
-	$errorcount = __Do_updateloop ( $host_config, $options, $hash_subst, @sortedkeys );
+	$errorcount = __Do_updateloop ( $host_config, $options, $hash_subst, $global_config, @sortedkeys );
 
 	Log( $errorcount . " error(s) detected." );
 	FlushLog();




More information about the pf-tools-commits mailing list