From 8b9738392ac203950da45b9eba8020c8cc1f73c2 Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Fri, 21 Oct 2022 22:02:55 -0500 Subject: [PATCH] Begin to revise check_files, install_files, execute_commands This commit removes the local %info hashes in these functions. --- gatekeeper.pl | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/gatekeeper.pl b/gatekeeper.pl index 9bd470d..2b743d1 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -1783,7 +1783,6 @@ sub check_vulnerabilities { sub check_files { my $header = shift; my $files = shift; - my %info = @_; my ($sig_file,$upload_file) = ($files->{"sig"}, $files->{"upload"}); my $sig_file_size = -s $sig_file; @@ -1794,8 +1793,8 @@ sub check_files { ftp_syslog('debug', "DEBUG: " ."$upload_file size is $upload_file_size") if DEBUG; - my @keyrings = keyring_file ($info{package},$info{directory}); - fatal("no keyring for package $info{package}",0) if ($#keyrings < 0); + my @keyrings = keyring_file ($header->{package},$header->{directory}); + fatal("no keyring for package $header->{package}",0) if ($#keyrings < 0); my $valid = 0; foreach my $keyring (@keyrings) { @@ -1857,10 +1856,9 @@ sub archive { sub install_files { my $header = shift; my $files = shift; - my %info = @_; my ($sig_file,$upload_file) = ($files->{"sig"}, $files->{"upload"}); - my $destdir = "$destfinal/$info{directory}"; + my $destdir = "$destfinal/$header->{directory}"; # File::Path is 200 lines of Perl and requires reading an external # text file. In my mind, it is a toss-up as to whether that or # forking the system mkdir is safer. We could debate endlessly, @@ -1873,25 +1871,25 @@ sub install_files { # We now allow overwriting of files - without warning!! if (-e "$destdir/$sig_file") { - if (not exists($info{'replace'}) or ($info{'replace'} ne 'true')) { - fatal("This signature file exists: $destdir/$sig_file, if you want to " - ."replace the pair please use the 'replace' directive",1); - } else { - archive($destdir, $info{directory}, $sig_file); + if ($header->{options}{replace}) { + archive($destdir, $header->{directory}, $sig_file); ftp_syslog('info', "archived and overwrote " ."$destdir/$sig_file with uploaded version"); $t1 = 1; + } else { + fatal("This signature file exists: $destdir/$sig_file, if you want to " + ."replace the pair please use the 'replace' directive",1); } } if (-e "$destdir/$upload_file") { - if (not exists($info{'replace'}) or ($info{'replace'} ne 'true')) { - fatal("This file exists: $destdir/$upload_file, if you want to " - ."replace the pair please use the 'replace' directive",1); - } else { - archive($destdir, $info{directory}, $upload_file); + if ($header->{options}{replace}) { + archive($destdir, $header->{directory}, $upload_file); ftp_syslog('info', "overwrote " ."$destdir/$upload_file with uploaded version"); $t2 = 1; + } else { + fatal("This file exists: $destdir/$upload_file, if you want to " + ."replace the pair please use the 'replace' directive",1); } } my $notification_str = ''; @@ -1922,16 +1920,9 @@ sub install_files { } } -# Actual executing of commands. Respects the cronological order -# they were specified in, thanks to the 'order' value in the %info -# hash sub execute_commands { my $oplist = shift; my $files = shift; - my %info = @_; - - # Keep the hash as temporary scaffolding for check_files & install_files - my %originfo = %info; ftp_abort("invalid internal operation list") unless $oplist->[0][0] eq 'header'; @@ -1940,8 +1931,8 @@ sub execute_commands { my $destdir = "$destfinal/$header->{directory}"; foreach my $step (@{$oplist}[1..$#$oplist]) { # skip the header if ($step->[0] eq 'install') { - check_files($header, $files, %originfo); - install_files($header, $files, %originfo); + check_files($header, $files); + install_files($header, $files); } elsif ($step->[0] eq 'symlink') { my $target = $step->[1]; my $linkname = $step->[2]; @@ -2088,8 +2079,7 @@ foreach my $packet (@packets) { # each list element is an array reference # do the work execute_commands($oplist, {directive => $directive_file, upload => $upload_file, - sig => $sig_file, directive_only => $directive_only}, - %info); + sig => $sig_file, directive_only => $directive_only}); # report success if (!$directive_only) { -- 2.25.1