line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sys::User::UIDhelper; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
28573
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
314
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Sys::User::UIDhelper - Helps for locating free UIDs. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.0.1 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.0.1'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
This finds a |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Sys::User::UIDhelper; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#implements it with the default values |
26
|
|
|
|
|
|
|
my $foo = Sys::User::UIDhelper->new(); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#sets the min to 0 and the max to 4000 |
29
|
|
|
|
|
|
|
my $foo = Sys::User::UIDhelper->new({max=>'0', min=>'4000'}); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#finds the first free one |
32
|
|
|
|
|
|
|
my $first = $foo->firstfree(); |
33
|
|
|
|
|
|
|
if(defined($first)){ |
34
|
|
|
|
|
|
|
print $first."\n"; |
35
|
|
|
|
|
|
|
}else{ |
36
|
|
|
|
|
|
|
print "not found\n"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#finds the first last one |
40
|
|
|
|
|
|
|
my $last = $foo->lastfree(); |
41
|
|
|
|
|
|
|
if(defined($last)){ |
42
|
|
|
|
|
|
|
print $last."\n"; |
43
|
|
|
|
|
|
|
}else{ |
44
|
|
|
|
|
|
|
print "not found\n"; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 EXPORT |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 FUNCTIONS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 new |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
This initiates the module. It accepts one arguement, a hash. Please See below |
56
|
|
|
|
|
|
|
for accepted values. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head3 min |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
The minimum UID. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head3 max |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
The maximum UID. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub new { |
69
|
0
|
|
|
0
|
1
|
|
my %args; |
70
|
0
|
0
|
|
|
|
|
if(defined($_[1])){ |
71
|
0
|
|
|
|
|
|
%args= %{$_[1]}; |
|
0
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my $self={error=>undef, set=>undef}; |
75
|
0
|
|
|
|
|
|
bless $self; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
#set default max |
78
|
|
|
|
|
|
|
#this number is based on FreeBSD |
79
|
0
|
|
|
|
|
|
$self->{max}=32767; |
80
|
0
|
0
|
|
|
|
|
if (defined($args{max})) { |
81
|
0
|
|
|
|
|
|
$self->{max}=$args{max}; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
#this is choosen as on most systems 1000 is the general base for |
85
|
|
|
|
|
|
|
#new users |
86
|
0
|
|
|
|
|
|
$self->{min}=1000; |
87
|
0
|
0
|
|
|
|
|
if (defined($args{min})) { |
88
|
0
|
|
|
|
|
|
$self->{min}=$args{min}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
return $self; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 firstfree |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
This finds the first free UID. If it returns undef, no free ones were found. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub firstfree { |
101
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my $int=$self->{min}; |
104
|
0
|
|
|
|
|
|
while ( $int <= $self->{max}) { |
105
|
0
|
0
|
|
|
|
|
if (!getpwuid($int)) { |
106
|
0
|
|
|
|
|
|
return $int |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$int++; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
return undef; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 lastfree |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This finds the first last UID. If it returns undef, no free ones were found. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub lastfree { |
122
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
my $int=$self->{max}; |
125
|
0
|
|
|
|
|
|
while ( $int >= $self->{min}) { |
126
|
0
|
0
|
|
|
|
|
if (!getpwuid($int)) { |
127
|
0
|
|
|
|
|
|
return $int |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
$int--; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
return undef; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
#=head2 errorBlank |
137
|
|
|
|
|
|
|
# |
138
|
|
|
|
|
|
|
#A internal function user for clearing an error. |
139
|
|
|
|
|
|
|
# |
140
|
|
|
|
|
|
|
#=cut |
141
|
|
|
|
|
|
|
# |
142
|
|
|
|
|
|
|
#blanks the error flags |
143
|
|
|
|
|
|
|
#sub errorBlank{ |
144
|
|
|
|
|
|
|
# my $self=$_[0]; |
145
|
|
|
|
|
|
|
# |
146
|
|
|
|
|
|
|
# #error handling |
147
|
|
|
|
|
|
|
# $self->{error}=undef; |
148
|
|
|
|
|
|
|
# $self->{errorString}=""; |
149
|
|
|
|
|
|
|
# |
150
|
|
|
|
|
|
|
# return 1; |
151
|
|
|
|
|
|
|
#}; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 Todo |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Implement various backends for system, LDAP, and passwd. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 AUTHOR |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Zane C. Bowers, C<< >> |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 BUGS |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
164
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
165
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 SUPPORT |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
perldoc Sys::User::UIDhelper |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
You can also look for information at: |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=over 4 |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
L |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
L |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item * CPAN Ratings |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
L |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item * Search CPAN |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
L |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=back |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Copyright 2008 Zane C. Bowers, all rights reserved. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
208
|
|
|
|
|
|
|
under the same terms as Perl itself. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=cut |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
1; # End of Sys::User::UIDhelper |