#!/bin/bash

INSTANCE=instance_bdb
do_import()
{
	dsctl ${INSTANCE} stop
	dsctl ${INSTANCE} ldifgen users --number 1000000 --suffix 'dc=example,dc=com' --parent 'ou=people,dc=example,dc=com' --generic
	dsctl ${INSTANCE} start
	dsconf ${INSTANCE} backend config set --cache-autosize 0
	dsconf ${INSTANCE} backend suffix set --cache-memsize 100000000 userroot
	dsconf ${INSTANCE} backend config set --import-cachesize 100000000
	dsconf ${INSTANCE} backend index add --index-type eq --reindex --attr title userroot
	dsctl ${INSTANCE} stop
	dsctl ${INSTANCE} ldif2db userroot /var/lib/dirsrv/slapd-localhost/ldif/ldifgen.ldif
	dsctl ${INSTANCE} start
}
do_craft_entries()
{
	dsctl ${INSTANCE} start
	#dsconf ${INSTANCE} config replace nsslapd-sizelimit=10000
	dsconf ${INSTANCE} config replace nsslapd-statlog-level=1
	ldapsearch -LLL -H 'ldap://localhost:389' -D "cn=directory manager" -w password -b "dc=example,dc=com"  'title=Senior Visionary' -z 20 dn | grep '^dn' > /tmp/idlscanlimit_victim
	rm /tmp/do_it
	cat /tmp/idlscanlimit_victim | while read f
	do
		echo "$f" >> /tmp/do_it
		echo "changetype: modify" >> /tmp/do_it
		echo "replace: title" >> /tmp/do_it
		echo "title: idlscanlimit_victim" >> /tmp/do_it
		echo  >> /tmp/do_it

	done
	ldapmodify -H 'ldap://localhost:389' -D "cn=directory manager" -w password -f /tmp/do_it
}

do_searchrate()
{
	searchrate -h localhost -p 389 -D "cn=directory manager" -w password -b "dc=example,dc=com"  -f 'title=idlscanlimit_victim' -A dn -t 10
}
do_import
do_craft_entries
#do_searchrate
exit
