/usr/share/perl5/Rex/Sudo/File.pm is in rex 1.4.1-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 | #
# (c) Jan Gehring <jan.gehring@gmail.com>
#
# vim: set ts=2 sw=2 tw=0:
# vim: set expandtab:
###### DEPRECATED
package Rex::Sudo::File;
use strict;
use warnings;
our $VERSION = '1.4.1'; # VERSION
use Rex;
use Rex::Commands;
use Rex::Commands::Run;
use Rex::Commands::Fs;
use Rex::Helper::Path;
use IO::File;
sub open {
my $that = shift;
my $proto = ref($that) || $that;
my $self = {};
$self->{mode} = shift;
$self->{file} = shift;
$self->{rndfile} = get_tmp_file;
if ( my $sftp = Rex::get_sftp() ) {
if ( $self->{mode} eq ">" ) {
$self->{fh} =
$sftp->open( $self->{rndfile}, O_WRONLY | O_CREAT | O_TRUNC );
}
elsif ( $self->{mode} eq ">>" ) {
cp( $self->{file}, $self->{rndfile} );
chmod( 666, $self->{rndfile} );
$self->{fh} = $sftp->open( $self->{rndfile}, O_WRONLY | O_APPEND );
my %stat = stat $self->{rndfile};
$self->{fh}->seek( $stat{size} );
}
else {
cp( $self->{file}, $self->{rndfile} );
chmod( 666, $self->{rndfile} );
$self->{fh} = $sftp->open( $self->{rndfile}, O_RDONLY );
}
}
else {
$self->{fh} = IO::File->new;
$self->{fh}->open( $self->{mode} . " " . $self->{rndfile} );
}
bless( $self, $proto );
return $self;
}
sub write {
my ( $self, $content ) = @_;
if ( ref( $self->{fh} ) eq "Net::SSH2::File" ) {
$self->{fh}->write($content);
}
else {
$self->{fh}->print($content);
}
}
sub seek {
my ( $self, $offset ) = @_;
if ( ref( $self->{fh} ) eq "Net::SSH2::File" ) {
$self->{fh}->seek($offset);
}
else {
$self->{fh}->seek( $offset, 0 );
}
}
sub read {
my ( $self, $len ) = @_;
$len ||= 64;
my $buf;
$self->{fh}->read( $buf, $len );
return $buf;
}
sub close {
my ($self) = @_;
return unless $self->{fh};
if ( ref( $self->{fh} ) eq "Net::SSH2::File" ) {
$self->{fh} = undef;
}
else {
$self->{fh}->close;
}
# use cat to not overwrite attributes/owner/group
if ( $self->{mode} eq ">" || $self->{mode} eq ">>" ) {
run "cat " . $self->{rndfile} . " >" . $self->{file};
rm( $self->{rndfile} );
}
}
sub DESTROY {
my ($self) = @_;
$self->close;
}
1;
|