| 1 | package Monitoring::Sneck::Checks::accounts; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use parent 'Monitoring::Sneck::Checks::base'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use File::Slurp qw(read_file); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | Monitoring::Sneck::Checks::accounts - checks local user accounts | ||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | =head1 VERSION | ||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | Version 0.0.1 | ||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | 7 | our $VERSION = '0.0.1'; | |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | # Where things are. Set by tests. | ||||||||||||||||||||||||||||||||||
| 22 | 7 | our $PASSWD = '/etc/passwd'; | |||||||||||||||||||||||||||||||||
| 23 | 7 | our $SHADOW = '/etc/shadow'; | |||||||||||||||||||||||||||||||||
| 24 | 7 | our $MASTER_PASSWD = '/etc/master.passwd'; | |||||||||||||||||||||||||||||||||
| 25 | 7 | our $SHELLS = '/etc/shells'; | |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | !accounts|control=CIS-6.2 framework=CIS|perl:accounts -s | ||||||||||||||||||||||||||||||||||
| 30 | !no_guest||perl:accounts -a guest -a test -p backup | ||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | Checks the local accounts, from the files, not through NSS, so those | ||||||||||||||||||||||||||||||||||
| 35 | from LDAP and the like are not looked at. Each of these is CRITICAL. | ||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | - a UID of 0 :: For any account not given by --uid0, by default root, | ||||||||||||||||||||||||||||||||||
| 38 | and toor on FreeBSD. | ||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | - no password :: An account with a empty password field, which can log | ||||||||||||||||||||||||||||||||||
| 41 | in without one. Locked accounts, * or !, are fine. This needs reading | ||||||||||||||||||||||||||||||||||
| 42 | /etc/shadow, or /etc/master.passwd on FreeBSD, so root. Not being able | ||||||||||||||||||||||||||||||||||
| 43 | to is UNKNOWN, unless --no-passwords is given. A empty field in | ||||||||||||||||||||||||||||||||||
| 44 | /etc/passwd itself counts too, as that is what is used then, whatever | ||||||||||||||||||||||||||||||||||
| 45 | /etc/shadow has. | ||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | - duplicates :: Two accounts with the same name or UID. UID 0 is left to | ||||||||||||||||||||||||||||||||||
| 48 | the check above. | ||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | - --absent and --present :: Accounts that must not, or must, be there. | ||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | - --system-shells :: System accounts, those under --min-uid, with a | ||||||||||||||||||||||||||||||||||
| 53 | shell from /etc/shells, read as getusershell does, so one that can log | ||||||||||||||||||||||||||||||||||
| 54 | in. root, sync, shutdown, halt, and toor are left out, as are those | ||||||||||||||||||||||||||||||||||
| 55 | given by --ignore. | ||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | Other OSes than Linux and FreeBSD are UNKNOWN. | ||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | =head1 OPTIONS | ||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||
| 61 | - -u, --uid0 :: A account that may have a UID of 0. May be given more | ||||||||||||||||||||||||||||||||||
| 62 | than once. | ||||||||||||||||||||||||||||||||||
| 63 | Default :: root, and toor on FreeBSD | ||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||
| 65 | - -n, --no-passwords :: Do not check for empty passwords. | ||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | - -s, --system-shells :: Check system accounts do not have a login shell. | ||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | - -m, --min-uid :: The lowest UID of accounts for people. | ||||||||||||||||||||||||||||||||||
| 70 | Default :: 1000 | ||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||
| 72 | - -i, --ignore :: A system account that may have a login shell. May be | ||||||||||||||||||||||||||||||||||
| 73 | given more than once. | ||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | - -a, --absent :: A account that must not be there. May be given more | ||||||||||||||||||||||||||||||||||
| 76 | than once. | ||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||
| 78 | - -p, --present :: A account that must be there. May be given more than | ||||||||||||||||||||||||||||||||||
| 79 | once. | ||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||
| 83 | 8 | ▶ | sub option_spec { | ||||||||||||||||||||||||||||||||
|
Subroutine
option_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 84 | return ( | ||||||||||||||||||||||||||||||||||
| 85 | 8 | 'uid0|u=s@', 'no-passwords|n', 'system-shells|s', 'min-uid|m=i', | |||||||||||||||||||||||||||||||||
| 86 | 'ignore|i=s@', 'absent|a=s@', 'present|p=s@' | ||||||||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | 8 | ▶ | sub defaults { return { 'min-uid' => 1000 } } | ||||||||||||||||||||||||||||||||
|
Subroutine
defaults: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | =head1 METHODS | ||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||
| 94 | =head2 check | ||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||
| 96 | Does the check. | ||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||
| 98 | =cut | ||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||
| 100 | 7 | ▶ | sub check { | ||||||||||||||||||||||||||||||||
|
Subroutine
check: called CC=26 SCAR=32.6
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 101 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||
| 103 | 7 | my $accounts = $self->accounts; | |||||||||||||||||||||||||||||||||
| 104 | 7 | ▶ | my %uid0 = map { $_ => 1 } @{ $self->opt('uid0') // [ 'root', ( $self->os eq 'freebsd' ? 'toor' : () ) ] }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->opt("uid0") // ["root", $self->os eq "freebsd" ? "toor" : ()]
MC/DC0%0/1
$self->opt("uid0") // ["root", $self->os eq "freebsd" ? "toor" : ()]
$self->opt("uid0")
Truth table50%1/2
A
A= $self->opt("uid0")
| |||||||||||||||||||||||||||||||||||
| 105 | 7 | my %by_name = map { $_->{name} => $_ } @{$accounts}; | |||||||||||||||||||||||||||||||||
| 106 | 7 | my @problems; | |||||||||||||||||||||||||||||||||
| 107 | my @unknown; | ||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | 7 | ▶ | my @root_like = grep { $_->{uid} == 0 && !$uid0{ $_->{name} } } @{$accounts}; | ||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_->{'uid'} == 0 && !$uid0{$_->{'name'}}
MC/DC100%2/2
$_->{'uid'} == 0 && !$uid0{$_->{'name'}}
$_->{'uid'} == 0
!$uid0{$_->{'name'}}
Truth table100%3/3
A && not(B)
A= $_->{'uid'} == 0B= !$uid0{$_->{'name'}}
| |||||||||||||||||||||||||||||||||||
| 110 | 7 | ▶ | push( @problems, 'UID 0 for ' . join( ', ', map { $_->{name} } @root_like ) ) if defined( $root_like[0] ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||
| 112 | 7 | foreach my $field ( 'name', 'uid' ) { | |||||||||||||||||||||||||||||||||
| 113 | 14 | my %count; | |||||||||||||||||||||||||||||||||
| 114 | # UID 0 is left to the check for it above, as toor shares it with root on FreeBSD | ||||||||||||||||||||||||||||||||||
| 115 | 14 | ▶ | $count{ $_->{$field} }++ foreach grep { $field ne 'uid' || $_->{uid} != 0 } @{$accounts}; | ||||||||||||||||||||||||||||||||
|
Condition100%3/3
$field ne 'uid' || $_->{'uid'} != 0
MC/DC100%2/2
$field ne 'uid' || $_->{'uid'} != 0
$field ne 'uid'
$_->{'uid'} != 0
Truth table100%3/3
A || B
A= $field ne 'uid'B= $_->{'uid'} != 0
| |||||||||||||||||||||||||||||||||||
| 116 | 14 | my @duplicates = sort( grep { $count{$_} > 1 } keys(%count) ); | |||||||||||||||||||||||||||||||||
| 117 | 14 | ▶ | push( @problems, 'more than one account with the ' . $field . ' ' . join( ', ', @duplicates ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 118 | if defined( $duplicates[0] ); | ||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | 7 | ▶ | if ( !$self->opt('no-passwords') ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 122 | 5 | my $passwords = $self->passwords($accounts); | |||||||||||||||||||||||||||||||||
| 123 | 5 | ▶ | if ( !defined($passwords) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 124 | 3 | ▶ | push( @unknown, 'can not read the passwords, ' . ( $self->os eq 'freebsd' ? $MASTER_PASSWD : $SHADOW ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 125 | } else { | ||||||||||||||||||||||||||||||||||
| 126 | 2 | my @empty = sort( grep { $passwords->{$_} eq '' } keys( %{$passwords} ) ); | |||||||||||||||||||||||||||||||||
| 127 | 2 | ▶ | push( @problems, 'no password for ' . join( ', ', @empty ) ) if defined( $empty[0] ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||
| 131 | 7 | ▶ | if ( $self->opt('system-shells') ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 132 | 2 | my %shells = map { $_ => 1 } $self->shells; | |||||||||||||||||||||||||||||||||
| 133 | 2 | ▶ | my %ignored = map { $_ => 1 } ( 'root', 'sync', 'shutdown', 'halt', 'toor', @{ $self->opt('ignore') // [] } ); | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->opt("ignore") // []
MC/DC0%0/1
$self->opt("ignore") // []
$self->opt("ignore")
Truth table50%1/2
A
A= $self->opt("ignore")
| |||||||||||||||||||||||||||||||||||
| 134 | 1 | my @can_log_in = map { $_->{name} } | |||||||||||||||||||||||||||||||||
| 135 | 12 | ▶ | grep { $_->{uid} < $self->opt('min-uid') && !$ignored{ $_->{name} } && $shells{ $_->{shell} } } | ||||||||||||||||||||||||||||||||
|
Condition100%6/6
$_->{'uid'} < $self->opt('min-uid') && !$ignored{$_->{'name'}} && $shells{$_->{'shell'}}
$_->{"uid"} < $self->opt("min-uid") and not $ignored{$_->{"name"}}
MC/DC100%3/3
$_->{'uid'} < $self->opt('min-uid') && !$ignored{$_->{'name'}} && $shells{$_->{'shell'}}
$_->{"uid"} < $self->opt("min-uid")
not $ignored{$_->{"name"}}
$shells{$_->{'shell'}}
Truth table100%4/4
A and not(B) && C
A= $_->{"uid"} < $self->opt("min-uid")B= not $ignored{$_->{"name"}}C= $shells{$_->{'shell'}}
| |||||||||||||||||||||||||||||||||||
| 136 | 2 | @{$accounts}; | |||||||||||||||||||||||||||||||||
| 137 | 2 | ▶ | push( @problems, 'system accounts with a login shell, ' . join( ', ', @can_log_in ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 138 | if defined( $can_log_in[0] ); | ||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||
| 141 | 7 | ▶ | my @there = grep { $by_name{$_} } @{ $self->opt('absent') // [] }; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->opt("absent") // []
MC/DC100%1/1
$self->opt("absent") // []
$self->opt("absent")
Truth table100%2/2
A
A= $self->opt("absent")
| |||||||||||||||||||||||||||||||||||
| 142 | 7 | ▶ | push( @problems, 'there but should not be, ' . join( ', ', @there ) ) if defined( $there[0] ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 143 | 7 | ▶ | my @missing = grep { !$by_name{$_} } @{ $self->opt('present') // [] }; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->opt("present") // []
MC/DC100%1/1
$self->opt("present") // []
$self->opt("present")
Truth table100%2/2
A
A= $self->opt("present")
| |||||||||||||||||||||||||||||||||||
| 144 | 7 | ▶ | push( @problems, 'missing ' . join( ', ', @missing ) ) if defined( $missing[0] ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||
| 146 | 7 | ▶ | my @codes = ( defined( $problems[0] ) ? $self->CRITICAL : $self->OK ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 147 | 7 | ▶ | push( @codes, $self->UNKNOWN ) if defined( $unknown[0] ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 148 | 7 | my $message = scalar( @{$accounts} ) . ' accounts'; | |||||||||||||||||||||||||||||||||
| 149 | 7 | ▶ | $message = $message . ', ' . join( ', ', @problems, @unknown ) if defined( $problems[0] ) || defined( $unknown[0] ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $problems[0] or defined $unknown[0]
MC/DC100%2/2
defined $problems[0] or defined $unknown[0]
defined $problems[0]
defined $unknown[0]
Truth table100%3/3
A or B
A= defined $problems[0]B= defined $unknown[0]
| |||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||
| 151 | 7 | return $self->finish( $self->worst(@codes), $message ); | |||||||||||||||||||||||||||||||||
| 152 | } ## end sub check | ||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||
| 154 | =head2 accounts | ||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||
| 156 | Returns a array ref of the local accounts, as hash refs of name, uid, | ||||||||||||||||||||||||||||||||||
| 157 | password, the field as it is in the file, and shell, in the order they | ||||||||||||||||||||||||||||||||||
| 158 | are in the file. Dies if it can not be read. | ||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||
| 160 | =cut | ||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||
| 162 | 7 | ▶ | sub accounts { | ||||||||||||||||||||||||||||||||
|
Subroutine
accounts: called CC=8 SCAR=22.4
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 163 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||
| 165 | 7 | ▶ | die( 'not supported on ' . $self->os . "\n" ) if $self->os ne 'linux' && $self->os ne 'freebsd'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->os ne "linux" and $self->os ne "freebsd"
MC/DC0%0/2
$self->os ne "linux" and $self->os ne "freebsd"
$self->os ne "linux"
$self->os ne "freebsd"
Truth table66%2/3
A and B
A= $self->os ne "linux"B= $self->os ne "freebsd"
| |||||||||||||||||||||||||||||||||||
| 166 | 7 | my $content = read_file( $PASSWD, err_mode => 'quiet' ); | |||||||||||||||||||||||||||||||||
| 167 | 7 | ▶ | die( 'can not read ' . $PASSWD . ', ' . $! . "\n" ) if !defined($content); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||
| 169 | 7 | my @accounts; | |||||||||||||||||||||||||||||||||
| 170 | 7 | foreach my $line ( split( /\n/, $content ) ) { | |||||||||||||||||||||||||||||||||
| 171 | 35 | ▶ | next if $line =~ /\A\s*(?:#|\z)/ || $line =~ /\A[+-]/; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$line =~ /\A\s*(?:#|\z)/u or $line =~ /\A[+-]/u
MC/DC0%0/2
$line =~ /\A\s*(?:#|\z)/u or $line =~ /\A[+-]/u
$line =~ /\A\s*(?:#|\z)/u
$line =~ /\A[+-]/u
Truth table33%1/3
A or B
A= $line =~ /\A\s*(?:#|\z)/uB= $line =~ /\A[+-]/u
| |||||||||||||||||||||||||||||||||||
| 172 | 35 | my @fields = split( /:/, $line, -1 ); | |||||||||||||||||||||||||||||||||
| 173 | 35 | ▶ | next if scalar(@fields) < 7; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 174 | 35 | push( @accounts, { name => $fields[0], uid => $fields[2], password => $fields[1], shell => $fields[6] } ); | |||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||
| 177 | 7 | return \@accounts; | |||||||||||||||||||||||||||||||||
| 178 | } ## end sub accounts | ||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||
| 180 | =head2 passwords | ||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||
| 182 | Returns a hash ref of account names to the password fields that are | ||||||||||||||||||||||||||||||||||
| 183 | used for them, or undef if the shadow file can not be read. | ||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||
| 185 | - accounts :: From L</accounts>, for the fields in passwd itself. | ||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||
| 187 | The field is the one from /etc/shadow, or /etc/master.passwd on | ||||||||||||||||||||||||||||||||||
| 188 | FreeBSD, unless the one in passwd is empty, as the C library and PAM | ||||||||||||||||||||||||||||||||||
| 189 | go by passwd then, and a empty one there means no password. | ||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||
| 191 | my $passwords = $check->passwords( $check->accounts ); | ||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||
| 193 | =cut | ||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||
| 195 | 5 | ▶ | sub passwords { | ||||||||||||||||||||||||||||||||
|
Subroutine
passwords: called CC=12 SCAR=26.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 196 | 5 | my ( $self, $accounts ) = @_; | |||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||
| 198 | 5 | ▶ | my $file = $self->os eq 'freebsd' ? $MASTER_PASSWD : $SHADOW; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 199 | 5 | ▶ | my $content = read_file( $file, err_mode => 'quiet' ) // return undef; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
read_file($file, "err_mode", "quiet") // (return undef)
MC/DC100%1/1
read_file($file, "err_mode", "quiet") // (return undef)
read_file($file, "err_mode", "quiet")
Truth table100%2/2
A
A= read_file($file, "err_mode", "quiet")
| |||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||
| 201 | 2 | ▶ | my %passwords = map { $_->{name} => $_->{password} } @{ $accounts // [] }; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$accounts // []
MC/DC0%0/1
$accounts // []
$accounts
Truth table50%1/2
A
A= $accounts
| |||||||||||||||||||||||||||||||||||
| 202 | 2 | foreach my $line ( split( /\n/, $content ) ) { | |||||||||||||||||||||||||||||||||
| 203 | 7 | ▶ | next if $line =~ /\A\s*(?:#|\z)/ || $line =~ /\A[+-]/; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$line =~ /\A\s*(?:#|\z)/u or $line =~ /\A[+-]/u
MC/DC0%0/2
$line =~ /\A\s*(?:#|\z)/u or $line =~ /\A[+-]/u
$line =~ /\A\s*(?:#|\z)/u
$line =~ /\A[+-]/u
Truth table33%1/3
A or B
A= $line =~ /\A\s*(?:#|\z)/uB= $line =~ /\A[+-]/u
| |||||||||||||||||||||||||||||||||||
| 204 | 7 | my ( $name, $password ) = split( /:/, $line, -1 ); | |||||||||||||||||||||||||||||||||
| 205 | 7 | ▶ | next if !defined($name) || $name eq ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $name or $name eq ""
MC/DC0%0/2
not defined $name or $name eq ""
not defined $name
$name eq ""
Truth table33%1/3
not(A) or B
A= not defined $nameB= $name eq ""
| |||||||||||||||||||||||||||||||||||
| 206 | 7 | ▶ | $passwords{$name} = $password // '' if ( $passwords{$name} // 'x' ) ne ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
$passwords{$name} // "x"
$password // ""
MC/DC0%0/1
$passwords{$name} // "x"
$passwords{$name}
MC/DC0%0/1
$password // ""
$password
Truth table50%1/2
A
A= $passwords{$name}
Truth table50%1/2
A
A= $password
| |||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||
| 209 | 2 | return \%passwords; | |||||||||||||||||||||||||||||||||
| 210 | } ## end sub passwords | ||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||
| 212 | =head2 shells | ||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||
| 214 | Returns the login shells in /etc/shells, read as getusershell does. | ||||||||||||||||||||||||||||||||||
| 215 | Each line gives one, the first thing on it starting with a /, and | ||||||||||||||||||||||||||||||||||
| 216 | lines with a # before that are comments. None if it can not be read. | ||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||
| 218 | =cut | ||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||
| 220 | 3 | ▶ | sub shells { | ||||||||||||||||||||||||||||||||
|
Subroutine
shells: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 221 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||
| 223 | 3 | ▶ | my $content = read_file( $SHELLS, err_mode => 'quiet' ) // ''; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
read_file($Monitoring::Sneck::Checks::accounts::SHELLS, "err_mode", "quiet") // ""
MC/DC0%0/1
read_file($Monitoring::Sneck::Checks::accounts::SHELLS, "err_mode", "quiet") // ""
read_file($Monitoring::Sneck::Checks::accounts::SHELLS, "err_mode", "quiet")
Truth table50%1/2
A
A= read_file($Monitoring::Sneck::Checks::accounts::SHELLS, "err_mode", "quiet")
| |||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||
| 225 | 3 | ▶ | return map { m{\A[^#/]*(/[^\s#]*)} ? $1 : () } split( /\n/, $content ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||
| 228 | 7 | 1; | |||||||||||||||||||||||||||||||||