pf-tools commit: r819 [ccaillet-guest] - in /branches/next-gen: TODO debian/changelog lib/PFTools/Conf.pm lib/PFTools/Update.pm lib/PFTools/Update/ lib/PFTools/Update/Common.pm lib/PFTools/Update/File.pm lib/PFTools/Utils.pm
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Sat Aug 7 09:46:44 UTC 2010
Author: ccaillet-guest
Date: Sat Aug 7 09:46:42 2010
New Revision: 819
URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=819
Log:
* lib/PFTools/Utils.pm
* lib/PFTools/Update.pm
- splitting $FUNCTION and $DEPENDS to perl package under PFTools::Update::*
* lib/PFTools/Update/Common.pm
- extracting common functions from Update.pm which are used by $FUNCTION
and $DEPENDS in lib/PFTools/Update.pm
Added:
branches/next-gen/lib/PFTools/Update/
branches/next-gen/lib/PFTools/Update/Common.pm
branches/next-gen/lib/PFTools/Update/File.pm
Modified:
branches/next-gen/TODO
branches/next-gen/debian/changelog
branches/next-gen/lib/PFTools/Conf.pm
branches/next-gen/lib/PFTools/Update.pm
branches/next-gen/lib/PFTools/Utils.pm
Modified: branches/next-gen/TODO
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/TODO?rev=819&op=diff
==============================================================================
--- branches/next-gen/TODO (original)
+++ branches/next-gen/TODO Sat Aug 7 09:46:42 2010
@@ -5,7 +5,6 @@
LM creating a tool to see vlan mapping e.g. all hosts defined for a specified vlan
on a given site (including empty range into this vlan)
LH alias definition like CONFIG: in pf-tools.conf file for using in Get_source
-NM interface 0.0.0.0 promisc pour uml (ex: sondes)
NM permit interface with no IP in promisc mode (ex: for probing hosts)
NH implementing monitoring as defined in hostfile-syntax with PFTools::Monitoring
Modified: branches/next-gen/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/debian/changelog?rev=819&op=diff
==============================================================================
--- branches/next-gen/debian/changelog (original)
+++ branches/next-gen/debian/changelog Sat Aug 7 09:46:42 2010
@@ -8,10 +8,15 @@
* lib/PFTools/Conf.pm
- small fixes on Get_source for order and substitution regex
- rollback for CONFIG: alias with the 0.33-stable substitution value
- * lib/Utils.pm
+ * lib/PFTools/Utils.pm
- fix on Ini_TOOLS : if storable file doesn't exist we need to parse
-
- -- Christophe Caillet <quadchris at free.fr> Sat, 07 Aug 2010 08:38:00 +0200
+ * lib/PFTools/Update.pm
+ - splitting $FUNCTION and $DEPENDS to perl package under PFTools::Update::*
+ * lib/PFTools/Update/Common.pm
+ - extracting common functions from Update.pm which are used by $FUNCTION
+ and $DEPENDS in lib/PFTools/Update.pm
+
+ -- Christophe Caillet <quadchris at free.fr> Sat, 07 Aug 2010 11:44:03 +0200
pf-tools (0.99.98-1) unstable; urgency=low
Modified: branches/next-gen/lib/PFTools/Conf.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Conf.pm?rev=819&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Conf.pm (original)
+++ branches/next-gen/lib/PFTools/Conf.pm Sat Aug 7 09:46:42 2010
@@ -904,9 +904,11 @@
my $flush_file = $path_global_file || $pf_config->{'path'}->{'global_struct'};
if ( ! store ( $global_config, $flush_file ) ) {
- Abort ( $CODE->{'STORABLE'},
+ Warn ( $CODE->{'STORABLE'},
"An error occured when trying to flush global structure to file ".$flush_file );
- }
+ return 1;
+ }
+ return 0;
}
sub Retrieve_GLOBAL ($) {
Modified: branches/next-gen/lib/PFTools/Update.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Update.pm?rev=819&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Update.pm (original)
+++ branches/next-gen/lib/PFTools/Update.pm Sat Aug 7 09:46:42 2010
@@ -41,6 +41,7 @@
use File::Compare;
use File::Copy;
+use PFTools::Update::Common;
use PFTools::Logger;
use PFTools::Parser;
use PFTools::Net;
@@ -64,10 +65,6 @@
###########################################
### Constants
-my $DEFAULT_MODE = '0640';
-my $DEFAULT_DIRMODE = '0750';
-my $DEFAULT_OWNER = 'root';
-my $DEFAULT_GROUP = 'root';
my $DEFAULT_FSTYPE = 'nfs';
my $DEFAULT_OPTIONS = 'defaults,noexec,nosuid,nodev,hard,intr';
my $APT_GET = 'LANG=C LC_ALL=C /usr/bin/apt-get -y --force-yes';
@@ -77,181 +74,6 @@
my $DPKG = 'LANG=C LC_ALL=C /usr/bin/dpkg';
# Fonctions utilisees dans les fichiers de conf
-
-##############################################
-###
-
-sub isipaddr ($) {
- my ($ip) = @_;
-
- my @sub = split( '\.', $ip );
- return 0 if ( $#sub != 3 );
-
- foreach my $octet ( 0 .. 3 ) {
- return 0 if ( $sub[$octet] < 0 || $sub[$octet] > 255 );
- }
- return 1;
-}
-
-sub __full_rights ($$$$;$) {
- my ( $type, $dest, $options, $right1, $right2 ) = @_;
-
- if ( $options->{'verbose'} || $options->{'simul'} ) {
- Log ( "(chown needed)" );
- }
- if ( $options->{'simul'} ) {
- return 0;
- }
- my ( $dev, $ino, $mode, $nlink, $uid, $gid, @others ) = stat($dest);
- if ( $type eq 'chown' ) {
- my $newuid = getpwnam ($right1);
- my $newgid = getgrnam ($right2);
- if (
- ( defined($uid) && $uid == $newuid )
- && ( defined($gid) && $gid == $newgid )
- ) {
- return 0;
- }
- return ! chown ( $newuid, $newgid, $dest );
- }
- elsif ( $type eq 'chmod' ) {
- if ( defined($mode) && ( $mode & 07777 ) == $right1 ) {
- return 0;
- }
- return ! chmod ( $right1, $dest );
- }
-}
-
-sub fullchown ($$$$) {
- my ( $owner, $group, $dest, $options ) = @_;
-
- return __full_rights ( 'chown', $dest, $options, $owner, $group );
-}
-
-sub fullchmod ($$$) {
- my ( $newmode, $dest, $options ) = @_;
-
- return __full_rights ( 'chmod', $dest, $options, $newmode );
-}
-
-sub ln_sfn ($$) {
- my ( $source, $dest ) = @_;
-
- unlink ( $dest );
- rmdir ( $dest );
- return ! symlink ( $source, $dest ) ;
-}
-
-sub dirname {
- my ($file) = @_;
-
- $file =~ s://:/:g;
-
- if ( $file =~ m|/| ) {
- $file =~ s|^(.*)/[^/]+/?$|$1|;
- }
- else {
- $file = '.';
- }
-
- return $file;
-}
-
-sub Do_moveold ($$) {
- my ( $dest, $options ) = @_;
-
- my $pf_config = Init_PF_CONFIG ();
- if ( -e $dest ) {
- my $old = $pf_config->{'path'}->{'checkout_dir'} . "/old/" . $dest . "." . $STARTTIME;
- if ( $options->{'verbose'} ) {
- Log( "(moving old to " . $old . ")" );
- }
- if ( ! $options->{'simul'} ) {
- Mk_dest_dir ( $old );
- return ! move ( $old, $dest )
- }
- }
-}
-
-sub Do_chownmod ($$$) {
- my ( $ref_section, $dest, $options ) = @_;
-
- 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'},
- "Unable to change owner and/or group to ".$owner." and ".$group
- ." for file ".$dest);
- return 1;
- }
-
- my $mode = defined( $ref_section->{'mode'} )
- ? $ref_section->{'mode'}
- : ( ( -d $dest ) ? $DEFAULT_DIRMODE : $DEFAULT_MODE );
- $mode =~ s/^[^0]/0$&/;
-
- if ( fullchmod( eval($mode), $dest, $options ) ) {
- Warn( $CODE->{'OPEN'},
- "unable to change rights to ".$mode." for file ".$dest );
- return 1;
- }
- return 0;
-}
-
-sub Exec_cmd ($) {
- my ( $cmd ) = @_;
-
- if ( deferredlogsystem ( $cmd ) ) {
- Warn( $CODE->{'OPEN'},
- "Unable to execute [".$cmd."]" );
- return 1;
- }
- return 0;
-}
-
-sub Do_on_config ($$$) {
- my ( $ref_section, $options, $hash_subst ) = @_;
-
- if ( ! $options->{'simul'}
- && defined ( $ref_section->{'on_config'} )
- ) {
- return Exec_cmd ( Subst_vars ( $ref_section->{'on_config'}, $hash_subst ) );
- }
-}
-
-sub Do_before_change ($$$) {
- my ( $ref_section, $options, $hash_subst ) = @_;
-
- if ( ! $options->{'simul'}
- && ! $options->{'noaction'}
- && defined ( $ref_section->{'before_change'} )
- ) {
- return Exec_cmd ( Subst_vars ( $ref_section->{'before_change'}, $hash_subst ) );
- }
-}
-
-sub Do_after_change ($$$) {
- my ( $ref_section, $options, $hash_subst ) = @_;
-
- if ( !$options->{'simul'}
- && defined ( $ref_section->{'after_change'} )
- && !$options->{'noaction'}
- ) {
- return Exec_cmd ( Subst_vars ( $ref_section->{'after_change'}, $hash_subst ) );
- }
-}
-
-sub Do_on_noaction ($$$) {
- my ( $ref_section, $options, $hash_subst ) = @_;
-
- if ( ! $options->{'simul'}
- && defined ( $ref_section->{'on_noaction'} )
- && $options->{'noaction'}
- ) {
- return Exec_cmd ( Subst_vars ( $ref_section->{'on_noaction'}, $hash_subst ) );
- }
-}
my %DEPENDS;
my %FUNCTIONS;
Added: branches/next-gen/lib/PFTools/Update/Common.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Update/Common.pm?rev=819&op=file
==============================================================================
--- branches/next-gen/lib/PFTools/Update/Common.pm (added)
+++ branches/next-gen/lib/PFTools/Update/Common.pm Sat Aug 7 09:46:42 2010
@@ -1,0 +1,238 @@
+package PFTools::Update::Common;
+##
+## $Id: Update.pm 805 2010-08-06 10:20:44Z ccaillet-guest $
+##
+## Copyright (C) 2010 Christophe Caillet <quadchris at free.fr>
+##
+## 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+##
+
+use strict;
+use warnings;
+
+use Exporter;
+
+our @ISA = ('Exporter');
+
+our @EXPORT = qw(
+ Do_on_config
+ Do_on_noaction
+ Do_before_change
+ Do_after_change
+ Do_chownmod
+ Do_moveold
+ Exec_cmd
+ dirname
+ isipaddr
+ ln_sfn
+);
+
+our @EXPORT_OK = qw();
+
+use File::Compare;
+use File::Copy;
+use PFTools::Logger;
+
+use Fcntl ':mode';
+
+###########################################
+### Constants
+my $DEFAULT_MODE = '0640';
+my $DEFAULT_DIRMODE = '0750';
+my $DEFAULT_OWNER = 'root';
+my $DEFAULT_GROUP = 'root';
+my $STARTTIME = time();
+
+# my $DEFAULT_FSTYPE = 'nfs';
+# my $DEFAULT_OPTIONS = 'defaults,noexec,nosuid,nodev,hard,intr';
+
+# Fonctions utilisees dans les fichiers de conf
+
+##############################################
+###
+
+sub isipaddr ($) {
+ my ($ip) = @_;
+
+ my @sub = split( '\.', $ip );
+ return 0 if ( $#sub != 3 );
+
+ foreach my $octet ( 0 .. 3 ) {
+ return 0 if ( $sub[$octet] < 0 || $sub[$octet] > 255 );
+ }
+ return 1;
+}
+
+sub __full_rights ($$$$;$) {
+ my ( $type, $dest, $options, $right1, $right2 ) = @_;
+
+ if ( $options->{'verbose'} || $options->{'simul'} ) {
+ Log ( "(chown needed)" );
+ }
+ if ( $options->{'simul'} ) {
+ return 0;
+ }
+ my ( $dev, $ino, $mode, $nlink, $uid, $gid, @others ) = stat($dest);
+ if ( $type eq 'chown' ) {
+ my $newuid = getpwnam ($right1);
+ my $newgid = getgrnam ($right2);
+ if (
+ ( defined($uid) && $uid == $newuid )
+ && ( defined($gid) && $gid == $newgid )
+ ) {
+ return 0;
+ }
+ return ! chown ( $newuid, $newgid, $dest );
+ }
+ elsif ( $type eq 'chmod' ) {
+ if ( defined($mode) && ( $mode & 07777 ) == $right1 ) {
+ return 0;
+ }
+ return ! chmod ( $right1, $dest );
+ }
+}
+
+sub fullchown ($$$$) {
+ my ( $owner, $group, $dest, $options ) = @_;
+
+ return __full_rights ( 'chown', $dest, $options, $owner, $group );
+}
+
+sub fullchmod ($$$) {
+ my ( $newmode, $dest, $options ) = @_;
+
+ return __full_rights ( 'chmod', $dest, $options, $newmode );
+}
+
+sub ln_sfn ($$) {
+ my ( $source, $dest ) = @_;
+
+ unlink ( $dest );
+ rmdir ( $dest );
+ return ! symlink ( $source, $dest ) ;
+}
+
+sub dirname {
+ my ($file) = @_;
+
+ $file =~ s://:/:g;
+
+ if ( $file =~ m|/| ) {
+ $file =~ s|^(.*)/[^/]+/?$|$1|;
+ }
+ else {
+ $file = '.';
+ }
+
+ return $file;
+}
+
+sub Do_moveold ($$) {
+ my ( $dest, $options ) = @_;
+
+ my $pf_config = Init_PF_CONFIG ();
+ if ( -e $dest ) {
+ my $old = $pf_config->{'path'}->{'checkout_dir'} . "/old/" . $dest . "." . $STARTTIME;
+ if ( $options->{'verbose'} ) {
+ Log( "(moving old to " . $old . ")" );
+ }
+ if ( ! $options->{'simul'} ) {
+ Mk_dest_dir ( $old );
+ return ! move ( $old, $dest )
+ }
+ }
+}
+
+sub Do_chownmod ($$$) {
+ my ( $ref_section, $dest, $options ) = @_;
+
+ 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'},
+ "Unable to change owner and/or group to ".$owner." and ".$group
+ ." for file ".$dest);
+ return 1;
+ }
+
+ my $mode = defined( $ref_section->{'mode'} )
+ ? $ref_section->{'mode'}
+ : ( ( -d $dest ) ? $DEFAULT_DIRMODE : $DEFAULT_MODE );
+ $mode =~ s/^[^0]/0$&/;
+
+ if ( fullchmod( eval($mode), $dest, $options ) ) {
+ Warn( $CODE->{'OPEN'},
+ "unable to change rights to ".$mode." for file ".$dest );
+ return 1;
+ }
+ return 0;
+}
+
+sub Exec_cmd ($) {
+ my ( $cmd ) = @_;
+
+ if ( deferredlogsystem ( $cmd ) ) {
+ Warn( $CODE->{'OPEN'},
+ "Unable to execute [".$cmd."]" );
+ return 1;
+ }
+ return 0;
+}
+
+sub Do_on_config ($$$) {
+ my ( $ref_section, $options, $hash_subst ) = @_;
+
+ if ( ! $options->{'simul'}
+ && defined ( $ref_section->{'on_config'} )
+ ) {
+ return Exec_cmd ( Subst_vars ( $ref_section->{'on_config'}, $hash_subst ) );
+ }
+}
+
+sub Do_before_change ($$$) {
+ my ( $ref_section, $options, $hash_subst ) = @_;
+
+ if ( ! $options->{'simul'}
+ && ! $options->{'noaction'}
+ && defined ( $ref_section->{'before_change'} )
+ ) {
+ return Exec_cmd ( Subst_vars ( $ref_section->{'before_change'}, $hash_subst ) );
+ }
+}
+
+sub Do_after_change ($$$) {
+ my ( $ref_section, $options, $hash_subst ) = @_;
+
+ if ( !$options->{'simul'}
+ && defined ( $ref_section->{'after_change'} )
+ && !$options->{'noaction'}
+ ) {
+ return Exec_cmd ( Subst_vars ( $ref_section->{'after_change'}, $hash_subst ) );
+ }
+}
+
+sub Do_on_noaction ($$$) {
+ my ( $ref_section, $options, $hash_subst ) = @_;
+
+ if ( ! $options->{'simul'}
+ && defined ( $ref_section->{'on_noaction'} )
+ && $options->{'noaction'}
+ ) {
+ return Exec_cmd ( Subst_vars ( $ref_section->{'on_noaction'}, $hash_subst ) );
+ }
+}
+
+1;
Added: branches/next-gen/lib/PFTools/Update/File.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Update/File.pm?rev=819&op=file
==============================================================================
--- branches/next-gen/lib/PFTools/Update/File.pm (added)
+++ branches/next-gen/lib/PFTools/Update/File.pm Sat Aug 7 09:46:42 2010
@@ -1,0 +1,2 @@
+package PFTools::Update::File;
+
Modified: branches/next-gen/lib/PFTools/Utils.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Utils.pm?rev=819&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Utils.pm (original)
+++ branches/next-gen/lib/PFTools/Utils.pm Sat Aug 7 09:46:42 2010
@@ -107,6 +107,7 @@
Unset_deferredlog ();
}
$global_struct = Init_GLOBAL_NETCONFIG ( $source, $hostname, $pf_config );
+ Flush2disk_GLOBAL ( $global_struct, $pf_config );
}
else {
$global_struct = Retrieve_GLOBAL ( $global_store_file );
More information about the pf-tools-commits
mailing list