This file is indexed.

/usr/share/perl5/Mail/MtPolicyd/PluginChain.pm is in mtpolicyd 2.02-3.

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
package Mail::MtPolicyd::PluginChain;

use Moose;
use namespace::autoclean;

our $VERSION = '2.02'; # VERSION
# ABSTRACT: class for a VirtualHost instance

use Mail::MtPolicyd::Profiler;
use Mail::MtPolicyd::Result;

has 'plugins' => (
	is => 'ro',
	isa => 'ArrayRef[Mail::MtPolicyd::Plugin]',
	default => sub { [] },
	traits => [ 'Array' ],
	handles => {
		'add_plugin' => 'push',
	}
);

has 'plugin_prefix' => (
	is => 'ro', isa => 'Str', default => 'Mail::MtPolicyd::Plugin::',
);

has 'vhost_name' => ( is => 'rw', isa => 'Maybe[Str]' );

sub run {
	my ( $self, $r ) = @_;
	my $result = Mail::MtPolicyd::Result->new;

	foreach my $plugin ( @{$self->plugins} ) {
		my $abort = 0;
        Mail::MtPolicyd::Profiler->new_timer('plugin '.$plugin->name);
        my @plugin_results;
        eval { @plugin_results = $plugin->run($r); };
        my $e = $@;
        if( $e ) {
            my $msg = 'plugin '.$plugin->name.' failed: '.$e;
            if( ! defined $plugin->on_error || $plugin->on_error ne 'continue' ) {
                die($msg);
            }
            $r->log(0, $msg);
        }
        Mail::MtPolicyd::Profiler->stop_current_timer;
    if( scalar @plugin_results ) {
      $result->last_match( $plugin->name );
    }
		foreach my $plugin_result ( @plugin_results ) {
			$result->add_plugin_result($plugin_result);
			if( $plugin_result->abort ) {
				$abort = 1;
			}
		}
		if( $abort ) { last; }
	}

	return $result;
}

sub cron {
    my $self = shift;
    my $server = shift;

    foreach my $plugin ( @{$self->plugins} ) {
        $server->log(3, 'running cron for plugin '.$plugin->name);
        eval { $plugin->cron( $server, @_ ); };
        my $e = $@;
        if( $e ) {
            $server->log(0, 'plugin '.$plugin->name.' failed in cron: '.$e );
        }
    }
	return;
}

sub load_plugin {
	my ( $self, $plugin_name, $params ) = @_;
	if( ! defined $params->{'module'} ) {
		die('no module defined for plugin '.$plugin_name.'!');
	}
	my $module = $params->{'module'};
	my $plugin_class = $self->plugin_prefix.$module;
	my $plugin;

	my $code = "require ".$plugin_class.";";
	eval $code; ## no critic (ProhibitStringyEval)
	if($@) {
        die('could not load module '.$module.' for plugin '.$plugin_name.': '.$@);
    }

	eval {
        $plugin = $plugin_class->new(
            name => $plugin_name,
            vhost_name => $self->vhost_name,
            %$params,
        );
        $plugin->init();
    };
    if($@) {
        die('could not initialize plugin '.$plugin_name.': '.$@);
    }
	$self->add_plugin($plugin);
	return;
}

sub new_from_config {
	my ( $class, $vhost_name, $config ) = @_;

	my $self = $class->new( vhost_name => $vhost_name );

	if( ! defined $config ) {
		return( $self );
	}

	if( ref($config) ne 'HASH' ) {
		die('config must be an hashref!');
	}

	foreach my $plugin_name ( keys %{$config} ) {
		$self->load_plugin($plugin_name,
			$config->{$plugin_name} );
	}

	return $self;
}

__PACKAGE__->meta->make_immutable;

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Mail::MtPolicyd::PluginChain - class for a VirtualHost instance

=head1 VERSION

version 2.02

=head1 AUTHOR

Markus Benning <ich@markusbenning.de>

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>.

This is free software, licensed under:

  The GNU General Public License, Version 2, June 1991

=cut