This is a multi-part message in MIME format.
--------------AED2FFEE73F73B1613190B64
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
The tool to generate the test LDIF is attached. It reads an LDIF containing 500,000 users on stdin, and outputs the same LDIF,
with aliases interspersed, on stdout.
Slightly tweaked, creates the alias after the target entry. In case the server does referential integrity on loading.
--
-- Howard Chu
CTO, Symas Corp.
http://www.symas.com
Director, Highland Sun
http://highlandsun.com/hyc/
Chief Architect, OpenLDAP
http://www.openldap.org/project/
--------------AED2FFEE73F73B1613190B64
Content-Type: text/x-csrc;
name="mkalias.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="mkalias.c"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define NUMUSERS 500000
#define NUMALIASES 30000
#define NUMSUBALIASES 435
#define SUFFIX "dc=example,dc=com"
static const char ou1[] = "\
dn: ou=alias1," SUFFIX "\n\
objectclass: top\n\
objectclass: organizationalUnit\n\
ou: alias1\n";
static const char ou2[] = "\
dn: ou=alias2," SUFFIX "\n\
objectclass: top\n\
objectclass: organizationalUnit\n\
ou: alias2\n";
int qcmp(const void *a, const void *b)
{
const int *i = a, *j = b;
return *i - *j;
}
int main() {
char line[1024], dn[1024], *ou;
int aliases[NUMALIASES];
int subaliases[NUMSUBALIASES];
int i;
int nusers=0, naliases=0, nsubaliases=0, showalias=0;
/* select a random subset of users to generate aliases */
srand(time(0L));
for (i=0; i<NUMALIASES; i++) {
aliases[i] = rand() % NUMUSERS;
}
uniq1:
qsort(aliases, NUMALIASES, sizeof(int), qcmp);
/* make sure they're unique */
for (i=1; i<NUMALIASES; i++) {
if (aliases[i-1] == aliases[i]) {
aliases[i] = rand() % NUMUSERS;
goto uniq1;
}
}
/* select a random susbset of aliases for the target subtree */
for (i=0; i<NUMSUBALIASES; i++) {
subaliases[i] = rand() % NUMALIASES;
}
uniq2:
qsort(subaliases, NUMSUBALIASES, sizeof(int), qcmp);
/* make sure they're unique */
for (i=1; i<NUMSUBALIASES; i++) {
if (subaliases[i-1] == subaliases[i]) {
subaliases[i] = rand() % NUMALIASES;
goto uniq2;
}
}
for (i=0; i<NUMSUBALIASES; i++) {
subaliases[i] = aliases[subaliases[i]];
}
/* read LDIF */
while (fgets(line, sizeof(line), stdin) != NULL) {
if (line[0] == '#')
continue;
if (!strncmp(line, "dn: ", 4)) {
/* we assume all users' DNs use uid for RDN */
if (!strncmp(line+4, "uid=", 4)) {
if (!nusers) {
puts(ou1);
puts(ou2);
}
if (showalias) {
printf("dn: uid=x.%d,ou=%s," SUFFIX "\n", nusers, ou);
puts("objectclass: alias");
puts("objectclass: extensibleObject");
printf("aliasedObjectName: %s\n", dn);
showalias = 0;
}
if (nusers == aliases[naliases] ||
nusers == subaliases[nsubaliases]) {
if (nusers == subaliases[nsubaliases]) {
ou = "alias2";
nsubaliases++;
} else {
ou = "alias1";
}
naliases++;
strcpy(dn, line+4);
showalias = 1;
}
nusers++;
}
}
fputs(line, stdout);
}
return 0;
}
--------------AED2FFEE73F73B1613190B64--