1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
#!perl
#
# BEGIN COPYRIGHT BLOCK
# Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
# Copyright (C) 2005 Red Hat, Inc.
# All rights reserved.
# END COPYRIGHT BLOCK
#
# makemccvlvindexes
sub usage_and_exit
{
print "makemccvlvindexes usage\n";
print "\n";
print "This script analyses an LDAP directory in order to create VLV indices which\n";
print "could be configured to improve the performance of one-level searches.\n";
print "This is principally to be used to tune the directory browsing feature\n";
print "of the Mission Control Console.\n";
print "\n";
print "An LDAP client can only take advantage of these indices if it is itself\n";
print "VLV enabled. See the following specification for full details.\n";
print "\n";
print "ftp://ftp.ietf.org/internet-drafts/draft-ietf-ldapext-ldapv3-vlv-00.txt\n";
print "\n";
print "Command Line Arguments\n";
print "-? - help\n";
print "-D rootdn - Provide a root DN. Default= '$rootdn'\n";
print "-w password - Provide a password for the root DN.\n";
print "-h host - Provide a host name. Default= '$host'\n";
print "-p port - Provide a port. Default= '$port'\n";
print "-t threshold - Provide a container subordinate threshold. Default= $threshold\n";
print "-f filter - Provide a search filter. Default= '$vlvfilter'\n";
print "-s sort - Provide a sort specification. Default='$vlvsort'\n";
print "-n - Do the work, but don't create the indices\n";
exit;
}
# Initialise some things
$vlvfilter= "(objectclass=*)";
$vlvsort= "sn givenname cn ou o";
$rootdn= "cn= Directory Manager";
$host= "localhost";
$port= "389";
$threshold= 1000;
$really_do_it= "1";
# Process the command line arguments
while( $arg = shift)
{
if($arg eq "-?")
{
usage_and_exit();
}
elsif($arg eq "-D")
{
$rootdn= shift @ARGV;
}
elsif($arg eq "-w")
{
$rootpw= shift @ARGV;
}
elsif($arg eq "-h")
{
$host= shift @ARGV;
}
elsif($arg eq "-p")
{
$port= shift @ARGV;
}
elsif($arg eq "-t")
{
$threshold= shift @ARGV;
}
elsif($arg eq "-f")
{
$vlvfilter= shift @ARGV;
}
elsif($arg eq "-s")
{
$vlvsort= shift @ARGV;
}
elsif($arg eq "-n")
{
$really_do_it= "0";
}
else
{
print "$arg: Unknown command line argument.\n";
}
}
$ldapsearch= "ldapsearch -h $host -p $port";
$ldapmodify= "ldapmodify -h $host -p $port -D \"$rootdn\" -w $rootpw";
if( $vlvfilter eq "" ||
$vlvsort eq "" ||
$rootdn eq "" ||
$host eq "" ||
$port eq "" ||
$threshold eq "")
{
print "Error: Need command line information..\n";
usage_and_exit();
}
if( $rootpw eq "" )
{
print "Warning: No root DN password provided. Won't be able to add VLV Search and Index entries.\n";
}
# Tell the user what we're up to.
print "Searching all naming contexts on '$host:$port' for containers with more than $threshold subordinate entries\n";
# Read the naming contexts from the root dse
@namingcontexts= `$ldapsearch -s base -b \"\" \"objectclass=*\" namingcontexts`;
# Get rid of the first line 'dn:'
shift @namingcontexts;
# Foreach naming context...
foreach $nc (@namingcontexts)
{
# Extract the base from the naming context
@base= split ' ', $nc;
shift @base;
# Find all the containers
print "Searching naming context '@base' for containers.\n";
@containers= `$ldapsearch -s subtree -b \"@base\" \"numsubordinates=*\" numsubordinates`;
chop @containers;
# Foreach container
while(@containers)
{
# <dn, count, blank>
$dn_line= shift @containers;
$count_line= shift @containers;
shift @containers;
# Extract the count, and check it against the threshold
@count_array= split ' ', $count_line;
$count= @count_array[1];
$dn= substr($dn_line,4);
print "Found container '$dn' with $count subordinates. ";
if($count > $threshold)
{
# We've found a container that should be indexed.
# Extract the DN and RDN of the container
$comma_position= (index $dn, ',');
if($comma_position== -1)
{
$rdn= $dn
}
else
{
$rdn= substr($dn, 0, $comma_position);
}
# Tell the user what we're up to.
print "Adding VLV Search and Index entries.\n";
# Build the vlv search and index entries to be added.
$vlvsearch_name= "MCC $rdn";
@vlvsearch= (
"dn: cn=$vlvsearch_name, cn=config, cn=ldbm\n",
"objectclass: top\n",
"objectclass: vlvSearch\n",
"cn: $vlvsearch_name\n",
"vlvbase: $dn\n",
"vlvfilter: $vlvfilter\n",
"vlvscope: 1\n\n" );
$vlvindex_name= "SN $vlvsearch_name";
@vlvindex= (
"dn: cn=$vlvindex_name, cn=$vlvsearch_name, cn=config, cn=ldbm\n",
"objectclass: top\n",
"objectclass: vlvIndex\n",
"cn: $vlvindex_name\n",
"vlvsort: $vlvsort\n\n" );
@vlvnames = ( @vlvnames, "\"" . $vlvindex_name . "\"");
if($really_do_it eq "1")
{
open(FD,"| $ldapmodify -a -c");
print FD @vlvsearch;
print FD @vlvindex;
close(FD);
}
}
else
{
print "Too small.\n";
}
}
}
# Dump a script to actually create the indexes
if($really_do_it eq "1" && $#vlvnames > 0)
{
print "\n";
print "$#vlvnames VLV indices have been declared. Execute the following commands to build the index files.\n";
print "\n";
print "<instance-dir>\\stop\n";
print "slapd db2index -f <instance-dir>\\config\\slapd.conf -V @vlvnames\n";
print "<instance-dir>\\start\n";
}
|