Imported Debian patch 4.0.5-6~numeezy
This commit is contained in:
committed by
Mario Fetka
parent
c44de33144
commit
10dfc9587b
@@ -24,25 +24,23 @@ import tempfile
|
||||
import time
|
||||
import pwd
|
||||
from optparse import OptionGroup
|
||||
from ConfigParser import SafeConfigParser
|
||||
from ipaplatform.paths import paths
|
||||
from ipaplatform import services
|
||||
|
||||
from six.moves.configparser import SafeConfigParser
|
||||
|
||||
from ipalib import api, errors
|
||||
from ipapython import version
|
||||
from ipapython.ipautil import run, write_tmp_file
|
||||
from ipapython import admintool
|
||||
from ipapython.config import IPAOptionParser
|
||||
from ipapython.dn import DN
|
||||
from ipaserver.install.dsinstance import realm_to_serverid, DS_USER
|
||||
from ipaserver.install.replication import wait_for_task
|
||||
from ipaserver.install import installutils
|
||||
from ipapython import ipaldap
|
||||
from ipalib.session import ISO8601_DATETIME_FMT
|
||||
from ipalib.constants import CACERT
|
||||
from six.moves.configparser import SafeConfigParser
|
||||
from ipaplatform.constants import constants
|
||||
from ipaplatform.tasks import tasks
|
||||
from ConfigParser import SafeConfigParser
|
||||
|
||||
"""
|
||||
A test gpg can be generated like this:
|
||||
@@ -65,6 +63,8 @@ EOF
|
||||
--keyring /root/backup.pub --list-secret-keys
|
||||
"""
|
||||
|
||||
BACKUP_DIR = paths.IPA_BACKUP_DIR
|
||||
|
||||
|
||||
def encrypt_file(filename, keyring, remove_original=True):
|
||||
source = filename
|
||||
@@ -85,9 +85,9 @@ def encrypt_file(filename, keyring, remove_original=True):
|
||||
args.append('-e')
|
||||
args.append(source)
|
||||
|
||||
result = run(args, raiseonerr=False)
|
||||
if result.returncode != 0:
|
||||
raise admintool.ScriptError('gpg failed: %s' % result.error_log)
|
||||
(stdout, stderr, rc) = run(args, raiseonerr=False)
|
||||
if rc != 0:
|
||||
raise admintool.ScriptError('gpg failed: %s' % stderr)
|
||||
|
||||
if remove_original:
|
||||
os.unlink(source)
|
||||
@@ -105,13 +105,14 @@ class Backup(admintool.AdminTool):
|
||||
|
||||
dirs = (paths.IPA_HTML_DIR,
|
||||
paths.ROOT_PKI,
|
||||
paths.ETC_PKI_CA_DIR,
|
||||
paths.PKI_TOMCAT,
|
||||
paths.SYSCONFIG_PKI,
|
||||
paths.HTTPD_ALIAS_DIR,
|
||||
paths.VAR_LIB_PKI_DIR,
|
||||
paths.VAR_LIB_PKI_CA_DIR,
|
||||
paths.SYSRESTORE,
|
||||
paths.IPA_CLIENT_SYSRESTORE,
|
||||
paths.IPA_DNSSEC_DIR,
|
||||
paths.SSSD_PUBCONF_KRB5_INCLUDE_D_DIR,
|
||||
paths.AUTHCONFIG_LAST,
|
||||
paths.VAR_LIB_CERTMONGER_DIR,
|
||||
@@ -124,18 +125,16 @@ class Backup(admintool.AdminTool):
|
||||
paths.NAMED_CONF,
|
||||
paths.NAMED_KEYTAB,
|
||||
paths.RESOLV_CONF,
|
||||
paths.SYSCONFIG_PKI_CA_DIR,
|
||||
paths.SYSCONFIG_PKI_TOMCAT,
|
||||
paths.SYSCONFIG_DIRSRV,
|
||||
paths.SYSCONFIG_NTPD,
|
||||
paths.SYSCONFIG_KRB5KDC_DIR,
|
||||
paths.SYSCONFIG_IPA_DNSKEYSYNCD,
|
||||
paths.SYSCONFIG_IPA_ODS_EXPORTER,
|
||||
paths.SYSCONFIG_NAMED,
|
||||
paths.SYSCONFIG_ODS,
|
||||
paths.SYSCONFIG_PKI_CA_PKI_CA_DIR,
|
||||
paths.ETC_SYSCONFIG_AUTHCONFIG,
|
||||
paths.IPA_NSSDB_PWDFILE_TXT,
|
||||
paths.IPA_P11_KIT,
|
||||
paths.SYSTEMWIDE_IPA_CA_CRT,
|
||||
paths.NSSDB_CERT8_DB,
|
||||
paths.NSSDB_KEY3_DB,
|
||||
paths.NSSDB_SECMOD_DB,
|
||||
paths.NSSWITCH_CONF,
|
||||
paths.KRB5_KEYTAB,
|
||||
paths.SSSD_CONF,
|
||||
@@ -143,7 +142,6 @@ class Backup(admintool.AdminTool):
|
||||
paths.LIMITS_CONF,
|
||||
paths.HTTPD_PASSWORD_CONF,
|
||||
paths.IPA_KEYTAB,
|
||||
paths.HTTPD_IPA_KDCPROXY_CONF,
|
||||
paths.HTTPD_IPA_PKI_PROXY_CONF,
|
||||
paths.HTTPD_IPA_REWRITE_CONF,
|
||||
paths.HTTPD_NSS_CONF,
|
||||
@@ -151,14 +149,15 @@ class Backup(admintool.AdminTool):
|
||||
paths.SSHD_CONFIG,
|
||||
paths.SSH_CONFIG,
|
||||
paths.KRB5_CONF,
|
||||
paths.GROUP,
|
||||
paths.PASSWD,
|
||||
CACERT,
|
||||
paths.IPA_DEFAULT_CONF,
|
||||
paths.DS_KEYTAB,
|
||||
paths.NTP_CONF,
|
||||
paths.SMB_CONF,
|
||||
paths.SAMBA_KEYTAB,
|
||||
paths.DOGTAG_ADMIN_P12,
|
||||
paths.KRA_AGENT_PEM,
|
||||
paths.CA_AGENT_P12,
|
||||
paths.CACERT_P12,
|
||||
paths.KRB5KDC_KDC_CONF,
|
||||
paths.SYSTEMD_IPA_SERVICE,
|
||||
@@ -166,43 +165,25 @@ class Backup(admintool.AdminTool):
|
||||
paths.SYSTEMD_CERTMONGER_SERVICE,
|
||||
paths.SYSTEMD_PKI_TOMCAT_SERVICE,
|
||||
paths.SVC_LIST_FILE,
|
||||
paths.OPENDNSSEC_CONF_FILE,
|
||||
paths.OPENDNSSEC_KASP_FILE,
|
||||
paths.OPENDNSSEC_ZONELIST_FILE,
|
||||
paths.OPENDNSSEC_KASP_DB,
|
||||
paths.DNSSEC_SOFTHSM2_CONF,
|
||||
paths.DNSSEC_SOFTHSM_PIN_SO,
|
||||
paths.IPA_ODS_EXPORTER_KEYTAB,
|
||||
paths.IPA_DNSKEYSYNCD_KEYTAB,
|
||||
paths.HOSTS,
|
||||
) + tuple(
|
||||
os.path.join(paths.IPA_NSSDB_DIR, file)
|
||||
for file in ('cert8.db', 'key3.db', 'secmod.db')
|
||||
)
|
||||
|
||||
logs=(
|
||||
paths.PKI_CA_LOG_DIR,
|
||||
paths.VAR_LOG_PKI_DIR,
|
||||
paths.VAR_LOG_SLAPD_PKI_IPA_DIR,
|
||||
paths.VAR_LOG_HTTPD_DIR,
|
||||
paths.IPASERVER_INSTALL_LOG,
|
||||
paths.KADMIND_LOG,
|
||||
paths.PKI_CA_INSTALL_LOG,
|
||||
paths.MESSAGES,
|
||||
paths.IPACLIENT_INSTALL_LOG,
|
||||
paths.LOG_SECURE,
|
||||
paths.IPASERVER_UNINSTALL_LOG,
|
||||
paths.PKI_CA_UNINSTALL_LOG,
|
||||
paths.IPACLIENT_UNINSTALL_LOG,
|
||||
paths.NAMED_RUN,
|
||||
)
|
||||
|
||||
required_dirs=(
|
||||
paths.TOMCAT_TOPLEVEL_DIR,
|
||||
paths.TOMCAT_CA_DIR,
|
||||
paths.TOMCAT_SIGNEDAUDIT_DIR,
|
||||
paths.TOMCAT_CA_ARCHIVE_DIR,
|
||||
paths.TOMCAT_KRA_DIR,
|
||||
paths.TOMCAT_KRA_SIGNEDAUDIT_DIR,
|
||||
paths.TOMCAT_KRA_ARCHIVE_DIR,
|
||||
)
|
||||
|
||||
def __init__(self, options, args):
|
||||
super(Backup, self).__init__(options, args)
|
||||
self._conn = None
|
||||
@@ -264,14 +245,14 @@ class Backup(admintool.AdminTool):
|
||||
|
||||
self.log.info("Preparing backup on %s", api.env.host)
|
||||
|
||||
pent = pwd.getpwnam(constants.DS_USER)
|
||||
pent = pwd.getpwnam(DS_USER)
|
||||
|
||||
self.top_dir = tempfile.mkdtemp("ipa")
|
||||
os.chown(self.top_dir, pent.pw_uid, pent.pw_gid)
|
||||
os.chmod(self.top_dir, 0o750)
|
||||
os.chmod(self.top_dir, 0750)
|
||||
self.dir = os.path.join(self.top_dir, "ipa")
|
||||
os.mkdir(self.dir)
|
||||
os.chmod(self.dir, 0o750)
|
||||
os.mkdir(self.dir, 0750)
|
||||
|
||||
os.chown(self.dir, pent.pw_uid, pent.pw_gid)
|
||||
|
||||
self.header = os.path.join(self.top_dir, 'header')
|
||||
@@ -296,18 +277,13 @@ class Backup(admintool.AdminTool):
|
||||
self.log.info('Stopping IPA services')
|
||||
run(['ipactl', 'stop'])
|
||||
|
||||
instance = installutils.realm_to_serverid(api.env.realm)
|
||||
if os.path.exists(paths.VAR_LIB_SLAPD_INSTANCE_DIR_TEMPLATE %
|
||||
instance):
|
||||
if os.path.exists(paths.SLAPD_INSTANCE_DB_DIR_TEMPLATE %
|
||||
(instance, 'ipaca')):
|
||||
self.db2ldif(instance, 'ipaca', online=options.online)
|
||||
self.db2ldif(instance, 'userRoot', online=options.online)
|
||||
self.db2bak(instance, online=options.online)
|
||||
for instance in [realm_to_serverid(api.env.realm), 'PKI-IPA']:
|
||||
if os.path.exists(paths.VAR_LIB_SLAPD_INSTANCE_DIR_TEMPLATE % instance):
|
||||
if os.path.exists(paths.IPACA_DIRSRV_INSTANCE_DB_TEMPLATE % instance):
|
||||
self.db2ldif(instance, 'ipaca', online=options.online)
|
||||
self.db2ldif(instance, 'userRoot', online=options.online)
|
||||
self.db2bak(instance, online=options.online)
|
||||
if not options.data_only:
|
||||
# create backup of auth configuration
|
||||
auth_backup_path = os.path.join(paths.VAR_LIB_IPA, 'auth_backup')
|
||||
tasks.backup_auth_configuration(auth_backup_path)
|
||||
self.file_backup(options)
|
||||
self.finalize_backup(options.data_only, options.gpg, options.gpg_keyring)
|
||||
|
||||
@@ -322,7 +298,7 @@ class Backup(admintool.AdminTool):
|
||||
finally:
|
||||
try:
|
||||
os.chdir(cwd)
|
||||
except Exception as e:
|
||||
except Exception, e:
|
||||
self.log.error('Cannot change directory to %s: %s' % (cwd, e))
|
||||
shutil.rmtree(self.top_dir)
|
||||
|
||||
@@ -331,21 +307,31 @@ class Backup(admintool.AdminTool):
|
||||
'''
|
||||
Add instance-specific files and directories.
|
||||
|
||||
NOTE: this adds some things that may not get backed up.
|
||||
NOTE: this adds some things that may not get backed up, like the PKI-IPA
|
||||
instance.
|
||||
'''
|
||||
serverid = installutils.realm_to_serverid(api.env.realm)
|
||||
|
||||
for dir in [paths.ETC_DIRSRV_SLAPD_INSTANCE_TEMPLATE % serverid,
|
||||
paths.VAR_LIB_DIRSRV_INSTANCE_SCRIPTS_TEMPLATE % serverid,
|
||||
paths.VAR_LIB_SLAPD_INSTANCE_DIR_TEMPLATE % serverid]:
|
||||
for dir in [
|
||||
paths.ETC_DIRSRV_SLAPD_INSTANCE_TEMPLATE % realm_to_serverid(api.env.realm),
|
||||
paths.VAR_LIB_DIRSRV_INSTANCE_SCRIPTS_TEMPLATE % realm_to_serverid(api.env.realm),
|
||||
paths.VAR_LIB_SLAPD_INSTANCE_DIR_TEMPLATE % realm_to_serverid(api.env.realm),
|
||||
paths.VAR_LIB_SLAPD_PKI_IPA_DIR_TEMPLATE,
|
||||
paths.USR_LIB_SLAPD_PKI_IPA_DIR,
|
||||
paths.ETC_SLAPD_PKI_IPA_DIR,
|
||||
paths.VAR_LIB_SLAPD_PKI_IPA_DIR_TEMPLATE,
|
||||
self.__find_scripts_dir('PKI-IPA'),
|
||||
]:
|
||||
if os.path.exists(dir):
|
||||
self.dirs.append(dir)
|
||||
|
||||
file = paths.SYSCONFIG_DIRSRV_INSTANCE % serverid
|
||||
if os.path.exists(file):
|
||||
self.files.append(file)
|
||||
for file in [
|
||||
paths.SYSCONFIG_DIRSRV_INSTANCE % realm_to_serverid(api.env.realm),
|
||||
paths.SYSCONFIG_DIRSRV_PKI_IPA_DIR]:
|
||||
if os.path.exists(file):
|
||||
self.files.append(file)
|
||||
|
||||
self.logs.append(paths.VAR_LOG_DIRSRV_INSTANCE_TEMPLATE % serverid)
|
||||
for log in [
|
||||
paths.VAR_LOG_DIRSRV_INSTANCE_TEMPLATE % realm_to_serverid(api.env.realm),]:
|
||||
self.logs.append(log)
|
||||
|
||||
|
||||
def get_connection(self):
|
||||
@@ -363,7 +349,7 @@ class Backup(admintool.AdminTool):
|
||||
try:
|
||||
pw_name = pwd.getpwuid(os.geteuid()).pw_name
|
||||
self._conn.do_external_bind(pw_name)
|
||||
except Exception as e:
|
||||
except Exception, e:
|
||||
self.log.error("Unable to bind to LDAP server %s: %s" %
|
||||
(self._conn.host, e))
|
||||
|
||||
@@ -406,21 +392,20 @@ class Backup(admintool.AdminTool):
|
||||
|
||||
try:
|
||||
conn.add_entry(ent)
|
||||
except Exception as e:
|
||||
except Exception, e:
|
||||
raise admintool.ScriptError('Unable to add LDIF task: %s'
|
||||
% e)
|
||||
|
||||
self.log.info("Waiting for LDIF to finish")
|
||||
wait_for_task(conn, dn)
|
||||
else:
|
||||
args = [paths.DB2LDIF,
|
||||
'-Z', instance,
|
||||
args = ['%s/db2ldif' % self.__find_scripts_dir(instance),
|
||||
'-r',
|
||||
'-n', backend,
|
||||
'-a', ldiffile]
|
||||
result = run(args, raiseonerr=False)
|
||||
if result.returncode != 0:
|
||||
self.log.critical('db2ldif failed: %s', result.error_log)
|
||||
(stdout, stderr, rc) = run(args, raiseonerr=False)
|
||||
if rc != 0:
|
||||
self.log.critical("db2ldif failed: %s", stderr)
|
||||
|
||||
# Move the LDIF backup to our location
|
||||
shutil.move(ldiffile, os.path.join(self.dir, ldifname))
|
||||
@@ -454,17 +439,17 @@ class Backup(admintool.AdminTool):
|
||||
|
||||
try:
|
||||
conn.add_entry(ent)
|
||||
except Exception as e:
|
||||
except Exception, e:
|
||||
raise admintool.ScriptError('Unable to to add backup task: %s'
|
||||
% e)
|
||||
|
||||
self.log.info("Waiting for BAK to finish")
|
||||
wait_for_task(conn, dn)
|
||||
else:
|
||||
args = [paths.DB2BAK, bakdir, '-Z', instance]
|
||||
result = run(args, raiseonerr=False)
|
||||
if result.returncode != 0:
|
||||
self.log.critical('db2bak failed: %s', result.error_log)
|
||||
args = ['%s/db2bak' % self.__find_scripts_dir(instance), bakdir]
|
||||
(stdout, stderr, rc) = run(args, raiseonerr=False)
|
||||
if rc != 0:
|
||||
self.log.critical("db2bak failed: %s" % stderr)
|
||||
|
||||
shutil.move(bakdir, self.dir)
|
||||
|
||||
@@ -474,15 +459,13 @@ class Backup(admintool.AdminTool):
|
||||
def verify_directories(dirs):
|
||||
return [s for s in dirs if os.path.exists(s)]
|
||||
|
||||
tarfile = os.path.join(self.dir, 'files.tar')
|
||||
|
||||
self.log.info("Backing up files")
|
||||
args = ['tar',
|
||||
'--exclude=/var/lib/ipa/backup',
|
||||
'--xattrs',
|
||||
'--selinux',
|
||||
'-cf',
|
||||
tarfile
|
||||
'-czf',
|
||||
os.path.join(self.dir, 'files.tar')
|
||||
]
|
||||
|
||||
args.extend(verify_directories(self.dirs))
|
||||
@@ -491,45 +474,9 @@ class Backup(admintool.AdminTool):
|
||||
if options.logs:
|
||||
args.extend(verify_directories(self.logs))
|
||||
|
||||
result = run(args, raiseonerr=False)
|
||||
if result.returncode != 0:
|
||||
raise admintool.ScriptError('tar returned non-zero code %d: %s' %
|
||||
(result.returncode, result.error_log))
|
||||
|
||||
# Backup the necessary directory structure. This is a separate
|
||||
# call since we are using the '--no-recursion' flag to store
|
||||
# the directory structure only, no files.
|
||||
missing_directories = verify_directories(self.required_dirs)
|
||||
|
||||
if missing_directories:
|
||||
args = ['tar',
|
||||
'--exclude=/var/lib/ipa/backup',
|
||||
'--xattrs',
|
||||
'--selinux',
|
||||
'--no-recursion',
|
||||
'-rf', # -r appends to an existing archive
|
||||
tarfile,
|
||||
]
|
||||
args.extend(missing_directories)
|
||||
|
||||
result = run(args, raiseonerr=False)
|
||||
if result.returncode != 0:
|
||||
raise admintool.ScriptError(
|
||||
'tar returned non-zero code %d '
|
||||
'when adding directory structure: %s' %
|
||||
(result.returncode, result.error_log))
|
||||
|
||||
# Compress the archive. This is done separately, since 'tar' cannot
|
||||
# append to a compressed archive.
|
||||
result = run(['gzip', tarfile], raiseonerr=False)
|
||||
if result.returncode != 0:
|
||||
raise admintool.ScriptError(
|
||||
'gzip returned non-zero code %d '
|
||||
'when compressing the backup: %s' %
|
||||
(result.returncode, result.error_log))
|
||||
|
||||
# Rename the archive back to files.tar to preserve compatibility
|
||||
os.rename(os.path.join(self.dir, 'files.tar.gz'), tarfile)
|
||||
(stdout, stderr, rc) = run(args, raiseonerr=False)
|
||||
if rc != 0:
|
||||
raise admintool.ScriptError('tar returned non-zero %d: %s' % (rc, stdout))
|
||||
|
||||
|
||||
def create_header(self, data_only):
|
||||
@@ -556,7 +503,7 @@ class Backup(admintool.AdminTool):
|
||||
except errors.NetworkError:
|
||||
self.log.critical(
|
||||
"Unable to obtain list of master services, continuing anyway")
|
||||
except Exception as e:
|
||||
except Exception, e:
|
||||
self.log.error("Failed to read services from '%s': %s" %
|
||||
(conn.host, e))
|
||||
else:
|
||||
@@ -581,14 +528,13 @@ class Backup(admintool.AdminTool):
|
||||
'''
|
||||
|
||||
if data_only:
|
||||
backup_dir = os.path.join(paths.IPA_BACKUP_DIR, time.strftime('ipa-data-%Y-%m-%d-%H-%M-%S'))
|
||||
backup_dir = os.path.join(BACKUP_DIR, time.strftime('ipa-data-%Y-%m-%d-%H-%M-%S'))
|
||||
filename = os.path.join(backup_dir, "ipa-data.tar")
|
||||
else:
|
||||
backup_dir = os.path.join(paths.IPA_BACKUP_DIR, time.strftime('ipa-full-%Y-%m-%d-%H-%M-%S'))
|
||||
backup_dir = os.path.join(BACKUP_DIR, time.strftime('ipa-full-%Y-%m-%d-%H-%M-%S'))
|
||||
filename = os.path.join(backup_dir, "ipa-full.tar")
|
||||
|
||||
os.mkdir(backup_dir)
|
||||
os.chmod(backup_dir, 0o700)
|
||||
os.mkdir(backup_dir, 0700)
|
||||
|
||||
cwd = os.getcwd()
|
||||
os.chdir(self.dir)
|
||||
@@ -599,11 +545,9 @@ class Backup(admintool.AdminTool):
|
||||
filename,
|
||||
'.'
|
||||
]
|
||||
result = run(args, raiseonerr=False)
|
||||
if result.returncode != 0:
|
||||
raise admintool.ScriptError(
|
||||
'tar returned non-zero code %s: %s' %
|
||||
(result.returncode, result.error_log))
|
||||
(stdout, stderr, rc) = run(args, raiseonerr=False)
|
||||
if rc != 0:
|
||||
raise admintool.ScriptError('tar returned non-zero %d: %s' % (rc, stdout))
|
||||
|
||||
if encrypt:
|
||||
self.log.info('Encrypting %s' % filename)
|
||||
@@ -611,4 +555,16 @@ class Backup(admintool.AdminTool):
|
||||
|
||||
shutil.move(self.header, backup_dir)
|
||||
|
||||
self.log.info('Backed up to %s', backup_dir)
|
||||
def __find_scripts_dir(self, instance):
|
||||
"""
|
||||
IPA stores its 389-ds scripts in a different directory than dogtag
|
||||
does so we need to probe for it.
|
||||
"""
|
||||
if instance != 'PKI-IPA':
|
||||
return os.path.join(paths.VAR_LIB_DIRSRV, 'scripts-%s' % instance)
|
||||
else:
|
||||
if sys.maxsize > 2**32L:
|
||||
libpath = 'lib64'
|
||||
else:
|
||||
libpath = 'lib'
|
||||
return os.path.join(paths.USR_DIR, libpath, 'dirsrv', 'slapd-PKI-IPA')
|
||||
|
||||
Reference in New Issue
Block a user