| 1 | package Apache::Htpasswd; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; # Restrict unsafe variables, references, barewords | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use POSIX qw ( SEEK_SET SEEK_END ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Fcntl qw ( LOCK_EX LOCK_UN ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | @EXPORT = qw(); | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | @EXPORT_OK = | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | qw(htpasswd htDelete fetchPass fetchInfo writeInfo htCheckPassword error Version); | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | %EXPORT_TAGS = ( all => [@EXPORT_OK] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | $VERSION = '1.9'; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub Version { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
Version: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | return $VERSION; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # Public Methods | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | my $args = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | my $passwdFile; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | ▶ | if ( ref $args eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | $passwdFile = $args->{'passwdFile'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | $passwdFile = $args; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 3 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 3 | my ($self) = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | 3 | bless( $self, $class ); | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | $self->{'PASSWD'} = $passwdFile; | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | $self->{'ERROR'} = ""; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | $self->{'LOCK'} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | $self->{'OPEN'} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 3 | ▶ | $self->{'READONLY'} = $args->{'ReadOnly'} if ref $args eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | ▶ | $self->{'USEMD5'} = $args->{'UseMD5'} if ref $args eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | ▶ | $self->{'USEPLAIN'} = $args->{'UsePlain'} if ref $args eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | ▶ | sub error { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 2 | return $self->{'ERROR'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 7 | ▶ | sub htCheckPassword { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
htCheckPassword: called CC=10 SCAR=24.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 7 | my $Id = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | 7 | my $pass = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | 7 | my $MD5Magic = '$apr1$'; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 7 | my $SHA1Magic = '{SHA}'; | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 7 | my $cryptPass = $self->fetchPass($Id); | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | 7 | ▶ | if ( !$cryptPass ) { return undef; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 6 | ▶ | if (index($cryptPass, $MD5Magic) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # This is an MD5 password | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | require Crypt::PasswdMD5; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | my $salt = $cryptPass; | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | $salt =~ s/^\Q$MD5Magic//; # Take care of the magic string if present | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | $salt =~ s/^(.*)\$/$1/; # Salt can have up to 8 chars... | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | $salt = substr( $salt, 0, 8 ); # That means no more than 8 chars too. | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | ▶ | return 1 if Crypt::PasswdMD5::apache_md5_crypt( $pass, $salt ) eq $cryptPass; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | elsif (index($cryptPass, $SHA1Magic) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # This is an SHA1 password | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | require Digest::SHA; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | require MIME::Base64; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | return 1 if '{SHA}'.MIME::Base64::encode_base64( Digest::SHA::sha1( $pass ), '' ) eq $cryptPass; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # See if it is encrypted using crypt | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 4 | ▶ | return 1 if crypt($pass, $cryptPass) eq $cryptPass; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # See if it is a plain, unencrypted password | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | ▶ | return 1 if $self->{USEPLAIN} && $pass eq $cryptPass; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"USEPLAIN"} and $pass eq $cryptPass
MC/DC0%0/2
$self->{"USEPLAIN"} and $pass eq $cryptPass
$self->{"USEPLAIN"}
$pass eq $cryptPass
Truth table33%1/3
A and B
A= $self->{"USEPLAIN"}B= $pass eq $cryptPass
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $self->{'ERROR'} = | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | __PACKAGE__ . "::htCheckPassword - Passwords do not match."; | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | carp $self->error() if caller eq $self; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 5 | ▶ | sub htpasswd { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
htpasswd: called CC=10 SCAR=23.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | 5 | my $Id = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | 5 | my $newPass = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | 5 | my $oldPass = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | 5 | my $noOld = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 5 | ▶ | if ( $self->{READONLY} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | $self->{'ERROR'} = | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | __PACKAGE__ . "::htpasswd - Can't change passwords in ReadOnly mode"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | carp $self->error(); | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 4 | ▶ | if ( !defined($oldPass) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | $noOld = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 4 | ▶ | if ( defined($oldPass) && ref $oldPass eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $oldPass and ref $oldPass eq "HASH"
MC/DC100%2/2
defined $oldPass and ref $oldPass eq "HASH"
defined $oldPass
ref $oldPass eq "HASH"
Truth table100%3/3
A and B
A= defined $oldPassB= ref $oldPass eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | ▶ | if ($oldPass->{'overwrite'}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | ▶ | $newPass = $Id unless $newPass; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | my $newEncrypted = $self->CryptPasswd($newPass); | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | return $self->writePassword( $Id, $newEncrypted ); | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # New Entry | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 3 | ▶ | if ($noOld) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | my $passwdFile = $self->{'PASSWD'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # Encrypt new password string | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | my $passwordCrypted = $self->CryptPasswd($newPass); | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | $self->_open(); | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | ▶ | if ( $self->fetchPass($Id) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # User already has a password in the file. | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $self->{'ERROR'} = | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | __PACKAGE__ . "::htpasswd - $Id already exists in $passwdFile"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | carp $self->error(); | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | $self->_close(); | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # If we can add the user. | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | seek( FH, 0, SEEK_END ); | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | print FH "$Id\:$passwordCrypted\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | $self->_close(); | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | $self->_close(); | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 2 | $self->_open(); | |||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 2 | my $exists = $self->htCheckPassword( $Id, $oldPass ); | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 2 | ▶ | if ($exists) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | my ($newCrypted) = $self->CryptPasswd($newPass); | |||||||||||||||||||||||||||||||||||||||||||||
| 171 | 1 | return $self->writePassword( $Id, $newCrypted ); | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 173 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # ERROR returned from htCheckPass | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | $self->{'ERROR'} = | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | __PACKAGE__ . "::htpasswd - Password not changed."; | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | carp $self->error(); | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | $self->_close(); | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } # end htpasswd | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | ▶ | sub htDelete { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
htDelete: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | 1 | my $Id = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | my $passwdFile = $self->{'PASSWD'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | my @cache; | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | my $return; | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # Loop through the file, building a cache of exising records | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # which don't match the Id. | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | $self->_open(); | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | seek( FH, 0, SEEK_SET ); | |||||||||||||||||||||||||||||||||||||||||||||
| 201 | 1 | ▶ | while (<FH>) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 2 | ▶ | if (/^$Id\:/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | $return = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1 | push ( @cache, $_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # Write out the @cache if needed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 1 | ▶ | if ($return) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # Return to beginning of file | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 1 | seek( FH, 0, SEEK_SET ); | |||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | ▶ | while (@cache) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 1 | print FH shift (@cache); | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # Cut everything beyond current position | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | truncate( FH, tell(FH) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $self->{'ERROR'} = | |||||||||||||||||||||||||||||||||||||||||||||
| 228 | __PACKAGE__ . "::htDelete - User $Id not found in $passwdFile: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | carp $self->error(); | |||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | $self->_close(); | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 1 | return $return; | |||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 9 | ▶ | sub fetchPass { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetchPass: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 241 | 9 | my $Id = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 242 | 9 | my $passwdFile = $self->{'PASSWD'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 9 | my $passwd = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 9 | $self->_open(); | |||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 9 | ▶ | while (<FH>) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 23 | chop; | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | 23 | my @tmp = split ( /:/, $_, 3 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 251 | 23 | ▶ | if ( $tmp[0] eq $Id ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 7 | $passwd = $tmp[1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | 7 | last; | |||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 9 | $self->_close(); | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 9 | return $passwd; | |||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 2 | ▶ | sub writePassword { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
writePassword: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 266 | 2 | my $Id = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | 2 | my $newPass = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 2 | my $passwdFile = $self->{'PASSWD'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 270 | 2 | my @cache; | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | my $return; | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 2 | $self->_open(); | |||||||||||||||||||||||||||||||||||||||||||||
| 274 | 2 | seek( FH, 0, SEEK_SET ); | |||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 2 | ▶ | while (<FH>) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 4 | my @tmp = split ( /:/, $_, 3 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 279 | 4 | ▶ | if ( $tmp[0] eq $Id ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 2 | ▶ | my $info = $tmp[2] ? $tmp[2] : ""; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 2 | chomp $info; | |||||||||||||||||||||||||||||||||||||||||||||
| 282 | 2 | push ( @cache, "$Id\:$newPass\:$info\n" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 283 | 2 | $return = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 2 | push ( @cache, $_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # Write out the @cache, if needed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 2 | ▶ | if ($return) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # Return to beginning of file | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 2 | seek( FH, 0, SEEK_SET ); | |||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 2 | ▶ | while (@cache) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 4 | print FH shift (@cache); | |||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # Cut everything beyond current position | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 2 | truncate( FH, tell(FH) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | $self->{'ERROR'} = __PACKAGE__ | |||||||||||||||||||||||||||||||||||||||||||||
| 308 | . "::writePassword - User $Id not found in $passwdFile: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | carp $self->error() . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 2 | $self->_close(); | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 2 | return $return; | |||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 1 | ▶ | sub fetchInfo { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetchInfo: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 321 | 1 | my $Id = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 322 | 1 | my $passwdFile = $self->{'PASSWD'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 1 | my $info = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 1 | $self->_open(); | |||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 1 | ▶ | while (<FH>) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 1 | chop; | |||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1 | my @tmp = split ( /:/, $_, 3 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 331 | 1 | ▶ | if ( $tmp[0] eq $Id ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 1 | $info = $tmp[2]; | |||||||||||||||||||||||||||||||||||||||||||||
| 333 | 1 | last; | |||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 1 | $self->_close(); | |||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 1 | return $info; | |||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 2 | ▶ | sub fetchUsers { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetchUsers: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 346 | 2 | my $passwdFile = $self->{'PASSWD'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 347 | 2 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 348 | 2 | my @users; | |||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 2 | $self->_open(); | |||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 2 | ▶ | while (<FH>) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 2 | chop; | |||||||||||||||||||||||||||||||||||||||||||||
| 354 | 2 | my @tmp = split ( /:/, $_, 3 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 355 | 2 | ▶ | push ( @users, $tmp[0] ) unless !$tmp[0]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 2 | $self->_close(); | |||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 2 | ▶ | return wantarray() ? @users : scalar @users; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||
| 363 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 1 | ▶ | sub writeInfo { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
writeInfo: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 367 | 1 | my $Id = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 368 | 1 | my $newInfo = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 1 | my ($passwdFile) = $self->{'PASSWD'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 371 | 1 | my (@cache); | |||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||
| 373 | my ($return); | ||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 1 | $self->_open(); | |||||||||||||||||||||||||||||||||||||||||||||
| 376 | 1 | seek( FH, 0, SEEK_SET ); | |||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 1 | ▶ | while (<FH>) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 2 | my @tmp = split ( /:/, $_, 3 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 2 | ▶ | if ( $tmp[0] eq $Id ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 1 | ▶ | chomp $tmp[1] if ( @tmp == 2 ); # Cut out EOL if there was no info | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 1 | push ( @cache, "$Id\:$tmp[1]\:$newInfo\n" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 385 | 1 | $return = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 388 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 1 | push ( @cache, $_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||
| 393 | # Write out the @cache, if needed. | ||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 1 | ▶ | if ($return) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||
| 397 | # Return to beginning of file | ||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 1 | seek( FH, 0, SEEK_SET ); | |||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 1 | ▶ | while (@cache) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 2 | print FH shift (@cache); | |||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||
| 404 | # Cut everything beyond current position | ||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 1 | truncate( FH, tell(FH) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 408 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | $self->{'ERROR'} = | |||||||||||||||||||||||||||||||||||||||||||||
| 410 | __PACKAGE__ . "::writeInfo - User $Id not found in $passwdFile: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | carp $self->error() . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 1 | $self->_close(); | |||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 1 | return $return; | |||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||
| 419 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 3 | ▶ | sub CryptPasswd { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CryptPasswd: called CC=11 SCAR=34.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 423 | 3 | my $passwd = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 424 | 3 | my $salt = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 425 | 3 | my @chars = ( '.', '/', 0 .. 9, 'A' .. 'Z', 'a' .. 'z' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 426 | 3 | my $Magic = '$apr1$'; # Apache specific Magic chars | |||||||||||||||||||||||||||||||||||||||||||||
| 427 | 3 | ▶ | my $cryptType = ( $^O =~ /^MSWin/i || $self->{'USEMD5'} ) ? "MD5" : "crypt"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$^O =~ /^MSWin/i or $self->{"USEMD5"}
MC/DC0%0/2
$^O =~ /^MSWin/i or $self->{"USEMD5"}
$^O =~ /^MSWin/i
$self->{"USEMD5"}
Truth table33%1/3
A or B
A= $^O =~ /^MSWin/iB= $self->{"USEMD5"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 3 | ▶ | if ( $salt && $cryptType =~ /MD5/i && $salt =~ /^\Q$Magic/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
$salt and $cryptType =~ /MD5/i and $salt =~ /^\Q$Magic\E/
$salt and $cryptType =~ /MD5/i
MC/DC0%0/3
$salt and $cryptType =~ /MD5/i and $salt =~ /^\Q$Magic\E/
$salt
$cryptType =~ /MD5/i
$salt =~ /^\Q$Magic\E/
Truth table25%1/4
A and B and C
A= $saltB= $cryptType =~ /MD5/iC= $salt =~ /^\Q$Magic\E/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # Borrowed from Crypt::PasswdMD5 | ||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | $salt =~ s/^\Q$Magic//; # Take care of the magic string if present | |||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $salt =~ s/^(.*)\$.*$/$1/; # Salt can have up to 8 chars... | |||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | $salt = substr( $salt, 0, 8 ); # That means no more than 8 chars too. | |||||||||||||||||||||||||||||||||||||||||||||
| 435 | # For old crypt only | ||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | ▶ | elsif ( $salt && $cryptType =~ /crypt/i ) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$salt and $cryptType =~ /crypt/i
MC/DC0%0/2
$salt and $cryptType =~ /crypt/i
$salt
$cryptType =~ /crypt/i
Truth table33%1/3
A and B
A= $saltB= $cryptType =~ /crypt/i
| |||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | if ($salt =~ /\$2a\$\d+\$(.{23})/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | $salt = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 440 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 441 | # Make sure only use 2 chars | ||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | $salt = substr( $salt, 0, 2 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 445 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||
| 447 | # If we use MD5, create apache MD5 with 8 char salt: 3 randoms, 5 dots | ||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 3 | ▶ | if ( $cryptType =~ /MD5/i ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 449 | $salt = | ||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | join ( '', map { $chars[ int rand @chars ] } ( 0 .. 2 ) ) | |||||||||||||||||||||||||||||||||||||||||||||
| 451 | . "." x 5; | ||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||
| 453 | # Otherwise fallback to standard archaic crypt | ||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 455 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 3 | $salt = join ( '', map { $chars[ int rand @chars ] } ( 0 .. 1 ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 3 | ▶ | if ( $cryptType =~ /MD5/i ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | require Crypt::PasswdMD5; | |||||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | return Crypt::PasswdMD5::apache_md5_crypt( $passwd, $salt ); | |||||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 464 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 3 | return crypt( $passwd, $salt ); | |||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||
| 469 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 2 | ▶ | sub DESTROY { close(FH); }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||
| 473 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 15 | ▶ | sub _lock { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lock: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 15 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||
| 478 | # Lock if we don't have the lock | ||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 15 | ▶ | flock( FH, LOCK_EX ) if ( $self->{'LOCK'} == 0 ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||
| 481 | # We have the lock | ||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 15 | $self->{'LOCK'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||
| 484 | # Seek to head | ||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 15 | seek( FH, 0, SEEK_SET ); | |||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||
| 488 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 13 | ▶ | sub _unlock { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unlock: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 13 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 13 | flock( FH, LOCK_UN ); | |||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 13 | $self->{'LOCK'} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||
| 498 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 19 | ▶ | sub _open { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_open: called CC=6 SCAR=18.6
| |||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 19 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 19 | ▶ | if ( $self->{'OPEN'} > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 13 | $self->{'OPEN'}++; | |||||||||||||||||||||||||||||||||||||||||||||
| 505 | 13 | $self->_lock(); | |||||||||||||||||||||||||||||||||||||||||||||
| 506 | 13 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 6 | my $passwdFile = $self->{'PASSWD'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 6 | ▶ | if ( $self->{READONLY} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 4 | ▶ | if ( !open( FH, $passwdFile ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | $self->{'ERROR'} = | |||||||||||||||||||||||||||||||||||||||||||||
| 514 | __PACKAGE__ . "::fetchPass - Cannot open $passwdFile: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | croak $self->error(); | |||||||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 518 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 2 | ▶ | if ( !open( FH, "+<$passwdFile" ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | $self->{'ERROR'} = | |||||||||||||||||||||||||||||||||||||||||||||
| 521 | __PACKAGE__ . "::fetchPass - Cannot open $passwdFile: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | croak $self->error(); | |||||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 6 | binmode(FH); | |||||||||||||||||||||||||||||||||||||||||||||
| 527 | 6 | $self->{'OPEN'}++; | |||||||||||||||||||||||||||||||||||||||||||||
| 528 | 6 | ▶ | $self->_lock() unless $self->{READONLY}; # No lock on r/o | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||
| 531 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 17 | ▶ | sub _close { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_close: called CC=4 SCAR=15.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 17 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 535 | 17 | ▶ | $self->_unlock() unless $self->{READONLY}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 17 | $self->{'OPEN'}--; | |||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 17 | ▶ | if ( $self->{'OPEN'} > 0 ) { return; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 5 | ▶ | if ( !close(FH) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | my $passwdFile = $self->{'PASSWD'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | $self->{'ERROR'} = | |||||||||||||||||||||||||||||||||||||||||||||
| 544 | __PACKAGE__ . "::htDelete - Cannot close $passwdFile: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | carp $self->error(); | |||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||
| 550 | #-----------------------------------------------------------# | ||||||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||||||
| 554 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||