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
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License as
|
2008-02-04 14:15:52 -06:00
|
|
|
# published by the Free Software Foundation; version 2 only
|
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
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
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
|
2008-02-19 09:20:13 -06:00
|
|
|
import ldap
|
0000-12-31 18:09:24 -05:50
|
|
|
|
|
|
|
from ipa import ipautil
|
|
|
|
|
|
|
|
from ipaserver import dsinstance, replication, installutils, krbinstance, service
|
2008-02-19 09:20:13 -06:00
|
|
|
from ipaserver import httpinstance, ntpinstance, certs, ipaldap
|
2008-05-08 10:45:38 -05:00
|
|
|
from ipaserver import version
|
0000-12-31 18:09:24 -05:50
|
|
|
|
|
|
|
class ReplicaConfig:
|
|
|
|
def __init__(self):
|
|
|
|
self.realm_name = ""
|
|
|
|
self.master_host_name = ""
|
|
|
|
self.dirman_password = ""
|
|
|
|
self.ds_user = ""
|
|
|
|
self.host_name = ""
|
|
|
|
self.repl_password = ""
|
|
|
|
self.dir = ""
|
|
|
|
|
|
|
|
def parse_options():
|
|
|
|
from optparse import OptionParser
|
2008-05-08 10:45:38 -05:00
|
|
|
parser = OptionParser(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")
|
0000-12-31 18:09:24 -05:50
|
|
|
|
|
|
|
options, args = parser.parse_args()
|
|
|
|
|
|
|
|
if len(args) != 1:
|
|
|
|
parser.error("you must provide a file generated by ipa-replica-prepare")
|
|
|
|
|
|
|
|
return options, args[0]
|
|
|
|
|
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
|
|
|
|
|
|
|
def expand_info(filename):
|
|
|
|
top_dir = tempfile.mkdtemp("ipa")
|
|
|
|
dir = top_dir + "/realm_info"
|
|
|
|
ipautil.run(["tar", "xfz", filename, "-C", top_dir])
|
|
|
|
|
|
|
|
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")
|
0000-12-31 18:09:24 -05:50
|
|
|
|
|
|
|
def get_host_name():
|
|
|
|
hostname = installutils.get_fqdn()
|
|
|
|
try:
|
|
|
|
installutils.verify_fqdn(hostname)
|
|
|
|
except RuntimeError, e:
|
|
|
|
logging.error(str(e))
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
return hostname
|
|
|
|
|
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)
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
def install_ds(config):
|
|
|
|
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",
|
0000-12-31 18:09:24 -05:50
|
|
|
config.dir + "/pwdfile.txt")
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
ds = dsinstance.DsInstance()
|
2008-02-15 19:47:29 -06:00
|
|
|
ds.create_instance(config.ds_user, config.realm_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
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
def install_krb(config):
|
|
|
|
krb = krbinstance.KrbInstance()
|
|
|
|
ldappwd_filename = config.dir + "/ldappwd"
|
2008-04-09 15:57:41 -05:00
|
|
|
kpasswd_filename = config.dir + "/kpasswd.keytab"
|
0000-12-31 18:09:24 -05:50
|
|
|
krb.create_replica(config.ds_user, config.realm_name, config.host_name,
|
2008-04-09 15:57:41 -05:00
|
|
|
config.domain_name, config.dirman_password,
|
|
|
|
ldappwd_filename, kpasswd_filename)
|
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",
|
|
|
|
config.dir + "/pwdfile.txt")
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
http = httpinstance.HTTPInstance()
|
2008-02-15 19:47:29 -06:00
|
|
|
http.create_instance(config.realm_name, config.host_name, config.domain_name, False, pkcs12_info)
|
2008-02-05 11:23:53 -06:00
|
|
|
|
|
|
|
# Now copy the autoconfiguration files
|
|
|
|
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")
|
|
|
|
shutil.copy(config.dir + "/ca.crt", "/usr/share/ipa/html/ca.crt")
|
2008-03-26 11:11:58 -05:00
|
|
|
os.chmod("/usr/share/ipa/html/ca.crt", 0444)
|
2008-02-05 11:23:53 -06:00
|
|
|
except Exception, e:
|
|
|
|
print "error copying files: " + str(e)
|
|
|
|
sys.exit(1)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
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."
|
|
|
|
yesno = raw_input("Do you wish to remove it and create a new one? [no]: ")
|
|
|
|
if not yesno or yesno.lower()[0] != "y":
|
|
|
|
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)
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
def main():
|
|
|
|
options, filename = parse_options()
|
2008-03-27 08:33:01 -05:00
|
|
|
installutils.standard_logging_setup("/var/log/ipareplica-install.log", options.debug)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2008-04-14 18:04:43 -05:00
|
|
|
check_dirsrv()
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
top_dir, dir = expand_info(filename)
|
2008-02-20 09:16:19 -06:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
config = ReplicaConfig()
|
|
|
|
read_info(dir, config)
|
|
|
|
config.host_name = get_host_name()
|
2008-02-19 09:46:22 -06:00
|
|
|
p = filename.split('-')
|
2008-03-27 09:20:15 -05:00
|
|
|
host = '-'.join(p[2:])
|
|
|
|
if host != config.host_name:
|
2008-02-19 09:46:22 -06:00
|
|
|
try:
|
2008-03-27 09:20:15 -05:00
|
|
|
print "This replica was created for '%s' but this machine is named '%s'" % (host, config.host_name)
|
2008-02-19 09:46:22 -06:00
|
|
|
yesno = raw_input("This may cause problems. Continue? [Y/n]: ")
|
|
|
|
print ""
|
|
|
|
if not yesno or yesno.lower()[0] == "y":
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
sys.exit(0)
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
sys.exit(0)
|
0000-12-31 18:09:24 -05:50
|
|
|
config.repl_password = ipautil.ipa_generate_password()
|
0000-12-31 18:09:24 -05:50
|
|
|
config.dir = dir
|
|
|
|
|
|
|
|
# get the directory manager password
|
2008-02-19 09:20:13 -06:00
|
|
|
try:
|
|
|
|
config.dirman_password = get_dirman_password()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
# Try out the password
|
|
|
|
try:
|
|
|
|
conn = ipaldap.IPAdmin(config.master_host_name)
|
|
|
|
conn.do_simple_bind(bindpw=config.dirman_password)
|
|
|
|
conn.unbind()
|
|
|
|
except ldap.CONNECT_ERROR, e:
|
|
|
|
sys.exit("\nUnable to connect to LDAP server %s" % config.master_host_name)
|
|
|
|
except ldap.SERVER_DOWN, e:
|
|
|
|
sys.exit("\nUnable to connect to LDAP server %s" % config.master_host_name)
|
|
|
|
except ldap.INVALID_CREDENTIALS, e :
|
|
|
|
sys.exit("\nThe password provided is incorrect for LDAP server %s" % config.master_host_name)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2008-02-20 10:03:46 -06:00
|
|
|
# Configure ntpd
|
|
|
|
if options.conf_ntp:
|
|
|
|
ntp = ntpinstance.NTPInstance()
|
|
|
|
ntp.create_instance()
|
|
|
|
|
|
|
|
# Configure dirsrv
|
2008-03-27 08:33:01 -05:00
|
|
|
ds = install_ds(config)
|
2008-02-20 09:16:19 -06:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
repl = replication.ReplicationManager(config.host_name, config.dirman_password)
|
2008-02-19 09:20:13 -06:00
|
|
|
if repl is None:
|
|
|
|
raise RuntimeError("Unable to connect to LDAP server %s." % config.host_name)
|
0000-12-31 18:09:24 -05:50
|
|
|
ret = repl.setup_replication(config.master_host_name, config.realm_name)
|
2008-02-19 09:20:13 -06:00
|
|
|
if ret is None:
|
|
|
|
raise RuntimeError("Unable to connect to LDAP server %s." % config.master_host_name)
|
0000-12-31 18:09:24 -05:50
|
|
|
if ret != 0:
|
2008-02-19 09:20:13 -06:00
|
|
|
raise RuntimeError("Failed to start replication")
|
0000-12-31 18:09:24 -05:50
|
|
|
|
|
|
|
install_krb(config)
|
|
|
|
install_http(config)
|
2008-02-20 09:16:19 -06:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
# Create a Web Gui instance
|
2008-02-05 11:23:53 -06:00
|
|
|
webgui = httpinstance.WebGuiInstance()
|
0000-12-31 18:09:24 -05:50
|
|
|
webgui.create_instance()
|
|
|
|
|
|
|
|
service.restart("dirsrv")
|
|
|
|
service.restart("krb5kdc")
|
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)
|
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)
|