[Fedora-directory-commits] ldapserver/ldap/admin/src/scripts DSMigration.pm.in, 1.10, 1.11

Richard Allen Megginson (rmeggins) fedora-directory-commits at redhat.com
Sat Sep 8 02:16:30 UTC 2007


Author: rmeggins

Update of /cvs/dirsec/ldapserver/ldap/admin/src/scripts
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv26837/ldapserver/ldap/admin/src/scripts

Modified Files:
	DSMigration.pm.in 
Log Message:
Resolves: bug 282741
Bug Description: Show-Stopper - Migration from DS 6.21 to DS80
Reviewed by: nhosoi (Thanks!)
Fix Description: Added a new function migrateNetscapeRoot which will create a temporary LDIF file from the given NetscapeRoot.ldif file.  The function will look for all \bNetscape\b occurances and convert them to @capbrand@ where that is defined as the capitalized brand name in configure.   It will then import this temporary LDIF file and delete it.
Platforms tested: RHEL5 x86_64
Flag Day: no
Doc impact: no
QA impact: should be covered by regular nightly and manual testing
New Tests integrated into TET: none



Index: DSMigration.pm.in
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/admin/src/scripts/DSMigration.pm.in,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- DSMigration.pm.in	4 Sep 2007 17:50:49 -0000	1.10
+++ DSMigration.pm.in	8 Sep 2007 02:16:27 -0000	1.11
@@ -62,6 +62,8 @@
 use Mozilla::LDAP::API qw(ldap_explode_dn);
 use Mozilla::LDAP::LDIF;
 
+use Carp;
+
 use Exporter;
 @ISA       = qw(Exporter);
 @EXPORT    = qw(migrateDS);
@@ -253,6 +255,35 @@
     return ();
 }
 
+# older versions may use the old Netscape names e.g. Netscape Administration Server
+# we have to convert these to the new names e.g. @capbrand@ Administration Server
+sub migrateNetscapeRoot {
+    my $ldiffile = shift;
+    my ($fh, $tmpldiffile);
+    # create a temp inf file for writing for other processes
+    # never overwrite the user supplied inf file
+    ($fh, $tmpldiffile) = tempfile("nsrootXXXXXX", UNLINK => 0,
+                                   SUFFIX => ".ldif", OPEN => 1,
+                                   DIR => File::Spec->tmpdir);
+    open( MYLDIF, "$ldiffile" ) || confess "Can't open $ldiffile: $!";
+    my $in = new Mozilla::LDAP::LDIF(*MYLDIF);
+    while (my $ent = readOneEntry $in) {
+        my $dn = $ent->getDN();
+        $dn =~ s/\bNetscape\b/@capbrand@/g;
+        $ent->setDN($dn);
+        foreach my $attr (keys %{$ent}) {
+            my @vals = $ent->getValues($attr);
+            map { s/\bNetscape\b/@capbrand@/g } @vals;
+            $ent->setValues($attr, @vals);
+        }
+        Mozilla::LDAP::LDIF::put_LDIF($fh, 78, $ent);        
+    }
+    close( MYLDIF );
+    close( $fh );
+
+    return $tmpldiffile;
+}
+
 # migrate all of the databases in an instance
 sub migrateDatabases {
     my $mig = shift; # the Migration object
@@ -269,13 +300,22 @@
     # database
     my $foundldif;
     for (glob("$mig->{oldsroot}/$inst/db/*.ldif")) {
-        my $dbname = basename($_, '.ldif');
-        my $cmd = "$inst_dir/ldif2db -n \"$dbname\" -i \"$_\"";
+        my $fname = $_;
+        my $dbname = basename($fname, '.ldif');
+        my $deleteflag = 0;
+        if ($fname =~ /NetscapeRoot.ldif$/) {
+            $fname = migrateNetscapeRoot($fname);
+            $deleteflag = 1;
+        }
+        my $cmd = "$inst_dir/ldif2db -n \"$dbname\" -i \"$fname\"";
         debug(1, "migrateDatabases: executing command $cmd\n");
         $? = 0; # clear error condition
         my $output = `$cmd 2>&1`;
+        if ($deleteflag) {
+            unlink($fname);
+        }
         if ($?) {
-            return ('error_importing_migrated_db', $_, $?, $output);
+            return ('error_importing_migrated_db', $fname, $?, $output);
         }
         debug(1, $output);
         $foundldif = 1;




More information about the Fedora-directory-commits mailing list