From de1ed613f8622ff34424b74d7400a121076e8e99 Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Fri, 28 Oct 2022 23:22:55 -0500 Subject: [PATCH] Revise main code to prepare for future improvements --- gatekeeper.pl | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/gatekeeper.pl b/gatekeeper.pl index d94e99e..f02b8b6 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -2386,14 +2386,18 @@ foreach my $packet (@packets) { # each list element is an array reference my $stem = substr $packet->[0],0,-(length '.directive.asc'); ftp_syslog('info',"found directive: $packet->[0]"); + # variables preserved for the report if an exception is thrown + my $directive_text; my $directive; my $sig_info; my $oplist; my $op_header; + my $complete = 0; # direct flag to indicate successful processing + # scaffolding to be cleaned up as the internal API is improved my $directive_only = (1 == scalar @$packet); my $directive_file = $packet->[0]; my $upload_file = ''; my $sig_file = ''; eval { # trap exceptions encountered while processing a packet - my $directive_text = slurp_clearsigned_message($packet->[0]); - my $directive = read_directive_from_string($directive_text); + $directive_text = slurp_clearsigned_message($packet->[0]); + $directive = read_directive_from_string($directive_text); # This would imply that the directive file did not contain a signed # message. There is nothing further to do. @@ -2409,8 +2413,8 @@ foreach my $packet (@packets) { # each list element is an array reference # this function just updates $info{email} guess_email_address_from_signature($directive_text); - my $oplist = interpret_directive($directive, $directive_text); - my $op_header = $oplist->[0][1]; + $oplist = interpret_directive($directive, $directive_text); + $op_header = $oplist->[0][1]; # Phone home. E-mail the contents of the directive file to the maintainer, # for debugging purposes. After this point, we don't need to pass the @@ -2427,14 +2431,14 @@ foreach my $packet (@packets) { # each list element is an array reference my @keyrings = directory_keyrings($op_header->{directory}); fatal("no keyring for package $op_header->{package}",0) if ($#keyrings < 0); - my $result = verify_clearsigned_message($directive_text, @keyrings); + $sig_info = verify_clearsigned_message($directive_text, @keyrings); fatal("gpg verify of directive file failed",1,'',2) - if $result->{exitcode} != 0 || defined $result->{TILT}; + if $sig_info->{exitcode} != 0 || defined $sig_info->{TILT}; fatal("gpg verification problem: could not extract timestamp",1) - unless defined $result->{sig_creation}; + unless defined $sig_info->{sig_creation}; - check_replay($oplist, $result->{sig_creation}); + check_replay($oplist, $sig_info->{sig_creation}); if ($oplist) { # do the work @@ -2447,16 +2451,20 @@ foreach my $packet (@packets) { # each list element is an array reference success_directive($directive_file); } } + $complete = 1; }; - ftp_warn ("eval failed: $@") - if $@; - # clean up files if we abort while processing a triplet - cleanup ($sig_file, $upload_file, $directive_file) - if ($@); + unless ($complete) { + ftp_warn ("eval failed: $@"); + + # clean up files if we abort while processing a triplet + cleanup ($sig_file, $upload_file, $directive_file) + } + # clear out the current package that we just finished processing undef %info; } + if ((scalar @packets) == 0) { ftp_syslog('info', "No files found for processing."); } else { -- 2.25.1