| 1 | package Plugtools::Plugins::HomeOUremove; | ||||||||||
| 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 | |||||||||||
| 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 | 2 | 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 | 0 | ▶ | sub plugin{ | ||||||||
|
Subroutine
plugin: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||
| 40 | 0 | my %opts; | |||||||||
| 41 | 0 | ▶ | if(defined($_[1])){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 0 | %opts= %{$_[1]}; | |||||||||
| 43 | }; | ||||||||||
| 44 | 0 | my %args; | |||||||||
| 45 | 0 | ▶ | if(defined($_[2])){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 0 | %args= %{$_[2]}; | |||||||||
| 47 | }; | ||||||||||
| 48 | |||||||||||
| 49 | 0 | my %returned; | |||||||||
| 50 | 0 | $returned{error}=undef; | |||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | if (!defined( $opts{self}->{ini}->{HomeOU}->{homebase} )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | if (!defined( $args{user} )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | my $mesg=$opts{ldap}->search( | ||||||||||
| 69 | 0 | base=>$dn, | |||||||||
| 70 | filter=>'(objectClass=*)', | ||||||||||
| 71 | scope=>'sub', | ||||||||||
| 72 | ); | ||||||||||
| 73 | 0 | ▶ | if (!$mesg->{errorMessage} eq '') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 0 | $returned{error}=4; | |||||||||
| 75 | $returned{errorString}='$entry->update($ldap) failed. $mesg->{errorMessage}="'. | ||||||||||
| 76 | 0 | $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)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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])) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | if (!$mesg2->{errorMessage} eq '') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 0 | $returned{error}=3; | |||||||||
| 106 | $returned{errorString}='$entry->update($ldap) failed. $mesg2->{errorMessage}="'. | ||||||||||
| 107 | 0 | $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<< <vvelox at vvelox.net> >> | ||||||||||
| 149 | |||||||||||
| 150 | =head1 BUGS | ||||||||||
| 151 | |||||||||||
| 152 | Please report any bugs or feature requests to C<bug-plugtools at rt.cpan.org>, or through | ||||||||||
| 153 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Plugtools-Plugins-HomeOU>. 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<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Plugtools-Plugins-HomeOU> | ||||||||||
| 174 | |||||||||||
| 175 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 176 | |||||||||||
| 177 | L<http://annocpan.org/dist/Plugtools-Plugins-HomeOU> | ||||||||||
| 178 | |||||||||||
| 179 | =item * CPAN Ratings | ||||||||||
| 180 | |||||||||||
| 181 | L<http://cpanratings.perl.org/d/Plugtools-Plugins-HomeOU> | ||||||||||
| 182 | |||||||||||
| 183 | =item * Search CPAN | ||||||||||
| 184 | |||||||||||
| 185 | L<http://search.cpan.org/dist/Plugtools-Plugins-HomeOU/> | ||||||||||
| 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 | 2 | 1; # End of Plugtools | |||||||||