Author: nhosoi
Update of /cvs/dirsec/adminserver/admserv/cgi-src40 In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv20336/admserv/cgi-src40
Modified Files: ds_remove.in Log Message: resolves: #247215 Summary: Reimplement ds_remove (cgi) and ds_removal (command line wrapper) without setuputil code (comment #23)
Index: ds_remove.in =================================================================== RCS file: /cvs/dirsec/adminserver/admserv/cgi-src40/ds_remove.in,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ds_remove.in 24 Jul 2007 20:10:15 -0000 1.3 +++ ds_remove.in 27 Jul 2007 01:35:29 -0000 1.4 @@ -30,16 +30,24 @@ use FileConn; use Resource;
+# remove_tree($centry, $key, $instname, [$isparent, [$dontremove]]) +# $centry: entry to look for the path to be removed +# $key: key to look for the path in the entry +# $instname: instance name "slapd-<ID>" to check the path +# $isparent: specify 1 to remove from the parent dir +# $dontremove: pattern not to be removed (e.g., ".db$") sub remove_tree { my $centry = shift; my $key = shift; my $instname = shift; my $isparent = shift; + my $dontremove = shift;
foreach my $path ( @{$centry->{$key}} ) { my $rmdir = ""; + my $rc = 0; if ( 1 == $isparent ) { $rmdir = dirname($path); @@ -50,8 +58,55 @@ } if ( -d $rmdir && $rmdir =~ /$instname/ ) { - my $rc = rmtree($rmdir); - print STDERR "rmtree: $rmdir => RC: $rc\n"; + if ( "" eq "$dontremove" ) + { + $rc = rmtree($rmdir); + if ( 0 == $rc ) + { + print "Content-type: text/plain\n\n"; + print "NMC_ErrInfo: $rmdir was not removed.\n"; + print STDERR "Warning: $rmdir was not removed.\n"; + } + } + else + { + # Skip the dontremove files + $rc = opendir(DIR, $rmdir); + if ($rc) + { + while (defined(my $file = readdir(DIR))) + { + next if ( "$file" =~ /$dontremove/ ); + next if ( "$file" eq "." ); + next if ( "$file" eq ".." ); + my $rmfile = $rmdir . "/" . $file; + my $rc0 = rmtree($rmfile); + if ( 0 == $rc0 ) + { + print "Content-type: text/plain\n\n"; + print "NMC_ErrInfo: $rmfile was not removed.\n"; + print STDERR "Warning: $rmfile was not removed.\n"; + } + } + closedir(DIR); + } + my $newrmdir = $rmdir . ".removed"; + my $rc1 = 1; + if ( -d $newrmdir ) + { + $rc1 = rmtree($newrmdir); + if ( 0 == $rc1 ) + { + print "Content-type: text/plain\n\n"; + print "NMC_ErrInfo: $newrmdir was not removed.\n"; + print STDERR "Warning: $newrmdir was not removed.\n"; + } + } + if ( 0 < $rc1 ) + { + rename($rmdir, $newrmdir); + } + } } } } @@ -83,12 +138,23 @@
my $instname = $query->param('InstanceName'); my ($slapd, $inst) = split(/-/, $instname, 2); +my $configdir = "@instconfigdir@/slapd-$inst"; +if ( ! -d $configdir ) +{ + print "Content-type: text/plain\n\n"; + print "NMC_ErrInfo: $configdir does not exist\n"; + print "NMC_Status: 1\n"; + print STDERR "Error: $configdir does not exist\n"; + exit 1; +} my @errs; -my $inf = createInfFromConfig("@instconfigdir@/slapd-$inst", $inst, @errs); -if (@errs) { +my $inf = createInfFromConfig($configdir, $inst, @errs); +if (@errs) +{ print "Content-type: text/plain\n\n"; print "NMC_ErrInfo: ", $res->getText(@errs), "\n"; print "NMC_Status: 1\n"; + print STDERR "Error: ", $res->getText(@errs), "\n"; exit 1; }
@@ -108,14 +174,43 @@
my $dn = "cn=config"; my $entry = $conn->search($dn, "base", "(cn=*)", 0); -if (!$entry) { +if (!$entry) +{ print "Content-type: text/plain\n\n"; print "NMC_ErrInfo: Search $dn in $dseldif failed: $entry\n"; print "NMC_Status: 1\n"; + print STDERR "Error: Search $dn in $dseldif failed: $entry\n"; + exit 1; +} + +# Unregister the server from the configuration ds +# get config ds url from input or admconf +# get admin id from input or admconf +# must get admin password from input (PASSWORD_PIPE?) +# get admin domain +# config ds info +if (!unregisterDSWithConfigDS($inst, @errs, $inf)) +{ + print "Content-type: text/plain\n\n"; + print "NMC_ErrInfo: ", $res->getText(@errs), "\n"; + print "NMC_Status: 1\n"; + print STDERR "Error:", $res->getText(@errs), "\n"; + exit 1; +} + +$dn = "cn=config,cn=ldbm database,cn=plugins,cn=config"; +my $dbentry = $conn->search($dn, "base", "(cn=*)", 0); +if (!$dbentry) +{ + print "Content-type: text/plain\n\n"; + print "NMC_ErrInfo: Search $dn in $dseldif failed: $dbentry\n"; + print "NMC_Status: 1\n"; + print "Error: Search $dn in $dseldif failed: $dbentry\n"; exit 1; } +$conn->close();
-# stop the server first +# stop the server my $instdir = ""; foreach my $path ( @{$entry->{"nsslapd-instancedir"}} ) { @@ -131,56 +226,51 @@ # Ignore the stop failure print "Content-type: text/plain\n\n"; print "NMC_ErrInfo: Could not stop directory server: $output\n"; + print STDERR "Warning: Could not stop directory server: $output\n"; } $instdir = $path; # need to use it later... } else { print "Content-type: text/plain\n\n"; print "NMC_ErrInfo: The program $prog does not exist\n"; print "NMC_Status: 1\n"; + print STDERR "Error: The program $prog does not exist\n"; exit 1; } } } - -# Unregister the server from the configuration ds -# get config ds url from input or admconf -# get admin id from input or admconf -# must get admin password from input (PASSWORD_PIPE?) -# get admin domain -# config ds info -if (!unregisterDSWithConfigDS($inst, @errs, $inf)) { - print "Content-type: text/plain\n\n"; - print "NMC_ErrInfo: ", $res->getText(@errs), "\n"; - print "NMC_Status: 1\n"; - exit 1; -} - + # remove physical dirs/files -$dn = "cn=config,cn=ldbm database,cn=plugins,cn=config"; -my $dbentry = $conn->search($dn, "base", "(cn=*)", 0); -if (!$dbentry) { - print "Content-type: text/plain\n\n"; - print "NMC_ErrInfo: Search $dn in $dseldif failed: $dbentry\n"; - print "NMC_Status: 1\n"; - exit 1; -} remove_tree($dbentry, "nsslapd-directory", $instname, 1); remove_tree($dbentry, "nsslapd-db-logdirectory", $instname, 1); remove_tree($entry, "nsslapd-lockdir", $instname); remove_tree($entry, "nsslapd-tmpdir", $instname); remove_tree($entry, "nsslapd-bakdir", $instname, 1); remove_tree($entry, "nsslapd-errorlog", $instname, 1); -remove_tree($entry, "nsslapd-schemadir", $instname, 1);
# instance dir -if ( -d $instdir ) +if ( -d $instdir && $instdir =~ /$instname/ ) { # clean up pid files (if any) remove_pidfile("STARTPIDFILE", $instdir, $instname); remove_pidfile("PIDFILE", $instdir, $instname);
+ if ( 1 == isConfigDS($instname, "@instconfigdir@/admin-serv") ) + { + # if it is the Config DS, adm.conf and local.conf needs to be removed. + unlink("@instconfigdir@/admin-serv/adm.conf"); + unlink("@instconfigdir@/admin-serv/local.conf"); + } + my $rc = rmtree($instdir); + if ( 0 == $rc ) + { + print "Content-type: text/plain\n\n"; + print "NMC_ErrInfo: $instdir was not removed.\n"; + print STDERR "Warning: $instdir was not removed.\n"; + } } +# Finally, config dir +remove_tree($entry, "nsslapd-schemadir", $instname, 1, ".db$");
# if we got here, report success print "Content-type: text/plain\n\n";
389-commits@lists.fedoraproject.org