[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Fedora-directory-commits] adminserver/admserv/cgi-src40 ds_create.in, NONE, 1.1 ds_create.res, NONE, 1.1 Cgi.pm, 1.1.1.1, NONE Makefile, 1.13, NONE



Author: rmeggins

Update of /cvs/dirsec/adminserver/admserv/cgi-src40
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv30934/adminserver/admserv/cgi-src40

Added Files:
	ds_create.in ds_create.res 
Removed Files:
	Cgi.pm Makefile 
Log Message:
Resolves: bug 246683
Bug Description: Reimplement ds_create without setuputil code
Reviewed by: nhosoi (Thanks!)
Fix Description: ds_create was a CGI program that would create a new instance, set it up to be managed by console, and register it with the config ds.  The new ds_create CGI perl script does just that.  One tricky part was that, rather than enabling the pass through auth plugin and having to restart the server, the new server is created without being started, then the modification is done to the new server dse.ldif file directly, using the new FileConn.pm module, which simulates a Mozilla::LDAP::Conn on an LDIF file.  This also allows us to create a new instance with a pre-hashed rootdn password, rather than having to send the cleartext password.
I had to move around some code in AdminServer and AdminUtil so that I could use it from ds_create.  I also implemented support for the admin server PASSWORD_PIPE in perl so we could use it in other CGI perl scripts.
Finally, the error handling was not consistent in our code, so I made explicit the passing of error messages up and down the stack.  Oh how I wish we could just do this in python and use exception handling . . .
I added a test for ds_create.
Platforms tested: RHEL4
Flag Day: Yes - autotool changes
Doc impact: No.  Should work the same way as the old ds_create.



--- NEW FILE ds_create.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 CGI qw(:cgi :oldstyle_urls);
use Inf;
use AdminUtil;
use Util;
use Resource;

my $res = new Resource("@propertydir@/ds_create.res",
                       "@propertydir@/setup-ds-admin.res",
                       "@propertydir@/setup-ds.res");

# parse the input parameters
my $query = new CGI;
# look at arguments
# save old start_server param
# set start_server=0
my $start_server = $query->param('start_server');
$query->param('start_server', '0'); # create server but do not start

# call ds_newinst as a GET (GET or POST works, GET is simpler)
$ENV{REQUEST_METHOD} = "GET";
$ENV{QUERY_STRING} = $query->query_string();

# make sure the child exit code is reset before starting the fake
# cgi program
my $prog = "@bindir@/ds_newinst";
if (! -x $prog) {
    $prog = "@dslibdir@/ds_newinst";
}
$? = 0;
# run the CGI
my $output = `$prog 2>&1`;
my $status = $?;
# check for and report errors
if ($status) {
    print $output;
    exit $status;
}

# set up new DS to be managed by config DS - acis, pta config

# new ds info, needed for registration (or get from new dse.ldif)
#     temp = ds_a_get_cgi_var("servport", NULL, NULL);
#     if (!(cf->servid = ds_a_get_cgi_var("servid", "Server Identifier",
#                                         "Please give your server a short identifier.")))
#     cf->rootdn = dn_normalize_convert(ds_a_get_cgi_var("rootdn", NULL, NULL));
#	if (!(cf->rootpw = ds_a_get_cgi_var("rootpw", NULL, NULL)))
#    cf->start_server = ds_a_get_cgi_var("start_server", NULL, NULL);
my $inst = $query->param('servid');
my @errs;
my $inf = createInfFromConfig("@instconfigdir@/slapd-$inst", $inst, \ errs);
if (@errs) {
    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}->{ConfigDirectoryAdminID} = $query->param('cfg_sspt_uid');
$inf->{General}->{ConfigDirectoryAdminPwd} = $query->param('cfg_sspt_uid_pw');
$inf->{General}->{AdminDomain} = $query->param('admin_domain') ||
    $admConf->{AdminDomain};

if (!createSubDSNoConn($inf, \ errs)) {
    print "NMC_ErrInfo: ", $res->getText(@errs), "\n";
    print "NMC_Status: 1\n";
    exit 1;
}

my $servid = $query->param('servid');
if ($start_server) {
    # ok to use here because not only will ds_newinst have validated that
    # servid contains only good characters, but we test for the existence
    # of this file first
    $prog = "@dslibdir@/slapd-$servid/start-slapd";
    if (-x $prog) {
        $? = 0;
        # run the CGI
        my $output = `$prog 2>&1`;
        my $status = $?;
        if ($status) {
            print "NMC_ErrInfo: Could not start directory server: $output\n";
            print "NMC_Status: $status\n";
            exit $status;
        }
    } else {
        print "NMC_ErrInfo: The program $prog does not exist\n";
        print "NMC_Status: 1\n";
        exit 1;
    }
}

# register the new server with 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 (!registerDSWithConfigDS($servid, \ errs, $inf)) {
    print "NMC_ErrInfo: ", $res->getText(@errs), "\n";
    print "NMC_Status: 1\n";
    exit 1;
}

# if we got here, report success
print "NMC_Status: 0\n";
exit 0;


--- NEW FILE ds_create.res ---
# resources for ds_create


--- Cgi.pm DELETED ---


--- Makefile DELETED ---


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]