Author: nhosoi
Update of /cvs/dirsec/adminserver/admserv/cgi-src40
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv8193/admserv/cgi-src40
Added Files:
ds_remove.in ds_remove.res
Log Message:
Resolves: #247215
Summary: Reimplement ds_remove without setuputil code (comment #7)
Description: adding Perl version of ds_remove
--- NEW FILE ds_remove.in ---
#!/usr/bin/env perl
# BEGIN COPYRIGHT BLOCK
# This Program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 2 of the License.
#
# This Program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA.
#
# In addition, as a special exception, Red Hat, Inc. gives You the additional
# right to link the code of this Program with code not covered under the GNU
# General Public License ("Non-GPL Code") and to distribute linked combinations
# including the two, subject to the limitations in this paragraph. Non-GPL Code
# permitted under this exception must only link to the code of this Program
# through those well defined interfaces identified in the file named EXCEPTION
# found in the source code files (the "Approved Interfaces"). The files of
# Non-GPL Code may instantiate templates or use macros or inline functions from
# the Approved Interfaces without causing the resulting work to be covered by
# the GNU General Public License. Only Red Hat, Inc. may make changes or
# additions to the list of Approved Interfaces. You must obey the GNU General
# Public License in all respects for all of the Program code and other code used
# in conjunction with the Program except the Non-GPL Code covered by this
# exception. If you modify this file, you may extend this exception to your
# version of the file, but you are not obligated to do so. If you do not wish to
# provide this exception without modification, you must delete this exception
# statement from your version and license this file solely under the GPL without
# exception.
#
#
# Copyright (C) 2007 Red Hat, Inc.
# All rights reserved.
# END COPYRIGHT BLOCK
#
use lib '@perldir@';
use strict;
use File::Basename;
use File::Path;
use CGI qw(:cgi :oldstyle_urls);
use Inf;
use AdminUtil;
use Util;
use FileConn;
use Resource;
sub remove_tree
{
my $centry = shift;
my $key = shift;
my $instname = shift;
my $isparent = shift;
foreach my $path ( @{$centry->{$key}} )
{
my $rmdir = "";
if ( 1 == $isparent )
{
$rmdir = dirname($path);
}
else
{
$rmdir = $path;
}
if ( -d $rmdir && $rmdir =~ /$instname/ )
{
my $rc = rmtree($rmdir);
print STDERR "rmtree: $rmdir => RC: $rc\n";
}
}
}
sub remove_pidfile
{
my ($type, $instdir, $instname) = @_;
my $pattern = "^" . $type . ".*=";
my $pidline = `grep $pattern $instdir/start-slapd`;
chomp($pidline);
my ($key, $pidfile) = split(/=/, $pidline);
if ( -e $pidfile && $pidfile =~ /$instname/ )
{
unlink($pidfile);
}
}
my $res = new Resource("@propertydir(a)/ds_remove.res",
"@propertydir(a)/setup-ds-admin.res",
"@propertydir(a)/setup-ds.res");
# parse the input parameters
my $query = new CGI;
# call ds_newinst as a GET (GET or POST works, GET is simpler)
$ENV{REQUEST_METHOD} = "GET";
$ENV{QUERY_STRING} = $query->query_string();
my $instname = $query->param('InstanceName');
my ($slapd, $inst) = split(/-/, $instname, 2);
my @errs;
my $inf = createInfFromConfig("@instconfigdir@/slapd-$inst", $inst, \@errs);
if (@errs) {
print "Content-type: text/html\n\n";
print "NMC_ErrInfo: ", $res->getText(@errs), "\n";
print "NMC_Status: 1\n";
exit 1;
}
# add the parmeters necessary to configure this DS to be managed
# by the console and to be registered with the config DS - these
# are usually passed in via the CGI params, or use reasonable
# default values
my $admConf = getAdmConf("@instconfigdir@/admin-serv");
$inf->{General}->{ConfigDirectoryLdapURL} = $query->param('ldap_url') ||
$admConf->{ldapurl};
$inf->{General}->{AdminDomain} = $query->param('admin_domain') ||
$admConf->{AdminDomain};
# read the config file to find out the paths
my $dseldif = "@instconfigdir(a)/$instname/dse.ldif";
my $conn = new FileConn($dseldif);
my $dn = "cn=config";
my $entry = $conn->search($dn, "base", "(cn=*)", 0);
if (!$entry) {
print "Content-type: text/html\n\n";
print "NMC_ErrInfo: Search $dn in $dseldif failed: $entry\n";
print "NMC_Status: 1\n";
exit 1;
}
# stop the server first
my $instdir = "";
foreach my $path ( @{$entry->{"nsslapd-instancedir"}} )
{
if ( -d $path )
{
my $prog = $path . "/stop-slapd";
if (-x $prog) {
$? = 0;
# run the CGI
my $output = `$prog 2>&1`;
my $status = $?;
if ($status) {
# Ignore the stop failure
print "Content-type: text/html\n\n";
print "NMC_ErrInfo: Could not stop directory server:
$output\n";
}
$instdir = $path; # need to use it later...
} else {
print "Content-type: text/html\n\n";
print "NMC_ErrInfo: The program $prog does not exist\n";
print "NMC_Status: 1\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/html\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/html\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 )
{
# clean up pid files (if any)
remove_pidfile("STARTPIDFILE", $instdir, $instname);
remove_pidfile("PIDFILE", $instdir, $instname);
my $rc = rmtree($instdir);
}
# if we got here, report success
print "Content-type: text/html\n\n";
print "NMC_Status: 0\n";
exit 0;
--- NEW FILE ds_remove.res ---
# resources for ds_remove