Imported Debian patch 4.0.5-6~numeezy

This commit is contained in:
Alexandre Ellert
2016-02-17 15:07:45 +01:00
committed by Mario Fetka
parent c44de33144
commit 10dfc9587b
1203 changed files with 53869 additions and 241462 deletions

View File

@@ -23,38 +23,54 @@
# TODO
# save undo files?
from __future__ import print_function
import os
import sys
import six
import krbV
from ipalib import api
from ipapython import ipautil, admintool
from ipaplatform.paths import paths
from ipaserver.install import installutils, dsinstance, schemaupdate
from ipaserver.install.ldapupdate import LDAPUpdate, UPDATES_DIR, BadSyntax
from ipaserver.install.ldapupdate import LDAPUpdate, UPDATES_DIR
from ipaserver.install.upgradeinstance import IPAUpgrade
if six.PY3:
unicode = str
class LDAPUpdater(admintool.AdminTool):
command_name = 'ipa-ldap-updater'
usage = "%prog [options] input_file(s)\n"
usage += "%prog [options]\n"
@classmethod
def add_options(cls, parser):
super(LDAPUpdater, cls).add_options(parser, debug_option=True)
parser.add_option("-t", "--test", action="store_true", dest="test",
default=False,
help="run through the update without changing anything")
parser.add_option("-y", dest="password",
help="file containing the Directory Manager password")
parser.add_option("-l", '--ldapi', action="store_true", dest="ldapi",
default=False,
help="connect to the LDAP server using the ldapi socket")
parser.add_option("-u", '--upgrade', action="store_true",
dest="upgrade", default=False,
help="upgrade an installed server in offline mode")
parser.add_option("-p", '--plugins', action="store_true",
dest="plugins", default=False,
help="execute update plugins " +
"(implied when no input files are given)")
parser.add_option("-s", '--schema', action="store_true",
dest="update_schema", default=False,
help="update the schema "
"(implied when no input files are given)")
parser.add_option("-S", '--schema-file', action="append",
dest="schema_files",
help="custom schema ldif file to use (implies -s)")
parser.add_option("-W", '--password', action="store_true",
dest="ask_password",
help="prompt for the Directory Manager password")
@classmethod
def get_command_class(cls, options, args):
@@ -63,28 +79,38 @@ class LDAPUpdater(admintool.AdminTool):
else:
return LDAPUpdater_NonUpgrade
def validate_options(self):
def validate_options(self, **kwargs):
options = self.options
super(LDAPUpdater, self).validate_options(needs_root=True)
super(LDAPUpdater, self).validate_options(**kwargs)
self.files = self.args
if not (self.files or options.schema_files):
self.log.info("To execute overall IPA upgrade please use "
"'ipa-server-upgrade' command")
raise admintool.ScriptError("No update files or schema file were "
"specified")
for filename in self.files:
if not os.path.exists(filename):
raise admintool.ScriptError("%s: file not found" % filename)
try:
installutils.check_server_configuration()
except RuntimeError as e:
print(unicode(e))
if os.getegid() == 0:
try:
installutils.check_server_configuration()
except RuntimeError, e:
print unicode(e)
sys.exit(1)
elif not os.path.exists(paths.IPA_DEFAULT_CONF):
print "IPA is not configured on this system."
sys.exit(1)
if options.password:
pw = ipautil.template_file(options.password, [])
self.dirman_password = pw.strip()
else:
self.dirman_password = None
if options.schema_files or not self.files:
options.update_schema = True
if not options.schema_files:
options.schema_files = [os.path.join(ipautil.SHARE_DIR, f) for f
in dsinstance.ALL_SCHEMA_FILES]
def setup_logging(self):
super(LDAPUpdater, self).setup_logging(log_file_mode='a')
@@ -101,52 +127,91 @@ class LDAPUpdater(admintool.AdminTool):
class LDAPUpdater_Upgrade(LDAPUpdater):
log_file_name = paths.IPAUPGRADE_LOG
def validate_options(self):
if os.getegid() != 0:
raise admintool.ScriptError('Must be root to do an upgrade.', 1)
super(LDAPUpdater_Upgrade, self).validate_options(needs_root=True)
def run(self):
super(LDAPUpdater_Upgrade, self).run()
options = self.options
realm = api.env.realm
upgrade = IPAUpgrade(realm, self.files,
updates = None
realm = krbV.default_context().default_realm
upgrade = IPAUpgrade(realm, self.files, live_run=not options.test,
schema_files=options.schema_files)
upgrade.create_instance()
upgradefailed = upgrade.upgradefailed
try:
upgrade.create_instance()
except BadSyntax:
if upgrade.badsyntax:
raise admintool.ScriptError(
'Bad syntax detected in upgrade file(s).', 1)
except RuntimeError:
elif upgrade.upgradefailed:
raise admintool.ScriptError('IPA upgrade failed.', 1)
else:
if upgrade.modified:
self.log.info('Update complete')
else:
self.log.info('Update complete, no data were modified')
elif upgrade.modified and options.test:
self.log.info('Update complete, changes to be made, test mode')
return 2
class LDAPUpdater_NonUpgrade(LDAPUpdater):
log_file_name = paths.IPAUPGRADE_LOG
def validate_options(self):
super(LDAPUpdater_NonUpgrade, self).validate_options()
options = self.options
# Only run plugins if no files are given
self.run_plugins = not self.files or options.plugins
# Need root for running plugins
if os.getegid() != 0:
if self.run_plugins:
raise admintool.ScriptError(
'Plugins can only be run as root.', 1)
else:
# Can't log to the default file as non-root
self.log_file_name = None
def ask_for_options(self):
super(LDAPUpdater_NonUpgrade, self).ask_for_options()
options = self.options
if not self.dirman_password:
if options.ask_password or not options.ldapi:
password = installutils.read_password("Directory Manager",
confirm=False, validate=False)
if password is None:
raise admintool.ScriptError(
"Directory Manager password required")
self.dirman_password = password
def run(self):
super(LDAPUpdater_NonUpgrade, self).run()
options = self.options
modified = False
if options.schema_files:
ld = LDAPUpdate(
dm_password=self.dirman_password,
sub_dict={},
live_run=not options.test,
ldapi=options.ldapi,
plugins=options.plugins or self.run_plugins)
modified = ld.pre_schema_update(ordered=True)
if options.update_schema:
modified = schemaupdate.update_schema(
options.schema_files,
ldapi=True) or modified
ld = LDAPUpdate(
sub_dict={},
ldapi=True)
dm_password=self.dirman_password,
live_run=not options.test,
ldapi=options.ldapi) or modified
if not self.files:
self.files = ld.get_all_files(UPDATES_DIR)
modified = ld.update(self.files) or modified
modified = ld.update(self.files, ordered=True) or modified
if modified:
self.log.info('Update complete')
else:
self.log.info('Update complete, no data were modified')
if modified and options.test:
self.log.info('Update complete, changes to be made, test mode')
return 2