From 303914d0e7e69a2bf0de4eae221af5fc5af7bdb4 Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Thu, 27 Oct 2022 22:59:19 -0500 Subject: [PATCH] Factor scanning loop out of directory_keyrings This allows the same loop to be used to support other per-directory items. --- gatekeeper.pl | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/gatekeeper.pl b/gatekeeper.pl index f5007f8..471685f 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -873,31 +873,43 @@ sub verify_clearsigned_message { # - Package configuration access # -=item @keyrings = directory_keyrings ( $directory ) +=item @files = directory_configuration_files ( $file, $directory ) -Return list of keyrings present in package configuration and applicable to -DIRECTORY, which is a relative name beginning with the appropriate package. +Return list of FILEs applicable to DIRECTORY. The rule used is that each +FILE applies to its own directory and is inherited by all subdirectories. =cut -sub directory_keyrings { +sub directory_configuration_files { + my $file = shift; my $directory = shift; - my @keyrings; my @candidates; for (my @directory = File::Spec::Unix->splitdir($directory); @directory; pop @directory) { push @candidates, File::Spec->catfile - ($package_config_base, @directory, 'pubring.gpg') } - push @candidates, File::Spec->catfile($package_config_base, 'pubring.gpg'); + ($package_config_base, @directory, $file) } + push @candidates, File::Spec->catfile($package_config_base, $file); - foreach my $keyring (@candidates) { - if (-f $keyring) { - ftp_syslog('debug', "DEBUG: found keyring $keyring") if DEBUG; - push @keyrings, $keyring; - } + return grep -f $_ && -r _ && -s _, @candidates; +} + +=item @keyrings = directory_keyrings ( $directory ) + +Return list of keyrings present in package configuration and applicable to +DIRECTORY, which is a relative name beginning with the appropriate package. + +=cut + +sub directory_keyrings { + my $directory = shift; + + my @keyrings = directory_configuration_files('pubring.gpg', $directory); + + if (DEBUG) { + ftp_syslog('debug', "DEBUG: found keyring $_") for @keyrings; } return @keyrings; -- 2.25.1