2007-09-20 14:10:21 -05:00
|
|
|
# Authors: Simo Sorce <ssorce@redhat.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.
|
2007-09-20 14:10:21 -05:00
|
|
|
#
|
|
|
|
# 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/>.
|
2007-09-20 14:10:21 -05:00
|
|
|
#
|
|
|
|
|
2015-08-12 06:44:11 -05:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2007-09-20 14:10:21 -05:00
|
|
|
import tempfile
|
|
|
|
import os
|
2009-06-04 14:33:49 -05:00
|
|
|
import pwd
|
2011-01-31 08:30:43 -06:00
|
|
|
import netaddr
|
2012-05-31 10:02:44 -05:00
|
|
|
import re
|
2014-08-27 06:50:21 -05:00
|
|
|
import sys
|
2014-10-17 06:24:49 -05:00
|
|
|
import time
|
2007-09-20 14:10:21 -05:00
|
|
|
|
2009-06-04 14:33:49 -05:00
|
|
|
import ldap
|
2015-08-10 11:29:33 -05:00
|
|
|
import six
|
2013-01-21 05:05:07 -06:00
|
|
|
|
2015-07-31 03:15:01 -05:00
|
|
|
from ipaserver.install import installutils
|
|
|
|
from ipaserver.install import service
|
2013-04-15 05:19:11 -05:00
|
|
|
from ipaserver.install.cainstance import IPA_CA_RECORD
|
2013-01-31 05:59:35 -06:00
|
|
|
from ipapython import sysrestore, ipautil, ipaldap
|
2013-01-21 05:05:07 -06:00
|
|
|
from ipapython.ipa_log_manager import *
|
|
|
|
from ipapython.dn import DN
|
|
|
|
import ipalib
|
|
|
|
from ipalib import api, errors
|
2014-10-16 09:31:53 -05:00
|
|
|
from ipaplatform import services
|
2015-10-06 08:27:21 -05:00
|
|
|
from ipaplatform.constants import constants
|
2014-05-29 07:47:17 -05:00
|
|
|
from ipaplatform.paths import paths
|
2014-10-16 09:31:53 -05:00
|
|
|
from ipaplatform.tasks import tasks
|
2014-05-16 05:21:04 -05:00
|
|
|
from ipalib.util import (validate_zonemgr_str, normalize_zonemgr,
|
2012-09-05 02:56:27 -05:00
|
|
|
get_dns_forward_zone_update_policy, get_dns_reverse_zone_update_policy,
|
2014-10-16 09:27:00 -05:00
|
|
|
normalize_zone, get_reverse_zone_default, zone_is_reverse,
|
2015-04-22 08:29:21 -05:00
|
|
|
validate_dnssec_global_forwarder, DNSSECSignatureMissingError,
|
|
|
|
EDNS0UnsupportedError, UnresolvableRecordError)
|
2013-09-11 03:27:34 -05:00
|
|
|
from ipalib.constants import CACERT
|
2007-12-13 03:31:28 -06:00
|
|
|
|
2015-09-11 06:43:28 -05:00
|
|
|
if six.PY3:
|
|
|
|
unicode = str
|
|
|
|
|
2014-05-29 07:47:17 -05:00
|
|
|
NAMED_CONF = paths.NAMED_CONF
|
|
|
|
RESOLV_CONF = paths.RESOLV_CONF
|
2012-05-31 10:02:44 -05:00
|
|
|
|
2013-03-05 05:02:58 -06:00
|
|
|
named_conf_section_ipa_start_re = re.compile('\s*dynamic-db\s+"ipa"\s+{')
|
|
|
|
named_conf_section_options_start_re = re.compile('\s*options\s+{')
|
|
|
|
named_conf_section_end_re = re.compile('};')
|
|
|
|
named_conf_arg_ipa_re = re.compile(r'(?P<indent>\s*)arg\s+"(?P<name>\S+)\s(?P<value>[^"]+)";')
|
|
|
|
named_conf_arg_options_re = re.compile(r'(?P<indent>\s*)(?P<name>\S+)\s+"(?P<value>[^"]+)"\s*;')
|
|
|
|
named_conf_arg_ipa_template = "%(indent)sarg \"%(name)s %(value)s\";\n"
|
|
|
|
named_conf_arg_options_template = "%(indent)s%(name)s \"%(value)s\";\n"
|
2014-06-27 10:04:15 -05:00
|
|
|
# non string args for options section
|
|
|
|
named_conf_arg_options_re_nonstr = re.compile(r'(?P<indent>\s*)(?P<name>\S+)\s+(?P<value>[^"]+)\s*;')
|
|
|
|
named_conf_arg_options_template_nonstr = "%(indent)s%(name)s %(value)s;\n"
|
2014-10-02 07:55:10 -05:00
|
|
|
# include directive
|
|
|
|
named_conf_include_re = re.compile(r'\s*include\s+"(?P<path>)"\s*;')
|
|
|
|
named_conf_include_template = "include \"%(path)s\";\n"
|
2012-05-31 10:02:44 -05:00
|
|
|
|
2008-05-28 21:46:08 -05:00
|
|
|
|
2011-01-04 07:55:47 -06:00
|
|
|
def create_reverse():
|
|
|
|
return ipautil.user_input("Do you want to configure the reverse zone?", True)
|
2010-11-11 12:27:27 -06:00
|
|
|
|
2011-01-03 07:48:29 -06:00
|
|
|
def named_conf_exists():
|
2012-05-31 10:02:44 -05:00
|
|
|
try:
|
|
|
|
named_fd = open(NAMED_CONF, 'r')
|
|
|
|
except IOError:
|
|
|
|
return False
|
2011-01-03 07:48:29 -06:00
|
|
|
lines = named_fd.readlines()
|
|
|
|
named_fd.close()
|
|
|
|
for line in lines:
|
|
|
|
if line.startswith('dynamic-db "ipa"'):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2013-03-05 05:02:58 -06:00
|
|
|
NAMED_SECTION_OPTIONS = "options"
|
|
|
|
NAMED_SECTION_IPA = "ipa"
|
2014-06-27 10:04:15 -05:00
|
|
|
def named_conf_get_directive(name, section=NAMED_SECTION_IPA, str_val=True):
|
|
|
|
"""Get a configuration option in bind-dyndb-ldap section of named.conf
|
|
|
|
|
|
|
|
:str_val - set to True if directive value is string
|
|
|
|
(only for NAMED_SECTION_OPTIONS)
|
|
|
|
"""
|
2013-03-05 05:02:58 -06:00
|
|
|
if section == NAMED_SECTION_IPA:
|
|
|
|
named_conf_section_start_re = named_conf_section_ipa_start_re
|
|
|
|
named_conf_arg_re = named_conf_arg_ipa_re
|
|
|
|
elif section == NAMED_SECTION_OPTIONS:
|
|
|
|
named_conf_section_start_re = named_conf_section_options_start_re
|
2014-06-27 10:04:15 -05:00
|
|
|
if str_val:
|
|
|
|
named_conf_arg_re = named_conf_arg_options_re
|
|
|
|
else:
|
|
|
|
named_conf_arg_re = named_conf_arg_options_re_nonstr
|
2013-03-05 05:02:58 -06:00
|
|
|
else:
|
|
|
|
raise NotImplementedError('Section "%s" is not supported' % section)
|
2012-05-31 10:02:44 -05:00
|
|
|
|
|
|
|
with open(NAMED_CONF, 'r') as f:
|
2013-03-05 05:02:58 -06:00
|
|
|
target_section = False
|
2012-05-31 10:02:44 -05:00
|
|
|
for line in f:
|
2013-03-05 05:02:58 -06:00
|
|
|
if named_conf_section_start_re.match(line):
|
|
|
|
target_section = True
|
2012-05-31 10:02:44 -05:00
|
|
|
continue
|
2013-03-05 05:02:58 -06:00
|
|
|
if named_conf_section_end_re.match(line):
|
|
|
|
if target_section:
|
2012-05-31 10:02:44 -05:00
|
|
|
break
|
|
|
|
|
2013-03-05 05:02:58 -06:00
|
|
|
if target_section:
|
|
|
|
match = named_conf_arg_re.match(line)
|
2012-05-31 10:02:44 -05:00
|
|
|
|
|
|
|
if match and name == match.group('name'):
|
|
|
|
return match.group('value')
|
|
|
|
|
2014-06-27 10:04:15 -05:00
|
|
|
def named_conf_set_directive(name, value, section=NAMED_SECTION_IPA,
|
|
|
|
str_val=True):
|
2012-05-31 10:02:44 -05:00
|
|
|
"""
|
|
|
|
Set configuration option in bind-dyndb-ldap section of named.conf.
|
|
|
|
|
|
|
|
When the configuration option with given name does not exist, it
|
|
|
|
is added at the end of ipa section in named.conf.
|
|
|
|
|
|
|
|
If the value is set to None, the configuration option is removed
|
|
|
|
from named.conf.
|
2014-06-27 10:04:15 -05:00
|
|
|
|
|
|
|
:str_val - set to True if directive value is string
|
|
|
|
(only for NAMED_SECTION_OPTIONS)
|
2012-05-31 10:02:44 -05:00
|
|
|
"""
|
|
|
|
new_lines = []
|
|
|
|
|
2013-03-05 05:02:58 -06:00
|
|
|
if section == NAMED_SECTION_IPA:
|
|
|
|
named_conf_section_start_re = named_conf_section_ipa_start_re
|
|
|
|
named_conf_arg_re = named_conf_arg_ipa_re
|
|
|
|
named_conf_arg_template = named_conf_arg_ipa_template
|
|
|
|
elif section == NAMED_SECTION_OPTIONS:
|
|
|
|
named_conf_section_start_re = named_conf_section_options_start_re
|
2014-06-27 10:04:15 -05:00
|
|
|
if str_val:
|
|
|
|
named_conf_arg_re = named_conf_arg_options_re
|
|
|
|
named_conf_arg_template = named_conf_arg_options_template
|
|
|
|
else:
|
|
|
|
named_conf_arg_re = named_conf_arg_options_re_nonstr
|
|
|
|
named_conf_arg_template = named_conf_arg_options_template_nonstr
|
2013-03-05 05:02:58 -06:00
|
|
|
else:
|
|
|
|
raise NotImplementedError('Section "%s" is not supported' % section)
|
|
|
|
|
2012-05-31 10:02:44 -05:00
|
|
|
with open(NAMED_CONF, 'r') as f:
|
2013-03-05 05:02:58 -06:00
|
|
|
target_section = False
|
2012-05-31 10:02:44 -05:00
|
|
|
matched = False
|
|
|
|
last_indent = "\t"
|
|
|
|
for line in f:
|
2013-03-05 05:02:58 -06:00
|
|
|
if named_conf_section_start_re.match(line):
|
|
|
|
target_section = True
|
|
|
|
if named_conf_section_end_re.match(line):
|
|
|
|
if target_section and not matched and \
|
|
|
|
value is not None:
|
2012-05-31 10:02:44 -05:00
|
|
|
# create a new conf
|
2013-03-05 05:02:58 -06:00
|
|
|
new_conf = named_conf_arg_template \
|
2012-05-31 10:02:44 -05:00
|
|
|
% dict(indent=last_indent,
|
|
|
|
name=name,
|
|
|
|
value=value)
|
|
|
|
new_lines.append(new_conf)
|
2013-03-05 05:02:58 -06:00
|
|
|
target_section = False
|
2012-05-31 10:02:44 -05:00
|
|
|
|
2013-03-05 05:02:58 -06:00
|
|
|
if target_section and not matched:
|
|
|
|
match = named_conf_arg_re.match(line)
|
2012-05-31 10:02:44 -05:00
|
|
|
|
|
|
|
if match:
|
|
|
|
last_indent = match.group('indent')
|
|
|
|
if name == match.group('name'):
|
|
|
|
matched = True
|
|
|
|
if value is not None:
|
2015-08-10 11:29:33 -05:00
|
|
|
if not isinstance(value, six.string_types):
|
2012-05-31 10:02:44 -05:00
|
|
|
value = str(value)
|
2013-03-05 05:02:58 -06:00
|
|
|
new_conf = named_conf_arg_template \
|
2012-05-31 10:02:44 -05:00
|
|
|
% dict(indent=last_indent,
|
|
|
|
name=name,
|
|
|
|
value=value)
|
|
|
|
new_lines.append(new_conf)
|
|
|
|
continue
|
|
|
|
new_lines.append(line)
|
|
|
|
|
|
|
|
# write new configuration
|
|
|
|
with open(NAMED_CONF, 'w') as f:
|
|
|
|
f.write("".join(new_lines))
|
|
|
|
|
2014-10-02 07:55:10 -05:00
|
|
|
def named_conf_include_exists(path):
|
|
|
|
"""
|
|
|
|
Check if include exists in named.conf
|
|
|
|
:param path: path in include directive
|
|
|
|
:return: True if include exists, else False
|
|
|
|
"""
|
|
|
|
with open(NAMED_CONF, 'r') as f:
|
|
|
|
for line in f:
|
|
|
|
match = named_conf_include_re.match(line)
|
|
|
|
if match and path == match.group('path'):
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def named_conf_add_include(path):
|
|
|
|
"""
|
|
|
|
append include at the end of file
|
|
|
|
:param path: path to be insert to include directive
|
|
|
|
"""
|
|
|
|
with open(NAMED_CONF, 'a') as f:
|
|
|
|
f.write(named_conf_include_template % {'path': path})
|
|
|
|
|
2014-08-27 08:06:42 -05:00
|
|
|
def dns_container_exists(fqdn, suffix, dm_password=None, ldapi=False, realm=None,
|
|
|
|
autobind=ipaldap.AUTOBIND_DISABLED):
|
2010-02-08 07:21:46 -06:00
|
|
|
"""
|
|
|
|
Test whether the dns container exists.
|
|
|
|
"""
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(suffix, DN)
|
2010-09-29 13:51:35 -05:00
|
|
|
try:
|
2011-10-06 01:37:17 -05:00
|
|
|
# At install time we may need to use LDAPI to avoid chicken/egg
|
|
|
|
# issues with SSL certs and truting CAs
|
|
|
|
if ldapi:
|
|
|
|
conn = ipaldap.IPAdmin(host=fqdn, ldapi=True, realm=realm)
|
|
|
|
else:
|
2013-09-11 03:27:34 -05:00
|
|
|
conn = ipaldap.IPAdmin(host=fqdn, port=636, cacert=CACERT)
|
2011-10-06 01:37:17 -05:00
|
|
|
|
2014-08-27 08:06:42 -05:00
|
|
|
conn.do_bind(dm_password, autobind=autobind)
|
2010-09-29 13:51:35 -05:00
|
|
|
except ldap.SERVER_DOWN:
|
|
|
|
raise RuntimeError('LDAP server on %s is not responding. Is IPA installed?' % fqdn)
|
2010-02-08 07:21:46 -06:00
|
|
|
|
2014-08-27 08:06:42 -05:00
|
|
|
ret = conn.entry_exists(DN(('cn', 'dns'), suffix))
|
2013-01-30 05:46:48 -06:00
|
|
|
conn.unbind()
|
2010-02-08 07:21:46 -06:00
|
|
|
|
|
|
|
return ret
|
|
|
|
|
2015-03-04 03:35:06 -06:00
|
|
|
def dns_zone_exists(name, api=api):
|
2011-01-03 07:48:29 -06:00
|
|
|
try:
|
2011-01-12 14:02:05 -06:00
|
|
|
zone = api.Command.dnszone_show(unicode(name))
|
|
|
|
except ipalib.errors.NotFound:
|
2011-01-03 07:48:29 -06:00
|
|
|
return False
|
|
|
|
|
|
|
|
if len(zone) == 0:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return True
|
|
|
|
|
2011-07-11 03:14:53 -05:00
|
|
|
def get_reverse_record_name(zone, ip_address):
|
|
|
|
ip = netaddr.IPAddress(ip_address)
|
|
|
|
rev = '.' + normalize_zone(zone)
|
|
|
|
fullrev = '.' + normalize_zone(ip.reverse_dns)
|
|
|
|
|
|
|
|
if not fullrev.endswith(rev):
|
|
|
|
raise ValueError("IP address does not match reverse zone")
|
|
|
|
|
|
|
|
return fullrev[1:-len(rev)]
|
|
|
|
|
|
|
|
def verify_reverse_zone(zone, ip_address):
|
|
|
|
try:
|
|
|
|
get_reverse_record_name(zone, ip_address)
|
|
|
|
except ValueError:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2015-03-04 03:35:06 -06:00
|
|
|
def find_reverse_zone(ip_address, api=api):
|
2011-07-11 03:14:53 -05:00
|
|
|
ip = netaddr.IPAddress(ip_address)
|
|
|
|
zone = normalize_zone(ip.reverse_dns)
|
|
|
|
|
|
|
|
while len(zone) > 0:
|
2015-03-04 03:35:06 -06:00
|
|
|
if dns_zone_exists(zone, api):
|
2011-07-11 03:14:53 -05:00
|
|
|
return zone
|
|
|
|
foo, bar, zone = zone.partition('.')
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def read_reverse_zone(default, ip_address):
|
|
|
|
while True:
|
|
|
|
zone = ipautil.user_input("Please specify the reverse zone name", default=default)
|
|
|
|
if not zone:
|
|
|
|
return None
|
|
|
|
if verify_reverse_zone(zone, ip_address):
|
|
|
|
break
|
2014-08-27 06:50:21 -05:00
|
|
|
else:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Invalid reverse zone %s for IP address %s" % (zone, ip_address))
|
2011-07-11 03:14:53 -05:00
|
|
|
|
|
|
|
return normalize_zone(zone)
|
|
|
|
|
2014-09-12 06:20:16 -05:00
|
|
|
def add_zone(name, zonemgr=None, dns_backup=None, ns_hostname=None,
|
2015-03-04 03:35:06 -06:00
|
|
|
update_policy=None, force=False, api=api):
|
2014-09-12 06:20:16 -05:00
|
|
|
|
|
|
|
# always normalize zones
|
|
|
|
name = normalize_zone(name)
|
2012-09-25 03:36:01 -05:00
|
|
|
|
2011-06-01 07:51:06 -05:00
|
|
|
if update_policy is None:
|
2012-09-25 03:36:01 -05:00
|
|
|
if zone_is_reverse(name):
|
|
|
|
update_policy = get_dns_reverse_zone_update_policy(api.env.realm, name)
|
|
|
|
else:
|
|
|
|
update_policy = get_dns_forward_zone_update_policy(api.env.realm)
|
2009-11-10 06:21:09 -06:00
|
|
|
|
2011-11-23 09:03:51 -06:00
|
|
|
if zonemgr is None:
|
2011-11-23 09:09:29 -06:00
|
|
|
zonemgr = 'hostmaster.%s' % name
|
2011-11-23 09:03:51 -06:00
|
|
|
|
2014-09-12 06:20:16 -05:00
|
|
|
if ns_hostname:
|
|
|
|
ns_hostname = normalize_zone(ns_hostname)
|
|
|
|
ns_hostname = unicode(ns_hostname)
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
|
2009-11-10 06:21:09 -06:00
|
|
|
try:
|
2011-01-12 14:02:05 -06:00
|
|
|
api.Command.dnszone_add(unicode(name),
|
2014-09-12 06:20:16 -05:00
|
|
|
idnssoamname=ns_hostname,
|
2011-01-12 14:02:05 -06:00
|
|
|
idnssoarname=unicode(zonemgr),
|
|
|
|
idnsallowdynupdate=True,
|
2012-02-24 02:30:39 -06:00
|
|
|
idnsupdatepolicy=unicode(update_policy),
|
|
|
|
idnsallowquery=u'any',
|
2012-10-25 01:47:34 -05:00
|
|
|
idnsallowtransfer=u'none',
|
|
|
|
force=force)
|
2009-11-10 06:21:09 -06:00
|
|
|
except (errors.DuplicateEntry, errors.EmptyModlist):
|
|
|
|
pass
|
|
|
|
|
2015-03-04 03:35:06 -06:00
|
|
|
def add_rr(zone, name, type, rdata, dns_backup=None, api=api, **kwargs):
|
2011-02-07 11:52:07 -06:00
|
|
|
addkw = { '%srecord' % str(type.lower()) : unicode(rdata) }
|
2011-01-31 11:05:07 -06:00
|
|
|
addkw.update(kwargs)
|
2009-11-10 06:21:09 -06:00
|
|
|
try:
|
2011-01-12 14:02:05 -06:00
|
|
|
api.Command.dnsrecord_add(unicode(zone), unicode(name), **addkw)
|
2009-11-10 06:21:09 -06:00
|
|
|
except (errors.DuplicateEntry, errors.EmptyModlist):
|
|
|
|
pass
|
2009-11-24 17:49:40 -06:00
|
|
|
if dns_backup:
|
|
|
|
dns_backup.add(zone, type, name, rdata)
|
2009-11-10 06:21:09 -06:00
|
|
|
|
2015-03-04 03:35:06 -06:00
|
|
|
def add_fwd_rr(zone, host, ip_address, api=api):
|
2011-01-31 08:30:43 -06:00
|
|
|
addr = netaddr.IPAddress(ip_address)
|
|
|
|
if addr.version == 4:
|
2015-03-04 03:35:06 -06:00
|
|
|
add_rr(zone, host, "A", ip_address, None, api)
|
2011-01-31 08:30:43 -06:00
|
|
|
elif addr.version == 6:
|
2015-03-04 03:35:06 -06:00
|
|
|
add_rr(zone, host, "AAAA", ip_address, None, api)
|
2011-01-31 08:30:43 -06:00
|
|
|
|
2015-03-04 03:35:06 -06:00
|
|
|
def add_ptr_rr(zone, ip_address, fqdn, dns_backup=None, api=api):
|
2011-07-11 03:14:53 -05:00
|
|
|
name = get_reverse_record_name(zone, ip_address)
|
2015-03-04 03:35:06 -06:00
|
|
|
add_rr(zone, name, "PTR", normalize_zone(fqdn), dns_backup, api)
|
2009-11-24 17:49:40 -06:00
|
|
|
|
2015-07-15 12:14:35 -05:00
|
|
|
|
|
|
|
def add_ns_rr(zone, hostname, dns_backup=None, force=True, api=api):
|
2013-05-03 08:00:24 -05:00
|
|
|
hostname = normalize_zone(hostname)
|
2012-09-27 06:45:32 -05:00
|
|
|
add_rr(zone, "@", "NS", hostname, dns_backup=dns_backup,
|
2015-07-15 12:14:35 -05:00
|
|
|
force=force, api=api)
|
|
|
|
|
2011-06-01 07:51:06 -05:00
|
|
|
|
2015-07-15 12:14:35 -05:00
|
|
|
def del_rr(zone, name, type, rdata, api=api):
|
2011-02-07 11:52:07 -06:00
|
|
|
delkw = { '%srecord' % str(type.lower()) : unicode(rdata) }
|
2011-01-21 13:46:58 -06:00
|
|
|
try:
|
|
|
|
api.Command.dnsrecord_del(unicode(zone), unicode(name), **delkw)
|
2012-11-19 09:32:28 -06:00
|
|
|
except (errors.NotFound, errors.AttrValueNotFound, errors.EmptyModlist):
|
2011-01-21 13:46:58 -06:00
|
|
|
pass
|
|
|
|
|
2015-07-15 12:14:35 -05:00
|
|
|
|
|
|
|
def del_fwd_rr(zone, host, ip_address, api=api):
|
2013-04-15 05:19:11 -05:00
|
|
|
addr = netaddr.IPAddress(ip_address)
|
|
|
|
if addr.version == 4:
|
2015-07-15 12:14:35 -05:00
|
|
|
del_rr(zone, host, "A", ip_address, api=api)
|
2013-04-15 05:19:11 -05:00
|
|
|
elif addr.version == 6:
|
2015-07-15 12:14:35 -05:00
|
|
|
del_rr(zone, host, "AAAA", ip_address, api=api)
|
|
|
|
|
2013-04-15 05:19:11 -05:00
|
|
|
|
2015-07-15 12:14:35 -05:00
|
|
|
def del_ns_rr(zone, name, rdata, api=api):
|
|
|
|
del_rr(zone, name, 'NS', rdata, api=api)
|
2014-09-12 06:20:16 -05:00
|
|
|
|
2015-03-04 03:35:06 -06:00
|
|
|
def get_rr(zone, name, type, api=api):
|
2011-01-21 13:46:58 -06:00
|
|
|
rectype = '%srecord' % unicode(type.lower())
|
|
|
|
ret = api.Command.dnsrecord_find(unicode(zone), unicode(name))
|
|
|
|
if ret['count'] > 0:
|
|
|
|
for r in ret['result']:
|
|
|
|
if rectype in r:
|
|
|
|
return r[rectype]
|
|
|
|
|
|
|
|
return []
|
|
|
|
|
2015-03-04 03:35:06 -06:00
|
|
|
def get_fwd_rr(zone, host, api=api):
|
|
|
|
return [x for t in ("A", "AAAA") for x in get_rr(zone, host, t, api)]
|
2013-04-15 05:19:11 -05:00
|
|
|
|
2011-10-24 11:35:48 -05:00
|
|
|
def zonemgr_callback(option, opt_str, value, parser):
|
|
|
|
"""
|
|
|
|
Properly validate and convert --zonemgr Option to IA5String
|
|
|
|
"""
|
2014-11-24 05:46:37 -06:00
|
|
|
if value is not None:
|
|
|
|
# validate the value first
|
|
|
|
try:
|
|
|
|
# IDNA support requires unicode
|
2014-11-25 07:03:27 -06:00
|
|
|
encoding = getattr(sys.stdin, 'encoding', None)
|
|
|
|
if encoding is None:
|
|
|
|
encoding = 'utf-8'
|
|
|
|
value = value.decode(encoding)
|
2014-11-24 05:46:37 -06:00
|
|
|
validate_zonemgr_str(value)
|
2015-07-30 09:49:29 -05:00
|
|
|
except ValueError as e:
|
2014-12-12 07:23:32 -06:00
|
|
|
# FIXME we can do this in better way
|
|
|
|
# https://fedorahosted.org/freeipa/ticket/4804
|
|
|
|
# decode to proper stderr encoding
|
|
|
|
stderr_encoding = getattr(sys.stderr, 'encoding', None)
|
|
|
|
if stderr_encoding is None:
|
|
|
|
stderr_encoding = 'utf-8'
|
|
|
|
error = unicode(e).encode(stderr_encoding)
|
|
|
|
parser.error("invalid zonemgr: " + error)
|
2011-10-24 11:35:48 -05:00
|
|
|
|
|
|
|
parser.values.zonemgr = value
|
2009-11-24 17:49:40 -06:00
|
|
|
|
2014-08-27 06:50:21 -05:00
|
|
|
def check_reverse_zones(ip_addresses, reverse_zones, options, unattended, search_reverse_zones=False):
|
|
|
|
reverse_asked = False
|
|
|
|
|
|
|
|
ret_reverse_zones = []
|
|
|
|
# check that there is IP address in every reverse zone
|
|
|
|
if reverse_zones:
|
|
|
|
for rz in reverse_zones:
|
|
|
|
for ip in ip_addresses:
|
|
|
|
if verify_reverse_zone(rz, ip):
|
|
|
|
ret_reverse_zones.append(normalize_zone(rz))
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
# no ip matching reverse zone found
|
|
|
|
sys.exit("There is no IP address matching reverse zone %s." % rz)
|
|
|
|
if not options.no_reverse:
|
|
|
|
# check that there is reverse zone for every IP
|
|
|
|
for ip in ip_addresses:
|
|
|
|
if search_reverse_zones and find_reverse_zone(str(ip)):
|
|
|
|
# reverse zone is already in LDAP
|
|
|
|
continue
|
|
|
|
for rz in ret_reverse_zones:
|
|
|
|
if verify_reverse_zone(rz, ip):
|
|
|
|
# reverse zone was entered by user
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
# no reverse zone for ip found
|
|
|
|
if not reverse_asked:
|
|
|
|
if not unattended and not reverse_zones:
|
|
|
|
# user did not specify reverse_zone nor no_reverse
|
|
|
|
options.no_reverse = not create_reverse()
|
|
|
|
if options.no_reverse:
|
|
|
|
# user decided not to create reverse zone
|
|
|
|
return []
|
|
|
|
reverse_asked = True
|
|
|
|
rz = get_reverse_zone_default(str(ip))
|
|
|
|
if not unattended:
|
|
|
|
rz = read_reverse_zone(rz, str(ip))
|
|
|
|
ret_reverse_zones.append(rz)
|
|
|
|
|
|
|
|
return ret_reverse_zones
|
|
|
|
|
2014-10-16 09:27:00 -05:00
|
|
|
def check_forwarders(dns_forwarders, logger):
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Checking DNS forwarders, please wait ...")
|
2014-10-16 09:27:00 -05:00
|
|
|
forwarders_dnssec_valid = True
|
|
|
|
for forwarder in dns_forwarders:
|
2015-04-22 08:29:21 -05:00
|
|
|
logger.debug("Checking DNS server: %s", forwarder)
|
|
|
|
try:
|
|
|
|
validate_dnssec_global_forwarder(forwarder, log=logger)
|
|
|
|
except DNSSECSignatureMissingError as e:
|
2014-10-16 09:27:00 -05:00
|
|
|
forwarders_dnssec_valid = False
|
2015-04-22 08:29:21 -05:00
|
|
|
logger.warning("DNS server %s does not support DNSSEC: %s",
|
|
|
|
forwarder, e)
|
2014-10-16 09:27:00 -05:00
|
|
|
logger.warning("Please fix forwarder configuration to enable DNSSEC support.\n"
|
|
|
|
"(For BIND 9 add directive \"dnssec-enable yes;\" to \"options {}\")")
|
2015-08-12 06:44:11 -05:00
|
|
|
print("DNS server %s: %s" % (forwarder, e))
|
|
|
|
print("Please fix forwarder configuration to enable DNSSEC support.")
|
|
|
|
print("(For BIND 9 add directive \"dnssec-enable yes;\" to \"options {}\")")
|
2015-04-22 08:29:21 -05:00
|
|
|
except EDNS0UnsupportedError as e:
|
|
|
|
forwarders_dnssec_valid = False
|
|
|
|
logger.warning("DNS server %s does not support ENDS0 "
|
|
|
|
"(RFC 6891): %s", forwarder, e)
|
|
|
|
logger.warning("Please fix forwarder configuration. "
|
|
|
|
"DNSSEC support cannot be enabled without EDNS0")
|
2015-08-12 06:44:11 -05:00
|
|
|
print(("WARNING: DNS server %s does not support EDNS0 "
|
|
|
|
"(RFC 6891): %s" % (forwarder, e)))
|
2015-04-22 08:29:21 -05:00
|
|
|
except UnresolvableRecordError as e:
|
|
|
|
logger.error("DNS server %s: %s", forwarder, e)
|
|
|
|
raise RuntimeError("DNS server %s: %s" % (forwarder, e))
|
2014-10-16 09:27:00 -05:00
|
|
|
|
|
|
|
return forwarders_dnssec_valid
|
|
|
|
|
2014-08-27 06:50:21 -05:00
|
|
|
|
2009-11-24 17:49:40 -06:00
|
|
|
class DnsBackup(object):
|
|
|
|
def __init__(self, service):
|
|
|
|
self.service = service
|
|
|
|
self.zones = {}
|
|
|
|
|
|
|
|
def add(self, zone, record_type, host, rdata):
|
|
|
|
"""
|
|
|
|
Backup a DNS record in the file store so it can later be removed.
|
|
|
|
"""
|
|
|
|
if zone not in self.zones:
|
|
|
|
zone_id = len(self.zones)
|
|
|
|
self.zones[zone] = (zone_id, 0)
|
|
|
|
self.service.backup_state("dns_zone_%s" % zone_id, zone)
|
|
|
|
|
|
|
|
(zone_id, record_id) = self.zones[zone]
|
|
|
|
self.service.backup_state("dns_record_%s_%s" % (zone_id, record_id),
|
|
|
|
"%s %s %s" % (record_type, host, rdata))
|
|
|
|
self.zones[zone] = (zone_id, record_id + 1)
|
|
|
|
|
|
|
|
def clear_records(self, have_ldap):
|
|
|
|
"""
|
|
|
|
Remove all records from the file store. If we are connected to
|
|
|
|
ldap, we will also remove them there.
|
|
|
|
"""
|
|
|
|
i = 0
|
|
|
|
while True:
|
|
|
|
zone = self.service.restore_state("dns_zone_%s" % i)
|
|
|
|
if not zone:
|
|
|
|
return
|
|
|
|
|
|
|
|
j = 0
|
|
|
|
while True:
|
|
|
|
dns_record = self.service.restore_state("dns_record_%s_%s" % (i, j))
|
|
|
|
if not dns_record:
|
|
|
|
break
|
|
|
|
if have_ldap:
|
|
|
|
type, host, rdata = dns_record.split(" ", 2)
|
|
|
|
try:
|
2011-02-07 11:52:07 -06:00
|
|
|
delkw = { '%srecord' % str(type.lower()) : unicode(rdata) }
|
2011-01-12 14:02:05 -06:00
|
|
|
api.Command.dnsrecord_del(unicode(zone), unicode(host), **delkw)
|
2009-11-24 17:49:40 -06:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
j += 1
|
|
|
|
|
|
|
|
i += 1
|
|
|
|
|
2009-11-10 06:21:09 -06:00
|
|
|
|
2007-12-13 03:31:28 -06:00
|
|
|
class BindInstance(service.Service):
|
2015-03-12 11:05:39 -05:00
|
|
|
def __init__(self, fstore=None, dm_password=None, api=api, ldapi=False,
|
|
|
|
start_tls=False, autobind=ipaldap.AUTOBIND_DISABLED):
|
2015-03-12 10:14:22 -05:00
|
|
|
service.Service.__init__(
|
|
|
|
self, "named",
|
2012-10-11 02:32:17 -05:00
|
|
|
service_desc="DNS",
|
|
|
|
dm_password=dm_password,
|
2015-03-12 11:05:39 -05:00
|
|
|
ldapi=ldapi,
|
|
|
|
autobind=autobind,
|
2015-03-12 10:14:22 -05:00
|
|
|
start_tls=start_tls
|
|
|
|
)
|
2009-11-24 17:49:40 -06:00
|
|
|
self.dns_backup = DnsBackup(self)
|
2009-06-04 14:33:49 -05:00
|
|
|
self.named_user = None
|
2009-05-12 08:20:24 -05:00
|
|
|
self.domain = None
|
2007-09-20 14:10:21 -05:00
|
|
|
self.host = None
|
2014-08-27 06:50:21 -05:00
|
|
|
self.ip_addresses = []
|
2007-09-20 14:10:21 -05:00
|
|
|
self.realm = None
|
2009-09-01 16:28:52 -05:00
|
|
|
self.forwarders = None
|
2007-09-20 14:10:21 -05:00
|
|
|
self.sub_dict = None
|
2014-08-27 06:50:21 -05:00
|
|
|
self.reverse_zones = []
|
2011-10-06 01:37:17 -05:00
|
|
|
self.dm_password = dm_password
|
2015-03-04 03:35:06 -06:00
|
|
|
self.api = api
|
2014-10-16 09:31:53 -05:00
|
|
|
self.named_regular = services.service('named-regular')
|
2007-09-20 14:10:21 -05:00
|
|
|
|
2008-03-27 18:01:38 -05:00
|
|
|
if fstore:
|
|
|
|
self.fstore = fstore
|
|
|
|
else:
|
2014-05-29 07:47:17 -05:00
|
|
|
self.fstore = sysrestore.FileStore(paths.SYSRESTORE)
|
2008-03-27 18:01:38 -05:00
|
|
|
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
suffix = ipautil.dn_attribute_property('_suffix')
|
|
|
|
|
2014-08-27 06:50:21 -05:00
|
|
|
def setup(self, fqdn, ip_addresses, realm_name, domain_name, forwarders, ntp,
|
2015-10-06 08:27:21 -05:00
|
|
|
reverse_zones, named_user=constants.NAMED_USER, zonemgr=None,
|
2014-10-16 09:27:00 -05:00
|
|
|
ca_configured=None, no_dnssec_validation=False):
|
2009-06-04 14:33:49 -05:00
|
|
|
self.named_user = named_user
|
2007-09-20 14:10:21 -05:00
|
|
|
self.fqdn = fqdn
|
2014-08-27 06:50:21 -05:00
|
|
|
self.ip_addresses = ip_addresses
|
2007-09-20 14:10:21 -05:00
|
|
|
self.realm = realm_name
|
2008-02-15 19:47:29 -06:00
|
|
|
self.domain = domain_name
|
2009-09-01 16:28:52 -05:00
|
|
|
self.forwarders = forwarders
|
2008-05-15 10:33:07 -05:00
|
|
|
self.host = fqdn.split(".")[0]
|
2012-04-18 10:22:35 -05:00
|
|
|
self.suffix = ipautil.realm_to_suffix(self.realm)
|
2009-11-10 08:16:38 -06:00
|
|
|
self.ntp = ntp
|
2014-08-27 06:50:21 -05:00
|
|
|
self.reverse_zones = reverse_zones
|
2012-11-19 09:32:28 -06:00
|
|
|
self.ca_configured = ca_configured
|
2014-10-16 09:27:00 -05:00
|
|
|
self.no_dnssec_validation=no_dnssec_validation
|
2007-09-20 14:10:21 -05:00
|
|
|
|
2011-11-23 09:03:51 -06:00
|
|
|
if not zonemgr:
|
2014-11-07 05:45:43 -06:00
|
|
|
self.zonemgr = 'hostmaster.%s' % normalize_zone(self.domain)
|
2011-11-23 09:03:51 -06:00
|
|
|
else:
|
|
|
|
self.zonemgr = normalize_zonemgr(zonemgr)
|
2010-09-20 14:41:20 -05:00
|
|
|
|
2013-04-23 01:59:07 -05:00
|
|
|
self.first_instance = not dns_container_exists(
|
|
|
|
self.fqdn, self.suffix, realm=self.realm, ldapi=True,
|
2015-03-12 11:05:39 -05:00
|
|
|
dm_password=self.dm_password, autobind=self.autobind)
|
2013-04-23 01:59:07 -05:00
|
|
|
|
2007-09-20 14:10:21 -05:00
|
|
|
self.__setup_sub_dict()
|
|
|
|
|
2012-04-04 09:31:04 -05:00
|
|
|
@property
|
|
|
|
def host_domain(self):
|
2013-04-23 01:59:07 -05:00
|
|
|
return self.fqdn.split(".", 1)[1]
|
2012-04-04 09:31:04 -05:00
|
|
|
|
|
|
|
@property
|
|
|
|
def host_in_rr(self):
|
|
|
|
# when a host is not in a default domain, it needs to be referred
|
|
|
|
# with FQDN and not in a domain-relative host name
|
|
|
|
if not self.host_in_default_domain():
|
|
|
|
return normalize_zone(self.fqdn)
|
|
|
|
return self.host
|
|
|
|
|
|
|
|
def host_in_default_domain(self):
|
|
|
|
return normalize_zone(self.host_domain) == normalize_zone(self.domain)
|
|
|
|
|
2007-09-20 14:10:21 -05:00
|
|
|
def create_sample_bind_zone(self):
|
2007-12-13 03:31:28 -06:00
|
|
|
bind_txt = ipautil.template_file(ipautil.SHARE_DIR + "bind.zone.db.template", self.sub_dict)
|
2007-09-20 14:10:21 -05:00
|
|
|
[bind_fd, bind_name] = tempfile.mkstemp(".db","sample.zone.")
|
|
|
|
os.write(bind_fd, bind_txt)
|
|
|
|
os.close(bind_fd)
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Sample zone file for bind has been created in "+bind_name)
|
2007-09-20 14:10:21 -05:00
|
|
|
|
|
|
|
def create_instance(self):
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.stop()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2011-01-05 06:46:30 -06:00
|
|
|
# get a connection to the DS
|
|
|
|
self.ldap_connect()
|
|
|
|
|
2014-08-27 06:50:21 -05:00
|
|
|
for ip_address in self.ip_addresses:
|
|
|
|
if installutils.record_in_hosts(str(ip_address), self.fqdn) is None:
|
|
|
|
installutils.add_record_to_hosts(str(ip_address), self.fqdn)
|
2011-02-10 14:47:45 -06:00
|
|
|
|
2014-04-18 08:44:11 -05:00
|
|
|
# Make sure generate-rndc-key.sh runs before named restart
|
|
|
|
self.step("generating rndc key file", self.__generate_rndc_key)
|
|
|
|
|
2013-04-23 01:59:07 -05:00
|
|
|
if self.first_instance:
|
2010-02-08 07:21:46 -06:00
|
|
|
self.step("adding DNS container", self.__setup_dns_container)
|
2013-04-23 01:59:07 -05:00
|
|
|
|
2015-07-15 12:14:35 -05:00
|
|
|
if not dns_zone_exists(self.domain, self.api):
|
2011-01-03 07:48:29 -06:00
|
|
|
self.step("setting up our zone", self.__setup_zone)
|
2014-08-27 06:50:21 -05:00
|
|
|
if self.reverse_zones:
|
2010-11-11 12:27:27 -06:00
|
|
|
self.step("setting up reverse zone", self.__setup_reverse_zone)
|
2013-04-23 01:59:07 -05:00
|
|
|
|
2011-01-03 07:48:29 -06:00
|
|
|
self.step("setting up our own record", self.__add_self)
|
2013-04-23 01:59:07 -05:00
|
|
|
if self.first_instance:
|
|
|
|
self.step("setting up records for other masters", self.__add_others)
|
2014-09-12 06:20:16 -05:00
|
|
|
# all zones must be created before this step
|
|
|
|
self.step("adding NS record to the zones", self.__add_self_ns)
|
2013-04-15 05:19:11 -05:00
|
|
|
self.step("setting up CA record", self.__add_ipa_ca_record)
|
2009-06-04 14:33:49 -05:00
|
|
|
|
2009-06-27 00:53:45 -05:00
|
|
|
self.step("setting up kerberos principal", self.__setup_principal)
|
|
|
|
self.step("setting up named.conf", self.__setup_named_conf)
|
2008-03-27 18:01:38 -05:00
|
|
|
|
2014-10-16 09:31:53 -05:00
|
|
|
# named has to be started after softhsm initialization
|
|
|
|
# self.step("restarting named", self.__start)
|
2008-03-27 18:01:38 -05:00
|
|
|
|
2014-10-16 09:31:53 -05:00
|
|
|
self.step("configuring named to start on boot", self.__enable)
|
2009-06-27 00:53:45 -05:00
|
|
|
self.step("changing resolv.conf to point to ourselves", self.__setup_resolv_conf)
|
2012-10-11 02:32:17 -05:00
|
|
|
self.start_creation()
|
2007-09-20 14:10:21 -05:00
|
|
|
|
2014-10-16 09:31:53 -05:00
|
|
|
def start_named(self):
|
|
|
|
self.print_msg("Restarting named")
|
|
|
|
self.__start()
|
|
|
|
|
2008-03-27 18:01:38 -05:00
|
|
|
def __start(self):
|
2007-10-03 16:37:13 -05:00
|
|
|
try:
|
2014-10-16 09:31:53 -05:00
|
|
|
if self.get_state("running") is None:
|
|
|
|
# first time store status
|
|
|
|
self.backup_state("running", self.is_running())
|
2008-03-27 18:01:38 -05:00
|
|
|
self.restart()
|
2014-10-16 09:31:53 -05:00
|
|
|
except Exception as e:
|
|
|
|
root_logger.error("Named service failed to start (%s)", e)
|
2015-08-12 06:44:11 -05:00
|
|
|
print("named service failed to start")
|
2007-09-20 14:10:21 -05:00
|
|
|
|
2008-03-27 18:01:38 -05:00
|
|
|
def __enable(self):
|
2014-10-16 09:31:53 -05:00
|
|
|
if self.get_state("enabled") is None:
|
|
|
|
self.backup_state("enabled", self.is_running())
|
|
|
|
self.backup_state("named-regular-enabled",
|
|
|
|
self.named_regular.is_running())
|
2010-12-04 14:42:14 -06:00
|
|
|
# We do not let the system start IPA components on its own,
|
|
|
|
# Instead we reply on the IPA init script to start only enabled
|
|
|
|
# components as found in our LDAP configuration tree
|
2012-05-10 02:28:02 -05:00
|
|
|
try:
|
|
|
|
self.ldap_enable('DNS', self.fqdn, self.dm_password, self.suffix)
|
|
|
|
except errors.DuplicateEntry:
|
|
|
|
# service already exists (forced DNS reinstall)
|
|
|
|
# don't crash, just report error
|
|
|
|
root_logger.error("DNS service already exists")
|
2008-03-27 18:01:38 -05:00
|
|
|
|
2014-10-16 09:31:53 -05:00
|
|
|
# disable named, we need to run named-pkcs11 only
|
2015-02-09 10:28:45 -06:00
|
|
|
if self.get_state("named-regular-running") is None:
|
|
|
|
# first time store status
|
|
|
|
self.backup_state("named-regular-running",
|
|
|
|
self.named_regular.is_running())
|
2014-10-16 09:31:53 -05:00
|
|
|
try:
|
|
|
|
self.named_regular.stop()
|
|
|
|
except Exception as e:
|
|
|
|
root_logger.debug("Unable to stop named (%s)", e)
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.named_regular.mask()
|
|
|
|
except Exception as e:
|
|
|
|
root_logger.debug("Unable to mask named (%s)", e)
|
|
|
|
|
2007-09-20 14:10:21 -05:00
|
|
|
def __setup_sub_dict(self):
|
2009-09-01 16:28:52 -05:00
|
|
|
if self.forwarders:
|
|
|
|
fwds = "\n"
|
|
|
|
for forwarder in self.forwarders:
|
|
|
|
fwds += "\t\t%s;\n" % forwarder
|
|
|
|
fwds += "\t"
|
|
|
|
else:
|
|
|
|
fwds = " "
|
|
|
|
|
2009-11-10 08:16:38 -06:00
|
|
|
if self.ntp:
|
|
|
|
optional_ntp = "\n;ntp server\n"
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
optional_ntp += "_ntp._udp\t\tIN SRV 0 100 123\t%s" % self.host_in_rr
|
2009-11-10 08:16:38 -06:00
|
|
|
else:
|
|
|
|
optional_ntp = ""
|
2012-06-28 09:46:48 -05:00
|
|
|
|
2014-08-27 06:50:21 -05:00
|
|
|
ipa_ca = ""
|
|
|
|
for addr in self.ip_addresses:
|
|
|
|
if addr.version in (4, 6):
|
|
|
|
ipa_ca += "%s\t\t\tIN %s\t\t\t%s\n" % (
|
|
|
|
IPA_CA_RECORD,
|
|
|
|
"A" if addr.version == 4 else "AAAA",
|
|
|
|
str(addr))
|
2013-04-15 05:19:11 -05:00
|
|
|
|
2013-08-09 04:55:49 -05:00
|
|
|
self.sub_dict = dict(
|
|
|
|
FQDN=self.fqdn,
|
2014-08-27 06:50:21 -05:00
|
|
|
IP=[str(ip) for ip in self.ip_addresses],
|
2013-08-09 04:55:49 -05:00
|
|
|
DOMAIN=self.domain,
|
|
|
|
HOST=self.host,
|
|
|
|
REALM=self.realm,
|
2015-04-27 07:42:31 -05:00
|
|
|
SERVER_ID=installutils.realm_to_serverid(self.realm),
|
2013-08-09 04:55:49 -05:00
|
|
|
FORWARDERS=fwds,
|
|
|
|
SUFFIX=self.suffix,
|
|
|
|
OPTIONAL_NTP=optional_ntp,
|
|
|
|
ZONEMGR=self.zonemgr,
|
|
|
|
IPA_CA_RECORD=ipa_ca,
|
2014-10-02 07:55:10 -05:00
|
|
|
BINDKEYS_FILE=paths.NAMED_BINDKEYS_FILE,
|
|
|
|
MANAGED_KEYS_DIR=paths.NAMED_MANAGED_KEYS_DIR,
|
|
|
|
ROOT_KEY=paths.NAMED_ROOT_KEY,
|
2014-10-02 09:31:24 -05:00
|
|
|
NAMED_KEYTAB=paths.NAMED_KEYTAB,
|
|
|
|
RFC1912_ZONES=paths.NAMED_RFC1912_ZONES,
|
|
|
|
NAMED_PID=paths.NAMED_PID,
|
|
|
|
NAMED_VAR_DIR=paths.NAMED_VAR_DIR,
|
2013-08-09 04:55:49 -05:00
|
|
|
)
|
2007-09-20 14:10:21 -05:00
|
|
|
|
2009-11-10 06:21:09 -06:00
|
|
|
def __setup_dns_container(self):
|
2009-05-12 08:20:24 -05:00
|
|
|
self._ldap_mod("dns.ldif", self.sub_dict)
|
2014-10-17 06:24:49 -05:00
|
|
|
self.__fix_dns_privilege_members()
|
|
|
|
|
|
|
|
def __fix_dns_privilege_members(self):
|
2015-07-15 12:14:35 -05:00
|
|
|
ldap = self.api.Backend.ldap2
|
2014-10-17 06:24:49 -05:00
|
|
|
|
|
|
|
cn = 'Update PBAC memberOf %s' % time.time()
|
|
|
|
task_dn = DN(('cn', cn), ('cn', 'memberof task'), ('cn', 'tasks'),
|
|
|
|
('cn', 'config'))
|
2015-07-15 12:14:35 -05:00
|
|
|
basedn = DN(self.api.env.container_privilege, self.api.env.basedn)
|
2014-10-17 06:24:49 -05:00
|
|
|
entry = ldap.make_entry(
|
|
|
|
task_dn,
|
|
|
|
objectclass=['top', 'extensibleObject'],
|
|
|
|
cn=[cn],
|
|
|
|
basedn=[basedn],
|
|
|
|
filter=['(objectclass=*)'],
|
|
|
|
ttl=[10])
|
|
|
|
ldap.add_entry(entry)
|
|
|
|
|
|
|
|
start_time = time.time()
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
task = ldap.get_entry(task_dn)
|
|
|
|
except errors.NotFound:
|
|
|
|
break
|
|
|
|
if 'nstaskexitcode' in task:
|
|
|
|
break
|
|
|
|
time.sleep(1)
|
|
|
|
if time.time() > (start_time + 60):
|
|
|
|
raise errors.TaskTimeout(task='memberof', task_dn=task_dn)
|
2009-06-27 00:53:45 -05:00
|
|
|
|
2009-11-10 06:21:09 -06:00
|
|
|
def __setup_zone(self):
|
2012-11-09 02:25:43 -06:00
|
|
|
# Always use force=True as named is not set up yet
|
2011-06-01 07:51:06 -05:00
|
|
|
add_zone(self.domain, self.zonemgr, dns_backup=self.dns_backup,
|
2015-07-15 12:14:35 -05:00
|
|
|
ns_hostname=self.api.env.host, force=True, api=self.api)
|
2011-01-31 11:05:07 -06:00
|
|
|
|
2015-07-15 12:14:35 -05:00
|
|
|
add_rr(self.domain, "_kerberos", "TXT", self.realm, api=self.api)
|
2013-04-23 01:59:07 -05:00
|
|
|
|
2011-05-03 04:31:16 -05:00
|
|
|
def __add_self_ns(self):
|
2014-09-12 06:20:16 -05:00
|
|
|
# add NS record to all zones
|
2015-07-15 12:14:35 -05:00
|
|
|
ns_hostname = normalize_zone(self.api.env.host)
|
|
|
|
result = self.api.Command.dnszone_find()
|
2014-09-12 06:20:16 -05:00
|
|
|
for zone in result['result']:
|
|
|
|
zone = unicode(zone['idnsname'][0]) # we need unicode due to backup
|
|
|
|
root_logger.debug("adding self NS to zone %s apex", zone)
|
2015-07-15 12:14:35 -05:00
|
|
|
add_ns_rr(zone, ns_hostname, self.dns_backup, force=True,
|
|
|
|
api=self.api)
|
2011-01-03 07:48:29 -06:00
|
|
|
|
2013-04-23 01:59:07 -05:00
|
|
|
def __setup_reverse_zone(self):
|
|
|
|
# Always use force=True as named is not set up yet
|
2014-08-27 06:50:21 -05:00
|
|
|
for reverse_zone in self.reverse_zones:
|
2015-07-15 12:14:35 -05:00
|
|
|
add_zone(reverse_zone, self.zonemgr, ns_hostname=self.api.env.host,
|
|
|
|
dns_backup=self.dns_backup, force=True, api=self.api)
|
2013-04-23 01:59:07 -05:00
|
|
|
|
|
|
|
def __add_master_records(self, fqdn, addrs):
|
|
|
|
host, zone = fqdn.split(".", 1)
|
|
|
|
|
|
|
|
if normalize_zone(zone) == normalize_zone(self.domain):
|
|
|
|
host_in_rr = host
|
|
|
|
else:
|
|
|
|
host_in_rr = normalize_zone(fqdn)
|
|
|
|
|
|
|
|
srv_records = (
|
|
|
|
("_ldap._tcp", "0 100 389 %s" % host_in_rr),
|
|
|
|
("_kerberos._tcp", "0 100 88 %s" % host_in_rr),
|
|
|
|
("_kerberos._udp", "0 100 88 %s" % host_in_rr),
|
|
|
|
("_kerberos-master._tcp", "0 100 88 %s" % host_in_rr),
|
|
|
|
("_kerberos-master._udp", "0 100 88 %s" % host_in_rr),
|
|
|
|
("_kpasswd._tcp", "0 100 464 %s" % host_in_rr),
|
|
|
|
("_kpasswd._udp", "0 100 464 %s" % host_in_rr),
|
|
|
|
)
|
|
|
|
if self.ntp:
|
|
|
|
srv_records += (
|
|
|
|
("_ntp._udp", "0 100 123 %s" % host_in_rr),
|
|
|
|
)
|
|
|
|
|
|
|
|
for (rname, rdata) in srv_records:
|
2015-07-15 12:14:35 -05:00
|
|
|
add_rr(self.domain, rname, "SRV", rdata, self.dns_backup,
|
|
|
|
api=self.api)
|
2013-04-23 01:59:07 -05:00
|
|
|
|
2015-03-04 03:35:06 -06:00
|
|
|
if not dns_zone_exists(zone, self.api):
|
2013-04-23 01:59:07 -05:00
|
|
|
# add DNS domain for host first
|
|
|
|
root_logger.debug(
|
|
|
|
"Host domain (%s) is different from DNS domain (%s)!" % (
|
|
|
|
zone, self.domain))
|
|
|
|
root_logger.debug("Add DNS zone for host first.")
|
|
|
|
|
|
|
|
add_zone(zone, self.zonemgr, dns_backup=self.dns_backup,
|
2015-03-04 03:35:06 -06:00
|
|
|
ns_hostname=self.fqdn, force=True, api=self.api)
|
2013-04-23 01:59:07 -05:00
|
|
|
|
|
|
|
# Add forward and reverse records to self
|
|
|
|
for addr in addrs:
|
2015-07-15 12:14:35 -05:00
|
|
|
add_fwd_rr(zone, host, addr, api=self.api)
|
2013-04-23 01:59:07 -05:00
|
|
|
|
2015-03-04 03:35:06 -06:00
|
|
|
reverse_zone = find_reverse_zone(addr, self.api)
|
2013-04-23 01:59:07 -05:00
|
|
|
if reverse_zone:
|
2015-07-15 12:14:35 -05:00
|
|
|
add_ptr_rr(reverse_zone, addr, fqdn, None, api=self.api)
|
2013-04-23 01:59:07 -05:00
|
|
|
|
|
|
|
def __add_self(self):
|
2014-08-27 06:50:21 -05:00
|
|
|
self.__add_master_records(self.fqdn, self.ip_addresses)
|
2013-04-23 01:59:07 -05:00
|
|
|
|
|
|
|
def __add_others(self):
|
|
|
|
entries = self.admin_conn.get_entries(
|
|
|
|
DN(('cn', 'masters'), ('cn', 'ipa'), ('cn', 'etc'),
|
|
|
|
self.suffix),
|
|
|
|
self.admin_conn.SCOPE_ONELEVEL, None, ['dn'])
|
|
|
|
|
|
|
|
for entry in entries:
|
|
|
|
fqdn = entry.dn[0]['cn']
|
|
|
|
if fqdn == self.fqdn:
|
|
|
|
continue
|
|
|
|
|
|
|
|
addrs = installutils.resolve_host(fqdn)
|
|
|
|
|
|
|
|
root_logger.debug("Adding DNS records for master %s" % fqdn)
|
|
|
|
self.__add_master_records(fqdn, addrs)
|
|
|
|
|
2013-04-23 02:21:33 -05:00
|
|
|
def __add_ipa_ca_records(self, fqdn, addrs, ca_configured):
|
2013-04-15 05:19:11 -05:00
|
|
|
if ca_configured is False:
|
|
|
|
root_logger.debug("CA is not configured")
|
2012-11-19 09:32:28 -06:00
|
|
|
return
|
2013-04-15 05:19:11 -05:00
|
|
|
elif ca_configured is None:
|
2012-11-19 09:32:28 -06:00
|
|
|
# we do not know if CA is configured for this host and we can
|
2013-04-15 05:19:11 -05:00
|
|
|
# add the CA record. So we need to find out
|
2012-11-19 09:32:28 -06:00
|
|
|
root_logger.debug("Check if CA is enabled for this host")
|
2013-04-15 05:19:11 -05:00
|
|
|
base_dn = DN(('cn', fqdn), ('cn', 'masters'), ('cn', 'ipa'),
|
2015-03-04 03:35:06 -06:00
|
|
|
('cn', 'etc'), self.api.env.basedn)
|
2012-11-19 09:32:28 -06:00
|
|
|
ldap_filter = '(&(objectClass=ipaConfigObject)(cn=CA))'
|
|
|
|
try:
|
2015-03-04 03:35:06 -06:00
|
|
|
self.api.Backend.ldap2.find_entries(filter=ldap_filter, base_dn=base_dn)
|
2012-11-19 09:32:28 -06:00
|
|
|
except ipalib.errors.NotFound:
|
|
|
|
root_logger.debug("CA is not configured")
|
|
|
|
return
|
|
|
|
else:
|
2013-04-15 05:19:11 -05:00
|
|
|
root_logger.debug("CA is configured for this host")
|
|
|
|
|
|
|
|
try:
|
|
|
|
for addr in addrs:
|
2015-07-15 12:14:35 -05:00
|
|
|
add_fwd_rr(self.domain, IPA_CA_RECORD, addr, api=self.api)
|
2013-04-15 05:19:11 -05:00
|
|
|
except errors.ValidationError:
|
|
|
|
# there is a CNAME record in ipa-ca, we can't add A/AAAA records
|
|
|
|
pass
|
2012-11-19 09:32:28 -06:00
|
|
|
|
2013-04-15 05:19:11 -05:00
|
|
|
def __add_ipa_ca_record(self):
|
2014-08-27 06:50:21 -05:00
|
|
|
self.__add_ipa_ca_records(self.fqdn, self.ip_addresses,
|
2013-04-23 02:21:33 -05:00
|
|
|
self.ca_configured)
|
|
|
|
|
2013-05-09 10:50:15 -05:00
|
|
|
if self.first_instance:
|
2015-03-04 03:35:06 -06:00
|
|
|
ldap = self.api.Backend.ldap2
|
2013-05-09 10:50:15 -05:00
|
|
|
try:
|
|
|
|
entries = ldap.get_entries(
|
|
|
|
DN(('cn', 'masters'), ('cn', 'ipa'), ('cn', 'etc'),
|
2015-07-15 12:14:35 -05:00
|
|
|
self.api.env.basedn),
|
2013-05-09 10:50:15 -05:00
|
|
|
ldap.SCOPE_SUBTREE, '(&(objectClass=ipaConfigObject)(cn=CA))',
|
|
|
|
['dn'])
|
|
|
|
except errors.NotFound:
|
|
|
|
root_logger.debug('No server with CA found')
|
|
|
|
entries = []
|
2013-04-23 02:21:33 -05:00
|
|
|
|
|
|
|
for entry in entries:
|
|
|
|
fqdn = entry.dn[1]['cn']
|
|
|
|
if fqdn == self.fqdn:
|
|
|
|
continue
|
|
|
|
|
|
|
|
host, zone = fqdn.split('.', 1)
|
2015-03-04 03:35:06 -06:00
|
|
|
if dns_zone_exists(zone, self.api):
|
2015-07-15 12:14:35 -05:00
|
|
|
addrs = get_fwd_rr(zone, host, api=self.api)
|
2013-04-23 02:21:33 -05:00
|
|
|
else:
|
|
|
|
addrs = installutils.resolve_host(fqdn)
|
|
|
|
|
|
|
|
self.__add_ipa_ca_records(fqdn, addrs, True)
|
2012-11-19 09:32:28 -06:00
|
|
|
|
2009-06-04 14:33:49 -05:00
|
|
|
def __setup_principal(self):
|
|
|
|
dns_principal = "DNS/" + self.fqdn + "@" + self.realm
|
|
|
|
installutils.kadmin_addprinc(dns_principal)
|
|
|
|
|
|
|
|
# Store the keytab on disk
|
2014-05-29 07:47:17 -05:00
|
|
|
self.fstore.backup_file(paths.NAMED_KEYTAB)
|
|
|
|
installutils.create_keytab(paths.NAMED_KEYTAB, dns_principal)
|
2010-04-14 11:52:12 -05:00
|
|
|
p = self.move_service(dns_principal)
|
|
|
|
if p is None:
|
|
|
|
# the service has already been moved, perhaps we're doing a DNS reinstall
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
dns_principal = DN(('krbprincipalname', dns_principal),
|
|
|
|
('cn', 'services'), ('cn', 'accounts'), self.suffix)
|
2010-04-14 11:52:12 -05:00
|
|
|
else:
|
|
|
|
dns_principal = p
|
2009-06-04 14:33:49 -05:00
|
|
|
|
|
|
|
# Make sure access is strictly reserved to the named user
|
|
|
|
pent = pwd.getpwnam(self.named_user)
|
2014-05-29 07:47:17 -05:00
|
|
|
os.chown(paths.NAMED_KEYTAB, pent.pw_uid, pent.pw_gid)
|
2015-07-15 09:38:06 -05:00
|
|
|
os.chmod(paths.NAMED_KEYTAB, 0o400)
|
2009-06-04 14:33:49 -05:00
|
|
|
|
|
|
|
# modify the principal so that it is marked as an ipa service so that
|
|
|
|
# it can host the memberof attribute, then also add it to the
|
|
|
|
# dnsserver role group, this way the DNS is allowed to perform
|
|
|
|
# DNS Updates
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
dns_group = DN(('cn', 'DNS Servers'), ('cn', 'privileges'), ('cn', 'pbac'), self.suffix)
|
2009-12-07 22:17:00 -06:00
|
|
|
mod = [(ldap.MOD_ADD, 'member', dns_principal)]
|
2009-06-04 14:33:49 -05:00
|
|
|
|
|
|
|
try:
|
2011-01-05 06:46:30 -06:00
|
|
|
self.admin_conn.modify_s(dns_group, mod)
|
2010-04-14 11:52:12 -05:00
|
|
|
except ldap.TYPE_OR_VALUE_EXISTS:
|
|
|
|
pass
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2012-05-10 02:28:02 -05:00
|
|
|
root_logger.critical("Could not modify principal's %s entry: %s" \
|
|
|
|
% (dns_principal, str(e)))
|
|
|
|
raise
|
|
|
|
|
|
|
|
# bind-dyndb-ldap persistent search feature requires both size and time
|
|
|
|
# limit-free connection
|
|
|
|
mod = [(ldap.MOD_REPLACE, 'nsTimeLimit', '-1'),
|
|
|
|
(ldap.MOD_REPLACE, 'nsSizeLimit', '-1'),
|
|
|
|
(ldap.MOD_REPLACE, 'nsIdleTimeout', '-1'),
|
|
|
|
(ldap.MOD_REPLACE, 'nsLookThroughLimit', '-1')]
|
|
|
|
try:
|
|
|
|
self.admin_conn.modify_s(dns_principal, mod)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2012-05-10 02:28:02 -05:00
|
|
|
root_logger.critical("Could not set principal's %s LDAP limits: %s" \
|
|
|
|
% (dns_principal, str(e)))
|
|
|
|
raise
|
2009-06-04 14:33:49 -05:00
|
|
|
|
2007-09-20 14:10:21 -05:00
|
|
|
def __setup_named_conf(self):
|
2014-10-16 09:31:53 -05:00
|
|
|
if not self.fstore.has_file(NAMED_CONF):
|
|
|
|
self.fstore.backup_file(NAMED_CONF)
|
|
|
|
|
2007-12-13 03:31:28 -06:00
|
|
|
named_txt = ipautil.template_file(ipautil.SHARE_DIR + "bind.named.conf.template", self.sub_dict)
|
2012-05-31 10:02:44 -05:00
|
|
|
named_fd = open(NAMED_CONF, 'w')
|
2007-09-20 14:10:21 -05:00
|
|
|
named_fd.seek(0)
|
|
|
|
named_fd.truncate(0)
|
|
|
|
named_fd.write(named_txt)
|
|
|
|
named_fd.close()
|
|
|
|
|
2014-10-16 09:27:00 -05:00
|
|
|
if self.no_dnssec_validation:
|
|
|
|
# disable validation
|
|
|
|
named_conf_set_directive("dnssec-validation", "no",
|
|
|
|
section=NAMED_SECTION_OPTIONS,
|
|
|
|
str_val=False)
|
|
|
|
|
2008-05-13 12:35:20 -05:00
|
|
|
def __setup_resolv_conf(self):
|
2014-10-16 09:31:53 -05:00
|
|
|
if not self.fstore.has_file(RESOLV_CONF):
|
|
|
|
self.fstore.backup_file(RESOLV_CONF)
|
|
|
|
|
2014-08-27 06:50:21 -05:00
|
|
|
resolv_txt = "search "+self.domain+"\n"
|
|
|
|
|
|
|
|
for ip_address in self.ip_addresses:
|
|
|
|
if ip_address.version == 4:
|
|
|
|
resolv_txt += "nameserver 127.0.0.1\n"
|
|
|
|
break
|
|
|
|
|
|
|
|
for ip_address in self.ip_addresses:
|
|
|
|
if ip_address.version == 6:
|
|
|
|
resolv_txt += "nameserver ::1\n"
|
|
|
|
break
|
2014-01-14 03:48:31 -06:00
|
|
|
try:
|
|
|
|
resolv_fd = open(RESOLV_CONF, 'w')
|
|
|
|
resolv_fd.seek(0)
|
|
|
|
resolv_fd.truncate(0)
|
|
|
|
resolv_fd.write(resolv_txt)
|
|
|
|
resolv_fd.close()
|
|
|
|
except IOError as e:
|
|
|
|
root_logger.error('Could not write to resolv.conf: %s', e)
|
2007-09-20 14:10:21 -05:00
|
|
|
|
2014-04-18 08:44:11 -05:00
|
|
|
def __generate_rndc_key(self):
|
|
|
|
installutils.check_entropy()
|
2015-10-03 03:40:15 -05:00
|
|
|
ipautil.run([paths.GENERATE_RNDC_KEY])
|
2014-04-18 08:44:11 -05:00
|
|
|
|
2014-08-27 06:50:21 -05:00
|
|
|
def add_master_dns_records(self, fqdn, ip_addresses, realm_name, domain_name,
|
|
|
|
reverse_zones, ntp=False, ca_configured=None):
|
2011-01-21 13:46:58 -06:00
|
|
|
self.fqdn = fqdn
|
2014-08-27 06:50:21 -05:00
|
|
|
self.ip_addresses = ip_addresses
|
2011-01-21 13:46:58 -06:00
|
|
|
self.realm = realm_name
|
|
|
|
self.domain = domain_name
|
|
|
|
self.host = fqdn.split(".")[0]
|
2012-04-18 10:22:35 -05:00
|
|
|
self.suffix = ipautil.realm_to_suffix(self.realm)
|
2011-01-21 13:46:58 -06:00
|
|
|
self.ntp = ntp
|
2014-08-27 06:50:21 -05:00
|
|
|
self.reverse_zones = reverse_zones
|
2012-11-19 09:32:28 -06:00
|
|
|
self.ca_configured = ca_configured
|
2013-04-23 02:21:33 -05:00
|
|
|
self.first_instance = False
|
2014-02-26 03:06:29 -06:00
|
|
|
self.zonemgr = 'hostmaster.%s' % self.domain
|
2011-01-21 13:46:58 -06:00
|
|
|
|
|
|
|
self.__add_self()
|
2013-04-15 05:19:11 -05:00
|
|
|
self.__add_ipa_ca_record()
|
2012-11-19 09:32:28 -06:00
|
|
|
|
2013-04-15 05:19:11 -05:00
|
|
|
def add_ipa_ca_dns_records(self, fqdn, domain_name, ca_configured=True):
|
|
|
|
host, zone = fqdn.split(".", 1)
|
2015-07-15 12:14:35 -05:00
|
|
|
if dns_zone_exists(zone, self.api):
|
|
|
|
addrs = get_fwd_rr(zone, host, api=self.api)
|
2013-04-15 05:19:11 -05:00
|
|
|
else:
|
|
|
|
addrs = installutils.resolve_host(fqdn)
|
|
|
|
|
2013-04-23 02:21:33 -05:00
|
|
|
self.domain = domain_name
|
|
|
|
|
|
|
|
self.__add_ipa_ca_records(fqdn, addrs, ca_configured)
|
2013-04-15 05:19:11 -05:00
|
|
|
|
|
|
|
def convert_ipa_ca_cnames(self, domain_name):
|
|
|
|
# get ipa-ca CNAMEs
|
2015-07-15 12:14:35 -05:00
|
|
|
cnames = get_rr(domain_name, IPA_CA_RECORD, "CNAME", api=self.api)
|
2013-04-15 05:19:11 -05:00
|
|
|
if not cnames:
|
|
|
|
return
|
|
|
|
|
|
|
|
root_logger.info('Converting IPA CA CNAME records to A/AAAA records')
|
|
|
|
|
|
|
|
# create CNAME to FQDN mapping
|
|
|
|
cname_fqdn = {}
|
|
|
|
for cname in cnames:
|
|
|
|
if cname.endswith('.'):
|
|
|
|
fqdn = cname[:-1]
|
|
|
|
else:
|
|
|
|
fqdn = '%s.%s' % (cname, domain_name)
|
|
|
|
cname_fqdn[cname] = fqdn
|
|
|
|
|
|
|
|
# get FQDNs of all IPA masters
|
2015-07-15 12:14:35 -05:00
|
|
|
ldap = self.api.Backend.ldap2
|
2013-04-15 05:19:11 -05:00
|
|
|
try:
|
|
|
|
entries = ldap.get_entries(
|
|
|
|
DN(('cn', 'masters'), ('cn', 'ipa'), ('cn', 'etc'),
|
2015-07-15 12:14:35 -05:00
|
|
|
self.api.env.basedn),
|
2013-04-15 05:19:11 -05:00
|
|
|
ldap.SCOPE_ONELEVEL, None, ['cn'])
|
|
|
|
masters = set(e['cn'][0] for e in entries)
|
|
|
|
except errors.NotFound:
|
|
|
|
masters = set()
|
|
|
|
|
|
|
|
# check if all CNAMEs point to IPA masters
|
|
|
|
for cname in cnames:
|
|
|
|
fqdn = cname_fqdn[cname]
|
|
|
|
if fqdn not in masters:
|
|
|
|
root_logger.warning(
|
|
|
|
"Cannot convert IPA CA CNAME records to A/AAAA records, "
|
|
|
|
"please convert them manually if necessary")
|
|
|
|
return
|
|
|
|
|
|
|
|
# delete all CNAMEs
|
|
|
|
for cname in cnames:
|
2015-07-15 12:14:35 -05:00
|
|
|
del_rr(domain_name, IPA_CA_RECORD, "CNAME", cname, api=self.api)
|
2013-04-15 05:19:11 -05:00
|
|
|
|
|
|
|
# add A/AAAA records
|
|
|
|
for cname in cnames:
|
|
|
|
fqdn = cname_fqdn[cname]
|
|
|
|
self.add_ipa_ca_dns_records(fqdn, domain_name, None)
|
2011-01-21 13:46:58 -06:00
|
|
|
|
|
|
|
def remove_master_dns_records(self, fqdn, realm_name, domain_name):
|
2013-04-17 08:14:01 -05:00
|
|
|
host, zone = fqdn.split(".", 1)
|
2012-11-19 09:32:28 -06:00
|
|
|
self.host = host
|
|
|
|
self.fqdn = fqdn
|
|
|
|
self.domain = domain_name
|
2012-04-18 10:22:35 -05:00
|
|
|
suffix = ipautil.realm_to_suffix(realm_name)
|
2011-01-21 13:46:58 -06:00
|
|
|
|
|
|
|
resource_records = (
|
2012-11-19 09:32:28 -06:00
|
|
|
("_ldap._tcp", "SRV", "0 100 389 %s" % self.host_in_rr),
|
|
|
|
("_kerberos._tcp", "SRV", "0 100 88 %s" % self.host_in_rr),
|
|
|
|
("_kerberos._udp", "SRV", "0 100 88 %s" % self.host_in_rr),
|
|
|
|
("_kerberos-master._tcp", "SRV", "0 100 88 %s" % self.host_in_rr),
|
|
|
|
("_kerberos-master._udp", "SRV", "0 100 88 %s" % self.host_in_rr),
|
|
|
|
("_kpasswd._tcp", "SRV", "0 100 464 %s" % self.host_in_rr),
|
|
|
|
("_kpasswd._udp", "SRV", "0 100 464 %s" % self.host_in_rr),
|
|
|
|
("_ntp._udp", "SRV", "0 100 123 %s" % self.host_in_rr),
|
2011-01-21 13:46:58 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
for (record, type, rdata) in resource_records:
|
2015-07-15 12:14:35 -05:00
|
|
|
del_rr(self.domain, record, type, rdata, api=self.api)
|
2011-01-21 13:46:58 -06:00
|
|
|
|
2015-07-15 12:14:35 -05:00
|
|
|
areclist = get_fwd_rr(zone, host, api=self.api)
|
2013-04-15 05:19:11 -05:00
|
|
|
for rdata in areclist:
|
2015-07-15 12:14:35 -05:00
|
|
|
del_fwd_rr(zone, host, rdata, api=self.api)
|
2011-05-27 13:29:33 -05:00
|
|
|
|
2011-07-11 03:14:53 -05:00
|
|
|
rzone = find_reverse_zone(rdata)
|
|
|
|
if rzone is not None:
|
|
|
|
record = get_reverse_record_name(rzone, rdata)
|
2015-07-15 12:14:35 -05:00
|
|
|
del_rr(rzone, record, "PTR", normalize_zone(fqdn),
|
|
|
|
api=self.api)
|
2011-01-21 13:46:58 -06:00
|
|
|
|
2013-04-15 05:19:11 -05:00
|
|
|
def remove_ipa_ca_dns_records(self, fqdn, domain_name):
|
|
|
|
host, zone = fqdn.split(".", 1)
|
2015-07-15 12:14:35 -05:00
|
|
|
if dns_zone_exists(zone, self.api):
|
|
|
|
addrs = get_fwd_rr(zone, host, api=self.api)
|
2013-04-15 05:19:11 -05:00
|
|
|
else:
|
|
|
|
addrs = installutils.resolve_host(fqdn)
|
|
|
|
|
|
|
|
for addr in addrs:
|
2015-07-15 12:14:35 -05:00
|
|
|
del_fwd_rr(domain_name, IPA_CA_RECORD, addr, api=self.api)
|
2013-04-15 05:19:11 -05:00
|
|
|
|
2014-09-12 06:20:16 -05:00
|
|
|
def remove_server_ns_records(self, fqdn):
|
|
|
|
"""
|
|
|
|
Remove all NS records pointing to this server
|
|
|
|
"""
|
2015-07-15 12:14:35 -05:00
|
|
|
ldap = self.api.Backend.ldap2
|
2014-09-12 06:20:16 -05:00
|
|
|
ns_rdata = normalize_zone(fqdn)
|
|
|
|
|
|
|
|
# find all NS records pointing to this server
|
|
|
|
search_kw = {}
|
|
|
|
search_kw['nsrecord'] = ns_rdata
|
|
|
|
attr_filter = ldap.make_filter(search_kw, rules=ldap.MATCH_ALL)
|
|
|
|
attributes = ['idnsname', 'objectclass']
|
2015-07-15 12:14:35 -05:00
|
|
|
dn = DN(self.api.env.container_dns, self.api.env.basedn)
|
2014-09-12 06:20:16 -05:00
|
|
|
|
|
|
|
entries, truncated = ldap.find_entries(attr_filter, attributes, base_dn=dn)
|
|
|
|
|
|
|
|
# remove records
|
|
|
|
if entries:
|
|
|
|
root_logger.debug("Removing all NS records pointing to %s:", ns_rdata)
|
|
|
|
|
|
|
|
for entry in entries:
|
|
|
|
if 'idnszone' in entry['objectclass']:
|
|
|
|
# zone record
|
|
|
|
zone = entry.single_value['idnsname']
|
|
|
|
root_logger.debug("zone record %s", zone)
|
2015-07-15 12:14:35 -05:00
|
|
|
del_ns_rr(zone, u'@', ns_rdata, api=self.api)
|
2014-09-12 06:20:16 -05:00
|
|
|
else:
|
|
|
|
zone = entry.dn[1].value # get zone from DN
|
|
|
|
record = entry.single_value['idnsname']
|
|
|
|
root_logger.debug("record %s in zone %s", record, zone)
|
2015-07-15 12:14:35 -05:00
|
|
|
del_ns_rr(zone, record, ns_rdata, api=self.api)
|
2014-09-12 06:20:16 -05:00
|
|
|
|
2012-03-15 07:51:59 -05:00
|
|
|
def check_global_configuration(self):
|
|
|
|
"""
|
|
|
|
Check global DNS configuration in LDAP server and inform user when it
|
|
|
|
set and thus overrides his configured options in named.conf.
|
|
|
|
"""
|
2015-07-15 12:14:35 -05:00
|
|
|
result = self.api.Command.dnsconfig_show()
|
2012-03-15 07:51:59 -05:00
|
|
|
global_conf_set = any(param in result['result'] for \
|
2015-07-15 12:14:35 -05:00
|
|
|
param in self.api.Object['dnsconfig'].params)
|
2012-03-15 07:51:59 -05:00
|
|
|
|
|
|
|
if not global_conf_set:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Global DNS configuration in LDAP server is empty")
|
|
|
|
print("You can use 'dnsconfig-mod' command to set global DNS options that")
|
|
|
|
print("would override settings in local named.conf files")
|
2012-03-15 07:51:59 -05:00
|
|
|
return
|
|
|
|
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Global DNS configuration in LDAP server is not empty")
|
|
|
|
print("The following configuration options override local settings in named.conf:")
|
|
|
|
print("")
|
2015-07-15 12:14:35 -05:00
|
|
|
textui = ipalib.cli.textui(self.api)
|
|
|
|
self.api.Command.dnsconfig_show.output_for_cli(textui, result, None,
|
|
|
|
reverse=False)
|
2011-01-21 13:46:58 -06:00
|
|
|
|
2008-01-11 05:57:36 -06:00
|
|
|
def uninstall(self):
|
2010-05-03 14:21:51 -05:00
|
|
|
if self.is_configured():
|
|
|
|
self.print_msg("Unconfiguring %s" % self.service_name)
|
|
|
|
|
2008-01-11 05:57:36 -06:00
|
|
|
running = self.restore_state("running")
|
2008-03-27 18:01:38 -05:00
|
|
|
enabled = self.restore_state("enabled")
|
2014-10-21 07:13:29 -05:00
|
|
|
named_regular_running = self.restore_state("named-regular-running")
|
|
|
|
named_regular_enabled = self.restore_state("named-regular-enabled")
|
2008-01-11 05:57:36 -06:00
|
|
|
|
2015-07-15 12:14:35 -05:00
|
|
|
self.dns_backup.clear_records(self.api.Backend.ldap2.isconnected())
|
2009-11-24 17:49:40 -06:00
|
|
|
|
2008-01-11 05:57:36 -06:00
|
|
|
|
2012-05-31 10:02:44 -05:00
|
|
|
for f in [NAMED_CONF, RESOLV_CONF]:
|
2008-03-27 18:01:38 -05:00
|
|
|
try:
|
|
|
|
self.fstore.restore_file(f)
|
2015-07-30 09:49:29 -05:00
|
|
|
except ValueError as error:
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.debug(error)
|
2008-03-27 18:01:38 -05:00
|
|
|
pass
|
|
|
|
|
2015-01-27 04:04:03 -06:00
|
|
|
# disabled by default, by ldap_enable()
|
|
|
|
if enabled:
|
|
|
|
self.enable()
|
2008-01-11 05:57:36 -06:00
|
|
|
|
2015-01-27 04:04:03 -06:00
|
|
|
if running:
|
|
|
|
self.restart()
|
2014-10-16 09:31:53 -05:00
|
|
|
|
|
|
|
self.named_regular.unmask()
|
|
|
|
if named_regular_enabled:
|
|
|
|
self.named_regular.enable()
|
|
|
|
|
|
|
|
if named_regular_running:
|
|
|
|
self.named_regular.start()
|