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