Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

bugfix to calculate /usr/lib/psad directory paths to import psad perl…

… modules

git-svn-id: file:///home/mbr/svn/psad_repos/psad/trunk@1769 91a0a83b-1414-0410-bf9a-c3dbc33e90b6
  • Loading branch information...
commit 6cff015d5719fc33a0ab513603925f55c0c52f47 1 parent bdaeb3e
@mrash authored
Showing with 195 additions and 10 deletions.
  1. +50 −3 chainmgr_test.pl
  2. +49 −3 fwcheck_psad.pl
  3. +48 −2 kmsgsd.pl
  4. +48 −2 psadwatchd.pl
View
53 chainmgr_test.pl
@@ -1,10 +1,13 @@
#!/usr/bin/perl -w
-use lib '/usr/lib/psad';
-use IPTables::ChainMgr;
-use IPTables::Parse;
use strict;
+### path to default psad library directory for psad perl modules
+my $psad_lib_dir = '/usr/lib/psad';
+
+### import psad perl modules
+&import_psad_perl_modules();
+
my $ipt = new IPTables::ChainMgr(
'iptables' => '/sbin/iptables',
'verbose' => 1
@@ -64,3 +67,47 @@
print for @$err_aref;
exit 0;
+
+sub import_psad_perl_modules() {
+
+ my $mod_paths_ar = &get_psad_mod_paths();
+
+ splice @INC, 0, $#$mod_paths_ar+1, @$mod_paths_ar;
+
+ require IPTables::Parse;
+ require IPTables::ChainMgr;
+
+ return;
+}
+
+sub get_psad_mod_paths() {
+
+ my @paths = ();
+
+ unless (-d $psad_lib_dir) {
+ my $dir_tmp = $psad_lib_dir;
+ $dir_tmp =~ s|lib/|lib64/|;
+ if (-d $dir_tmp) {
+ $psad_lib_dir = $dir_tmp;
+ } else {
+ die "[*] psad lib directory: $psad_lib_dir does not exist, ",
+ "use --Lib-dir <dir>";
+ }
+ }
+
+ opendir D, $psad_lib_dir or die "[*] Could not open $psad_lib_dir: $!";
+ my @dirs = readdir D;
+ closedir D;
+ shift @dirs; shift @dirs;
+
+ push @paths, $psad_lib_dir;
+
+ for my $dir (@dirs) {
+ ### get directories like "/usr/lib/psad/x86_64-linux"
+ next unless -d "$psad_lib_dir/$dir";
+ push @paths, "$psad_lib_dir/$dir"
+ if $dir =~ m|linux| or $dir =~ m|thread|;
+ }
+ return \@paths;
+}
+
View
52 fwcheck_psad.pl
@@ -32,12 +32,12 @@
# $Id$
#
-use lib '/usr/lib/psad';
-use Psad;
-use IPTables::Parse;
use Getopt::Long 'GetOptions';
use strict;
+### path to default psad library directory for psad perl modules
+my $psad_lib_dir = '/usr/lib/psad';
+
### default psad config file.
my $config_file = '/etc/psad/psad.conf';
@@ -90,6 +90,9 @@
die '[*] fwcheck_psad.pl: You must be root (or equivalent ',
"UID 0 account) to execute fwcheck_psad.pl! Exiting.\n";
+### import psad perl modules
+&import_psad_perl_modules();
+
if ($fw_file) {
die "[*] iptables dump file: $fw_file does not exist."
unless -e $fw_file;
@@ -357,6 +360,49 @@ ()
return $rv;
}
+sub import_psad_perl_modules() {
+
+ my $mod_paths_ar = &get_psad_mod_paths();
+
+ splice @INC, 0, $#$mod_paths_ar+1, @$mod_paths_ar;
+
+ require Psad;
+ require IPTables::Parse;
+
+ return;
+}
+
+sub get_psad_mod_paths() {
+
+ my @paths = ();
+
+ unless (-d $psad_lib_dir) {
+ my $dir_tmp = $psad_lib_dir;
+ $dir_tmp =~ s|lib/|lib64/|;
+ if (-d $dir_tmp) {
+ $psad_lib_dir = $dir_tmp;
+ } else {
+ die "[*] psad lib directory: $psad_lib_dir does not exist, ",
+ "use --Lib-dir <dir>";
+ }
+ }
+
+ opendir D, $psad_lib_dir or die "[*] Could not open $psad_lib_dir: $!";
+ my @dirs = readdir D;
+ closedir D;
+ shift @dirs; shift @dirs;
+
+ push @paths, $psad_lib_dir;
+
+ for my $dir (@dirs) {
+ ### get directories like "/usr/lib/psad/x86_64-linux"
+ next unless -d "$psad_lib_dir/$dir";
+ push @paths, "$psad_lib_dir/$dir"
+ if $dir =~ m|linux| or $dir =~ m|thread|;
+ }
+ return \@paths;
+}
+
sub import_fw_search() {
open F, "< $fw_search_file" or die "[*] Could not open fw search ",
"string file $fw_search_file: $!";
View
50 kmsgsd.pl
@@ -34,8 +34,6 @@
# $Id$
#
-use lib '/usr/lib/psad';
-use Psad;
use POSIX 'setsid';
use Getopt::Long 'GetOptions';
use strict;
@@ -45,6 +43,9 @@
my $CONFIG_FILE = '/etc/psad/kmsgsd.conf';
my $fw_search_file = '/etc/psad/fw_search.conf';
+### path to default psad library directory for psad perl modules
+my $psad_lib_dir = '/usr/lib/psad';
+
### configuration hash
my %config;
@@ -63,6 +64,9 @@
'config=s' => \$CONFIG_FILE
));
+### import psad perl modules
+&import_psad_perl_modules();
+
### import config
&import_config();
@@ -127,6 +131,48 @@ ()
return 0;
}
+sub import_psad_perl_modules() {
+
+ my $mod_paths_ar = &get_psad_mod_paths();
+
+ splice @INC, 0, $#$mod_paths_ar+1, @$mod_paths_ar;
+
+ require Psad;
+
+ return;
+}
+
+sub get_psad_mod_paths() {
+
+ my @paths = ();
+
+ unless (-d $psad_lib_dir) {
+ my $dir_tmp = $psad_lib_dir;
+ $dir_tmp =~ s|lib/|lib64/|;
+ if (-d $dir_tmp) {
+ $psad_lib_dir = $dir_tmp;
+ } else {
+ die "[*] psad lib directory: $psad_lib_dir does not exist, ",
+ "use --Lib-dir <dir>";
+ }
+ }
+
+ opendir D, $psad_lib_dir or die "[*] Could not open $psad_lib_dir: $!";
+ my @dirs = readdir D;
+ closedir D;
+ shift @dirs; shift @dirs;
+
+ push @paths, $psad_lib_dir;
+
+ for my $dir (@dirs) {
+ ### get directories like "/usr/lib/psad/x86_64-linux"
+ next unless -d "$psad_lib_dir/$dir";
+ push @paths, "$psad_lib_dir/$dir"
+ if $dir =~ m|linux| or $dir =~ m|thread|;
+ }
+ return \@paths;
+}
+
sub import_config() {
### read in the configuration file
View
50 psadwatchd.pl
@@ -33,13 +33,14 @@
# $Id$
#
-use lib '/usr/lib/psad';
-use Psad;
use POSIX qw(setsid);
use Getopt::Long 'GetOptions';
use Sys::Hostname 'hostname';
use strict;
+### path to default psad library directory for psad perl modules
+my $psad_lib_dir = '/usr/lib/psad';
+
### establish the default path to the config file (can be
### over-ridden with the -c <file> command line option.
my $config_file = '/etc/psad/psadwatchd.conf';
@@ -72,6 +73,9 @@
'config=s' => \$config_file
));
+### import psad perl modules
+&import_psad_perl_modules();
+
### import config
&import_config();
@@ -164,6 +168,48 @@ ()
return;
}
+sub import_psad_perl_modules() {
+
+ my $mod_paths_ar = &get_psad_mod_paths();
+
+ splice @INC, 0, $#$mod_paths_ar+1, @$mod_paths_ar;
+
+ require Psad;
+
+ return;
+}
+
+sub get_psad_mod_paths() {
+
+ my @paths = ();
+
+ unless (-d $psad_lib_dir) {
+ my $dir_tmp = $psad_lib_dir;
+ $dir_tmp =~ s|lib/|lib64/|;
+ if (-d $dir_tmp) {
+ $psad_lib_dir = $dir_tmp;
+ } else {
+ die "[*] psad lib directory: $psad_lib_dir does not exist, ",
+ "use --Lib-dir <dir>";
+ }
+ }
+
+ opendir D, $psad_lib_dir or die "[*] Could not open $psad_lib_dir: $!";
+ my @dirs = readdir D;
+ closedir D;
+ shift @dirs; shift @dirs;
+
+ push @paths, $psad_lib_dir;
+
+ for my $dir (@dirs) {
+ ### get directories like "/usr/lib/psad/x86_64-linux"
+ next unless -d "$psad_lib_dir/$dir";
+ push @paths, "$psad_lib_dir/$dir"
+ if $dir =~ m|linux| or $dir =~ m|thread|;
+ }
+ return \@paths;
+}
+
sub get_psad_Cmdline() {
my $psad_cmd_file = shift;
my $noexit=0;
Please sign in to comment.
Something went wrong with that request. Please try again.