This file is indexed.

/usr/share/perl5/Lire/OldDlfAdapter.pm is in lire 2:2.1.1-2.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
package Lire::OldDlfAdapter;

use strict;

use base qw/ Lire::DlfConverter /;

use Carp;

use Fcntl;
use File::Basename qw/ basename /;
use Symbol;

use Lire::DlfSchema;
use Lire::Utils qw/ tempdir check_param /;
use Lire::DataTypes qw/ check_superservice /;
use File::Path qw/rmtree/;

=pod

=head1 NAME

Lire::OldDlfAdapter - Module which bridges with old-style DLF converters

=head1 SYNOPSIS

  my $converter = new Lire::OldDlfAdatper( "www",
                                           "/usr/libexec/lire/converters/combined2dlf" );

=head1 DESCRIPTION

This class can be used to integrate the script-based old-style DLF
converters to the new API.

=head2 new( $schema, $script )

The constructor takes the schema's supported by the script and the
path to the script which implements the DLF converter.

=cut

sub new {
    my ( $class, $schema, $script ) = @_;

    check_param( $schema, 'schema',
                 sub { Lire::DlfSchema->has_schema( $_[0] ); },
                 'invalid schema name' );
    check_param( $script, 'script', sub { -x $_[0] },
                 'script is not executable' );

    my ($name) = basename( $script );
    croak "invalid script name: $script (should be <service>2dlf)"
      unless $name =~ /^(\w+)2dlf$/;

    my $self = bless { '_name'   => $1,
                       '_script' => $script,
                       '_schema' => $schema,
                     }, ref $class || $class;
    return $self;
}

#------------------------------------------------------------------------
# Method name()
#
# Required by Lire::DlfConverter.
sub name {
    $_[0]{'_name'};
}

=pod

=head2 script()

Returns the path to the script which is used to create the DLF records

=cut

sub script {
    $_[0]{'_script'};
}

#------------------------------------------------------------------------
# Method title()
#
# Required by Lire::DlfConverter.
sub title {
    "$_[0]{'_name'} log file";
}

#------------------------------------------------------------------------
# Method description()
#
# Required by Lire::DlfConverter.
sub description {
    "<para>Adapter for old-style DLF converter $_[0]{'_script'}.</para>";
}

#------------------------------------------------------------------------
# Method schemas()
#
# Required by Lire::DlfConverter.
sub schemas {
    ( $_[0]{'_schema'} );
}


#------------------------------------------------------------------------
# Method handle_log_lines()
#
# Required by Lire::DlfConverter.
sub handle_log_lines { 1 }

#------------------------------------------------------------------------
# Method init_dlf_converter( $process )
#
# Required by Lire::DlfConverter.
sub init_dlf_converter {
    my ( $self, $process ) = @_;

    my $schema = Lire::DlfSchema::load_schema( $self->{'_schema'} );
    $self->{'_field_names'} = [];
    foreach my $f ( $schema->fields ) {
        push @{$self->{'_field_names'}}, $f->name;
    }

    $self->{'_dlffile'} = undef;
    $self->{'_logfile'} = undef;
    $self->{'_tmpdir'} = tempdir( $self->{'_name'} . "_XXXXXX" );
    open( $self->{'_dlffile'}, "+> $self->{'_tmpdir'}/$self->{'_name'}.dlf" )
      or die "can't open temporary dlf file: $!\n";
    open( $self->{'_logfile'}, "+> $self->{'_tmpdir'}/$self->{'_name'}.log" )
      or die "can't open temporary log file: $!\n";

    my ($read_fh, $write_fh) = ( gensym, gensym );
    pipe( $read_fh, $write_fh )
      or die "pipe failed: $!\n";
    $self->{'_convert_pid'} = fork;
    die "fork failed: $!\n" unless defined $self->{'_convert_pid'};
    if ( !$self->{'_convert_pid'} ) {
        close $write_fh;
        open( STDIN, "<&". fileno( $read_fh ) )
          or die "cannot redirect STDIN to pipe: $!\n";
        close $read_fh;
        open( STDOUT, ">&" . fileno( $self->{'_dlffile'} ) )
          or die "cannot redirect STDOUT to file: $!\n";
        close $self->{'_dlffile'};
        open( STDERR, ">&" . fileno( $self->{'_logfile'} ) )
          or die "cannot redirect STDERR to file:\n";
        close $self->{'_logfile'};
        exec( $self->{'_script'} )
          or die "exec $self->{'_script'} failed: $!\n";
    }
    close $read_fh;

    $self->{'_convert_fh'} = $write_fh;
}

#------------------------------------------------------------------------
# Method process_log_line( $process, $line )
#
# Required by Lire::DlfConverter.
sub process_log_line {
    my ( $self, $process, $line ) = @_;

    print {$self->{'_convert_fh'}} $line, "\n"
      or die "error while sending data to old dlf converter: $!\n";

    return;
}

#------------------------------------------------------------------------
# Method finish_conversion( $process )
#
# Required by Lire::DlfConverter.
sub finish_conversion {
    my ( $self, $process ) = @_;

    close $self->{'_convert_fh'}
      or die "closing pipe failed: $!\n";
    waitpid $self->{'_convert_pid'}, 0
      or die "waitpid failed: $!\n";
    my $status = $?;

    $self->_import_dlf( $process );
    $self->_import_errors( $process );

    die "old-style DLF converter exited with non-zero status: $?\n"
      if $status;

    rmtree( $self->{'_tmpdir'} );

    return;
}

sub _import_dlf {
    my ($self, $process)  = @_;

    my $fh = $self->{'_dlffile'};
    seek $fh, 0, 0
      or die "can't rewind temporary DLF file: $!\n";

    my $field_count = @{$self->{'_field_names'}};
    my $line;
    while ( defined( $line = <$fh>) ) {
        chomp $line;
        my %r = ();
        my $i=0;
        foreach my $v ( split / /, $line ) {
            $r{$self->{'_field_names'}[$i++]} =
              $v eq 'LIRE_NOTAVAIL' ? undef : $v;
        }
        if ($i != $field_count ) {
            $process->error( "only $i fields when $field_count expected",
                             $line );
        } else {
            $process->write_dlf( $self->{'_schema'}, \%r );
        }
    }
}

sub _import_errors {
    my ( $self,$process ) = @_;

    my $fh = $self->{'_logfile'};
    seek $fh, 0, 0
      or die "can't rewind temporary log file: $!\n";
    my $line;
    while (defined ( $line = <$fh> ) ) {
        chomp $line;
        my ($super,$service,$id,$prog,$level, $msg ) = split /\s+/, $line, 6;
        next unless $level =~ /^(crit|err|warning)$/;
        $process->error( $msg );
    }
}

# keep perl happy
1;

__END__

=pod

=head1 SEE ALSO

Lire::DlfConverterProcess(3pm), Lire::DlfStore(3pm), Lire::ImportJob(3pm),
Lire::PluginManager(3pm), Lire::DlfConverter(3pm)

=head1 AUTHOR

  Francis J. Lacoste <flacoste@logreport.org>

=head1 VERSION

$Id: OldDlfAdapter.pm,v 1.17 2006/07/23 13:16:29 vanbaal Exp $

=head1 COPYRIGHT

Copyright (C) 2002 Stichting LogReport Foundation LogReport@LogReport.org

This file is part of Lire.

Lire is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program (see COPYING); if not, check with
http://www.gnu.org/copyleft/gpl.html.

=cut