line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::LckPwdF; |
2
|
|
|
|
|
|
|
require 5.002; |
3
|
1
|
|
|
1
|
|
278859
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
88
|
|
4
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
803
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
require DynaLoader; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#use diagnostics; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
@ISA = qw(Exporter DynaLoader); |
12
|
|
|
|
|
|
|
@EXPORT = qw(lock_passwd unlock_passwd); |
13
|
|
|
|
|
|
|
@EXPORT_OK = |
14
|
|
|
|
|
|
|
qw(lckpwdf ulckpwdf $Default_Timeout $Rand_Wait $Passwd_Locked $EAGAIN); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
BEGIN: { |
17
|
|
|
|
|
|
|
undef($@); |
18
|
1
|
|
|
1
|
|
763
|
my($Errno_OK) = eval "use Errno qw(EAGAIN EACCES EINVAL EALREADY); 1;"; |
|
1
|
|
|
|
|
8848
|
|
|
1
|
|
|
|
|
153
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
if ($Errno_OK && (!defined($@) || ($@ eq ""))) { |
21
|
|
|
|
|
|
|
$EAGAIN = &EAGAIN(); |
22
|
|
|
|
|
|
|
} else { |
23
|
|
|
|
|
|
|
undef($@); |
24
|
|
|
|
|
|
|
my($Errno_OK) = |
25
|
|
|
|
|
|
|
eval "use Errno qw(EWOULDBLOCK EACCES EINVAL EALREADY); 1;"; |
26
|
|
|
|
|
|
|
if ($Errno_OK && (!defined($@) || ($@ eq ""))) { |
27
|
|
|
|
|
|
|
$EAGAIN = &EWOULDBLOCK(); |
28
|
|
|
|
|
|
|
} else { |
29
|
|
|
|
|
|
|
undef($@); |
30
|
|
|
|
|
|
|
my($POSIX_OK) = eval "use POSIX qw(EAGAIN EACCES EINVAL EALREADY); 1;"; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
if ($POSIX_OK && (!defined($@) || ($@ eq ""))) { |
33
|
|
|
|
|
|
|
$EAGAIN = &EAGAIN(); |
34
|
|
|
|
|
|
|
} else { |
35
|
|
|
|
|
|
|
my($POSIX_OK) = |
36
|
|
|
|
|
|
|
eval "use POSIX qw(EWOULDBLOCK EACCES EINVAL EALREADY); 1;"; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
if ($POSIX_OK && (!defined($@) || ($@ eq ""))) { |
39
|
|
|
|
|
|
|
$EAGAIN = &EWOULDBLOCK(); |
40
|
|
|
|
|
|
|
} else { |
41
|
|
|
|
|
|
|
require ("errno.ph"); |
42
|
|
|
|
|
|
|
$EAGAIN = eval "&EAGAIN();" || eval "&EWOULDBLOCK();"; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
$VERSION = '0.01'; |
48
|
|
|
|
|
|
|
$Default_Timeout = 15; |
49
|
|
|
|
|
|
|
$Rand_Wait = 10; |
50
|
|
|
|
|
|
|
$Passwd_Locked = 0; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
bootstrap File::LckPwdF $VERSION; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Preloaded methods go here. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub lock_passwd (;$) { |
58
|
0
|
|
|
0
|
1
|
|
my($time) = time; |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
unless ($> == 0) { |
61
|
0
|
0
|
|
|
|
|
if (&lckpwdf() >= 0) { |
62
|
0
|
|
|
|
|
|
$Passwd_Locked = 1; |
63
|
0
|
|
|
|
|
|
return 1; |
64
|
|
|
|
|
|
|
} else { |
65
|
0
|
0
|
|
|
|
|
if ($Passwd_Locked) { |
66
|
0
|
|
|
|
|
|
$! = &EALREADY(); |
67
|
|
|
|
|
|
|
} else { |
68
|
0
|
|
|
|
|
|
$! = &EACCES(); |
69
|
|
|
|
|
|
|
} |
70
|
0
|
|
|
|
|
|
return 0; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
if ($Passwd_Locked) { |
75
|
0
|
0
|
|
|
|
|
if (&lckpwdf() >= 0) { |
76
|
0
|
|
|
|
|
|
return 1; |
77
|
|
|
|
|
|
|
} else { |
78
|
0
|
|
|
|
|
|
$! = &EALREADY(); |
79
|
0
|
|
|
|
|
|
return 0; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my($timeout) = $Default_Timeout; |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
if ($#_ > -1) { |
86
|
0
|
|
|
|
|
|
$timeout = $_[0]; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
if ($timeout < 0) { |
|
|
0
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$! = &EINVAL(); |
91
|
0
|
|
|
|
|
|
carp("File::LckPwdF::lock_passwd fed a timeout value below 0"); |
92
|
0
|
|
|
|
|
|
return 0; |
93
|
|
|
|
|
|
|
} elsif ($timeout == 0) { |
94
|
0
|
|
|
|
|
|
until (&lckpwdf() >= 0) { |
95
|
0
|
0
|
|
|
|
|
if ($Rand_Wait > 0) { |
96
|
0
|
|
|
|
|
|
sleep int(rand($Rand_Wait) + 1); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
0
|
|
|
|
|
|
$Passwd_Locked = 1; |
100
|
0
|
|
|
|
|
|
return 1; |
101
|
|
|
|
|
|
|
} else { |
102
|
0
|
0
|
|
|
|
|
if (&lckpwdf() >= 0) { |
103
|
0
|
|
|
|
|
|
$Passwd_Locked = 1; |
104
|
0
|
|
|
|
|
|
return 1; |
105
|
|
|
|
|
|
|
} else { |
106
|
0
|
|
0
|
|
|
|
until ((($status = &lckpwdf()) >= 0) || ((time - $time) >= $timeout)) { |
107
|
0
|
0
|
|
|
|
|
if ($Rand_Wait > 0) { |
108
|
0
|
|
|
|
|
|
sleep int(rand($Rand_Wait) + 1); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
0
|
0
|
|
|
|
|
if ($status >= 0) { |
112
|
0
|
|
|
|
|
|
$Passwd_Locked = 1; |
113
|
0
|
|
|
|
|
|
return 1; |
114
|
|
|
|
|
|
|
} else { |
115
|
0
|
|
|
|
|
|
$! = $EAGAIN; |
116
|
0
|
|
|
|
|
|
return 0; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub unlock_passwd () { |
123
|
0
|
0
|
|
0
|
1
|
|
if (&ulckpwdf() >= 0) { |
124
|
0
|
|
|
|
|
|
$Passwd_Locked = 0; |
125
|
0
|
|
|
|
|
|
return 1; |
126
|
|
|
|
|
|
|
} else { |
127
|
0
|
0
|
|
|
|
|
if (! $Passwd_Locked) { |
|
|
0
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
$! = &EALREADY(); |
129
|
|
|
|
|
|
|
} elsif ($> == 0) { |
130
|
0
|
|
|
|
|
|
$! = &EINVAL; |
131
|
|
|
|
|
|
|
} else { |
132
|
0
|
|
|
|
|
|
$! = &EACCES; |
133
|
|
|
|
|
|
|
} |
134
|
0
|
|
|
|
|
|
return 0; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
END: { |
139
|
|
|
|
|
|
|
if ($Passwd_Locked) { |
140
|
|
|
|
|
|
|
unlock_passwd(); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |
145
|
|
|
|
|
|
|
__END__ |