This file is indexed.

/usr/lib/amanda/perl/Amanda/Archive.pm is in amanda-common 1:3.3.6-4.

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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 3.0.2
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.

package Amanda::Archive;
use base qw(Exporter);
use base qw(DynaLoader);
package Amanda::Archivec;
bootstrap Amanda::Archive;
package Amanda::Archive;
@EXPORT = qw();

# ---------- BASE METHODS -------------

package Amanda::Archive;

sub TIEHASH {
    my ($classname,$obj) = @_;
    return bless $obj, $classname;
}

sub CLEAR { }

sub FIRSTKEY { }

sub NEXTKEY { }

sub FETCH {
    my ($self,$field) = @_;
    my $member_func = "swig_${field}_get";
    $self->$member_func();
}

sub STORE {
    my ($self,$field,$newval) = @_;
    my $member_func = "swig_${field}_set";
    $self->$member_func($newval);
}

sub this {
    my $ptr = shift;
    return tied(%$ptr);
}


# ------- FUNCTION WRAPPERS --------

package Amanda::Archive;

*amar_new = *Amanda::Archivec::amar_new;
*amar_size = *Amanda::Archivec::amar_size;
*amar_close = *Amanda::Archivec::amar_close;
*amar_new_file = *Amanda::Archivec::amar_new_file;
*amar_file_size = *Amanda::Archivec::amar_file_size;
*amar_file_close = *Amanda::Archivec::amar_file_close;
*amar_new_attr = *Amanda::Archivec::amar_new_attr;
*amar_attr_size = *Amanda::Archivec::amar_attr_size;
*amar_attr_close = *Amanda::Archivec::amar_attr_close;
*amar_attr_add_data_buffer = *Amanda::Archivec::amar_attr_add_data_buffer;
*amar_attr_add_data_fd = *Amanda::Archivec::amar_attr_add_data_fd;
*amar_attr_add_data_fd_in_thread = *Amanda::Archivec::amar_attr_add_data_fd_in_thread;
*amar_read = *Amanda::Archivec::amar_read;
*amar_read_to = *Amanda::Archivec::amar_read_to;
*amar_stop_read = *Amanda::Archivec::amar_stop_read;
*amar_start_read = *Amanda::Archivec::amar_start_read;
*destroy_read_cb = *Amanda::Archivec::destroy_read_cb;
*set_amar_read_cb = *Amanda::Archivec::set_amar_read_cb;

# ------- VARIABLE STUBS --------

package Amanda::Archive;

*AMAR_ATTR_FILENAME = *Amanda::Archivec::AMAR_ATTR_FILENAME;
*AMAR_ATTR_EOF = *Amanda::Archivec::AMAR_ATTR_EOF;
*AMAR_ATTR_GENERIC_DATA = *Amanda::Archivec::AMAR_ATTR_GENERIC_DATA;
*AMAR_ATTR_RMAN_DATA = *Amanda::Archivec::AMAR_ATTR_RMAN_DATA;

@EXPORT_OK = ();
%EXPORT_TAGS = ();


=head1 NAME

Amanda::Archive - Perl access to the  amanda archive library

=head1 SYNOPSIS

  use Amanda::Archive

  # Write to the file descriptor or file handle $fd, and
  # add /etc/hosts to it
  my $archive = Amanda::Archive->new($fd, ">");
  my $file = $archive->new_file("/etc/hosts");
  my $attr = $file->new_attr(16);
  open(my $fh, "<", "/etc/hosts");
  $attr->add_data_fd($fh, 1);
  $file->close();
  $archive->close();

  # Read from an archive
  my $archive = Amanda::Archive->new($fd, "<");
  $ar->read(
      file_start => sub {
	  my ($user_data, $filenum, $filename) = @_;
	  # ...
	  return "foo"; # this becomes $file_data
      },
      file_finish => sub {
	  my ($user_data, $file_data, $filenum, $truncated) = @_;
	  # ...
      },
      21 => [ 32768,	# buffer into 32k chunks
	      sub {
		  my ($user_data, $filenum, $file_data, $attrid,
		      $attr_data, $data, $eoa, $truncated) = @_;
		  return "pants"; # becomes the new $attr_data for
				  # any subsequent fragments
	      } ],
      0 => sub {	# note no buffering here; attrid 0 is "default"
	  my ($user_data, $filenum, $file_data, $attrid,
	      $attr_data, $data, $eoa, $truncated) = @_;
	  return "shorts"; # becomes the new $attr_data for
			   # any subsequent fragments
      },
      user_data => [ "mydata" ], # sent to all callbacks
  );

=head1 WRITING

=head2 Amanda::Archive::Archive Objects

Note that C<< Amanda::Archive->new >> and C<<
Amanda::Archive::Archive->new >> are equivalent.

=over

=item C<new($fd, $mode)>

Create a new archive for reading ("<") or writing (">") from or to
file C<$fd> (a file handle or integer file descriptor).

=item C<size()>

Return the number of bytes already written to the archive.

=item C<new_file($filename, $want_posn)>

Create a new C<Amanda::Archive::File> object with the given filename
(writing only).  Equivalent to

  Amanda::Archive::File->new($archive, $filename, $want_posn);

if C<$want_posn> is false, then this method returns a new
C<Amanda::Archive::File> object.  If C<$want_posn> is true, then it
returns C<($file, $posn)> where C<$file> is the object and C<$posn> is
the offset into the datastream at which this file begins.  This offset
can be stored in an index and used later to seek into the file.

=item C<read(..)>

See I<READING>, below.

=item C<close()>

Flush all buffers and close this archive. This does not close the file
descriptor.

=back

=head2 Amanda::Archive::File Objects

=over

=item C<new($archive, $filename, $want_posn)>

Create a new file in the given archive.  See
C<Amanda::Archive::Archive::new_file>, above.

=item C<new_attr($attrid)>

Create a new C<Amanda::Archive::Attribute> object.  Equivalent to

  Amanda::Archive::Attr->new($file, $attrid);

=item C<size()>

Return the size on the archive of all attributes of the file.

=item C<close()>

Close this file, writing an EOF record.

=back

=head2 Amanda::Archive::Attribute Objects

=over

=item C<add_data($data, $eoa)>

Add C<$data> to this attribute, adding an EOA (end-of-attribute) bit
if C<$eoa> is true.

=item C<add_data_fd($fh, $eoa)>

Copy data from C<$fh> to this attribute, adding an EOA
(end-of-attribute) bit if C<$eoa> is true.

=item C<add_data_fd_in_thread($fh, $eoa)>

Same as C<add_data_fd> but the copy is done in a newly created thread.
This function return immediately.
Nothing should be done on the archive while it is running.
The next action on the archive must be $attr->close().

=item C<size()>

Return the size of the data of the attribute.

=item C<close()>

Close this attribute, adding an EOA bit if none has been written
already.

=back

=head1 READING

The C<Amanda::Archive::Archive> method C<read()> handles reading
archives via a callback mechanism.  It takes its arguments in hash
form, with the following keys:

    file_start => sub {
	my ($user_data, $filenum, $filename) = @_;
	# ..
    },

C<file_start> gives a sub which is called for every file in the
archive.  It can return an arbitrary value which will become the
C<$file_data> for subsequent callbacks in this file, or the string
"IGNORE" which will cause the reader to ignore all data for this file.
In this case, no other callbacks will be made for the file (not even
C<file_finish>).

    file_finish => sub {
	my ($user_data, $file_data, $filenum, $truncated) = @_;
	# ..
    },

C<file_finish> gives a sub which is called when an EOF record appears.
C<$file_data> comes from the return value of the C<file_start>
callback.  C<$truncated> is true if the file may be missing data
(e.g., when an early EOF is detected).

    user_data => $my_object,

C<user_data> gives an arbitrary value which is passed to each callback
as C<$user_data>.

    13 => sub {
	my ($user_data, $filenum, $file_data, $attrid,
	    $attr_data, $data, $eoa, $truncated) = @_;
	# ...
    },
    19 => [ 10240, sub { ... } ],

Any numeric key is treated as an attribute ID, and specifies the
handling for that attribute.  Attribute ID zero is treated as a
wildcard, and will match any attribute without an explicit handler.
The handler can be specified as a sub (as for attribute ID 13 in the
example above) or as an arrayref C<[$minsize, $sub]>.  In the latter
case, the sub is only called when at least C<$minsize> bytes of data
are available for the attribute, or at the end of the attribute data.

The parameters to the callback include C<$file_data>, the value
returned from C<file_start>, and C<$attr_data>, which is the return
value of the last invocation of this sub for this attribute.  If this
is the last fragment of data for this attribute, then C<$eoa> is true.
The meaning of C<$truncated> is similar to that in C<file_finish>.

=head2 EXAMPLE

    sub read_to_files {
	my ($arch_fh, $basedir) = @_;

	my $arch = Amanda::Archive->new(fileno($arch_fh), "<");
	$arch->read(
	    file_start => sub {
		my ($user_data, $filenum, $filename) = @_;
		return "$basedir/$filenum"; # becomes $file_data
	    },
	    0 => [ 32768, sub {
		my ($user_data, $filenum, $file_data, $attrid,
		    $attr_data, $data, $eoa, $truncated) = @_;
		warn("file $filename attribute $attrid is truncated")
		    if ($truncated);
		# store the open filehandle in $attr_data
		if (!$attr_data) {
		    open($attr_data, "$file_data.$attrid", ">")
			or die("open: $!");
		}
		print $attr_data $data;
		if ($eoa) {
		    close($attr_data);
		}
		return $attr_data;
	    },
	);
    }

=cut



push @EXPORT_OK, qw(amar_attr_to_string);
push @{$EXPORT_TAGS{"amar_attr"}}, qw(amar_attr_to_string);

my %_amar_attr_VALUES;
#Convert an enum value to a single string
sub amar_attr_to_string {
    my ($enumval) = @_;

    for my $k (keys %_amar_attr_VALUES) {
	my $v = $_amar_attr_VALUES{$k};

	#is this a matching flag?
	if ($enumval == $v) {
	    return $k;
	}
    }

#default, just return the number
    return $enumval;
}

push @EXPORT_OK, qw( $AMAR_ATTR_FILENAME  $AMAR_ATTR_EOF  $AMAR_ATTR_GENERIC_DATA  $AMAR_ATTR_RMAN_DATA);
push @{$EXPORT_TAGS{"amar_attr"}}, qw( $AMAR_ATTR_FILENAME  $AMAR_ATTR_EOF  $AMAR_ATTR_GENERIC_DATA  $AMAR_ATTR_RMAN_DATA);
      foreach (qw(  AMAR_ATTR_FILENAME  AMAR_ATTR_EOF  AMAR_ATTR_GENERIC_DATA  AMAR_ATTR_RMAN_DATA)) {  	$_amar_attr_VALUES{$_} = $$_;      }  

require Amanda::Config::FoldingHash;

=pod

Amar default attribute:       C<$AMAR_ATTR_FILENAME>  C<$AMAR_ATTR_EOF>  C<$AMAR_ATTR_GENERIC_DATA>  C<$AMAR_ATTR_RMAN_DATA>

=cut

package Amanda::Archive;

# Expose the Archive constructor at Amanda::Archive->new
sub new {
    my $pkg = shift;
    Amanda::Archive::Archive->new(@_);
}

package Amanda::Archive::Archive;

sub new {
    my ($class, $fd, $mode) = @_;
    my $arch = Amanda::Archive::amar_new($fd, $mode);
    return bless (\$arch, $class);
}

my $dat = undef;
sub close {
    my $self = shift;
    if ($$self) {
	Amanda::Archive::amar_close($$self);
	if ($dat) {
	    Amanda::Archive::destroy_read_cb($dat);
	    $dat = undef;
	}
	$$self = undef;
    }
}

sub size {
    my $self = shift;
    if ($$self) {
	return Amanda::Archive::amar_size($$self);
    }
    return 0;
}

sub DESTROY {
    my $self = shift;
    if ($dat) {
	Amanda::Archive::destroy_read_cb($dat);
	$dat = undef;
    }
    $self->close();
}

sub new_file {
    my ($self, $filename, $want_offset) = @_;
    return Amanda::Archive::File->new($self, $filename, $want_offset);
}

sub Amanda::Archive::Archive::read {
    my $self = shift;
    die "Archive is not open" unless ($$self);
    # pass a hashref to the C code
    my %h = @_;
    Amanda::Archive::amar_read($$self, \%h);
}

sub Amanda::Archive::Archive::set_read_cb {
    my $self = shift;
    die "Archive is not open" unless ($$self);
    # pass a hashref to the C code
    my %h = @_;
    $dat = Amanda::Archive::set_amar_read_cb($$self, \%h);
}

sub Amanda::Archive::Archive::read_to {
    my $self = shift;
    die "Archive is not open" unless ($$self);
    my $filenum  = shift;
    my $attrid   = shift;
    my $fd       = shift;
    Amanda::Archive::amar_read_to($$self, $filenum, $attrid, $fd);
}

sub Amanda::Archive::Archive::stop_read {
    my $self = shift;
    die "Archive is not open" unless ($$self);
    Amanda::Archive::amar_stop_read($$self);
}

sub Amanda::Archive::Archive::start_read {
    my $self = shift;
    die "Archive is not open" unless ($$self);
    Amanda::Archive::amar_start_read($$self);
}

package Amanda::Archive::File;

sub new {
    my ($class, $arch, $filename, $want_offset) = @_;
    die "Archive is not open" unless ($$arch);
    if ($want_offset) {
	# note that posn is returned first by the SWIG wrapper
	my ($file, $posn) = Amanda::Archive::amar_new_file($$arch, $filename, $want_offset);
	return (bless([ $file, $arch ], $class), $posn);
    } else {
	my $file = Amanda::Archive::amar_new_file($$arch, $filename, $want_offset);
	return bless([ $file, $arch ], $class);
    }
}

sub size {
    my $self = shift;
    if ($self->[0]) {
	return Amanda::Archive::amar_file_size($self->[0]);
    }
    return 0;
}

sub close {
    my $self = shift;
    if ($self->[0]) {
	Amanda::Archive::amar_file_close($self->[0]);
	$self->[0] = undef;
    }
}

sub DESTROY {
    my $self = shift;
    $self->close();
}

sub new_attr {
    my ($self, $attrid) = @_;
    return Amanda::Archive::Attr->new($self, $attrid);
}

package Amanda::Archive::Attr;

sub new {
    my ($class, $file, $attrid) = @_;
    die "File is not open" unless ($file->[0]);
    my $attr = Amanda::Archive::amar_new_attr($file->[0], $attrid);
    return bless ([$attr, $file], $class);
}

sub size {
    my $self = shift;
    if ($self->[0]) {
	return Amanda::Archive::amar_attr_size($self->[0]);
    }
    return 0;
}

sub close {
    my $self = shift;
    if ($self->[0]) {
	Amanda::Archive::amar_attr_close($self->[0]);
	$self->[0] = undef;
    }
}

sub DESTROY {
    my $self = shift;
    $self->close();
}

sub add_data {
    my ($self, $data, $eoa) = @_;
    die "Attr is not open" unless ($self->[0]);
    Amanda::Archive::amar_attr_add_data_buffer($self->[0], $data, $eoa);
}

sub add_data_fd {
    my ($self, $fd, $eoa) = @_;
    die "Attr is not open" unless ($self->[0]);
    return Amanda::Archive::amar_attr_add_data_fd($self->[0], $fd, $eoa);
}

sub add_data_fd_in_thread {
    my ($self, $fd, $eoa) = @_;
    die "Attr is not open" unless ($self->[0]);
    return Amanda::Archive::amar_attr_add_data_fd_in_thread($self->[0], $fd, $eoa);
}
1;