line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plugtools::Plugins::HomeOU; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
26445
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
5
|
1
|
|
|
1
|
|
938
|
use Net::LDAP::Entry; |
|
1
|
|
|
|
|
178991
|
|
|
1
|
|
|
|
|
448
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub plugin{ |
41
|
0
|
|
|
0
|
1
|
|
my %opts; |
42
|
0
|
0
|
|
|
|
|
if(defined($_[1])){ |
43
|
0
|
|
|
|
|
|
%opts= %{$_[1]}; |
|
0
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
}; |
45
|
0
|
|
|
|
|
|
my %args; |
46
|
0
|
0
|
|
|
|
|
if(defined($_[2])){ |
47
|
0
|
|
|
|
|
|
%args= %{$_[2]}; |
|
0
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my %returned; |
51
|
0
|
|
|
|
|
|
$returned{error}=undef; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
if (!defined( $opts{self}->{ini}->{HomeOU}->{homebase} )) { |
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
|
0
|
|
|
|
|
if (!defined( $args{user} )) { |
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
|
0
|
|
|
|
|
|
my $mesg=$opts{ldap}->search( |
70
|
|
|
|
|
|
|
base=>$opts{self}->{ini}->{HomeOU}->{homebase}, |
71
|
|
|
|
|
|
|
filter=>'(&(ou='.$args{user}.') (objectClass=organizationalUnit))' |
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-HomeOU plugin:4: '.$returned{errorString}); |
78
|
0
|
|
|
|
|
|
return %returned; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $entry=$mesg->pop_entry; |
82
|
0
|
|
|
|
|
|
while (defined($entry)) { |
83
|
0
|
|
|
|
|
|
my $dn2=$entry->dn; |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
if ($dn2 eq $dn) { |
86
|
0
|
0
|
|
|
|
|
if ($opts{self}->{ini}->{HomeOU}->{errorIfExists}){ |
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
|
0
|
|
|
|
|
|
$entry->add( |
102
|
|
|
|
|
|
|
objectClass=>['top', 'organizationalUnit'], |
103
|
|
|
|
|
|
|
'ou'=>$args{user}, |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
my $mesg2=$entry->update($opts{ldap}); |
107
|
0
|
0
|
|
|
|
|
if (!$mesg2->{errorMessage} eq '') { |
108
|
0
|
|
|
|
|
|
$returned{error}=3; |
109
|
0
|
|
|
|
|
|
$returned{errorString}='$entry->update($ldap) failed. $mesg2->{errorMessage}="'. |
110
|
|
|
|
|
|
|
$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<< >> |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 BUGS |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
173
|
|
|
|
|
|
|
the web interface at L. 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 |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
L |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item * CPAN Ratings |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
L |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item * Search CPAN |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
L |
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
|
|
|
|
|
|
|
1; # End of Plugtools |