This file is indexed.

/usr/share/perl5/Rex/Commands/Kernel.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
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
#
# (c) Jan Gehring <jan.gehring@gmail.com>
#
# vim: set ts=2 sw=2 tw=0:
# vim: set expandtab:

=head1 NAME

Rex::Commands::Kernel - Load/Unload Kernel Modules

=head1 DESCRIPTION

With this module you can load and unload kernel modules.

Version <= 1.0: All these functions will not be reported.

All these functions are not idempotent.

=head1 SYNOPSIS

 kmod load => "ipmi_si";
 
 kmod unload => "ipmi_si";

=head1 EXPORTED FUNCTIONS

=cut

package Rex::Commands::Kernel;

use strict;
use warnings;

our $VERSION = '1.4.1'; # VERSION

use Rex::Logger;
use Rex::Commands::Run;
use Rex::Commands::Gather;

use Data::Dumper;

require Rex::Exporter;

use base qw(Rex::Exporter);
use vars qw(@EXPORT);

@EXPORT = qw(kmod);

=head2 kmod($action => $module)

This function loads or unloads a kernel module.

 task "load", sub {
   kmod load => "ipmi_si";
 };
 
 task "unload", sub {
   kmod unload => "ipmi_si";
 };

If you're using NetBSD or OpenBSD you have to specify the complete path and, if needed the entry function.

 task "load", sub {
   kmod load => "/usr/lkm/ntfs.o";
   kmod load => "/path/to/module.o", entry => "entry_function";
 };

=cut

sub kmod {
  my ( $action, $module, @rest ) = @_;

  my $options = {@_};

  my $os = get_operating_system();

  my $load_command   = "modprobe";
  my $unload_command = "rmmod";

  if ( $os eq "FreeBSD" ) {
    $load_command   = "kldload";
    $unload_command = "kldunload";
  }
  elsif ( $os eq "NetBSD" || $os eq "OpenBSD" ) {
    $load_command   = "modload";
    $unload_command = "modunload";

    if ( $options->{"entry"} ) {
      $load_command .= " -e " . $options->{"entry"};
    }
  }
  elsif ( $os eq "SunOS" ) {
    $load_command = "modload -p ";

    if ( $options->{"exec_file"} ) {
      $load_command .= " -e " . $options->{"exec_file"} . " ";
    }

    $unload_command = sub {
      my @mod_split = split( /\//, $module );
      my $mod = $mod_split[-1];

      my ($mod_id) = map { /^\s*(\d+)\s+.*$mod/ } run "modinfo";
      my $cmd = "modunload -i $mod_id";

      if ( $options->{"exec_file"} ) {
        $cmd .= " -e " . $options->{"exec_file"};
      }

      return $cmd;
    };
  }
  elsif ( $os eq "OpenWrt" ) {
    $load_command = "insmod";
  }

  if ( $action eq "load" ) {
    Rex::Logger::debug("Loading Kernel Module: $module");
    run "$load_command $module";
    unless ( $? == 0 ) {
      Rex::Logger::info( "Error loading Kernel Module: $module", "warn" );
      die("Error loading Kernel Module: $module");
    }
    else {
      Rex::Logger::debug("Kernel Module $module loaded.");
    }
  }
  elsif ( $action eq "unload" ) {
    Rex::Logger::debug("Unloading Kernel Module: $module");
    my $unload_command_str = $unload_command;
    if ( ref($unload_command) eq "CODE" ) {
      $unload_command_str = &$unload_command();
    }

    run "$unload_command_str $module";
    unless ( $? == 0 ) {
      Rex::Logger::info( "Error unloading Kernel Module: $module", "warn" );
      die("Error unloading Kernel Module: $module");
    }
    else {
      Rex::Logger::debug("Kernel Module $module unloaded.");
    }
  }
  else {
    Rex::Logger::info("Unknown action $action");
    die("Unknown action $action");
  }
}

1;