HomeOU.pm

filter: Statementstmt 18.6% 11 / 59 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 3 / 4 Podpod 100% 1 / 1 totaltotal 18.2% 15 / 82 CC 10 SCAR 44.4
CC
10
Cov
14%
plugin
110.0
BEGIN
1.0
BEGIN
1.0
CRAP 84.8
↑ Summary HomeOUremove.pm »
1 package Plugtools::Plugins::HomeOU;
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::Entry;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 Plugtools::Plugins::HomeOU - Creates the home OU for a user.
10  
11 =head1 VERSION
12  
13 Version 0.0.0
14  
15 =cut
16  
17 2 our $VERSION = '0.0.0';
18  
19 =head1 SYNOPSIS
20  
21 This creates the home OU a user has access to.
22  
23 =cut
24  
25 =head1 Functions
26  
27 =head2 plugin
28  
29 The function that will be called by Plugtools.
30  
31 use Plugtools::Plugins::HomeOU;
32 %returned=Plugtools::Plugins::HomeOU->plugin(\%opts, \%args);
33
34 if($returned{error}){
35 print "Error!\n";
36 }
37  
38 =cut
39  
40 0 ▶sub plugin{
Subroutine plugin: not called CC=10 SCAR=47.0
Pod documented
41 0 my %opts;
42 0 ▶ if(defined($_[1])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
43 0 %opts= %{$_[1]};
44 };
45 0 my %args;
46 0 ▶ if(defined($_[2])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[2]) 0 0 0
47 0 %args= %{$_[2]};
48 };
49  
50 0 my %returned;
51 0 $returned{error}=undef;
52  
53 0 ▶ if (!defined( $opts{self}->{ini}->{HomeOU}->{homebase} )) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts{"self"}{"ini"}{"HomeOU"}{"homebase"}) 0 0 0
54 0 $returned{error}=1;
55 0 $returned{errorString}='The variable "homebase" in the section "HomeOU" is undefined';
56 0 warn('Plugtools-Plugins-HomeOU plugin:1: '.$returned{errorString}{errorString});
57 0 return %returned;
58 }
59  
60 0 ▶ if (!defined( $args{user} )) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"user"}) 0 0 0
61 0 $returned{error}=2;
62 0 $returned{errorString}='$args{user} is noet defined';
63 0 warn('Plugtools-Plugins-HomeOU plugin:2: '.$returned{errorString}{errorString});
64 0 return %returned;
65 }
66  
67 0 my $dn='ou='.$args{user}.','.$opts{self}->{ini}->{HomeOU}->{homebase};
68  
69 my $mesg=$opts{ldap}->search(
70 base=>$opts{self}->{ini}->{HomeOU}->{homebase},
71 0 filter=>'(&(ou='.$args{user}.') (objectClass=organizationalUnit))'
72 );
73 0 ▶ if (!$mesg->{errorMessage} eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (!$mesg->{"errorMessage"} eq "") 0 0 0
74 0 $returned{error}=4;
75 $returned{errorString}='$entry->update($ldap) failed. $mesg->{errorMessage}="'.
76 0 $mesg->{errorMessage}.'"';
77 0 warn('Plugtools-Plugins-HomeOU plugin:4: '.$returned{errorString});
78 0 return %returned;
79 }
80  
81 0 my $entry=$mesg->pop_entry;
82 0 ▶ while (defined($entry)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $entry) 0 0 0
83 0 my $dn2=$entry->dn;
84  
85 0 ▶ if ($dn2 eq $dn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dn2 eq $dn) 0 0 0
86 0 ▶ if ($opts{self}->{ini}->{HomeOU}->{errorIfExists}){
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{'self'}{'ini'}{'HomeOU'}{'errorIfExists'}) { } 0 0 0
87 0 $returned{error}=5;
88 0 $returned{errorString}='The DN "'.$dn.'" already exists.';
89 0 warn('Plugtools-Plugins-HomeOU plugin:5: '.$returned{errorString});
90 0 return %returned;
91 }else {
92 0 return %returned;
93 }
94 }
95  
96 0 $mesg->pop_entry;
97 }
98  
99 0 $entry=Net::LDAP::Entry->new;
100 0 $entry->dn($dn);
101 $entry->add(
102 objectClass=>['top', 'organizationalUnit'],
103 'ou'=>$args{user},
104 0 );
105  
106 0 my $mesg2=$entry->update($opts{ldap});
107 0 ▶ if (!$mesg2->{errorMessage} eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (!$mesg2->{"errorMessage"} eq "") 0 0 0
108 0 $returned{error}=3;
109 $returned{errorString}='$entry->update($ldap) failed. $mesg2->{errorMessage}="'.
110 0 $mesg2->{errorMessage}.'"';
111 0 warn('Plugtools-Plugins-HomeOU plugin:3: '.$returned{errorString});
112 0 return %returned;
113 }
114  
115 0 return %returned;
116 }
117  
118 =head1 ERROR CODES
119  
120 =head2 1
121  
122 The variable "homebase" in the section "HomeOU" is undefined.
123  
124 =head2 2
125  
126 $args{user} is not defined
127  
128 =head2 3
129  
130 Failed to add the new entry.
131  
132 =head2 4
133  
134 The search to check if it exists failed.
135  
136 =head2 5
137  
138 The home OU already exists.
139  
140 =head1 PLUGTOOLS CONFIG
141  
142 pluginAddUser=Plugtools::Plugins::HomeOU
143 [HomeOU]
144 homebase=ou=home,dc=foo,dc=bar
145 errorIfExists=0
146  
147 =head2 homebase
148  
149 This is the DB to create the home OU under.
150  
151 =head2 errorIfExists
152  
153 This controls if it it should error or not if it already exists. If this is defined, it will
154 check if it already exists.
155  
156 If this is not defined, it defaults to false.
157  
158 =head1 LDAP CONFIG
159  
160 A rule like the one below will need setup for this to be useful.
161  
162 access to dn.regex="^(.+,)?ou=([^,]+),ou=home,dc=foo,dc=bar$"
163 by dn.exact,expand="uid=$2,ou=users,dc=foo,dc=bar" write
164 by * none
165  
166 =head1 AUTHOR
167  
168 Zane C. Bowers, C<< <vvelox at vvelox.net> >>
169  
170 =head1 BUGS
171  
172 Please report any bugs or feature requests to C<bug-plugtools at rt.cpan.org>, or through
173 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Plugtools-Plugins-HomeOU>. I will be notified, and then you'll
174 automatically be notified of progress on your bug as I make changes.
175  
176  
177  
178  
179 =head1 SUPPORT
180  
181 You can find documentation for this module with the perldoc command.
182  
183 perldoc Plugtools::Plugins::HomeOU
184 perldoc Plugtools
185  
186  
187 You can also look for information at:
188  
189 =over 4
190  
191 =item * RT: CPAN's request tracker
192  
193 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Plugtools-Plugins-HomeOU>
194  
195 =item * AnnoCPAN: Annotated CPAN documentation
196  
197 L<http://annocpan.org/dist/Plugtools-Plugins-HomeOU>
198  
199 =item * CPAN Ratings
200  
201 L<http://cpanratings.perl.org/d/Plugtools-Plugins-HomeOU>
202  
203 =item * Search CPAN
204  
205 L<http://search.cpan.org/dist/Plugtools-Plugins-HomeOU/>
206  
207 =back
208  
209  
210 =head1 ACKNOWLEDGEMENTS
211  
212  
213 =head1 COPYRIGHT & LICENSE
214  
215 Copyright 2009 Zane C. Bowers, all rights reserved.
216  
217 This program is free software; you can redistribute it and/or modify it
218 under the same terms as Perl itself.
219  
220  
221 =cut
222  
223 2 1; # End of Plugtools
↑ Summary HomeOUremove.pm »