File Coverage

blib/lib/Plugtools/Plugins/HomeOUremove.pm
Criterion Covered Total %
statement 6 54 11.1
branch 0 12 0.0
condition n/a
subroutine 2 3 66.6
pod 1 1 100.0
total 9 70 12.8


line stmt bran cond sub pod time code
1             package Plugtools::Plugins::HomeOUremove;
2              
3 1     1   20431 use warnings;
  1         2  
  1         28  
4 1     1   6 use strict;
  1         2  
  1         441  
5              
6             =head1 NAME
7              
8             Plugtools::Plugins::HomeOUremove - Remove the home OU for a user.
9              
10             =head1 VERSION
11              
12             Version 0.0.0
13              
14             =cut
15              
16             our $VERSION = '0.0.0';
17              
18             =head1 SYNOPSIS
19              
20             This creates the home OU a user has access to.
21              
22             =cut
23              
24             =head1 Functions
25              
26             =head2 plugin
27              
28             The function that will be called by Plugtools.
29              
30             use Plugtools::Plugins::HomeOUremove;
31             %returned=Plugtools::Plugins::HomeOUremove->plugin(\%opts, \%args);
32            
33             if($returned{error}){
34             print "Error!\n";
35             }
36              
37             =cut
38              
39             sub plugin{
40 0     0 1   my %opts;
41 0 0         if(defined($_[1])){
42 0           %opts= %{$_[1]};
  0            
43             };
44 0           my %args;
45 0 0         if(defined($_[2])){
46 0           %args= %{$_[2]};
  0            
47             };
48              
49 0           my %returned;
50 0           $returned{error}=undef;
51              
52 0 0         if (!defined( $opts{self}->{ini}->{HomeOU}->{homebase} )) {
53 0           $returned{error}=1;
54 0           $returned{errorString}='The variable "homebase" in the section "HomeOU" is undefined';
55 0           warn('Plugtools-Plugins-HomeOUremove plugin:1: '.$returned{errorString}{errorString});
56 0           return %returned;
57             }
58              
59 0 0         if (!defined( $args{user} )) {
60 0           $returned{error}=2;
61 0           $returned{errorString}='$args{user} is noet defined';
62 0           warn('Plugtools-Plugins-HomeOUremove plugin:2: '.$returned{errorString}{errorString});
63 0           return %returned;
64             }
65              
66 0           my $dn='ou='.$args{user}.','.$opts{self}->{ini}->{HomeOU}->{homebase};
67              
68 0           my $mesg=$opts{ldap}->search(
69             base=>$dn,
70             filter=>'(objectClass=*)',
71             scope=>'sub',
72             );
73 0 0         if (!$mesg->{errorMessage} eq '') {
74 0           $returned{error}=4;
75 0           $returned{errorString}='$entry->update($ldap) failed. $mesg->{errorMessage}="'.
76             $mesg->{errorMessage}.'"';
77 0           warn('Plugtools-Plugins-HomeOUremove plugin:4: '.$returned{errorString});
78 0           return %returned;
79             }
80              
81 0           my $entry=$mesg->pop_entry;
82 0           my %entries;
83 0           while (defined($entry)) {
84 0           my $dn2=$entry->dn;
85              
86 0           $entries{$dn}=$entry;
87              
88 0           $entry=$mesg->pop_entry;
89             }
90              
91 0           my @DNs=keys(%entries);
92              
93 0           my @sortedDNs=sort(@DNs);
94              
95 0           my $int=$#sortedDNs;
96              
97 0           while (defined($sortedDNs[$int])) {
98 0           my $dn3=$sortedDNs[$int];
99              
100 0           $entry=$entries{$dn};
101 0           $entry->delete;
102              
103 0           my $mesg2=$entry->update($opts{ldap});
104 0 0         if (!$mesg2->{errorMessage} eq '') {
105 0           $returned{error}=3;
106 0           $returned{errorString}='$entry->update($ldap) failed. $mesg2->{errorMessage}="'.
107             $mesg2->{errorMessage}.'"';
108 0           warn('Plugtools-Plugins-HomeOUremove plugin:3: '.$returned{errorString});
109 0           return %returned;
110             }
111              
112 0           $int--;
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 delete the entry.
131              
132             =head2 4
133              
134             The search to check if it exists failed.
135              
136             =head1 PLUGTOOLS CONFIG
137              
138             pluginDeleteUser=Plugtools::Plugins::HomeOUremove
139             [HomeOU]
140             homebase=ou=home,dc=foo,dc=bar
141              
142             =head2 homebase
143              
144             This is the DB to create the home OU under.
145              
146             =head1 AUTHOR
147              
148             Zane C. Bowers, C<< >>
149              
150             =head1 BUGS
151              
152             Please report any bugs or feature requests to C, or through
153             the web interface at L. I will be notified, and then you'll
154             automatically be notified of progress on your bug as I make changes.
155              
156              
157              
158              
159             =head1 SUPPORT
160              
161             You can find documentation for this module with the perldoc command.
162              
163             perldoc Plugtools::Plugins::HomeOU
164             perldoc Plugtools
165              
166              
167             You can also look for information at:
168              
169             =over 4
170              
171             =item * RT: CPAN's request tracker
172              
173             L
174              
175             =item * AnnoCPAN: Annotated CPAN documentation
176              
177             L
178              
179             =item * CPAN Ratings
180              
181             L
182              
183             =item * Search CPAN
184              
185             L
186              
187             =back
188              
189              
190             =head1 ACKNOWLEDGEMENTS
191              
192              
193             =head1 COPYRIGHT & LICENSE
194              
195             Copyright 2009 Zane C. Bowers, all rights reserved.
196              
197             This program is free software; you can redistribute it and/or modify it
198             under the same terms as Perl itself.
199              
200              
201             =cut
202              
203             1; # End of Plugtools