File Coverage

lib/Rex/User/OpenWrt.pm
Criterion Covered Total %
statement 32 58 55.1
branch 0 6 0.0
condition 0 6 0.0
subroutine 11 15 73.3
pod 0 4 0.0
total 43 89 48.3


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4              
5             package Rex::User::OpenWrt;
6              
7 1     1   16 use v5.12.5;
  1         6  
8 1     1   7 use warnings;
  1         2  
  1         41  
9              
10             our $VERSION = '1.14.2.3'; # TRIAL VERSION
11              
12 1     1   11 use Rex::Logger;
  1         1  
  1         8  
13             require Rex::Commands;
14 1     1   28 use Rex::Helper::Run;
  1         2  
  1         54  
15 1     1   6 use Rex::Commands::Fs;
  1         2  
  1         10  
16 1     1   8 use Rex::Interface::File;
  1         2  
  1         5  
17 1     1   33 use Rex::Interface::Fs;
  1         2  
  1         6  
18 1     1   20 use Rex::Interface::Exec;
  1         2  
  1         6  
19 1     1   29 use Rex::Helper::Path;
  1         2  
  1         73  
20              
21 1     1   6 use Rex::User::Linux;
  1         2  
  1         6  
22 1     1   36 use base qw(Rex::User::Linux);
  1         2  
  1         501  
23              
24             sub new {
25 0     0 0   my $that = shift;
26 0   0       my $proto = ref($that) || $that;
27 0           my $self = $proto->SUPER::new(@_);
28              
29 0           bless( $self, $proto );
30              
31 0           return $self;
32             }
33              
34             sub get_user {
35 0     0 0   my ( $self, $user ) = @_;
36              
37 0           Rex::Logger::debug("Getting information for $user");
38 0           my $o_data = i_run "perl -e 'print join(\";\", getpwnam(\"$user\"))'";
39 0           chomp $o_data;
40 0           my @data = split( /;/, $o_data );
41              
42             return (
43 0           name => $data[0],
44             password => $data[1],
45             uid => $data[2],
46             gid => $data[3],
47             comment => $data[6],
48             home => $data[7],
49             shell => $data[8],
50             );
51             }
52              
53             sub user_groups {
54 0     0 0   my ( $self, $user ) = @_;
55              
56 0           Rex::Logger::debug("Getting group membership of $user");
57              
58 0           my $data_str = i_run "/usr/bin/id -Gn $user", fail_ok => 1;
59 0 0         if ( $? != 0 ) {
60 0           die("Error getting group list");
61             }
62              
63 0           my $wantarray = wantarray();
64              
65 0 0 0       if ( defined $wantarray && !$wantarray ) {
66              
67             # arrayref
68 0           return [ split( / /, $data_str ) ];
69             }
70              
71 0           return split( / /, $data_str );
72             }
73              
74             sub user_list {
75 0     0 0   my $self = shift;
76              
77 0           Rex::Logger::debug("Getting user list");
78              
79 0           my $data_str = i_run "cut -d':' -f1 /etc/passwd", fail_ok => 1;
80 0 0         if ( $? != 0 ) {
81 0           die("Error getting user list");
82             }
83              
84 0           return split( /\n/, $data_str );
85             }
86              
87             1;