0000-12-31 18:09:24 -05:50
|
|
|
#! /usr/bin/python -E
|
|
|
|
# Authors: Karl MacMillan <kmacmillan@mentalrootkit.com>
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007 Red Hat
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
2010-12-09 06:59:11 -06:00
|
|
|
# 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, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
0000-12-31 18:09:24 -05:50
|
|
|
#
|
|
|
|
# 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
|
2010-12-09 06:59:11 -06:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
0000-12-31 18:09:24 -05:50
|
|
|
#
|
|
|
|
|
|
|
|
import sys
|
2009-06-26 12:37:49 -05:00
|
|
|
import socket
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2008-02-05 11:23:53 -06:00
|
|
|
import tempfile, os, pwd, traceback, logging, shutil
|
0000-12-31 18:09:24 -05:50
|
|
|
from ConfigParser import SafeConfigParser
|
|
|
|
|
2009-02-05 14:03:08 -06:00
|
|
|
from ipapython import ipautil
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2010-12-07 17:23:05 -06:00
|
|
|
from ipaserver.install import dsinstance, installutils, krbinstance, service
|
2009-06-26 12:37:49 -05:00
|
|
|
from ipaserver.install import bindinstance, httpinstance, ntpinstance, certs
|
2010-12-13 13:28:11 -06:00
|
|
|
from ipaserver.install.replication import check_replication_plugin
|
2010-03-24 09:51:31 -05:00
|
|
|
from ipaserver.plugins.ldap2 import ldap2
|
2009-02-05 14:03:08 -06:00
|
|
|
from ipapython import version
|
2010-03-24 09:51:31 -05:00
|
|
|
from ipalib import api, errors, util
|
2010-10-29 13:24:31 -05:00
|
|
|
from ipapython.config import IPAOptionParser
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2010-12-07 17:23:05 -06:00
|
|
|
CACERT="/etc/ipa/ca.crt"
|
2008-08-11 15:15:30 -05:00
|
|
|
|
2009-06-26 12:37:49 -05:00
|
|
|
class HostnameLocalhost(Exception):
|
|
|
|
pass
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
class ReplicaConfig:
|
|
|
|
def __init__(self):
|
|
|
|
self.realm_name = ""
|
2008-05-23 13:51:50 -05:00
|
|
|
self.domain_name = ""
|
0000-12-31 18:09:24 -05:50
|
|
|
self.master_host_name = ""
|
|
|
|
self.dirman_password = ""
|
|
|
|
self.ds_user = ""
|
|
|
|
self.host_name = ""
|
|
|
|
self.dir = ""
|
2010-11-01 12:51:14 -05:00
|
|
|
self.subject_base = ""
|
0000-12-31 18:09:24 -05:50
|
|
|
|
|
|
|
def parse_options():
|
2010-10-11 12:06:11 -05:00
|
|
|
usage = "%prog [options] REPLICA_FILE"
|
2010-10-29 13:24:31 -05:00
|
|
|
parser = IPAOptionParser(usage=usage, version=version.VERSION)
|
2008-02-20 10:03:46 -06:00
|
|
|
parser.add_option("-N", "--no-ntp", dest="conf_ntp", action="store_false",
|
|
|
|
help="do not configure ntp", default=True)
|
0000-12-31 18:09:24 -05:50
|
|
|
parser.add_option("-d", "--debug", dest="debug", action="store_true",
|
|
|
|
default=False, help="gather extra debugging information")
|
2010-10-29 13:24:31 -05:00
|
|
|
parser.add_option("-p", "--password", dest="password", sensitive=True,
|
2008-06-04 14:37:12 -05:00
|
|
|
help="Directory Manager (existing master) password")
|
2009-06-26 12:37:49 -05:00
|
|
|
parser.add_option("--setup-dns", dest="setup_dns", action="store_true",
|
|
|
|
default=False, help="configure bind with our zone")
|
2009-09-01 16:28:52 -05:00
|
|
|
parser.add_option("--forwarder", dest="forwarders", action="append",
|
|
|
|
help="Add a DNS forwarder")
|
|
|
|
parser.add_option("--no-forwarders", dest="no_forwarders", action="store_true",
|
|
|
|
default=False, help="Do not add any DNS forwarders, use root servers instead")
|
2011-01-04 07:55:47 -06:00
|
|
|
parser.add_option("--no-reverse", dest="no_reverse", action="store_true",
|
|
|
|
default=False, help="Do not create reverse DNS zone")
|
2010-09-10 16:51:08 -05:00
|
|
|
parser.add_option("--no-host-dns", dest="no_host_dns", action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="Do not use DNS for hostname lookup during installation")
|
2010-11-03 17:17:36 -05:00
|
|
|
parser.add_option("--no-pkinit", dest="setup_pkinit", action="store_false",
|
|
|
|
default=True, help="disables pkinit setup steps")
|
2011-01-03 07:48:29 -06:00
|
|
|
parser.add_option("-U", "--unattended", dest="unattended", action="store_true",
|
|
|
|
default=False, help="unattended installation never prompts the user")
|
0000-12-31 18:09:24 -05:50
|
|
|
|
|
|
|
options, args = parser.parse_args()
|
2010-10-29 13:24:31 -05:00
|
|
|
safe_options = parser.get_safe_opts(options)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
|
|
|
if len(args) != 1:
|
|
|
|
parser.error("you must provide a file generated by ipa-replica-prepare")
|
|
|
|
|
2009-09-01 16:28:52 -05:00
|
|
|
if not options.setup_dns:
|
|
|
|
if options.forwarders:
|
|
|
|
parser.error("You cannot specify a --forwarder option without the --setup-dns option")
|
|
|
|
if options.no_forwarders:
|
|
|
|
parser.error("You cannot specify a --no-forwarders option without the --setup-dns option")
|
2011-01-04 07:55:47 -06:00
|
|
|
if options.no_reverse:
|
|
|
|
parser.error("You cannot specify a --no-reverse option without the --setup-dns option")
|
2009-09-01 16:28:52 -05:00
|
|
|
elif options.forwarders and options.no_forwarders:
|
|
|
|
parser.error("You cannot specify a --forwarder option together with --no-forwarders")
|
|
|
|
elif not options.forwarders and not options.no_forwarders:
|
|
|
|
parser.error("You must specify at least one --forwarder option or --no-forwarders option")
|
|
|
|
|
2010-10-29 13:24:31 -05:00
|
|
|
return safe_options, options, args[0]
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2008-05-08 14:17:59 -05:00
|
|
|
def get_dirman_password():
|
2008-04-29 13:12:00 -05:00
|
|
|
return installutils.read_password("Directory Manager (existing master)", confirm=False, validate=False)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2008-08-08 07:53:55 -05:00
|
|
|
def expand_info(filename, password):
|
0000-12-31 18:09:24 -05:50
|
|
|
top_dir = tempfile.mkdtemp("ipa")
|
2008-08-08 07:53:55 -05:00
|
|
|
tarfile = top_dir+"/files.tar"
|
0000-12-31 18:09:24 -05:50
|
|
|
dir = top_dir + "/realm_info"
|
2008-08-08 07:53:55 -05:00
|
|
|
ipautil.decrypt_file(filename, tarfile, password, top_dir)
|
|
|
|
ipautil.run(["tar", "xf", tarfile, "-C", top_dir])
|
|
|
|
os.remove(tarfile)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
|
|
|
return top_dir, dir
|
|
|
|
|
|
|
|
def read_info(dir, rconfig):
|
|
|
|
filename = dir + "/realm_info"
|
|
|
|
fd = open(filename)
|
|
|
|
config = SafeConfigParser()
|
|
|
|
config.readfp(fd)
|
|
|
|
|
|
|
|
rconfig.realm_name = config.get("realm", "realm_name")
|
|
|
|
rconfig.master_host_name = config.get("realm", "master_host_name")
|
|
|
|
rconfig.ds_user = config.get("realm", "ds_user")
|
2008-02-15 19:47:29 -06:00
|
|
|
rconfig.domain_name = config.get("realm", "domain_name")
|
2008-08-08 07:53:55 -05:00
|
|
|
rconfig.host_name = config.get("realm", "destination_host")
|
2010-01-20 10:26:20 -06:00
|
|
|
rconfig.subject_base = config.get("realm", "subject_base")
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2010-09-10 16:51:08 -05:00
|
|
|
def get_host_name(no_host_dns):
|
0000-12-31 18:09:24 -05:50
|
|
|
hostname = installutils.get_fqdn()
|
|
|
|
try:
|
2010-09-10 16:51:08 -05:00
|
|
|
installutils.verify_fqdn(hostname, no_host_dns)
|
0000-12-31 18:09:24 -05:50
|
|
|
except RuntimeError, e:
|
|
|
|
logging.error(str(e))
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
return hostname
|
|
|
|
|
2009-06-26 12:37:49 -05:00
|
|
|
def resolve_host(host_name):
|
2010-12-01 10:22:56 -06:00
|
|
|
try:
|
|
|
|
addrinfos = socket.getaddrinfo(host_name, None,
|
|
|
|
socket.AF_UNSPEC, socket.SOCK_STREAM)
|
|
|
|
for ai in addrinfos:
|
|
|
|
ip = ai[4][0]
|
|
|
|
if ip == "127.0.0.1" or ip == "::1":
|
|
|
|
raise HostnameLocalhost
|
|
|
|
|
|
|
|
return addrinfos[0][4][0]
|
|
|
|
except:
|
|
|
|
return None
|
2009-06-26 12:37:49 -05:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
def set_owner(config, dir):
|
|
|
|
pw = pwd.getpwnam(config.ds_user)
|
|
|
|
os.chown(dir, pw.pw_uid, pw.pw_gid)
|
|
|
|
|
2009-07-10 15:18:16 -05:00
|
|
|
def install_ca(config):
|
2009-09-10 15:15:14 -05:00
|
|
|
# FIXME, need to pass along the CA plugin to use
|
2010-03-30 14:25:46 -05:00
|
|
|
cafile = config.dir + "/cacert.p12"
|
2009-09-10 15:15:14 -05:00
|
|
|
|
2009-07-10 15:18:16 -05:00
|
|
|
if not ipautil.file_exists(cafile):
|
|
|
|
return None
|
|
|
|
|
|
|
|
try:
|
|
|
|
from ipaserver.install import cainstance
|
|
|
|
except ImportError:
|
|
|
|
print >> sys.stderr, "Import failed: %s" % sys.exc_value
|
|
|
|
sys.exit(1)
|
|
|
|
|
2009-09-10 15:15:14 -05:00
|
|
|
if not cainstance.check_inst():
|
|
|
|
print "A CA was specified but the dogtag certificate server"
|
|
|
|
print "is not installed on the system"
|
|
|
|
print "Please install dogtag and restart the setup program"
|
|
|
|
sys.exit(1)
|
|
|
|
|
2009-07-10 15:18:16 -05:00
|
|
|
cs = cainstance.CADSInstance()
|
|
|
|
cs.create_instance(config.ds_user, config.realm_name, config.host_name, config.domain_name, config.dirman_password)
|
2010-12-08 15:35:12 -06:00
|
|
|
ca = cainstance.CAInstance(config.realm_name, certs.NSS_DIR)
|
2010-01-20 10:26:20 -06:00
|
|
|
ca.configure_instance("pkiuser", config.host_name, config.dirman_password, config.dirman_password, pkcs12_info=(cafile,), master_host=config.master_host_name, subject_base=config.subject_base)
|
2009-07-10 15:18:16 -05:00
|
|
|
|
|
|
|
return ca
|
|
|
|
|
2010-12-07 17:23:05 -06:00
|
|
|
def install_replica_ds(config):
|
0000-12-31 18:09:24 -05:50
|
|
|
dsinstance.check_existing_installation()
|
|
|
|
dsinstance.check_ports()
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
# if we have a pkcs12 file, create the cert db from
|
|
|
|
# that. Otherwise the ds setup will create the CA
|
|
|
|
# cert
|
|
|
|
pkcs12_info = None
|
2008-02-05 11:23:53 -06:00
|
|
|
if ipautil.file_exists(config.dir + "/dscert.p12"):
|
|
|
|
pkcs12_info = (config.dir + "/dscert.p12",
|
2008-07-11 10:34:29 -05:00
|
|
|
config.dir + "/dirsrv_pin.txt")
|
0000-12-31 18:09:24 -05:50
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
ds = dsinstance.DsInstance()
|
2010-12-07 17:23:05 -06:00
|
|
|
ds.create_replica(config.ds_user, config.realm_name,
|
|
|
|
config.master_host_name, config.host_name,
|
|
|
|
config.domain_name, config.dirman_password,
|
|
|
|
pkcs12_info)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2008-03-27 08:33:01 -05:00
|
|
|
return ds
|
|
|
|
|
2010-11-03 17:17:36 -05:00
|
|
|
def install_krb(config, setup_pkinit=False):
|
0000-12-31 18:09:24 -05:50
|
|
|
krb = krbinstance.KrbInstance()
|
|
|
|
ldappwd_filename = config.dir + "/ldappwd"
|
2008-04-09 15:57:41 -05:00
|
|
|
kpasswd_filename = config.dir + "/kpasswd.keytab"
|
2010-11-03 17:17:36 -05:00
|
|
|
|
|
|
|
#pkinit files
|
|
|
|
pkcs12_info = None
|
|
|
|
if ipautil.file_exists(config.dir + "/pkinitcert.p12"):
|
|
|
|
pkcs12_info = (config.dir + "/pkinitcert.p12",
|
|
|
|
config.dir + "/pkinit_pin.txt")
|
|
|
|
|
2011-01-11 09:27:48 -06:00
|
|
|
krb.create_replica(config.ds_user, config.realm_name,
|
|
|
|
config.master_host_name, config.host_name,
|
2008-04-09 15:57:41 -05:00
|
|
|
config.domain_name, config.dirman_password,
|
2010-11-03 17:17:36 -05:00
|
|
|
ldappwd_filename, kpasswd_filename,
|
|
|
|
setup_pkinit, pkcs12_info)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2008-08-11 15:15:30 -05:00
|
|
|
def install_ca_cert(config):
|
2010-12-07 17:23:05 -06:00
|
|
|
cafile = config.dir + "/ca.crt"
|
|
|
|
if not ipautil.file_exists(cafile):
|
|
|
|
raise RuntimeError("Ca cert file is not available")
|
|
|
|
|
|
|
|
try:
|
|
|
|
shutil.copy(cafile, CACERT)
|
|
|
|
os.chmod(CACERT, 0444)
|
|
|
|
except Exception, e:
|
|
|
|
print "error copying files: " + str(e)
|
|
|
|
sys.exit(1)
|
2008-08-11 15:15:30 -05:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
def install_http(config):
|
2008-02-05 11:23:53 -06:00
|
|
|
# if we have a pkcs12 file, create the cert db from
|
|
|
|
# that. Otherwise the ds setup will create the CA
|
|
|
|
# cert
|
|
|
|
pkcs12_info = None
|
|
|
|
if ipautil.file_exists(config.dir + "/httpcert.p12"):
|
|
|
|
pkcs12_info = (config.dir + "/httpcert.p12",
|
2008-07-11 10:34:29 -05:00
|
|
|
config.dir + "/http_pin.txt")
|
2008-02-05 11:23:53 -06:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
http = httpinstance.HTTPInstance()
|
2009-12-07 22:17:00 -06:00
|
|
|
http.create_instance(config.realm_name, config.host_name, config.domain_name, config.dirman_password, False, pkcs12_info, self_signed_ca=True)
|
2008-02-05 11:23:53 -06:00
|
|
|
|
|
|
|
# Now copy the autoconfiguration files
|
2008-07-25 15:56:42 -05:00
|
|
|
if ipautil.file_exists(config.dir + "/preferences.html"):
|
|
|
|
try:
|
|
|
|
shutil.copy(config.dir + "/preferences.html", "/usr/share/ipa/html/preferences.html")
|
|
|
|
shutil.copy(config.dir + "/configure.jar", "/usr/share/ipa/html/configure.jar")
|
|
|
|
except Exception, e:
|
|
|
|
print "error copying files: " + str(e)
|
|
|
|
sys.exit(1)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2009-09-01 16:28:52 -05:00
|
|
|
def install_bind(config, options):
|
|
|
|
if options.forwarders:
|
|
|
|
forwarders = options.forwarders
|
|
|
|
else:
|
|
|
|
forwarders = ()
|
2009-06-26 12:37:49 -05:00
|
|
|
bind = bindinstance.BindInstance(dm_password=config.dirman_password)
|
|
|
|
ip_address = resolve_host(config.host_name)
|
2010-12-01 10:22:56 -06:00
|
|
|
if not ip_address:
|
|
|
|
sys.exit("Unable to resolve IP address for host name")
|
2011-01-04 07:55:47 -06:00
|
|
|
|
|
|
|
create_reverse = True
|
|
|
|
if options.unattended:
|
|
|
|
# In unattended mode just use the cmdline flag
|
|
|
|
create_reverse = not options.no_reverse
|
|
|
|
elif not options.no_reverse:
|
|
|
|
# In interactive mode, if the flag was not explicitly specified, ask the user
|
|
|
|
create_reverse = bindinstance.create_reverse()
|
|
|
|
|
2009-11-10 08:16:38 -06:00
|
|
|
bind.setup(config.host_name, ip_address, config.realm_name,
|
2010-11-11 12:27:27 -06:00
|
|
|
config.domain_name, forwarders, options.conf_ntp, create_reverse)
|
2009-06-26 12:37:49 -05:00
|
|
|
bind.create_instance()
|
|
|
|
|
2008-04-14 18:04:43 -05:00
|
|
|
def check_dirsrv():
|
|
|
|
serverids = dsinstance.check_existing_installation()
|
|
|
|
if serverids:
|
|
|
|
print ""
|
|
|
|
print "An existing Directory Server has been detected."
|
2008-08-06 12:17:13 -05:00
|
|
|
if not ipautil.user_input("Do you wish to remove it and create a new one?", False):
|
2008-04-14 18:04:43 -05:00
|
|
|
print ""
|
|
|
|
print "Only a single Directory Server instance is allowed on an IPA"
|
|
|
|
print "server, the one used by IPA itself."
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
try:
|
|
|
|
service.stop("dirsrv")
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
for serverid in serverids:
|
|
|
|
dsinstance.erase_ds_instance_data(serverid)
|
|
|
|
|
|
|
|
(ds_unsecure, ds_secure) = dsinstance.check_ports()
|
|
|
|
if not ds_unsecure or not ds_secure:
|
|
|
|
print "IPA requires ports 389 and 636 for the Directory Server."
|
|
|
|
print "These are currently in use:"
|
|
|
|
if not ds_unsecure:
|
|
|
|
print "\t389"
|
|
|
|
if not ds_secure:
|
|
|
|
print "\t636"
|
|
|
|
sys.exit(1)
|
|
|
|
|
2009-06-26 12:37:49 -05:00
|
|
|
def check_bind():
|
2009-11-13 09:57:51 -06:00
|
|
|
if not bindinstance.check_inst(unattended=True):
|
|
|
|
print "Aborting installation"
|
2009-06-26 12:37:49 -05:00
|
|
|
sys.exit(1)
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
def main():
|
2010-12-13 13:28:11 -06:00
|
|
|
if not check_replication_plugin():
|
|
|
|
sys.exit(1)
|
2010-10-29 13:24:31 -05:00
|
|
|
safe_options, options, filename = parse_options()
|
2008-03-27 08:33:01 -05:00
|
|
|
installutils.standard_logging_setup("/var/log/ipareplica-install.log", options.debug)
|
2010-10-29 13:24:31 -05:00
|
|
|
logging.debug('%s was invoked with argument "%s" and options: %s' % (sys.argv[0], filename, safe_options))
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2008-07-11 10:34:29 -05:00
|
|
|
if not ipautil.file_exists(filename):
|
|
|
|
sys.exit("Replica file %s does not exist" % filename)
|
|
|
|
|
2010-11-03 17:17:36 -05:00
|
|
|
# check the bind is installed
|
2009-06-26 12:37:49 -05:00
|
|
|
if options.setup_dns:
|
|
|
|
check_bind()
|
2010-11-03 17:17:36 -05:00
|
|
|
|
2008-04-14 18:04:43 -05:00
|
|
|
check_dirsrv()
|
|
|
|
|
2008-08-08 07:53:55 -05:00
|
|
|
# get the directory manager password
|
|
|
|
dirman_password = options.password
|
|
|
|
if not dirman_password:
|
|
|
|
try:
|
|
|
|
dirman_password = get_dirman_password()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
try:
|
|
|
|
top_dir, dir = expand_info(filename, dirman_password)
|
|
|
|
except Exception, e:
|
|
|
|
print "ERROR: Failed to decrypt or open the replica file."
|
|
|
|
print "Verify you entered the correct Directory Manager password."
|
|
|
|
sys.exit(1)
|
2008-02-20 09:16:19 -06:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
config = ReplicaConfig()
|
|
|
|
read_info(dir, config)
|
2008-08-08 07:53:55 -05:00
|
|
|
config.dirman_password = dirman_password
|
2010-09-10 16:51:08 -05:00
|
|
|
host = get_host_name(options.no_host_dns)
|
2008-08-08 07:53:55 -05:00
|
|
|
if config.host_name != host:
|
2008-02-19 09:46:22 -06:00
|
|
|
try:
|
2008-08-08 07:53:55 -05:00
|
|
|
print "This replica was created for '%s' but this machine is named '%s'" % (config.host_name, host)
|
2008-08-06 12:17:13 -05:00
|
|
|
if not ipautil.user_input("This may cause problems. Continue?", True):
|
2008-02-19 09:46:22 -06:00
|
|
|
sys.exit(0)
|
2008-08-08 07:53:55 -05:00
|
|
|
config.host_name = host
|
2008-07-21 05:25:37 -05:00
|
|
|
print ""
|
2008-02-19 09:46:22 -06:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
sys.exit(0)
|
0000-12-31 18:09:24 -05:50
|
|
|
config.dir = dir
|
|
|
|
|
2010-02-08 07:21:46 -06:00
|
|
|
# Create the management framework config file
|
|
|
|
# Note: We must do this before bootstraping and finalizing ipalib.api
|
|
|
|
fd = open("/etc/ipa/default.conf", "w")
|
|
|
|
fd.write("[global]\n")
|
|
|
|
fd.write("basedn=" + util.realm_to_suffix(config.realm_name) + "\n")
|
|
|
|
fd.write("realm=" + config.realm_name + "\n")
|
|
|
|
fd.write("domain=" + config.domain_name + "\n")
|
|
|
|
fd.write("xmlrpc_uri=https://%s/ipa/xml\n" % config.host_name)
|
|
|
|
fd.write("ldap_uri=ldapi://%%2fvar%%2frun%%2fslapd-%s.socket\n" % dsinstance.realm_to_serverid(config.realm_name))
|
2010-03-30 14:25:46 -05:00
|
|
|
if ipautil.file_exists(config.dir + "/cacert.p12"):
|
2010-02-08 07:21:46 -06:00
|
|
|
fd.write("enable_ra=True\n")
|
|
|
|
fd.write("ra_plugin=dogtag\n")
|
|
|
|
fd.close()
|
2009-09-28 22:34:15 -05:00
|
|
|
|
2010-02-08 07:21:46 -06:00
|
|
|
api.bootstrap(in_server=True)
|
2009-09-28 22:34:15 -05:00
|
|
|
api.finalize()
|
|
|
|
|
2010-11-22 12:29:56 -06:00
|
|
|
#Automatically disable pkinit w/ dogtag until that is supported
|
|
|
|
#[certs.ipa_self_signed() must be called only after api.finalize()]
|
|
|
|
if not ipautil.file_exists(config.dir + "/pkinitcert.p12") and not certs.ipa_self_signed():
|
|
|
|
options.setup_pkinit = False
|
|
|
|
|
2010-12-07 17:23:05 -06:00
|
|
|
# Install CA cert so that we can do SSL connections with ldap
|
|
|
|
install_ca_cert(config)
|
|
|
|
|
2010-05-27 16:41:13 -05:00
|
|
|
# Try out the password
|
2010-12-07 17:23:05 -06:00
|
|
|
ldapuri = 'ldaps://%s' % config.master_host_name
|
2010-05-27 16:41:13 -05:00
|
|
|
try:
|
|
|
|
conn = ldap2(shared_instance=False, ldap_uri=ldapuri, base_dn='')
|
2010-12-07 17:23:05 -06:00
|
|
|
conn.connect(bind_dn='cn=directory manager',
|
|
|
|
bind_pw=config.dirman_password,
|
|
|
|
tls_cacertfile=CACERT)
|
2010-05-27 16:41:13 -05:00
|
|
|
try:
|
|
|
|
entry = conn.find_entries(u'fqdn=%s' % host, ['dn', 'fqdn'], u'%s,%s' % (api.env.container_host, api.env.basedn))
|
2010-11-23 06:22:56 -06:00
|
|
|
print "The host %s already exists on the master server. Depending on your configuration, you may perform the following:\n" % host
|
2010-05-27 16:41:13 -05:00
|
|
|
print "Remove the replication agreement, if any:"
|
|
|
|
print " %% ipa-replica-manage del %s" % host
|
2010-11-23 06:22:56 -06:00
|
|
|
print "Remove the host entry:"
|
2010-05-27 16:41:13 -05:00
|
|
|
print " %% ipa host-del %s" % host
|
|
|
|
sys.exit(3)
|
|
|
|
except errors.NotFound:
|
|
|
|
pass
|
|
|
|
conn.disconnect()
|
|
|
|
except errors.ACIError:
|
|
|
|
sys.exit("\nThe password provided is incorrect for LDAP server %s" % config.master_host_name)
|
|
|
|
except errors.LDAPError:
|
|
|
|
sys.exit("\nUnable to connect to LDAP server %s" % config.master_host_name)
|
|
|
|
|
2008-02-20 10:03:46 -06:00
|
|
|
# Configure ntpd
|
|
|
|
if options.conf_ntp:
|
|
|
|
ntp = ntpinstance.NTPInstance()
|
|
|
|
ntp.create_instance()
|
|
|
|
|
2009-07-10 15:18:16 -05:00
|
|
|
# Configure the CA if necessary
|
|
|
|
CA = install_ca(config)
|
|
|
|
|
2008-02-20 10:03:46 -06:00
|
|
|
# Configure dirsrv
|
2010-12-07 17:23:05 -06:00
|
|
|
ds = install_replica_ds(config)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2010-12-10 13:53:06 -06:00
|
|
|
# We ned to ldap_enable the CA now that DS is up and running
|
|
|
|
if CA:
|
|
|
|
CA.ldap_enable('CA', host_name, dm_password,
|
|
|
|
util.realm_to_suffix(self.realm_name))
|
|
|
|
|
2010-11-03 17:17:36 -05:00
|
|
|
install_krb(config, setup_pkinit=options.setup_pkinit)
|
0000-12-31 18:09:24 -05:50
|
|
|
install_http(config)
|
2009-07-10 15:18:16 -05:00
|
|
|
if CA:
|
|
|
|
CA.import_ra_cert(dir + "/ra.p12")
|
|
|
|
CA.fix_ra_perms()
|
|
|
|
service.restart("httpd")
|
2010-01-20 10:26:20 -06:00
|
|
|
service.print_msg("Setting the certificate subject base")
|
|
|
|
CA.set_subject_in_config(util.realm_to_suffix(config.realm_name))
|
2008-02-20 09:16:19 -06:00
|
|
|
|
2009-12-07 22:17:00 -06:00
|
|
|
# The DS instance is created before the keytab, add the SSL cert we
|
|
|
|
# generated
|
|
|
|
ds.add_cert_to_service()
|
|
|
|
|
2008-12-01 14:33:15 -06:00
|
|
|
# Apply any LDAP updates. Needs to be done after the replica is synced-up
|
|
|
|
service.print_msg("Applying LDAP updates")
|
|
|
|
ds.apply_updates()
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
service.restart("dirsrv")
|
|
|
|
service.restart("krb5kdc")
|
2010-01-20 10:26:20 -06:00
|
|
|
service.restart("httpd")
|
2008-02-20 09:16:19 -06:00
|
|
|
|
2009-09-02 05:24:17 -05:00
|
|
|
if options.setup_dns:
|
2009-09-02 09:22:50 -05:00
|
|
|
api.Backend.ldap2.connect(bind_dn="cn=Directory Manager",
|
|
|
|
bind_pw=config.dirman_password)
|
|
|
|
|
2009-09-02 05:24:17 -05:00
|
|
|
install_bind(config, options)
|
|
|
|
|
2008-02-20 09:16:19 -06:00
|
|
|
# Call client install script
|
|
|
|
try:
|
2008-02-28 17:24:10 -06:00
|
|
|
ipautil.run(["/usr/sbin/ipa-client-install", "--on-master", "--unattended", "--domain", config.domain_name, "--server", config.host_name, "--realm", config.realm_name])
|
2008-02-20 09:16:19 -06:00
|
|
|
except Exception, e:
|
|
|
|
print "Configuration of client side components failed!"
|
|
|
|
print "ipa-client-install returned: " + str(e)
|
|
|
|
raise RuntimeError("Failed to configure the client")
|
2008-03-27 08:33:01 -05:00
|
|
|
|
|
|
|
ds.init_memberof()
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
try:
|
2008-02-05 11:23:53 -06:00
|
|
|
if not os.geteuid()==0:
|
|
|
|
sys.exit("\nYou must be root to run this script.\n")
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
main()
|
2008-05-08 14:21:20 -05:00
|
|
|
sys.exit(0)
|
|
|
|
except SystemExit, e:
|
|
|
|
sys.exit(e)
|
2009-06-26 12:37:49 -05:00
|
|
|
except socket.error, (errno, errstr):
|
|
|
|
print errstr
|
|
|
|
except HostnameLocalhost:
|
|
|
|
print "The hostname resolves to the localhost address (127.0.0.1/::1)"
|
|
|
|
print "Please change your /etc/hosts file so that the hostname"
|
|
|
|
print "resolves to the ip address of your network interface."
|
|
|
|
print ""
|
|
|
|
print "Please fix your /etc/hosts file and restart the setup program"
|
0000-12-31 18:09:24 -05:50
|
|
|
except Exception, e:
|
|
|
|
print "creation of replica failed: %s" % str(e)
|
|
|
|
message = str(e)
|
|
|
|
for str in traceback.format_tb(sys.exc_info()[2]):
|
|
|
|
message = message + "\n" + str
|
|
|
|
logging.debug(message)
|
2008-04-29 13:12:00 -05:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
print "Installation cancelled."
|
2008-05-08 14:21:20 -05:00
|
|
|
|
|
|
|
print ""
|
|
|
|
print "Your system may be partly configured."
|
|
|
|
print "Run /usr/sbin/ipa-server-install --uninstall to clean up."
|
|
|
|
|
|
|
|
# the only way to get here is on error or ^C
|
|
|
|
sys.exit(1)
|