blib/lib/Sys/Dev/LDAP/Populate.pm

filter: Statementstmt 13.4% 14 / 104 Branchbran 0.0% 0 / 58 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 100% 3 / 3 totaltotal 12.2% 21 / 172 CC 30 SCAR 66.5
CC
30
Cov
9%
populate
930.0
new
2.0
errorblank
2.0
CRAP 775.2
↑ Summary
1 package Sys::Dev::LDAP::Populate;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Net::LDAP::AutoDNs;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Net::LDAP::AutoServer;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Sys::Dev::LDAP::Populate - Populates various parts of /dev/ldap.
11  
12 =head1 VERSION
13  
14 Version 0.1.1
15  
16 =cut
17  
18 2 our $VERSION = '0.1.1';
19  
20  
21 =head1 SYNOPSIS
22  
23 use Sys::Dev::LDAP::Populate;
24  
25 my $foo = Sys::Dev::LDAP::Populate->new();
26  
27 $foo->populate
28  
29 if($foo->{error}){
30 print "Error!";
31 }
32  
33 For this Net::LDAP::AutoDNs and Net::LDAP::AutoServers is used, with
34 their methods set to the defaults, minus 'devldap'.
35  
36 =head1 METHODS
37  
38 =head2 new
39  
40 Initiates the object.
41  
42 my $foo=Sys::Dev::LDAP::Populate->new;
43  
44 =cut
45  
46 0 ▶sub new{
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
47 0 my $self={
48 error=>undef,
49 errorString=>'',
50 module=>'Sys-Dev-LDAP-Populate',
51 };
52 0 bless $self;
53  
54 0 return $self;
55 }
56  
57 =head2 populate
58  
59 This populates the entries under "/dev/ldap".
60  
61 $foo->populate;
62 if($foo->{error}){
63 print "Error!";
64 }
65  
66 =cut
67  
68 0 ▶sub populate{
Subroutine populate: not called CC=30 SCAR=68.4
Pod documented
69 0 my $self=$_[0];
70 0 my $method='populate';
71  
72 0 $self->errorblank;
73  
74 #makes sure that the ldap device exists
75 0 ▶ if (! -e "/dev/ldap/server") {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e "/dev/ldap/server") 0 0 0
76 0 $self->{error}=1;
77 0 $self->{errorString}='"/dev/ldap/server" does not exist';
78 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
79 0 return undef;
80 }
81  
82 #creates the new AutoDNs object
83 0 my $AutoDNs=Net::LDAP::AutoDNs->new({methods=>"env,hostname"});
84 0 my $AutoServers=Net::LDAP::AutoServer->new({methods=>'hostname,dns,env'});
85
86 #holds the file handle
87 0 my $fh;
88  
89 #writes out the user base
90 0 ▶ if (open($fh , '>', '/dev/ldap/userBase')) {
Branch: 1 branch
BranchTrueFalseTotal
if (open $fh, ">", "/dev/ldap/userBase") 0 0 0
91 0 ▶ if (defined($AutoDNs->{users})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AutoDNs->{'users'}) { } 0 0 0
92 0 print $fh $AutoDNs->{users};
93 }else {
94 0 print $fh '';
95 }
96
97 0 close $fh;
98 }
99  
100 #writes out the group scope
101 0 ▶ if (open($fh , '>', '/dev/ldap/userScope')) {
Branch: 1 branch
BranchTrueFalseTotal
if (open $fh, ">", "/dev/ldap/userScope") 0 0 0
102 0 ▶ if (defined($AutoDNs->{usersScope})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AutoDNs->{'usersScope'}) { } 0 0 0
103 0 print $fh $AutoDNs->{usersScope};
104 }else {
105 0 print $fh '';
106 }
107  
108 0 close $fh;
109 }
110  
111 #writes out the user base
112 0 ▶ if (open($fh , '>', '/dev/ldap/groupBase')) {
Branch: 1 branch
BranchTrueFalseTotal
if (open $fh, ">", "/dev/ldap/groupBase") 0 0 0
113 0 ▶ if (defined($AutoDNs->{groups})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AutoDNs->{'groups'}) { } 0 0 0
114 0 print $fh $AutoDNs->{groups};
115 }else {
116 0 print $fh '';
117 }
118  
119 0 close $fh;
120 }
121  
122 #writes out the group scope
123 0 ▶ if (open($fh , '>', '/dev/ldap/groupScope')) {
Branch: 1 branch
BranchTrueFalseTotal
if (open $fh, ">", "/dev/ldap/groupScope") 0 0 0
124 0 ▶ if (defined($AutoDNs->{groupsScope})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AutoDNs->{'groupsScope'}) { } 0 0 0
125 0 print $fh $AutoDNs->{groupsScope};
126 }else {
127 0 print $fh '';
128 }
129  
130 0 close $fh;
131 }
132  
133 #writes out the home
134 0 ▶ if (open($fh , '>', '/dev/ldap/homeBase')) {
Branch: 1 branch
BranchTrueFalseTotal
if (open $fh, ">", "/dev/ldap/homeBase") 0 0 0
135 0 ▶ if (defined($AutoDNs->{home})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AutoDNs->{'home'}) { } 0 0 0
136 0 print $fh $AutoDNs->{home};
137 }else {
138 0 print $fh '';
139 }
140  
141 0 print $fh $AutoDNs->{home};
142 0 close $fh;
143 }
144  
145 #writes out the base
146 0 ▶ if (open($fh , '>', '/dev/ldap/base')) {
Branch: 1 branch
BranchTrueFalseTotal
if (open $fh, ">", "/dev/ldap/base") 0 0 0
147 0 ▶ if (defined($AutoDNs->{base})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AutoDNs->{'base'}) { } 0 0 0
148 0 print $fh $AutoDNs->{base};
149 }else {
150 0 print $fh '';
151 }
152  
153 0 close $fh;
154 }
155  
156 #writes out the server
157 0 ▶ if (open($fh , '>', '/dev/ldap/server')) {
Branch: 1 branch
BranchTrueFalseTotal
if (open $fh, ">", "/dev/ldap/server") 0 0 0
158 0 ▶ if (defined($AutoServers->{server})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AutoServers->{'server'}) { } 0 0 0
159 0 print $fh $AutoServers->{server};
160 }else {
161 0 print $fh '';
162 }
163  
164 0 close $fh;
165 }
166  
167 #writes out the port
168 0 ▶ if (open($fh , '>', '/dev/ldap/port')) {
Branch: 1 branch
BranchTrueFalseTotal
if (open $fh, ">", "/dev/ldap/port") 0 0 0
169 0 ▶ if (defined($AutoServers->{port})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AutoServers->{'port'}) { } 0 0 0
170 0 print $fh $AutoServers->{port};
171 }else {
172 0 print $fh '';
173 }
174  
175 0 close $fh;
176 }
177  
178 #writes out the startTLS
179 0 ▶ if (open($fh , '>', '/dev/ldap/startTLS')) {
Branch: 1 branch
BranchTrueFalseTotal
if (open $fh, ">", "/dev/ldap/startTLS") 0 0 0
180 0 ▶ if (defined($AutoServers->{startTLS})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AutoServers->{'startTLS'}) { } 0 0 0
181 0 print $fh $AutoServers->{startTLS};
182 }else {
183 0 print $fh '';
184 }
185  
186 0 close $fh;
187 }
188  
189 #writes out the CAfile
190 0 ▶ if (open($fh , '>', '/dev/ldap/CAfile')) {
Branch: 1 branch
BranchTrueFalseTotal
if (open $fh, ">", "/dev/ldap/CAfile") 0 0 0
191 0 ▶ if (defined($AutoServers->{CAfile})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AutoServers->{'CAfile'}) { } 0 0 0
192 0 print $fh $AutoServers->{CAfile};
193 }else {
194 0 print $fh '';
195 }
196  
197 0 close $fh;
198 }
199  
200 #writes out the CApath
201 0 ▶ if (open($fh , '>', '/dev/ldap/CApath')) {
Branch: 1 branch
BranchTrueFalseTotal
if (open $fh, ">", "/dev/ldap/CApath") 0 0 0
202 0 ▶ if (defined($AutoServers->{CApath})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AutoServers->{'CApath'}) { } 0 0 0
203 0 print $fh $AutoServers->{CApath};
204 }else {
205 0 print $fh '';
206 }
207  
208 0 close $fh;
209 }
210  
211 #writes out the checkCRL
212 0 ▶ if (open($fh , '>', '/dev/ldap/checkCRL')) {
Branch: 1 branch
BranchTrueFalseTotal
if (open $fh, ">", "/dev/ldap/checkCRL") 0 0 0
213 0 ▶ if (defined($AutoServers->{checkCRL})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AutoServers->{'checkCRL'}) { } 0 0 0
214 0 print $fh $AutoServers->{checkCRL};
215 }else {
216 0 print $fh '';
217 }
218  
219 0 close $fh;
220 }
221  
222 #writes out the clientCert
223 0 ▶ if (open($fh , '>', '/dev/ldap/clientCert')) {
Branch: 1 branch
BranchTrueFalseTotal
if (open $fh, ">", "/dev/ldap/clientCert") 0 0 0
224 0 ▶ if (defined($AutoServers->{clientCert})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AutoServers->{'clientCert'}) { } 0 0 0
225 0 print $fh $AutoServers->{clientCert};
226 }else {
227 0 print $fh '';
228 }
229  
230 0 close $fh;
231 }
232  
233 #writes out the clientKey
234 0 ▶ if (open($fh , '>', '/dev/ldap/clientKey')) {
Branch: 1 branch
BranchTrueFalseTotal
if (open $fh, ">", "/dev/ldap/clientKey") 0 0 0
235 0 ▶ if (defined($AutoServers->{clientKey})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $AutoServers->{'clientKey'}) { } 0 0 0
236 0 print $fh $AutoServers->{clientKey};
237 }else {
238 0 print $fh '';
239 }
240  
241 0 close $fh;
242 }
243  
244 0 return 1;
245 }
246  
247 =head2 errorblank
248  
249 This blanks the error storage and is only meant for internal usage.
250  
251 It does the following.
252  
253 $zconf->{error}=undef;
254 $zconf->{errorString}="";
255  
256 =cut
257  
258 #blanks the error flags
259 0 ▶sub errorblank{
Subroutine errorblank: not called CC=1 SCAR=6.9
Pod documented
260 0 my $self=$_[0];
261  
262 0 $self->{error}=undef;
263 0 $self->{errorString}="";
264  
265 0 return 1;
266 };
267  
268  
269 =head1 ERROR CODES
270  
271 This may be tested via checking if "$foo->{error}" is true. If it is
272 true, then a description can be found via checking "$foo->{errorString}".
273  
274 =head2 1
275  
276 LDAP kmod does not appear to be present.
277  
278 =head1 AUTHOR
279  
280 Zane C. Bowers, C<< <vvelox at vvelox.net> >>
281  
282 =head1 BUGS
283  
284 Please report any bugs or feature requests to C<bug-sys-dev-ldap-populate at rt.cpan.org>, or through
285 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Sys-Dev-LDAP-Populate>. I will be notified, and then you'll
286 automatically be notified of progress on your bug as I make changes.
287  
288  
289  
290  
291 =head1 SUPPORT
292  
293 You can find documentation for this module with the perldoc command.
294  
295 perldoc Sys::Dev::LDAP::Populate
296  
297  
298 You can also look for information at:
299  
300 =over 4
301  
302 =item * RT: CPAN's request tracker
303  
304 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Sys-Dev-LDAP-Populate>
305  
306 =item * AnnoCPAN: Annotated CPAN documentation
307  
308 L<http://annocpan.org/dist/Sys-Dev-LDAP-Populate>
309  
310 =item * CPAN Ratings
311  
312 L<http://cpanratings.perl.org/d/Sys-Dev-LDAP-Populate>
313  
314 =item * Search CPAN
315  
316 L<http://search.cpan.org/dist/Sys-Dev-LDAP-Populate/>
317  
318 =back
319  
320  
321 =head1 ACKNOWLEDGEMENTS
322  
323  
324 =head1 COPYRIGHT & LICENSE
325  
326 Copyright 2009 Zane C. Bowers, all rights reserved.
327  
328 This program is free software; you can redistribute it and/or modify it
329 under the same terms as Perl itself.
330  
331  
332 =cut
333  
334 2 1; # End of Sys::Dev::LDAP::Populate
↑ Summary