From b5e653a844af60596f9bc6b16349ee902ddb51f5 Mon Sep 17 00:00:00 2001 From: Noriko Hosoi Date: Fri, 22 Jan 2010 09:47:52 -0800 Subject: Allow modrdn to move subtree and rename non-leaf node This patch includes - replacing the entrydn index with the entryrdn index - replacing a full DN in each entry in the DB with an RDN - extending Slapi_Entry, entry2str, and str2entry to absorb the changes made on the entry - adding DN/RDN helper functions - adding DN cache - adding a utility and a migration script to convert the DN format database to the RDN format - extending a database dump utility dbscan to support the entryrdn - slapi_dn_syntax_check by nkinder@redhat.com is added to check the dn before modify operations - big fix for 171338 - Enhancement: winsync modrdn not synced In addition to the above, compile warnings and memory leaks found in testing the new feature are fixed. For more details, see the feature design document at: http://directory.fedoraproject.org/wiki/Subtree_Rename and bugzilla at: https://bugzilla.redhat.com/show_bug.cgi?id=171338 --- ldap/admin/src/scripts/90subtreerename.pl | 52 +++++++++++++++++++++++++++++++ ldap/admin/src/scripts/DSUpdate.pm.in | 2 +- ldap/admin/src/scripts/template-dn2rdn.in | 24 ++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 ldap/admin/src/scripts/90subtreerename.pl create mode 100755 ldap/admin/src/scripts/template-dn2rdn.in (limited to 'ldap/admin/src/scripts') diff --git a/ldap/admin/src/scripts/90subtreerename.pl b/ldap/admin/src/scripts/90subtreerename.pl new file mode 100644 index 00000000..e4746d7b --- /dev/null +++ b/ldap/admin/src/scripts/90subtreerename.pl @@ -0,0 +1,52 @@ +use Mozilla::LDAP::Conn; +use Mozilla::LDAP::Utils qw(normalizeDN); +use Mozilla::LDAP::API qw(:constant ldap_url_parse ldap_explode_dn); + +sub runinst { + my ($inf, $inst, $dseldif, $conn) = @_; + + my @errs; + + my $ent0 = $conn->search("cn=config", "base", "(objectclass=*)"); + if (!$ent0) { + return ('error_finding_config_entry', 'cn=config', + $conn->getErrorString()); + } + my $rundir = $ent0->getValues('nsslapd-rundir'); + + # Check if the server is up or not + my $pidfile = $rundir . "/" . $inst . ".pid"; + if (-e $pidfile) { + return (); # server is running; do nothing. + } + + my $ent1 = $conn->search("cn=config,cn=ldbm database,cn=plugins,cn=config", + "base", "(objectclass=*)"); + if (!$ent1) { + return ('error_finding_config_entry', + 'cn=config,cn=ldbm database,cn=plugins,cn=config', + $conn->getErrorString()); + } + + # Get the value of nsslapd-subtree-rename-switch. + my $need_update = 0; + my $switch = $ent1->getValues('nsslapd-subtree-rename-switch'); + if ("" eq $switch) { + $ent1->addValue('nsslapd-subtree-rename-switch', "on"); + $need_update = 1; + } elsif ("off" eq $switch || "OFF" eq $switch) { + $ent1->setValues('nsslapd-subtree-rename-switch', "on"); + $need_update = 1; + } + + if (1 == $need_update) { + $conn->update($ent1); + # Convert the database format from entrydn to entryrdn + my $instdir = $ent0->getValue('nsslapd-instancedir'); + my $prog = $instdir . "/dn2rdn"; + my $output = `$prog 2>&1`; + my $stat = $?; + } + + return (); +} diff --git a/ldap/admin/src/scripts/DSUpdate.pm.in b/ldap/admin/src/scripts/DSUpdate.pm.in index 20bb40d1..3792afe2 100644 --- a/ldap/admin/src/scripts/DSUpdate.pm.in +++ b/ldap/admin/src/scripts/DSUpdate.pm.in @@ -449,7 +449,7 @@ sub initInfFromInst { $inf->{slapd}->{bak_dir} = $entry->getValue('nsslapd-bakdir'); } if (!$inf->{slapd}->{config_dir}) { - $inf->{slapd}->{config_dir} = $configdir; + $inf->{slapd}->{config_dir} = $configdir."/".$inst; } if (!$inf->{slapd}->{inst_dir}) { $inf->{slapd}->{inst_dir} = $entry->getValue('nsslapd-instancedir'); diff --git a/ldap/admin/src/scripts/template-dn2rdn.in b/ldap/admin/src/scripts/template-dn2rdn.in new file mode 100755 index 00000000..f8232df1 --- /dev/null +++ b/ldap/admin/src/scripts/template-dn2rdn.in @@ -0,0 +1,24 @@ +#!/bin/sh + +prefix="{{DS-ROOT}}" +if [ "$prefix" = "/" ] ; then + prefix="" +fi +LD_LIBRARY_PATH=$prefix/{{SERVER-DIR}}:$prefix@nss_libdir@:$prefix@libdir@ +if [ -n "$prefix" ] ; then + LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:@nss_libdir@" +fi +export LD_LIBRARY_PATH +SHLIB_PATH=$LD_LIBRARY_PATH +export SHLIB_PATH + +cd {{SERVERBIN-DIR}} +if [ $# -eq 0 ] +then + bak_dir={{BAK-DIR}}/reindex_`date +%Y_%m_%d_%H_%M_%S` + ./ns-slapd upgradedb -D {{CONFIG-DIR}} -f -r -a "$bak_dir" +else + echo "Usage: dn2rdn" + exit 1 +fi + -- cgit