This file is indexed.

/usr/share/perl5/Net/OpenSSH/OSTracer.pm is in libnet-openssh-perl 0.60-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
package Net::OpenSSH::OSTracer;

our $VERSION = '0.58_01';

use strict;
use warnings;

use POSIX;

our $cmd;
our $type;
our $output;
our $sudo;
our $delay;

our @EXTRA_ARGS;

my %type_by_os = (linux   => 'strace',
                  openbsd => 'ktrace',
                  freebsd => 'ktrace',
                  netbsd  => 'ktrace',
                  bsd     => 'ktrace',
                  'hp-ux' => 'tusc',
                  aix     => 'truss',
                  solaris => 'truss');

sub trace {
    my $class = shift;
    my ($cmd, $type) = ($cmd, $type); # copy globals


    if (not defined $type) {
        my $os = lc $^O;
        if ( defined $cmd and $cmd =~ /([sk]trace|k?truss|tusc)$/) {
            $type = $1;
        }
        elsif ($os =~ /(linux|openbsd|freebsd|netbsd|bsd|hp-ux|aix|solaris)/) {
            $type = $type_by_os{$1};
        }
        else {
            Net::OpenSSH::_debug("unable to determine tracer type for OS $os");
            return;
        }
    }

    my $output1 = (defined $output ? $output : "/tmp/net_openssh_master") . ".$$";
    my $file = "$output1.$type";
    my $err = "$output1.txt";

    $cmd = $type unless defined $cmd;

    my @args;
    if ($type eq 'strace') {
        @args = (-o => $file, -p => $$, -s => 1024, '-fx');
    }
    elsif ($type eq 'ktruss') {
        @args = (-o => $file, -p => $$, -m => 1024, '-d');
    }
    elsif ($type eq 'ktrace') {
        @args = (-f => $file, -p => $$, '-id');
    }
    elsif ($type eq 'tusc') {
        @args = (-o => $file, -b => 1024, '-fa', $$)
    }
    elsif ($type eq 'truss') {
        @args = (-o => $file, -faep => $$);
    }
    else {
        Net::OpenSSH::_debug("tracer type $type not supported");
        return
    }

    my @cmd = (defined $sudo ? ($sudo, '-A', $cmd) : $cmd);

    my $pid = fork;
    unless ($pid) {
        unless (defined $pid) {
            Net::OpenSSH::_debug("unable to launch tracer, fork failed: $!");
            return;
        }
        my ($in, $out);
        if (open $in, '</dev/null'      and
            open $out, '>', $err        and
            POSIX::dup2(fileno $in, 0)  and
            POSIX::dup2(fileno $out, 1) and
            POSIX::dup2(fileno $out, 2)) {
            exec (@cmd, @EXTRA_ARGS, @args);
        }
        else {
            eval { Net::OpenSSH::_debug("Unable to redirect tracer IO: $!") };
        }
        POSIX::_exit(1);
    }
    sleep (defined $delay ? $delay : 1); # wait for the tracer to come up
    Net::OpenSSH::_debug("tracer attached, ssh pid: $$, tracer pid: $pid");
    1;
}

1;

__END__

=head1 NAME

Net::OpenSSH::OSTracer - trace ssh master process at the OS level

=head1 SYNOPSIS

    use Net::OpenSSH;
    $Net::OpenSSH::debug |= 512;

    Net::OpenSSH->new($host)->system("echo hello world");

    system "less /tmp/net_openssh_master.*.strace";

=head1 DESCRIPTION

This is a Net::OpenSSH helper module that allows you to trace the
master ssh process at the operating system level using the proper
utility available in your system (i.e, strace, truss, ktruss, tusc,
etc.).

This feature can be used when debugging your programs or to report
bugs on the module.

It is enabled setting the flag 512 on the C<$Net::OpenSSH::debug> variable:

  $Net::OpenSSH::debug |= 512;

By default the output files of the tracer are saved as
C</tmp/net_openssh_master.$pid.$tracer_type>.

Also, the output send by the tracer to stdout/stderr is saved as
C</tmp/net_openssh_master.$pid.txt>.

The module can be configured through the following global variables:

=over 4

=item $Net::OpenSSH::OSTracer::type

By default, the module decides which tracer to use in base to the
operative system name. This variable allows one to select a different
tracer.

Currently accepted types are: strace (linux), ktrace (*bsd), tusc
(hp-ux) and truss (solaris and aix).

=item $Net::OpenSSH::OSTracer::cmd

Command to execute for tracing the ssh process.

By default, it inferres it from the tracer type selected.

=item $Net::OpenSSH::OSTracer::output

Basename for the destination file. The PID of the ssh process and the
tracer type will be appended.

=item $Net::OpenSSH::OSTracer::sudo

This variable can be used to request the tracer to be run with C<sudo>
(some operating systems as for example Ubuntu, do not allow to attach
tracers, even to your own processes, unless you do it as root).

The variable has to be set with the path of the C<sudo> binary. For
instance:

  $Net::OpenSSH::OSTracer::sudo = '/usr/bin/sudo';

If you need to pass a password to C<sudo>, set the environment
variable C<SUDO_ASKPASS>. For instance:

  SUDO_ASKPASS=/usr/bin/ssh-askpass

=item $Net::OpenSSH::OSTracer::delay

This variable can be used to delay the ssh execution so that the
tracer can attach the process first. This is specially handy when
using C<sudo> with a password.

=back

=head1 BUGS

This module has not been tested under all the operating systems is
says to support.

If you find any problem, just report it, please!

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2012 by Salvador FandiE<ntilde>o
(sfandino@yahoo.com)

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.0 or,
at your option, any later version of Perl 5 you may have available.


=cut