line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::LDAP::Makepath; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20902
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
5
|
1
|
|
|
1
|
|
847
|
use Net::LDAP::Entry; |
|
1
|
|
|
|
|
160590
|
|
|
1
|
|
|
|
|
28
|
|
6
|
1
|
|
|
1
|
|
9
|
use Exporter; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
42
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
409
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
our @EXPORT = qw(LDAPmakepathSimple); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw(LDAPmakepathSimple); |
13
|
|
|
|
|
|
|
our %EXPORT_TAGS = (DEFAULT => [qw(LDAPmakepathSimple)]); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Net::LDAP::Makepath - Provides a methode for creating paths in LDAP simply. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 VERSION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Version 1.0.1 |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $VERSION = '1.0.1'; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SYNOPSIS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
use Net::LDAP::Makepath; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#Uses $ldap to create the new entries. |
34
|
|
|
|
|
|
|
#The objectClasses used are top and organizationalUnit. |
35
|
|
|
|
|
|
|
#The attribute used for the DNs is ou. |
36
|
|
|
|
|
|
|
#The path to be created is "some/path". |
37
|
|
|
|
|
|
|
#The base is "dc=foo,dc=bar". |
38
|
|
|
|
|
|
|
# |
39
|
|
|
|
|
|
|
#The resulting entries are... |
40
|
|
|
|
|
|
|
#dn: ou=some,dc=foo,dc=bar |
41
|
|
|
|
|
|
|
#objectClass: top |
42
|
|
|
|
|
|
|
#objectClass: orginationalUnit |
43
|
|
|
|
|
|
|
#ou: some |
44
|
|
|
|
|
|
|
# |
45
|
|
|
|
|
|
|
#dn: ou=path,ou=some,dc=foo,dc=ath |
46
|
|
|
|
|
|
|
#objectClass: top |
47
|
|
|
|
|
|
|
#objectClass: orginationalUnit |
48
|
|
|
|
|
|
|
#ou: path |
49
|
|
|
|
|
|
|
my $returned=LDAPmakepathSimple($ldap, ["top", "organizationalUnit"], "ou", |
50
|
|
|
|
|
|
|
"some,path", "dc=foo,dc=bar") |
51
|
|
|
|
|
|
|
if(!returned){ |
52
|
|
|
|
|
|
|
print "LDAPmakepathSimple failed."; |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 EXPORT |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
LDAPmakepathSimple |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 FUNCTIONS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 LDAPmakepathSimple |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
This creates a path from a comma seperated path. Five arguements are required. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
The first arguement is a Net::LDAP connection object. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
The second arguement is a array of objectClasses. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
The third the attribute to use for creating the DNs. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
The fourth is the path to use. It is broken apart at each ,. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
The firth is the base DN to use. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
The returned object is a perl boolean value. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub LDAPmakepathSimple { |
81
|
0
|
|
|
0
|
1
|
|
my $ldap=$_[0]; #this contains the LDAP connection |
82
|
0
|
|
|
|
|
|
my @objectClasses=$_[1]; #a array holding the attributes |
83
|
0
|
|
|
|
|
|
my $attribute=$_[2]; # the attribute to use for each path part |
84
|
0
|
|
|
|
|
|
my $path=$_[3]; # a path using , as the delimiter |
85
|
0
|
|
|
|
|
|
my $start=$_[4]; # this is where it starts at |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
#splits $path at each , |
88
|
0
|
|
|
|
|
|
my @pathA=split(/,/, $path); |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my $pathAint=0;#used for intering through @pathA |
91
|
|
|
|
|
|
|
#sets the previous DN as it will be used in the construction in the loop |
92
|
0
|
|
|
|
|
|
my $previousDN=$start; |
93
|
|
|
|
|
|
|
#go through @pathA and add each one |
94
|
0
|
|
|
|
|
|
while(defined($pathA[$pathAint])){ |
95
|
0
|
|
|
|
|
|
my $dn=$attribute."=".$pathA[$pathAint].",".$previousDN; |
96
|
0
|
|
|
|
|
|
$previousDN=$dn; #sets the previous DN for use on the next path |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
#creates the new entry |
99
|
0
|
|
|
|
|
|
my $entry = Net::LDAP::Entry->new; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
#sets the DN |
102
|
0
|
|
|
|
|
|
$entry->dn($dn); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
#adds the attributes |
105
|
0
|
|
|
|
|
|
$entry->add(objectClass=>@objectClasses, $attribute=>$pathA[$pathAint]); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
#sets the change type on this entry to add as it is being added |
108
|
0
|
|
|
|
|
|
$entry->changetype("add"); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
#update it and warn if it fails. |
111
|
0
|
|
|
|
|
|
my $mesg=$entry->update($ldap); |
112
|
0
|
0
|
|
|
|
|
if($mesg->is_error){ |
113
|
0
|
0
|
|
|
|
|
if($pathAint == $#pathA){ |
114
|
0
|
|
|
|
|
|
warn("Adding '".$dn."' failed. Path creation failed."); |
115
|
0
|
|
|
|
|
|
return undef; |
116
|
|
|
|
|
|
|
}; |
117
|
|
|
|
|
|
|
}; |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
$pathAint++; |
120
|
|
|
|
|
|
|
}; |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
return 1; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 AUTHOR |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Zane C. Bowers, C<< >> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 BUGS |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
133
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
134
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 SUPPORT |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
perldoc Net::LDAP::Makepath |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
You can also look for information at: |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=over 4 |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
L |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
L |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item * CPAN Ratings |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
L |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item * Search CPAN |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
L |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=back |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Copyright 2008 Zane C. Bowers, all rights reserved. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
177
|
|
|
|
|
|
|
under the same terms as Perl itself. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
1; # End of Net::LDAP::Makepath |