Permalink
Browse files

matched all chdir() calls with getcwd() for easier test suite support

  • Loading branch information...
1 parent f2cf933 commit ef9d2dbc60e1e41a6e37dcd09cd6a496051a4c4a @mrash committed Apr 20, 2012
Showing with 19 additions and 2 deletions.
  1. +19 −2 psad
View
21 psad
@@ -143,7 +143,7 @@ use strict;
### ========================== main =================================
-### set the current psad version and file revision numbers
+### set the current version
my $version = '2.2';
### default config file for psad (can be changed with
@@ -3111,6 +3111,7 @@ sub import_perl_modules() {
require NetAddr::IP;
require Date::Calc;
require Unix::Syslog;
+ require Cwd;
require Storable if $store_file;
Date::Calc->import(qw(Timezone This_Year Decode_Month
@@ -8881,6 +8882,8 @@ sub import_ip_dirs() {
closedir D;
my $import_ctr = 0;
+
+ my $curr_pwd = getcwd();
chdir $config{'PSAD_DIR'} or die $!;
SRCIP: for my $src (@files) {
@@ -9046,6 +9049,8 @@ sub import_ip_dirs() {
}
$import_ctr++;
}
+ chdir $curr_pwd or die $!;
+
return;
}
@@ -9313,12 +9318,14 @@ sub remove_old_scans() {
my @files = readdir D;
closedir D;
+ my $curr_pwd = getcwd();
chdir $config{'PSAD_DIR'} or die $!;
SRCIP: for my $src (@files) {
next SRCIP unless ($src =~ /$ipv4_re/ and -d $src);
rmtree $src or die
"[*] Could not remove $config{'PSAD_DIR'}/$src: $!";
}
+ chdir $curr_pwd or die $!;
return;
}
@@ -9408,6 +9415,8 @@ sub warn_handler() {
}
sub archive_data() {
+
+ my $curr_pwd = getcwd();
chdir $config{'PSAD_DIR'} or die "[*] Could not chdir ",
"$config{'PSAD_DIR'}: $!";
unless (-d $config{'SCAN_DATA_ARCHIVE_DIR'}) {
@@ -9457,6 +9466,7 @@ sub archive_data() {
&truncate_file($fwarchive) unless $config{'ENABLE_SYSLOG_FILE'} eq 'Y';
}
unless (-e $fwdata) {
+ chdir $curr_pwd or die $!;
return;
}
open FW, "< $fwdata" or die "$fwdata exists but couldn't open it: $!";
@@ -9465,6 +9475,8 @@ sub archive_data() {
open AR, ">> $fwarchive" or die "Could not open $fwarchive: $!";
print AR $_ for @fwlines;
close AR;
+
+ chdir $curr_pwd or die $!;
return;
}
@@ -9825,6 +9837,8 @@ sub truncate_file() {
}
sub disk_space_exceeded() {
+
+ my $curr_pwd = getcwd();
my @df_data = @{&run_command($cmds{'df'}, $config{'PSAD_DIR'})};
my ($prcnt) = ($df_data[$#df_data] =~ /(\d+)%/);
my $rv = 0;
@@ -9894,6 +9908,7 @@ sub disk_space_exceeded() {
### the disk check interval was exceeded but the utilization is ok.
$rm_data_ctr = 0;
}
+ chdir $curr_pwd or die $!;
return $rv;
}
@@ -10123,6 +10138,7 @@ sub download_signatures() {
### for wget
&check_commands({'sendmail'=>'', 'mail'=>''});
+ my $curr_pwd = getcwd();
chdir '/tmp' or die $!;
print "[+] Downloading latest signatures from:\n",
@@ -10143,6 +10159,8 @@ sub download_signatures() {
" place. You can restart psad (or use 'psad -H') to import the\n",
" new sigs.\n";
+ chdir $curr_pwd or die $!;
+
return 0;
}
@@ -10177,7 +10195,6 @@ sub date_time() {
sub archive_conf() {
my $file = shift;
- require Cwd;
my $curr_pwd = getcwd();
chdir $config{'CONF_ARCHIVE_DIR'} or die $!;
my ($filename) = ($file =~ m|.*/(.*)|);

0 comments on commit ef9d2db

Please sign in to comment.