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
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.3'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
8
|
use Rex::Logger; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
13
|
|
|
|
|
|
|
require Rex::Commands; |
14
|
1
|
|
|
1
|
|
52
|
use Rex::Helper::Run; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
75
|
|
15
|
1
|
|
|
1
|
|
9
|
use Rex::Commands::Fs; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
16
|
1
|
|
|
1
|
|
6
|
use Rex::Interface::File; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
17
|
1
|
|
|
1
|
|
34
|
use Rex::Interface::Fs; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
18
|
1
|
|
|
1
|
|
20
|
use Rex::Interface::Exec; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
19
|
1
|
|
|
1
|
|
34
|
use Rex::Helper::Path; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
7
|
use Rex::User::Linux; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
18
|
|
22
|
1
|
|
|
1
|
|
34
|
use base qw(Rex::User::Linux); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
537
|
|
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; |