This file is indexed.

/usr/share/perl5/App/Parcimonie.pm is in parcimonie 0.8.4-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package App::Parcimonie;

use warnings;
use strict;

use App::Parcimonie::GnuPG::Interface;
use Carp;
use Clone qw{clone};
use Config::General qw/ParseConfig/;
use Encode;
use English qw/-no_match_vars/;
use File::HomeDir;
use List::MoreUtils qw/uniq/;
use List::Util qw/shuffle/;
use Path::Tiny;
use Try::Tiny;

use Exporter;
our @ISA = qw(Exporter);

use namespace::clean;


=head1 NAME

App::Parcimonie - tools for the parcimonie program

=head1 SYNOPSIS

See bin/parcimonie :)

=head1 EXPORT

=cut

our @EXPORT = qw/pickRandomItems gpgPublicKeys gpgRecvKeys
                 checkGpgHasDefinedKeyserver averageLapseTime/;

my $codeset;
try {
    require I18N::Langinfo;
    I18N::Langinfo->import(qw(langinfo CODESET));
    $codeset = langinfo(CODESET());
} catch {
    croak "No default character code set configured.\nPlease fix your locale settings.";
};


=head1 SUBROUTINES

=head2 pickRandomItems(N, @list)

Returns a list of N unique items picked at random from the input list.

=cut

sub pickRandomItems {
    my $n = shift;
    my @randomized_pool = shuffle(uniq(@_));

    defined $n
        or croak "pickRandomItems must be passed at least one argument";
    $n =~ m/[0-9]+/
        or croak "pickRandomItems must be passed an integer";
    $n <= @randomized_pool
        or croak "pickRandomItems can't return more unique items than you feed it";

    return @randomized_pool[0..$n - 1];
}

=head2 gpgPublicKeys()

Returns the list of key fingerprints found in the public keyring.

Args:
  - $gnupg_options: reference to a hash passed to ->hash_init

=cut

sub gpgPublicKeys {
    my $gnupg_options = shift;
    my %gi_args       = @_;

    my $gnupg = App::Parcimonie::GnuPG::Interface->new(%gi_args);
    $gnupg->options->hash_init(%{ clone($gnupg_options) });
    $gnupg->get_public_keys_hex();
}

=head2 gpgRecvKeys( @keyids )

Imports the keys with the given key IDs from a keyserver.

Args:
  - $keyids: reference to an array of key IDs
  - $gnupg_options: reference to a hash passed to ->hash_init

=cut

sub gpgRecvKeys {
    my $keyids        = shift;
    my $gnupg_options = shift;
    my %gi_args       = @_;

    my $gnupg = App::Parcimonie::GnuPG::Interface->new(%gi_args);
    $gnupg->options->hash_init(%{ clone($gnupg_options) });
    my $err_h = IO::Handle->new();
    my $handles = GnuPG::Handles->new(stderr => $err_h);
    my $pid = $gnupg->recv_keys( handles => $handles, command_args => $keyids );

    my @raw_stderr = <$err_h>;  # reading the output
    close $err_h;

    waitpid $pid, 0;  # clean up the finished GnuPG process

    my $std_err = decode($codeset, join('', @raw_stderr));

    # Filter out lines such as:
    # 11:21:19 libtorsocks(27234): The symbol res_query() was not found...
    $std_err =~ s{
                     ^                  # anchor at a line beginning
                     [[:digit:]]{2}
                     [:]
                     [[:digit:]]{2}     # time such as 11:21:19
                     [:]
                     [[:digit:]]{2}
                     [[:space:]]+
                     libtorsocks
                     [(]
                     [[:digit:]]+       # PID surrounded by parenthesis
                     [)]
                     [:]
                     [[:space:]]+
                     [^\n]*             # anything but a line break
                     $
                     [\n]?
             }{}xmsg;

    no warnings;
    unless ($CHILD_ERROR == 0) {
        use warnings;
        croak $std_err;
    }
    use warnings;

    return $std_err;
}

=head2 checkGpgHasDefinedKeyserver

Throws an exception if no keyserver is defined in GnuPG configuration.

=cut

sub checkGpgHasDefinedKeyserver {
    my $arg_ref = shift;
    my $gnupg_homedir = $arg_ref->{homedir};

    my $gpgconf;
    if (defined $gnupg_homedir) {
        $gpgconf = path($gnupg_homedir, 'gpg.conf');
    }
    else {
        $gpgconf = path(File::HomeDir->my_home, '.gnupg', 'gpg.conf');
    }

    -f $gpgconf
        or croak "No GnuPG configuration file was found in '$gpgconf'";
    -r $gpgconf
        or croak "The GnuPG configuration file ($gpgconf) is not readable";

    my %gpgconf = ParseConfig($gpgconf);

    defined $gpgconf{keyserver} && length $gpgconf{keyserver}
        or croak
            "No keyserver is defined in GnuPG configuration ($gpgconf).\n" .
            "See 'man parcimonie' to learn how to correct that.";

    return;
}

=head2 averageLapseTime

Argument: number of public keys in the keyring.
Returns the desirable average lapse time (in seconds) between two key
fetches.

=cut

sub averageLapseTime {
    604800 / shift;     # 1 week = 604800 seconds
}

1; # End of App::Parcimonie