0000-12-31 18:09:24 -05:50
|
|
|
# Authors: Karl MacMillan <kmacmillan@mentalrootkit.com>
|
2008-02-21 13:39:50 -06:00
|
|
|
# Simo Sorce <ssorce@redhat.com>
|
0000-12-31 18:09:24 -05:50
|
|
|
#
|
|
|
|
# Copyright (C) 2007 Red Hat
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
2010-12-09 06:59:11 -06:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
0000-12-31 18:09:24 -05:50
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2010-12-09 06:59:11 -06:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
0000-12-31 18:09:24 -05:50
|
|
|
#
|
|
|
|
|
|
|
|
import shutil
|
2007-07-02 14:51:04 -05:00
|
|
|
import pwd
|
0000-12-31 18:09:24 -05:50
|
|
|
import sys
|
0000-12-31 18:09:24 -05:50
|
|
|
import os
|
2008-02-26 09:48:45 -06:00
|
|
|
import re
|
2008-03-27 08:33:01 -05:00
|
|
|
import time
|
2010-10-13 11:21:48 -05:00
|
|
|
import tempfile
|
2013-05-14 11:36:50 -05:00
|
|
|
import stat
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2015-07-31 03:15:01 -05:00
|
|
|
import ldap
|
|
|
|
|
2013-01-31 05:59:35 -06:00
|
|
|
from ipapython.ipa_log_manager import *
|
2013-08-06 10:09:15 -05:00
|
|
|
from ipapython import ipautil, sysrestore, ipaldap
|
2015-07-31 03:15:01 -05:00
|
|
|
from ipaserver.install import service
|
|
|
|
from ipaserver.install import installutils
|
|
|
|
from ipaserver.install import certs
|
2009-02-02 12:50:53 -06:00
|
|
|
from ipaserver.install import ldapupdate
|
2010-12-07 17:23:05 -06:00
|
|
|
from ipaserver.install import replication
|
2013-07-29 11:33:09 -05:00
|
|
|
from ipaserver.install import sysupgrade
|
2015-04-27 03:34:25 -05:00
|
|
|
from ipaserver.install import upgradeinstance
|
2014-03-18 10:23:30 -05:00
|
|
|
from ipalib import api
|
|
|
|
from ipalib import certstore
|
|
|
|
from ipalib import errors
|
2015-05-14 03:49:55 -05:00
|
|
|
from ipalib import constants
|
2014-05-29 03:51:08 -05:00
|
|
|
from ipaplatform.tasks import tasks
|
2013-09-11 03:27:34 -05:00
|
|
|
from ipalib.constants import CACERT
|
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
|
|
|
from ipapython.dn import DN
|
2014-05-29 03:37:18 -05:00
|
|
|
from ipaplatform import services
|
2014-05-29 07:47:17 -05:00
|
|
|
from ipaplatform.paths import paths
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2011-01-28 14:45:19 -06:00
|
|
|
DS_USER = 'dirsrv'
|
|
|
|
DS_GROUP = 'dirsrv'
|
|
|
|
|
2013-04-26 05:55:56 -05:00
|
|
|
IPA_SCHEMA_FILES = ("60kerberos.ldif",
|
|
|
|
"60samba.ldif",
|
|
|
|
"60ipaconfig.ldif",
|
|
|
|
"60basev2.ldif",
|
|
|
|
"60basev3.ldif",
|
2014-10-16 08:33:32 -05:00
|
|
|
"60ipapk11.ldif",
|
2013-04-26 05:55:56 -05:00
|
|
|
"60ipadns.ldif",
|
2015-04-21 01:24:10 -05:00
|
|
|
"60certificate-profiles.ldif",
|
2013-04-26 05:55:56 -05:00
|
|
|
"61kerberos-ipav3.ldif",
|
2014-06-10 07:04:36 -05:00
|
|
|
"65ipacertstore.ldif",
|
2013-04-26 05:55:56 -05:00
|
|
|
"65ipasudo.ldif",
|
2013-04-29 11:09:45 -05:00
|
|
|
"70ipaotp.ldif",
|
2015-05-20 10:12:04 -05:00
|
|
|
"70topology.ldif",
|
2014-07-31 04:57:53 -05:00
|
|
|
"71idviews.ldif",
|
2015-05-14 03:49:55 -05:00
|
|
|
"72domainlevels.ldif",
|
2013-04-29 11:09:45 -05:00
|
|
|
"15rfc2307bis.ldif",
|
|
|
|
"15rfc4876.ldif")
|
2013-04-26 05:55:56 -05:00
|
|
|
|
|
|
|
ALL_SCHEMA_FILES = IPA_SCHEMA_FILES + ("05rfc2247.ldif", )
|
2015-01-21 06:40:36 -06:00
|
|
|
DS_INSTANCE_PREFIX = 'slapd-'
|
2013-04-26 05:55:56 -05:00
|
|
|
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
def find_server_root():
|
2014-10-03 18:27:57 -05:00
|
|
|
if ipautil.dir_exists(paths.USR_LIB_DIRSRV_64):
|
|
|
|
return paths.USR_LIB_DIRSRV_64
|
0000-12-31 18:09:24 -05:50
|
|
|
else:
|
2014-10-03 18:27:57 -05:00
|
|
|
return paths.USR_LIB_DIRSRV
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2008-01-22 05:57:59 -06:00
|
|
|
def config_dirname(serverid):
|
2014-05-29 07:47:17 -05:00
|
|
|
return (paths.ETC_DIRSRV_SLAPD_INSTANCE_TEMPLATE % serverid) + "/"
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2008-01-22 05:57:59 -06:00
|
|
|
def schema_dirname(serverid):
|
|
|
|
return config_dirname(serverid) + "/schema/"
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2011-08-29 10:16:52 -05:00
|
|
|
|
2015-01-21 06:40:36 -06:00
|
|
|
def remove_ds_instance(serverid, force=False):
|
|
|
|
"""A wrapper around the 'remove-ds.pl' script used by
|
|
|
|
389ds to remove a single directory server instance. In case of error
|
|
|
|
additional call with the '-f' flag is performed (forced removal). If this
|
|
|
|
also fails, then an exception is raised.
|
|
|
|
"""
|
|
|
|
instance_name = ''.join([DS_INSTANCE_PREFIX, serverid])
|
|
|
|
args = [paths.REMOVE_DS_PL, '-i', instance_name]
|
|
|
|
if force:
|
|
|
|
args.append('-f')
|
|
|
|
root_logger.debug("Forcing instance removal")
|
|
|
|
|
|
|
|
try:
|
|
|
|
ipautil.run(args)
|
|
|
|
except ipautil.CalledProcessError:
|
|
|
|
if force:
|
|
|
|
root_logger.error("Instance removal failed.")
|
|
|
|
raise
|
|
|
|
root_logger.debug("'%s' failed. "
|
|
|
|
"Attempting to force removal" % paths.REMOVE_DS_PL)
|
|
|
|
remove_ds_instance(serverid, force=True)
|
2011-08-29 10:16:52 -05:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2012-04-04 14:19:29 -05:00
|
|
|
def get_ds_instances():
|
|
|
|
'''
|
|
|
|
Return a sorted list of all 389ds instances.
|
|
|
|
|
|
|
|
If the instance name ends with '.removed' it is ignored. This
|
|
|
|
matches 389ds behavior.
|
|
|
|
'''
|
|
|
|
|
2015-01-21 06:40:36 -06:00
|
|
|
dirsrv_instance_dir = paths.ETC_DIRSRV
|
2012-04-04 14:19:29 -05:00
|
|
|
|
|
|
|
instances = []
|
|
|
|
|
|
|
|
for basename in os.listdir(dirsrv_instance_dir):
|
|
|
|
pathname = os.path.join(dirsrv_instance_dir, basename)
|
|
|
|
# Must be a directory
|
|
|
|
if os.path.isdir(pathname):
|
|
|
|
# Must start with prefix and not end with .removed
|
2015-01-21 06:40:36 -06:00
|
|
|
if (basename.startswith(DS_INSTANCE_PREFIX) and
|
|
|
|
not basename.endswith('.removed')):
|
2012-04-04 14:19:29 -05:00
|
|
|
# Strip off prefix
|
2015-01-21 06:40:36 -06:00
|
|
|
instance = basename[len(DS_INSTANCE_PREFIX):]
|
2012-04-04 14:19:29 -05:00
|
|
|
# Must be non-empty
|
|
|
|
if instance:
|
|
|
|
instances.append(instance)
|
|
|
|
|
|
|
|
instances.sort()
|
|
|
|
return instances
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
def check_ports():
|
2012-07-03 09:49:10 -05:00
|
|
|
"""
|
|
|
|
Check of Directory server ports are open.
|
|
|
|
|
|
|
|
Returns a tuple with two booleans, one for unsecure port 389 and one for
|
|
|
|
secure port 636. True means that the port is free, False means that the
|
|
|
|
port is taken.
|
|
|
|
"""
|
|
|
|
ds_unsecure = not ipautil.host_port_open(None, 389)
|
|
|
|
ds_secure = not ipautil.host_port_open(None, 636)
|
2008-01-22 02:03:06 -06:00
|
|
|
return (ds_unsecure, ds_secure)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2011-10-10 07:25:15 -05:00
|
|
|
def is_ds_running(server_id=''):
|
2014-05-29 03:37:18 -05:00
|
|
|
return services.knownservices.dirsrv.is_running(instance_name=server_id)
|
2008-04-14 20:18:24 -05:00
|
|
|
|
2013-09-02 03:56:19 -05:00
|
|
|
|
|
|
|
def create_ds_user():
|
2014-07-15 06:31:01 -05:00
|
|
|
"""Create DS user/group if it doesn't exist yet."""
|
2014-10-22 08:07:44 -05:00
|
|
|
tasks.create_system_user(
|
2014-07-15 06:31:01 -05:00
|
|
|
name=DS_USER,
|
|
|
|
group=DS_USER,
|
|
|
|
homedir=paths.VAR_LIB_DIRSRV,
|
|
|
|
shell=paths.NOLOGIN,
|
|
|
|
)
|
|
|
|
|
2013-09-02 03:56:19 -05:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
INF_TEMPLATE = """
|
|
|
|
[General]
|
2012-02-14 08:48:32 -06:00
|
|
|
FullMachineName= $FQDN
|
2007-07-02 14:51:04 -05:00
|
|
|
SuiteSpotUserID= $USER
|
2011-02-24 13:45:46 -06:00
|
|
|
SuiteSpotGroup= $GROUP
|
0000-12-31 18:09:24 -05:50
|
|
|
ServerRoot= $SERVER_ROOT
|
0000-12-31 18:09:24 -05:50
|
|
|
[slapd]
|
|
|
|
ServerPort= 389
|
|
|
|
ServerIdentifier= $SERVERID
|
|
|
|
Suffix= $SUFFIX
|
|
|
|
RootDN= cn=Directory Manager
|
|
|
|
RootDNPwd= $PASSWORD
|
2008-02-28 12:35:10 -06:00
|
|
|
InstallLdifFile= /var/lib/dirsrv/boot.ldif
|
2010-10-13 18:01:28 -05:00
|
|
|
inst_dir= /var/lib/dirsrv/scripts-$SERVERID
|
2008-02-28 12:35:10 -06:00
|
|
|
"""
|
|
|
|
|
|
|
|
BASE_TEMPLATE = """
|
|
|
|
dn: $SUFFIX
|
|
|
|
objectClass: top
|
|
|
|
objectClass: domain
|
|
|
|
objectClass: pilotObject
|
|
|
|
dc: $BASEDC
|
2009-12-02 15:25:27 -06:00
|
|
|
info: IPA V2.0
|
0000-12-31 18:09:24 -05:50
|
|
|
"""
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
class DsInstance(service.Service):
|
2013-03-15 04:09:58 -05:00
|
|
|
def __init__(self, realm_name=None, domain_name=None, dm_password=None,
|
2015-05-14 03:49:55 -05:00
|
|
|
fstore=None, domainlevel=None):
|
2012-10-11 02:32:17 -05:00
|
|
|
service.Service.__init__(self, "dirsrv",
|
|
|
|
service_desc="directory server",
|
|
|
|
dm_password=dm_password,
|
|
|
|
ldapi=False,
|
2014-08-27 08:06:42 -05:00
|
|
|
autobind=ipaldap.AUTOBIND_DISABLED
|
2012-10-11 02:32:17 -05:00
|
|
|
)
|
2014-08-05 02:06:39 -05:00
|
|
|
self.nickname = 'Server-Cert'
|
2012-09-19 22:35:42 -05:00
|
|
|
self.dm_password = dm_password
|
2013-10-11 02:38:10 -05:00
|
|
|
self.realm = realm_name
|
2008-03-27 08:33:01 -05:00
|
|
|
self.sub_dict = None
|
|
|
|
self.domain = domain_name
|
0000-12-31 18:09:24 -05:50
|
|
|
self.serverid = None
|
2014-06-12 03:21:34 -05:00
|
|
|
self.master_fqdn = None
|
2008-01-22 05:58:06 -06:00
|
|
|
self.pkcs12_info = None
|
2014-04-08 06:12:47 -05:00
|
|
|
self.cacert_name = None
|
2013-10-17 07:52:07 -05:00
|
|
|
self.ca_is_configured = True
|
2009-12-07 22:17:00 -06:00
|
|
|
self.dercert = None
|
2010-11-11 17:15:28 -06:00
|
|
|
self.idstart = None
|
|
|
|
self.idmax = None
|
2011-01-19 08:53:59 -06:00
|
|
|
self.subject_base = None
|
2011-04-27 05:37:04 -05:00
|
|
|
self.open_ports = []
|
2011-09-16 12:23:02 -05:00
|
|
|
self.run_init_memberof = True
|
2015-05-14 03:49:55 -05:00
|
|
|
self.domainlevel = domainlevel
|
2008-03-27 08:33:01 -05:00
|
|
|
if realm_name:
|
2013-10-11 02:38:10 -05:00
|
|
|
self.suffix = ipautil.realm_to_suffix(self.realm)
|
2008-03-27 08:33:01 -05:00
|
|
|
self.__setup_sub_dict()
|
|
|
|
else:
|
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
|
|
|
self.suffix = DN()
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2011-03-01 07:17:03 -06:00
|
|
|
if fstore:
|
|
|
|
self.fstore = fstore
|
|
|
|
else:
|
2014-05-29 07:47:17 -05:00
|
|
|
self.fstore = sysrestore.FileStore(paths.SYSRESTORE)
|
2010-11-17 11:25:01 -06: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
|
|
|
subject_base = ipautil.dn_attribute_property('_subject_base')
|
|
|
|
|
2012-09-19 22:35:42 -05:00
|
|
|
def __common_setup(self, enable_ssl=False):
|
2008-02-21 13:39:50 -06:00
|
|
|
|
2013-09-02 03:56:19 -05:00
|
|
|
self.step("creating directory server user", create_ds_user)
|
2007-12-13 03:31:28 -06:00
|
|
|
self.step("creating directory server instance", self.__create_instance)
|
|
|
|
self.step("adding default schema", self.__add_default_schemas)
|
0000-12-31 18:09:24 -05:50
|
|
|
self.step("enabling memberof plugin", self.__add_memberof_module)
|
2008-09-11 11:56:55 -05:00
|
|
|
self.step("enabling winsync plugin", self.__add_winsync_module)
|
2010-06-24 09:31:52 -05:00
|
|
|
self.step("configuring replication version plugin", self.__config_version_module)
|
2009-09-14 16:04:08 -05:00
|
|
|
self.step("enabling IPA enrollment plugin", self.__add_enrollment_module)
|
2009-08-26 13:09:36 -05:00
|
|
|
self.step("enabling ldapi", self.__enable_ldapi)
|
2008-02-21 21:31:16 -06:00
|
|
|
self.step("configuring uniqueness plugin", self.__set_unique_attrs)
|
2010-10-15 16:52:37 -05:00
|
|
|
self.step("configuring uuid plugin", self.__config_uuid_module)
|
2010-10-22 15:03:18 -05:00
|
|
|
self.step("configuring modrdn plugin", self.__config_modrdn_module)
|
2013-03-13 09:15:41 -05:00
|
|
|
self.step("configuring DNS plugin", self.__config_dns_module)
|
2010-11-23 09:35:49 -06:00
|
|
|
self.step("enabling entryUSN plugin", self.__enable_entryusn)
|
2011-01-18 13:58:58 -06:00
|
|
|
self.step("configuring lockout plugin", self.__config_lockout_module)
|
2015-07-10 08:16:31 -05:00
|
|
|
self.step("configuring topology plugin", self.__config_topology_module)
|
2008-01-25 12:29:49 -06:00
|
|
|
self.step("creating indices", self.__create_indices)
|
Expand Referential Integrity checks
Many attributes in IPA (e.g. manager, memberuser, managedby, ...)
are used to store DNs of linked objects in IPA (users, hosts, sudo
commands, etc.). However, when the linked objects is deleted or
renamed, the attribute pointing to it stays with the objects and
thus may create a dangling link causing issues in client software
reading the data.
Directory Server has a plugin to enforce referential integrity (RI)
by checking DEL and MODRDN operations and updating affected links.
It was already used for manager and secretary attributes and
should be expanded for the missing attributes to avoid dangling
links.
As a prerequisite, all attributes checked for RI must have pres
and eq indexes to avoid performance issues. Thus, the following
indexes are added:
* manager (pres index only)
* secretary (pres index only)
* memberHost
* memberUser
* sourcehost
* memberservice
* managedby
* memberallowcmd
* memberdenycmd
* ipasudorunas
* ipasudorunasgroup
Referential Integrity plugin is updated to enforce RI for all these
attributes. Unit tests covering RI checks for all these attributes
were added as well.
Note: this update will only fix RI on one master as RI plugin does
not check replicated operations.
https://fedorahosted.org/freeipa/ticket/2866
2012-09-12 03:00:35 -05:00
|
|
|
self.step("enabling referential integrity plugin", self.__add_referint_module)
|
2012-11-15 08:38:24 -06:00
|
|
|
if enable_ssl:
|
2013-10-15 12:30:14 -05:00
|
|
|
self.step("configuring ssl for ds instance", self.__enable_ssl)
|
2007-12-13 03:31:28 -06:00
|
|
|
self.step("configuring certmap.conf", self.__certmap_conf)
|
2011-01-19 14:17:25 -06:00
|
|
|
self.step("configure autobind for root", self.__root_autobind)
|
Move Managed Entries into their own container in the replicated space.
Repoint cn=Managed Entries,cn=plugins,cn=config in common_setup
Create: cn=Managed Entries,cn=etc,$SUFFIX
Create: cn=Definitions,cn=Managed Entries,cn=etc,$SUFFIX
Create: cn=Templates,cn=Managed Entries,cn=etc,$SUFFIX
Create method for dynamically migrating any and all custom Managed Entries
from the cn=config space into the new container.
Separate the connection creation during update so that a restart can
be performed to initialize changes before performing a delete.
Add wait_for_open_socket() method in installutils
https://fedorahosted.org/freeipa/ticket/1708
2011-09-08 14:07:26 -05:00
|
|
|
self.step("configure new location for managed entries", self.__repoint_managed_entries)
|
2013-05-14 11:36:50 -05:00
|
|
|
self.step("configure dirsrv ccache", self.configure_dirsrv_ccache)
|
2013-03-22 05:15:51 -05:00
|
|
|
self.step("enable SASL mapping fallback", self.__enable_sasl_mapping_fallback)
|
2007-12-13 03:31:28 -06:00
|
|
|
self.step("restarting directory server", self.__restart_instance)
|
2010-12-07 17:23:05 -06:00
|
|
|
|
|
|
|
def __common_post_setup(self):
|
|
|
|
self.step("initializing group membership", self.init_memberof)
|
|
|
|
self.step("adding master entry", self.__add_master_entry)
|
2015-05-14 03:49:55 -05:00
|
|
|
self.step("initializing domain level", self.__set_domain_level)
|
2010-12-07 17:23:05 -06:00
|
|
|
self.step("configuring Posix uid/gid generation",
|
|
|
|
self.__config_uidgid_gen)
|
2013-03-01 14:02:14 -06:00
|
|
|
self.step("adding replication acis", self.__add_replication_acis)
|
2010-08-11 14:26:37 -05:00
|
|
|
self.step("enabling compatibility plugin",
|
|
|
|
self.__enable_compat_plugin)
|
2015-05-12 07:31:46 -05:00
|
|
|
self.step("activating sidgen plugin", self._add_sidgen_plugin)
|
|
|
|
self.step("activating extdom plugin", self._add_extdom_plugin)
|
2010-11-16 11:45:21 -06:00
|
|
|
self.step("tuning directory server", self.__tuning)
|
2007-11-06 17:57:15 -06:00
|
|
|
|
2008-01-14 11:43:26 -06:00
|
|
|
self.step("configuring directory to start on boot", self.__enable)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2013-02-25 10:15:23 -06:00
|
|
|
def init_info(self, realm_name, fqdn, domain_name, dm_password,
|
2013-03-27 08:25:18 -05:00
|
|
|
subject_base, idstart, idmax, pkcs12_info, ca_file=None):
|
2013-10-11 02:38:10 -05:00
|
|
|
self.realm = realm_name.upper()
|
2015-04-27 07:42:31 -05:00
|
|
|
self.serverid = installutils.realm_to_serverid(self.realm)
|
2013-10-11 02:38:10 -05:00
|
|
|
self.suffix = ipautil.realm_to_suffix(self.realm)
|
2010-12-07 17:23:05 -06:00
|
|
|
self.fqdn = fqdn
|
|
|
|
self.dm_password = dm_password
|
|
|
|
self.domain = domain_name
|
2013-10-11 02:38:10 -05:00
|
|
|
self.principal = "ldap/%s@%s" % (self.fqdn, self.realm)
|
2010-12-07 17:23:05 -06:00
|
|
|
self.subject_base = subject_base
|
2013-02-25 10:15:23 -06:00
|
|
|
self.idstart = idstart
|
|
|
|
self.idmax = idmax
|
|
|
|
self.pkcs12_info = pkcs12_info
|
2013-10-17 07:52:07 -05:00
|
|
|
if pkcs12_info:
|
|
|
|
self.ca_is_configured = False
|
2013-03-26 09:31:07 -05:00
|
|
|
self.ca_file = ca_file
|
2010-12-07 17:23:05 -06:00
|
|
|
|
|
|
|
self.__setup_sub_dict()
|
2013-02-25 10:15:23 -06:00
|
|
|
|
|
|
|
def create_instance(self, realm_name, fqdn, domain_name,
|
2013-03-27 08:25:18 -05:00
|
|
|
dm_password, pkcs12_info=None,
|
2013-02-25 10:15:23 -06:00
|
|
|
idstart=1100, idmax=999999, subject_base=None,
|
2013-03-26 09:31:07 -05:00
|
|
|
hbac_allow=True, ca_file=None):
|
2013-02-25 10:15:23 -06:00
|
|
|
self.init_info(
|
2013-03-27 08:25:18 -05:00
|
|
|
realm_name, fqdn, domain_name, dm_password,
|
2013-03-26 09:31:07 -05:00
|
|
|
subject_base, idstart, idmax, pkcs12_info, ca_file=ca_file)
|
2013-02-25 10:15:23 -06:00
|
|
|
|
2010-12-07 17:23:05 -06:00
|
|
|
self.__common_setup()
|
|
|
|
|
|
|
|
self.step("adding default layout", self.__add_default_layout)
|
|
|
|
self.step("adding delegation layout", self.__add_delegation_layout)
|
Move Managed Entries into their own container in the replicated space.
Repoint cn=Managed Entries,cn=plugins,cn=config in common_setup
Create: cn=Managed Entries,cn=etc,$SUFFIX
Create: cn=Definitions,cn=Managed Entries,cn=etc,$SUFFIX
Create: cn=Templates,cn=Managed Entries,cn=etc,$SUFFIX
Create method for dynamically migrating any and all custom Managed Entries
from the cn=config space into the new container.
Separate the connection creation during update so that a restart can
be performed to initialize changes before performing a delete.
Add wait_for_open_socket() method in installutils
https://fedorahosted.org/freeipa/ticket/1708
2011-09-08 14:07:26 -05:00
|
|
|
self.step("creating container for managed entries", self.__managed_entries)
|
2011-01-14 14:34:59 -06:00
|
|
|
self.step("configuring user private groups", self.__user_private_groups)
|
|
|
|
self.step("configuring netgroups from hostgroups", self.__host_nis_groups)
|
2011-02-28 10:44:27 -06:00
|
|
|
self.step("creating default Sudo bind user", self.__add_sudo_binduser)
|
2011-08-30 19:48:15 -05:00
|
|
|
self.step("creating default Auto Member layout", self.__add_automember_config)
|
2012-06-18 14:25:31 -05:00
|
|
|
self.step("adding range check plugin", self.__add_range_check_plugin)
|
2010-12-07 17:23:05 -06:00
|
|
|
if hbac_allow:
|
|
|
|
self.step("creating default HBAC rule allow_all", self.add_hbac)
|
2015-05-25 07:39:07 -05:00
|
|
|
self.step("creating default CA ACL rule", self.add_caacl)
|
2015-05-20 10:12:04 -05:00
|
|
|
self.step("adding entries for topology management", self.__add_topology_entries)
|
2010-12-07 17:23:05 -06:00
|
|
|
|
|
|
|
self.__common_post_setup()
|
|
|
|
|
2012-10-11 02:32:17 -05:00
|
|
|
self.start_creation(runtime=60)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2013-10-15 12:30:14 -05:00
|
|
|
def enable_ssl(self):
|
|
|
|
self.steps = []
|
|
|
|
|
|
|
|
self.step("configuring ssl for ds instance", self.__enable_ssl)
|
|
|
|
self.step("restarting directory server", self.__restart_instance)
|
|
|
|
self.step("adding CA certificate entry", self.__upload_ca_cert)
|
|
|
|
|
|
|
|
self.start_creation(runtime=10)
|
|
|
|
|
2011-01-28 14:45:19 -06:00
|
|
|
def create_replica(self, realm_name, master_fqdn, fqdn,
|
2013-08-19 10:45:31 -05:00
|
|
|
domain_name, dm_password, subject_base,
|
2013-10-17 07:52:07 -05:00
|
|
|
pkcs12_info=None, ca_file=None, ca_is_configured=None):
|
2010-12-07 17:23:05 -06:00
|
|
|
# idstart and idmax are configured so that the range is seen as
|
|
|
|
# depleted by the DNA plugin and the replica will go and get a
|
|
|
|
# new range from the master.
|
|
|
|
# This way all servers use the initially defined range by default.
|
2013-02-25 10:15:23 -06:00
|
|
|
idstart = 1101
|
|
|
|
idmax = 1100
|
|
|
|
|
|
|
|
self.init_info(
|
2013-08-19 10:45:31 -05:00
|
|
|
realm_name=realm_name,
|
|
|
|
fqdn=fqdn,
|
|
|
|
domain_name=domain_name,
|
|
|
|
dm_password=dm_password,
|
|
|
|
subject_base=subject_base,
|
|
|
|
idstart=idstart,
|
|
|
|
idmax=idmax,
|
|
|
|
pkcs12_info=pkcs12_info,
|
|
|
|
ca_file=ca_file
|
|
|
|
)
|
2013-02-25 10:15:23 -06:00
|
|
|
self.master_fqdn = master_fqdn
|
2013-10-17 07:52:07 -05:00
|
|
|
if ca_is_configured is not None:
|
|
|
|
self.ca_is_configured = ca_is_configured
|
2010-12-07 17:23:05 -06:00
|
|
|
|
2012-09-19 22:35:42 -05:00
|
|
|
self.__common_setup(True)
|
2010-12-07 17:23:05 -06:00
|
|
|
|
2011-02-02 09:24:30 -06:00
|
|
|
self.step("setting up initial replication", self.__setup_replica)
|
2013-09-09 03:15:11 -05:00
|
|
|
self.step("updating schema", self.__update_schema)
|
2011-08-30 19:48:15 -05:00
|
|
|
# See LDIFs for automember configuration during replica install
|
|
|
|
self.step("setting Auto Member configuration", self.__add_replica_automember_config)
|
2012-02-02 13:15:02 -06:00
|
|
|
self.step("enabling S4U2Proxy delegation", self.__setup_s4u2proxy)
|
2014-06-12 03:23:19 -05:00
|
|
|
self.step("importing CA certificates from LDAP", self.__import_ca_certs)
|
2010-12-07 17:23:05 -06:00
|
|
|
|
|
|
|
self.__common_post_setup()
|
|
|
|
|
2012-10-11 02:32:17 -05:00
|
|
|
self.start_creation(runtime=60)
|
2010-12-07 17:23:05 -06:00
|
|
|
|
|
|
|
|
|
|
|
def __setup_replica(self):
|
2011-02-08 21:24:54 -06:00
|
|
|
replication.enable_replication_version_checking(self.fqdn,
|
2013-10-11 02:38:10 -05:00
|
|
|
self.realm,
|
2011-02-08 21:24:54 -06:00
|
|
|
self.dm_password)
|
|
|
|
|
2013-10-11 02:38:10 -05:00
|
|
|
repl = replication.ReplicationManager(self.realm,
|
2011-01-10 09:57:43 -06:00
|
|
|
self.fqdn,
|
|
|
|
self.dm_password)
|
|
|
|
repl.setup_replication(self.master_fqdn,
|
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
|
|
|
r_binddn=DN(('cn', 'Directory Manager')),
|
2011-07-14 22:35:01 -05:00
|
|
|
r_bindpw=self.dm_password)
|
2011-09-16 12:23:02 -05:00
|
|
|
self.run_init_memberof = repl.needs_memberof_fixup()
|
2010-12-07 17:23:05 -06:00
|
|
|
|
2013-09-09 03:15:11 -05:00
|
|
|
def __update_schema(self):
|
|
|
|
# FIXME: https://fedorahosted.org/389/ticket/47490
|
|
|
|
self._ldap_mod("schema-update.ldif")
|
|
|
|
|
2008-01-14 11:43:26 -06:00
|
|
|
def __enable(self):
|
|
|
|
self.backup_state("enabled", self.is_enabled())
|
2010-12-04 14:42:14 -06:00
|
|
|
# At the end of the installation ipa-server-install will enable the
|
|
|
|
# 'ipa' service wich takes care of starting/stopping dirsrv
|
2011-09-13 02:47:13 -05:00
|
|
|
self.disable()
|
2008-01-14 11:43:26 -06:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
def __setup_sub_dict(self):
|
0000-12-31 18:09:24 -05:50
|
|
|
server_root = find_server_root()
|
2012-08-13 02:38:24 -05:00
|
|
|
try:
|
|
|
|
idrange_size = self.idmax - self.idstart + 1
|
|
|
|
except TypeError:
|
|
|
|
idrange_size = None
|
2012-02-14 08:48:32 -06:00
|
|
|
self.sub_dict = dict(FQDN=self.fqdn, SERVERID=self.serverid,
|
2010-11-11 17:15:28 -06:00
|
|
|
PASSWORD=self.dm_password,
|
2011-02-23 13:37:07 -06:00
|
|
|
RANDOM_PASSWORD=self.generate_random(),
|
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=self.suffix,
|
2013-10-11 02:38:10 -05:00
|
|
|
REALM=self.realm, USER=DS_USER,
|
2008-03-27 08:33:01 -05:00
|
|
|
SERVER_ROOT=server_root, DOMAIN=self.domain,
|
2010-11-11 17:15:28 -06:00
|
|
|
TIME=int(time.time()), IDSTART=self.idstart,
|
|
|
|
IDMAX=self.idmax, HOST=self.fqdn,
|
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
|
|
|
ESCAPED_SUFFIX=str(self.suffix),
|
2011-02-24 13:45:46 -06:00
|
|
|
GROUP=DS_GROUP,
|
2015-05-14 03:49:55 -05:00
|
|
|
IDRANGE_SIZE=idrange_size,
|
|
|
|
DOMAIN_LEVEL=self.domainlevel,
|
|
|
|
MAX_DOMAIN_LEVEL=constants.MAX_DOMAIN_LEVEL,
|
|
|
|
MIN_DOMAIN_LEVEL=constants.MIN_DOMAIN_LEVEL,
|
2010-04-16 15:23:45 -05:00
|
|
|
)
|
2007-07-02 14:51:04 -05:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
def __create_instance(self):
|
2012-03-16 17:15:26 -05:00
|
|
|
pent = pwd.getpwnam(DS_USER)
|
|
|
|
|
2008-01-14 11:43:26 -06:00
|
|
|
self.backup_state("serverid", self.serverid)
|
2014-05-29 07:47:17 -05:00
|
|
|
self.fstore.backup_file(paths.SYSCONFIG_DIRSRV)
|
2008-02-28 12:35:10 -06:00
|
|
|
|
2013-10-11 02:38:10 -05:00
|
|
|
self.sub_dict['BASEDC'] = self.realm.split('.')[0].lower()
|
2008-02-28 12:35:10 -06:00
|
|
|
base_txt = ipautil.template_str(BASE_TEMPLATE, self.sub_dict)
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.debug(base_txt)
|
2011-08-30 09:32:40 -05:00
|
|
|
|
2014-05-29 07:47:17 -05:00
|
|
|
target_fname = paths.DIRSRV_BOOT_LDIF
|
2011-08-30 09:32:40 -05:00
|
|
|
base_fd = open(target_fname, "w")
|
|
|
|
base_fd.write(base_txt)
|
|
|
|
base_fd.close()
|
|
|
|
|
|
|
|
# Must be readable for dirsrv
|
2015-07-15 09:38:06 -05:00
|
|
|
os.chmod(target_fname, 0o440)
|
2012-03-16 17:15:26 -05:00
|
|
|
os.chown(target_fname, pent.pw_uid, pent.pw_gid)
|
2008-02-28 12:35:10 -06:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
inf_txt = ipautil.template_str(INF_TEMPLATE, self.sub_dict)
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.debug("writing inf template")
|
2008-02-26 09:48:45 -06:00
|
|
|
inf_fd = ipautil.write_tmp_file(inf_txt)
|
|
|
|
inf_txt = re.sub(r"RootDNPwd=.*\n", "", inf_txt)
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.debug(inf_txt)
|
2014-05-29 07:47:17 -05:00
|
|
|
if ipautil.file_exists(paths.SETUP_DS_PL):
|
|
|
|
args = [paths.SETUP_DS_PL, "--silent", "--logfile", "-", "-f", inf_fd.name]
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.debug("calling setup-ds.pl")
|
0000-12-31 18:09:24 -05:50
|
|
|
else:
|
2014-05-29 07:47:17 -05:00
|
|
|
args = [paths.DS_NEWINST_PL, inf_fd.name]
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.debug("calling ds_newinst.pl")
|
2007-10-03 16:37:13 -05:00
|
|
|
try:
|
0000-12-31 18:09:24 -05:50
|
|
|
ipautil.run(args)
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.debug("completed creating ds instance")
|
2015-07-30 09:49:29 -05:00
|
|
|
except ipautil.CalledProcessError as e:
|
2012-04-04 14:19:29 -05:00
|
|
|
root_logger.critical("failed to create ds instance %s" % e)
|
2011-06-08 09:54:41 -05:00
|
|
|
|
2011-04-27 05:37:04 -05:00
|
|
|
# check for open port 389 from now on
|
|
|
|
self.open_ports.append(389)
|
|
|
|
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.debug("restarting ds instance")
|
2007-10-03 16:37:13 -05:00
|
|
|
try:
|
2011-04-27 05:37:04 -05:00
|
|
|
self.__restart_instance()
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.debug("done restarting ds instance")
|
2015-07-30 09:49:29 -05:00
|
|
|
except ipautil.CalledProcessError as e:
|
2007-10-03 16:37:13 -05:00
|
|
|
print "failed to restart ds instance", e
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.debug("failed to restart ds instance %s" % e)
|
2008-02-28 12:35:10 -06:00
|
|
|
inf_fd.close()
|
2014-05-29 07:47:17 -05:00
|
|
|
os.remove(paths.DIRSRV_BOOT_LDIF)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
|
|
|
def __add_default_schemas(self):
|
2011-06-17 07:19:45 -05:00
|
|
|
pent = pwd.getpwnam(DS_USER)
|
2013-04-26 05:55:56 -05:00
|
|
|
for schema_fname in IPA_SCHEMA_FILES:
|
2011-06-17 07:19:45 -05:00
|
|
|
target_fname = schema_dirname(self.serverid) + schema_fname
|
|
|
|
shutil.copyfile(ipautil.SHARE_DIR + schema_fname, target_fname)
|
2015-07-15 09:38:06 -05:00
|
|
|
os.chmod(target_fname, 0o440) # read access for dirsrv user/group
|
2011-06-17 07:19:45 -05:00
|
|
|
os.chown(target_fname, pent.pw_uid, pent.pw_gid)
|
|
|
|
|
2009-10-14 10:50:00 -05:00
|
|
|
try:
|
|
|
|
shutil.move(schema_dirname(self.serverid) + "05rfc2247.ldif",
|
|
|
|
schema_dirname(self.serverid) + "05rfc2247.ldif.old")
|
2011-06-17 07:19:45 -05:00
|
|
|
|
|
|
|
target_fname = schema_dirname(self.serverid) + "05rfc2247.ldif"
|
|
|
|
shutil.copyfile(ipautil.SHARE_DIR + "05rfc2247.ldif", target_fname)
|
2015-07-15 09:38:06 -05:00
|
|
|
os.chmod(target_fname, 0o440)
|
2011-06-17 07:19:45 -05:00
|
|
|
os.chown(target_fname, pent.pw_uid, pent.pw_gid)
|
2009-10-14 10:50:00 -05:00
|
|
|
except IOError:
|
|
|
|
# Does not apply with newer DS releases
|
|
|
|
pass
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2011-04-27 05:37:04 -05:00
|
|
|
def restart(self, instance=''):
|
2007-12-13 03:31:28 -06:00
|
|
|
try:
|
2011-04-27 05:37:04 -05:00
|
|
|
super(DsInstance, self).restart(instance)
|
2011-10-10 07:25:15 -05:00
|
|
|
if not is_ds_running(instance):
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.critical("Failed to restart the directory server. See the installation log for details.")
|
2008-04-14 20:18:24 -05:00
|
|
|
sys.exit(1)
|
2015-07-30 09:49:29 -05:00
|
|
|
except SystemExit as e:
|
2008-04-14 20:18:24 -05:00
|
|
|
raise e
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2007-12-13 03:31:28 -06:00
|
|
|
# TODO: roll back here?
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.critical("Failed to restart the directory server (%s). See the installation log for details." % e)
|
2011-04-27 05:37:04 -05:00
|
|
|
|
|
|
|
def __restart_instance(self):
|
|
|
|
self.restart(self.serverid)
|
2007-12-13 03:31:28 -06:00
|
|
|
|
2010-11-23 09:35:49 -06:00
|
|
|
def __enable_entryusn(self):
|
|
|
|
self._ldap_mod("entryusn.ldif")
|
|
|
|
|
2007-12-13 03:31:28 -06:00
|
|
|
def __add_memberof_module(self):
|
2009-05-12 05:51:46 -05:00
|
|
|
self._ldap_mod("memberof-conf.ldif")
|
2007-10-16 09:17:39 -05:00
|
|
|
|
2008-03-27 08:33:01 -05:00
|
|
|
def init_memberof(self):
|
2011-09-16 12:23:02 -05:00
|
|
|
|
|
|
|
if not self.run_init_memberof:
|
|
|
|
return
|
|
|
|
|
2009-05-12 05:51:46 -05:00
|
|
|
self._ldap_mod("memberof-task.ldif", self.sub_dict)
|
2011-04-21 15:43:10 -05:00
|
|
|
# Note, keep dn in sync with dn in install/share/memberof-task.ldif
|
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
|
|
|
dn = DN(('cn', 'IPA install %s' % self.sub_dict["TIME"]), ('cn', 'memberof task'),
|
|
|
|
('cn', 'tasks'), ('cn', 'config'))
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.debug("Waiting for memberof task to complete.")
|
2013-01-16 03:05:43 -06:00
|
|
|
conn = ipaldap.IPAdmin(self.fqdn)
|
2011-06-10 15:30:13 -05:00
|
|
|
if self.dm_password:
|
2013-01-30 03:32:24 -06:00
|
|
|
conn.do_simple_bind(
|
|
|
|
DN(('cn', 'directory manager')), self.dm_password)
|
2011-06-10 15:30:13 -05:00
|
|
|
else:
|
|
|
|
conn.do_sasl_gssapi_bind()
|
2013-01-21 06:23:20 -06:00
|
|
|
replication.wait_for_task(conn, dn)
|
2011-04-21 15:43:10 -05:00
|
|
|
conn.unbind()
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2008-09-15 17:15:12 -05:00
|
|
|
def apply_updates(self):
|
2015-04-27 03:34:25 -05:00
|
|
|
data_upgrade = upgradeinstance.IPAUpgrade(self.realm)
|
2015-05-12 06:31:57 -05:00
|
|
|
try:
|
|
|
|
data_upgrade.create_instance()
|
|
|
|
except Exception as e:
|
|
|
|
# very fatal errors only will raise exception
|
|
|
|
raise RuntimeError("Update failed: %s" % e)
|
2015-04-10 08:42:58 -05:00
|
|
|
installutils.store_version()
|
|
|
|
|
2008-09-15 17:15:12 -05:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
def __add_referint_module(self):
|
2009-05-12 05:51:46 -05:00
|
|
|
self._ldap_mod("referint-conf.ldif")
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2008-02-21 21:31:16 -06:00
|
|
|
def __set_unique_attrs(self):
|
2009-05-12 05:51:46 -05:00
|
|
|
self._ldap_mod("unique-attributes.ldif", self.sub_dict)
|
2008-02-21 21:31:16 -06:00
|
|
|
|
2010-12-07 17:23:05 -06:00
|
|
|
def __config_uidgid_gen(self):
|
2010-11-11 17:15:28 -06:00
|
|
|
self._ldap_mod("dna.ldif", self.sub_dict)
|
2007-11-06 17:57:15 -06:00
|
|
|
|
2010-12-07 17:23:05 -06:00
|
|
|
def __add_master_entry(self):
|
2009-05-12 05:51:46 -05:00
|
|
|
self._ldap_mod("master-entry.ldif", self.sub_dict)
|
2007-11-06 17:57:15 -06:00
|
|
|
|
2015-05-20 10:12:04 -05:00
|
|
|
def __add_topology_entries(self):
|
|
|
|
self._ldap_mod("topology-entries.ldif", self.sub_dict)
|
|
|
|
|
2008-09-11 11:56:55 -05:00
|
|
|
def __add_winsync_module(self):
|
2009-05-12 05:51:46 -05:00
|
|
|
self._ldap_mod("ipa-winsync-conf.ldif")
|
2008-09-11 11:56:55 -05:00
|
|
|
|
2010-08-11 14:26:37 -05:00
|
|
|
def __enable_compat_plugin(self):
|
|
|
|
ld = ldapupdate.LDAPUpdate(dm_password=self.dm_password, sub_dict=self.sub_dict)
|
2014-05-29 07:47:17 -05:00
|
|
|
rv = ld.update([paths.SCHEMA_COMPAT_ULDIF])
|
2010-08-11 14:26:37 -05:00
|
|
|
if not rv:
|
|
|
|
raise RuntimeError("Enabling compatibility plugin failed")
|
|
|
|
|
2010-06-24 21:51:05 -05:00
|
|
|
def __config_version_module(self):
|
2010-07-20 13:00:43 -05:00
|
|
|
self._ldap_mod("version-conf.ldif")
|
2010-06-24 09:31:52 -05:00
|
|
|
|
2010-10-15 16:52:37 -05:00
|
|
|
def __config_uuid_module(self):
|
|
|
|
self._ldap_mod("uuid-conf.ldif")
|
2014-10-16 08:43:29 -05:00
|
|
|
self._ldap_mod("uuid.ldif", self.sub_dict)
|
2010-10-15 16:52:37 -05:00
|
|
|
|
2010-10-22 15:03:18 -05:00
|
|
|
def __config_modrdn_module(self):
|
|
|
|
self._ldap_mod("modrdn-conf.ldif")
|
|
|
|
self._ldap_mod("modrdn-krbprinc.ldif", self.sub_dict)
|
|
|
|
|
2013-03-13 09:15:41 -05:00
|
|
|
def __config_dns_module(self):
|
|
|
|
# Configure DNS plugin unconditionally as we would otherwise have
|
|
|
|
# troubles if other replica just configured DNS with ipa-dns-install
|
|
|
|
self._ldap_mod("ipa-dns-conf.ldif")
|
|
|
|
|
2011-01-18 13:58:58 -06:00
|
|
|
def __config_lockout_module(self):
|
|
|
|
self._ldap_mod("lockout-conf.ldif")
|
|
|
|
|
2015-05-20 10:12:04 -05:00
|
|
|
def __config_topology_module(self):
|
|
|
|
self._ldap_mod("ipa-topology-conf.ldif", self.sub_dict)
|
|
|
|
|
Move Managed Entries into their own container in the replicated space.
Repoint cn=Managed Entries,cn=plugins,cn=config in common_setup
Create: cn=Managed Entries,cn=etc,$SUFFIX
Create: cn=Definitions,cn=Managed Entries,cn=etc,$SUFFIX
Create: cn=Templates,cn=Managed Entries,cn=etc,$SUFFIX
Create method for dynamically migrating any and all custom Managed Entries
from the cn=config space into the new container.
Separate the connection creation during update so that a restart can
be performed to initialize changes before performing a delete.
Add wait_for_open_socket() method in installutils
https://fedorahosted.org/freeipa/ticket/1708
2011-09-08 14:07:26 -05:00
|
|
|
def __repoint_managed_entries(self):
|
|
|
|
self._ldap_mod("repoint-managed-entries.ldif", self.sub_dict)
|
|
|
|
|
2013-05-14 11:36:50 -05:00
|
|
|
def configure_dirsrv_ccache(self):
|
|
|
|
pent = pwd.getpwnam("dirsrv")
|
2014-05-29 07:47:17 -05:00
|
|
|
ccache = paths.TMP_KRB5CC % pent.pw_uid
|
|
|
|
filepath = paths.SYSCONFIG_DIRSRV
|
2013-05-14 11:36:50 -05:00
|
|
|
if not os.path.exists(filepath):
|
|
|
|
# file doesn't exist; create it with correct ownership & mode
|
|
|
|
open(filepath, 'a').close()
|
|
|
|
os.chmod(filepath,
|
|
|
|
stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
|
|
|
|
os.chown(filepath, 0, 0)
|
|
|
|
|
|
|
|
replacevars = {'KRB5CCNAME': ccache}
|
|
|
|
old_values = ipautil.backup_config_and_replace_variables(
|
|
|
|
self.fstore, filepath, replacevars=replacevars)
|
2014-05-29 03:18:21 -05:00
|
|
|
tasks.restore_context(filepath)
|
2013-05-14 11:36:50 -05:00
|
|
|
|
Move Managed Entries into their own container in the replicated space.
Repoint cn=Managed Entries,cn=plugins,cn=config in common_setup
Create: cn=Managed Entries,cn=etc,$SUFFIX
Create: cn=Definitions,cn=Managed Entries,cn=etc,$SUFFIX
Create: cn=Templates,cn=Managed Entries,cn=etc,$SUFFIX
Create method for dynamically migrating any and all custom Managed Entries
from the cn=config space into the new container.
Separate the connection creation during update so that a restart can
be performed to initialize changes before performing a delete.
Add wait_for_open_socket() method in installutils
https://fedorahosted.org/freeipa/ticket/1708
2011-09-08 14:07:26 -05:00
|
|
|
def __managed_entries(self):
|
|
|
|
self._ldap_mod("managed-entries.ldif", self.sub_dict)
|
|
|
|
|
2010-06-25 15:14:46 -05:00
|
|
|
def __user_private_groups(self):
|
2010-11-11 17:15:28 -06:00
|
|
|
self._ldap_mod("user_private_groups.ldif", self.sub_dict)
|
2010-06-25 15:14:46 -05:00
|
|
|
|
2010-12-10 17:21:39 -06:00
|
|
|
def __host_nis_groups(self):
|
|
|
|
self._ldap_mod("host_nis_groups.ldif", self.sub_dict)
|
|
|
|
|
2009-09-14 16:04:08 -05:00
|
|
|
def __add_enrollment_module(self):
|
|
|
|
self._ldap_mod("enrollment-conf.ldif", self.sub_dict)
|
|
|
|
|
2011-02-23 13:37:07 -06:00
|
|
|
def generate_random(self):
|
|
|
|
return ipautil.ipa_generate_password()
|
|
|
|
|
2013-10-15 12:30:14 -05:00
|
|
|
def __enable_ssl(self):
|
2008-01-22 05:57:59 -06:00
|
|
|
dirname = config_dirname(self.serverid)
|
2013-10-11 02:38:10 -05:00
|
|
|
dsdb = certs.CertDB(self.realm, nssdir=dirname, subject_base=self.subject_base)
|
0000-12-31 18:09:24 -05:50
|
|
|
if self.pkcs12_info:
|
2014-06-09 09:04:09 -05:00
|
|
|
if self.ca_is_configured:
|
|
|
|
trust_flags = 'CT,C,C'
|
|
|
|
else:
|
|
|
|
trust_flags = None
|
2013-03-26 09:31:07 -05:00
|
|
|
dsdb.create_from_pkcs12(self.pkcs12_info[0], self.pkcs12_info[1],
|
2014-06-09 09:04:09 -05:00
|
|
|
ca_file=self.ca_file,
|
|
|
|
trust_flags=trust_flags)
|
2009-04-13 12:39:15 -05:00
|
|
|
server_certs = dsdb.find_server_certs()
|
2008-07-11 10:34:29 -05:00
|
|
|
if len(server_certs) == 0:
|
2009-08-11 16:08:09 -05:00
|
|
|
raise RuntimeError("Could not find a suitable server cert in import in %s" % self.pkcs12_info[0])
|
2008-07-11 10:34:29 -05:00
|
|
|
|
|
|
|
# We only handle one server cert
|
2014-08-05 02:06:39 -05:00
|
|
|
self.nickname = server_certs[0][0]
|
|
|
|
self.dercert = dsdb.get_cert_from_db(self.nickname, pem=False)
|
0000-12-31 18:09:24 -05:50
|
|
|
else:
|
2013-10-11 02:38:10 -05:00
|
|
|
cadb = certs.CertDB(self.realm, host_name=self.fqdn, subject_base=self.subject_base)
|
2013-03-27 08:25:18 -05:00
|
|
|
|
|
|
|
# FIXME, need to set this nickname in the RA plugin
|
|
|
|
cadb.export_ca_cert('ipaCert', False)
|
|
|
|
dsdb.create_from_cacert(cadb.cacert_fname, passwd=None)
|
|
|
|
self.dercert = dsdb.create_server_cert(
|
2014-08-05 02:06:39 -05:00
|
|
|
self.nickname, self.fqdn, cadb)
|
2013-10-17 07:52:07 -05:00
|
|
|
dsdb.create_pin_file()
|
|
|
|
|
2014-04-08 06:12:47 -05:00
|
|
|
self.cacert_name = dsdb.cacert_name
|
|
|
|
|
2013-10-17 07:52:07 -05:00
|
|
|
if self.ca_is_configured:
|
2013-03-27 08:25:18 -05:00
|
|
|
dsdb.track_server_cert(
|
2014-08-05 02:06:39 -05:00
|
|
|
self.nickname, self.principal, dsdb.passwd_fname,
|
2013-03-27 08:25:18 -05:00
|
|
|
'restart_dirsrv %s' % self.serverid)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2013-01-16 03:05:43 -06:00
|
|
|
conn = ipaldap.IPAdmin(self.fqdn)
|
2013-01-30 03:32:24 -06:00
|
|
|
conn.do_simple_bind(DN(('cn', 'directory manager')), self.dm_password)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
|
|
|
mod = [(ldap.MOD_REPLACE, "nsSSLClientAuth", "allowed"),
|
2014-09-12 05:43:31 -05:00
|
|
|
(ldap.MOD_REPLACE, "nsSSL3Ciphers", "+all"),
|
|
|
|
(ldap.MOD_REPLACE, "allowWeakCipher", "off")]
|
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
|
|
|
conn.modify_s(DN(('cn', 'encryption'), ('cn', 'config')), mod)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2011-05-19 21:30:53 -05:00
|
|
|
mod = [(ldap.MOD_ADD, "nsslapd-security", "on")]
|
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
|
|
|
conn.modify_s(DN(('cn', 'config')), mod)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2013-01-18 08:24:35 -06:00
|
|
|
entry = conn.make_entry(
|
|
|
|
DN(('cn', 'RSA'), ('cn', 'encryption'), ('cn', 'config')),
|
|
|
|
objectclass=["top", "nsEncryptionModule"],
|
|
|
|
cn=["RSA"],
|
2014-08-05 02:06:39 -05:00
|
|
|
nsSSLPersonalitySSL=[self.nickname],
|
2013-01-18 08:24:35 -06:00
|
|
|
nsSSLToken=["internal (software)"],
|
|
|
|
nsSSLActivation=["on"],
|
|
|
|
)
|
2013-01-23 08:27:05 -06:00
|
|
|
conn.add_entry(entry)
|
2008-02-21 13:39:50 -06:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
conn.unbind()
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2011-04-27 05:37:04 -05:00
|
|
|
# check for open secure port 636 from now on
|
|
|
|
self.open_ports.append(636)
|
|
|
|
|
2013-10-15 12:30:14 -05:00
|
|
|
def __upload_ca_cert(self):
|
2012-11-12 16:43:05 -06:00
|
|
|
"""
|
2013-03-14 07:58:27 -05:00
|
|
|
Upload the CA certificate from the NSS database to the LDAP directory.
|
2012-11-12 16:43:05 -06:00
|
|
|
"""
|
|
|
|
|
|
|
|
dirname = config_dirname(self.serverid)
|
2014-06-12 03:21:34 -05:00
|
|
|
dsdb = certs.CertDB(self.realm, nssdir=dirname,
|
|
|
|
subject_base=self.subject_base)
|
|
|
|
trust_flags = dict(reversed(dsdb.list_certs()))
|
2013-03-14 07:58:27 -05:00
|
|
|
|
2014-01-02 07:28:22 -06:00
|
|
|
conn = ipaldap.IPAdmin(self.fqdn)
|
|
|
|
conn.do_simple_bind(DN(('cn', 'directory manager')), self.dm_password)
|
|
|
|
|
2014-06-12 03:21:34 -05:00
|
|
|
nicknames = dsdb.find_root_cert(self.cacert_name)[:-1]
|
|
|
|
for nickname in nicknames:
|
|
|
|
cert = dsdb.get_cert_from_db(nickname, pem=False)
|
|
|
|
certstore.put_ca_cert_nss(conn, self.suffix, cert, nickname,
|
|
|
|
trust_flags[nickname])
|
|
|
|
|
|
|
|
nickname = self.cacert_name
|
|
|
|
cert = dsdb.get_cert_from_db(nickname, pem=False)
|
|
|
|
certstore.put_ca_cert_nss(conn, self.suffix, cert, nickname,
|
|
|
|
trust_flags[nickname],
|
|
|
|
config_ipa=self.ca_is_configured,
|
|
|
|
config_compat=self.master_fqdn is None)
|
2012-11-12 16:43:05 -06:00
|
|
|
|
2014-01-02 07:28:22 -06:00
|
|
|
conn.unbind()
|
2012-11-12 16:43:05 -06:00
|
|
|
|
2014-06-12 03:23:19 -05:00
|
|
|
def __import_ca_certs(self):
|
|
|
|
dirname = config_dirname(self.serverid)
|
|
|
|
dsdb = certs.CertDB(self.realm, nssdir=dirname,
|
|
|
|
subject_base=self.subject_base)
|
|
|
|
|
|
|
|
conn = ipaldap.IPAdmin(self.fqdn)
|
|
|
|
conn.do_simple_bind(DN(('cn', 'directory manager')), self.dm_password)
|
|
|
|
|
|
|
|
self.import_ca_certs(dsdb, self.ca_is_configured, conn)
|
|
|
|
|
|
|
|
conn.unbind()
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
def __add_default_layout(self):
|
2009-05-12 05:51:46 -05:00
|
|
|
self._ldap_mod("bootstrap-template.ldif", self.sub_dict)
|
2008-02-21 13:39:50 -06:00
|
|
|
|
2009-06-04 14:33:49 -05:00
|
|
|
def __add_delegation_layout(self):
|
|
|
|
self._ldap_mod("delegation.ldif", self.sub_dict)
|
|
|
|
|
2010-12-11 10:02:08 -06:00
|
|
|
def __add_replication_acis(self):
|
|
|
|
self._ldap_mod("replica-acis.ldif", self.sub_dict)
|
|
|
|
|
2012-02-02 13:15:02 -06:00
|
|
|
def __setup_s4u2proxy(self):
|
|
|
|
self._ldap_mod("replica-s4u2proxy.ldif", self.sub_dict)
|
|
|
|
|
2008-01-25 12:29:49 -06:00
|
|
|
def __create_indices(self):
|
2009-05-12 05:51:46 -05:00
|
|
|
self._ldap_mod("indices.ldif")
|
2007-08-06 09:05:53 -05:00
|
|
|
|
|
|
|
def __certmap_conf(self):
|
2007-12-13 03:31:28 -06:00
|
|
|
shutil.copyfile(ipautil.SHARE_DIR + "certmap.conf.template",
|
2008-01-22 05:57:59 -06:00
|
|
|
config_dirname(self.serverid) + "certmap.conf")
|
2012-09-19 22:35:42 -05:00
|
|
|
installutils.update_file(config_dirname(self.serverid) + "certmap.conf",
|
2013-07-29 11:33:09 -05:00
|
|
|
'$SUBJECT_BASE', str(self.subject_base))
|
|
|
|
sysupgrade.set_upgrade_state(
|
|
|
|
'certmap.conf',
|
|
|
|
'subject_base',
|
|
|
|
str(self.subject_base)
|
|
|
|
)
|
2007-08-31 17:40:01 -05:00
|
|
|
|
2009-08-26 13:09:36 -05:00
|
|
|
def __enable_ldapi(self):
|
|
|
|
self._ldap_mod("ldapi.ldif", self.sub_dict)
|
|
|
|
|
2013-03-22 05:15:51 -05:00
|
|
|
def __enable_sasl_mapping_fallback(self):
|
|
|
|
self._ldap_mod("sasl-mapping-fallback.ldif", self.sub_dict)
|
|
|
|
|
2010-05-04 14:24:54 -05:00
|
|
|
def add_hbac(self):
|
|
|
|
self._ldap_mod("default-hbac.ldif", self.sub_dict)
|
|
|
|
|
2015-05-25 07:39:07 -05:00
|
|
|
def add_caacl(self):
|
|
|
|
self._ldap_mod("default-caacl.ldif", self.sub_dict)
|
|
|
|
|
2007-08-31 17:40:01 -05:00
|
|
|
def change_admin_password(self, password):
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.debug("Changing admin password")
|
2008-01-22 05:57:59 -06:00
|
|
|
dirname = config_dirname(self.serverid)
|
2010-10-13 11:21:48 -05:00
|
|
|
dmpwdfile = ""
|
|
|
|
admpwdfile = ""
|
|
|
|
|
2007-10-03 16:37:13 -05:00
|
|
|
try:
|
2014-05-29 07:47:17 -05:00
|
|
|
(dmpwdfd, dmpwdfile) = tempfile.mkstemp(dir=paths.VAR_LIB_IPA)
|
2010-10-13 11:21:48 -05:00
|
|
|
os.write(dmpwdfd, self.dm_password)
|
|
|
|
os.close(dmpwdfd)
|
|
|
|
|
2014-05-29 07:47:17 -05:00
|
|
|
(admpwdfd, admpwdfile) = tempfile.mkstemp(dir=paths.VAR_LIB_IPA)
|
2010-10-13 11:21:48 -05:00
|
|
|
os.write(admpwdfd, password)
|
|
|
|
os.close(admpwdfd)
|
|
|
|
|
2014-05-29 07:47:17 -05:00
|
|
|
args = [paths.LDAPPASSWD, "-h", self.fqdn,
|
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
|
|
|
"-ZZ", "-x", "-D", str(DN(('cn', 'Directory Manager'))),
|
2010-10-13 11:21:48 -05:00
|
|
|
"-y", dmpwdfile, "-T", admpwdfile,
|
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
|
|
|
str(DN(('uid', 'admin'), ('cn', 'users'), ('cn', 'accounts'), self.suffix))]
|
2010-10-13 11:21:48 -05:00
|
|
|
try:
|
2010-11-10 16:33:02 -06:00
|
|
|
env = { 'LDAPTLS_CACERTDIR':os.path.dirname(CACERT),
|
|
|
|
'LDAPTLS_CACERT':CACERT }
|
|
|
|
ipautil.run(args, env=env)
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.debug("ldappasswd done")
|
2015-07-30 09:49:29 -05:00
|
|
|
except ipautil.CalledProcessError as e:
|
2010-10-13 11:21:48 -05:00
|
|
|
print "Unable to set admin password", e
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.debug("Unable to set admin password %s" % e)
|
2010-10-13 11:21:48 -05:00
|
|
|
|
|
|
|
finally:
|
|
|
|
if os.path.isfile(dmpwdfile):
|
|
|
|
os.remove(dmpwdfile)
|
|
|
|
if os.path.isfile(admpwdfile):
|
|
|
|
os.remove(admpwdfile)
|
2007-08-31 17:40:01 -05: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 directory server")
|
|
|
|
|
2008-01-11 05:57:36 -06:00
|
|
|
enabled = self.restore_state("enabled")
|
|
|
|
|
2012-04-16 16:03:46 -05:00
|
|
|
# Just eat this state if it exists
|
|
|
|
running = self.restore_state("running")
|
|
|
|
|
2010-11-17 11:25:01 -06:00
|
|
|
try:
|
2014-05-29 07:47:17 -05:00
|
|
|
self.fstore.restore_file(paths.LIMITS_CONF)
|
|
|
|
self.fstore.restore_file(paths.SYSCONFIG_DIRSRV)
|
2015-07-30 09:49:29 -05:00
|
|
|
except ValueError as error:
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.debug(error)
|
2010-11-17 11:25:01 -06:00
|
|
|
pass
|
|
|
|
|
2015-01-27 04:04:03 -06:00
|
|
|
# disabled during IPA installation
|
|
|
|
if enabled:
|
|
|
|
self.enable()
|
2008-01-11 05:57:36 -06:00
|
|
|
|
|
|
|
serverid = self.restore_state("serverid")
|
2015-01-21 06:40:36 -06:00
|
|
|
if serverid is not None:
|
2013-03-26 12:06:50 -05:00
|
|
|
self.stop_tracking_certificates(serverid)
|
2015-01-21 06:40:36 -06:00
|
|
|
root_logger.debug("Removing DS instance %s" % serverid)
|
|
|
|
try:
|
|
|
|
remove_ds_instance(serverid)
|
|
|
|
root_logger.debug("Removing DS keytab")
|
|
|
|
installutils.remove_file(paths.DS_KEYTAB)
|
|
|
|
except ipautil.CalledProcessError:
|
|
|
|
root_logger.error("Failed to remove DS instance. You may "
|
|
|
|
"need to remove instance data manually")
|
2008-01-11 05:57:36 -06:00
|
|
|
|
2012-02-28 22:05:06 -06:00
|
|
|
# At one time we removed this user on uninstall. That can potentially
|
|
|
|
# orphan files, or worse, if another useradd runs in the intermim,
|
|
|
|
# cause files to have a new owner.
|
2008-01-11 05:57:36 -06:00
|
|
|
user_exists = self.restore_state("user_exists")
|
|
|
|
|
2011-08-24 10:28:20 -05:00
|
|
|
# Make sure some upgrade-related state is removed. This could cause
|
|
|
|
# re-installation problems.
|
|
|
|
self.restore_state('nsslapd-port')
|
|
|
|
self.restore_state('nsslapd-security')
|
|
|
|
self.restore_state('nsslapd-ldapiautobind')
|
|
|
|
|
2012-04-04 14:19:29 -05:00
|
|
|
# If any dirsrv instances remain after we've removed ours then
|
|
|
|
# (re)start them.
|
|
|
|
for ds_instance in get_ds_instances():
|
|
|
|
try:
|
2014-05-29 03:37:18 -05:00
|
|
|
services.knownservices.dirsrv.restart(ds_instance, wait=False)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2012-04-04 14:19:29 -05:00
|
|
|
root_logger.error('Unable to restart ds instance %s: %s', ds_instance, e)
|
2008-09-11 11:56:55 -05:00
|
|
|
|
2013-03-26 12:06:50 -05:00
|
|
|
def stop_tracking_certificates(self, serverid=None):
|
|
|
|
if serverid is None:
|
|
|
|
serverid = self.get_state("serverid")
|
|
|
|
if not serverid is None:
|
|
|
|
# drop the trailing / off the config_dirname so the directory
|
|
|
|
# will match what is in certmonger
|
|
|
|
dirname = config_dirname(serverid)[:-1]
|
2013-10-11 02:38:10 -05:00
|
|
|
dsdb = certs.CertDB(self.realm, nssdir=dirname)
|
2013-03-26 12:06:50 -05:00
|
|
|
dsdb.untrack_server_cert(self.nickname)
|
|
|
|
|
2008-09-11 11:56:55 -05:00
|
|
|
# we could probably move this function into the service.Service
|
|
|
|
# class - it's very generic - all we need is a way to get an
|
|
|
|
# instance of a particular Service
|
|
|
|
def add_ca_cert(self, cacert_fname, cacert_name=''):
|
|
|
|
"""Add a CA certificate to the directory server cert db. We
|
|
|
|
first have to shut down the directory server in case it has
|
|
|
|
opened the cert db read-only. Then we use the CertDB class
|
|
|
|
to add the CA cert. We have to provide a nickname, and we
|
2010-09-28 22:10:25 -05:00
|
|
|
do not use 'IPA CA' since that's the default, so
|
2008-09-11 11:56:55 -05:00
|
|
|
we use 'Imported CA' if none specified. Then we restart
|
|
|
|
the server."""
|
|
|
|
# first make sure we have a valid cacert_fname
|
|
|
|
try:
|
|
|
|
if not os.access(cacert_fname, os.R_OK):
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.critical("The given CA cert file named [%s] could not be read" %
|
|
|
|
cacert_fname)
|
2008-09-11 11:56:55 -05:00
|
|
|
return False
|
2015-07-30 09:49:29 -05:00
|
|
|
except OSError as e:
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.critical("The given CA cert file named [%s] could not be read: %s" %
|
|
|
|
(cacert_fname, str(e)))
|
2008-09-11 11:56:55 -05:00
|
|
|
return False
|
|
|
|
# ok - ca cert file can be read
|
|
|
|
# shutdown the server
|
2008-10-03 15:11:14 -05:00
|
|
|
self.stop()
|
2008-09-11 11:56:55 -05:00
|
|
|
|
2015-04-27 07:42:31 -05:00
|
|
|
dirname = config_dirname(installutils.realm_to_serverid(self.realm))
|
2013-10-11 02:38:10 -05:00
|
|
|
certdb = certs.CertDB(self.realm, nssdir=dirname, subject_base=self.subject_base)
|
2008-09-11 11:56:55 -05:00
|
|
|
if not cacert_name or len(cacert_name) == 0:
|
|
|
|
cacert_name = "Imported CA"
|
|
|
|
# we can't pass in the nickname, so we set the instance variable
|
|
|
|
certdb.cacert_name = cacert_name
|
|
|
|
status = True
|
|
|
|
try:
|
2014-12-02 06:13:51 -06:00
|
|
|
certdb.load_cacert(cacert_fname, 'C,,')
|
2015-07-30 09:49:29 -05:00
|
|
|
except ipautil.CalledProcessError as e:
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.critical("Error importing CA cert file named [%s]: %s" %
|
|
|
|
(cacert_fname, str(e)))
|
2008-09-11 11:56:55 -05:00
|
|
|
status = False
|
|
|
|
# restart the directory server
|
|
|
|
self.start()
|
|
|
|
|
|
|
|
return status
|
2010-11-16 11:45:21 -06:00
|
|
|
|
|
|
|
def tune_nofile(self, num=8192):
|
|
|
|
"""
|
|
|
|
Increase the number of files descriptors available to directory server
|
|
|
|
from the default 1024 to 8192. This will allow to support a greater
|
|
|
|
number of clients out of the box.
|
|
|
|
"""
|
|
|
|
|
2013-08-06 10:09:15 -05:00
|
|
|
# Do the platform-specific changes
|
2014-05-29 03:37:18 -05:00
|
|
|
proceed = services.knownservices.dirsrv.tune_nofile_platform(
|
2013-08-06 10:09:15 -05:00
|
|
|
num=num, fstore=self.fstore)
|
2010-11-16 11:45:21 -06:00
|
|
|
|
2013-08-06 10:09:15 -05:00
|
|
|
if proceed:
|
|
|
|
# finally change also DS configuration
|
|
|
|
# NOTE: dirsrv will not allow you to set max file descriptors unless
|
|
|
|
# the user limits allow it, so we have to restart dirsrv before
|
|
|
|
# attempting to change them in cn=config
|
|
|
|
self.__restart_instance()
|
2010-11-16 11:45:21 -06:00
|
|
|
|
2013-08-06 10:09:15 -05:00
|
|
|
nf_sub_dict = dict(NOFILES=str(num))
|
|
|
|
self._ldap_mod("ds-nfiles.ldif", nf_sub_dict)
|
2010-11-16 11:45:21 -06:00
|
|
|
|
|
|
|
def __tuning(self):
|
|
|
|
self.tune_nofile(8192)
|
2011-01-19 14:17:25 -06:00
|
|
|
|
|
|
|
def __root_autobind(self):
|
|
|
|
self._ldap_mod("root-autobind.ldif")
|
|
|
|
|
2011-02-23 13:37:07 -06:00
|
|
|
def __add_sudo_binduser(self):
|
|
|
|
self._ldap_mod("sudobind.ldif", self.sub_dict)
|
|
|
|
|
2011-08-30 19:48:15 -05:00
|
|
|
def __add_automember_config(self):
|
|
|
|
self._ldap_mod("automember.ldif", self.sub_dict)
|
|
|
|
|
|
|
|
def __add_replica_automember_config(self):
|
|
|
|
self._ldap_mod("replica-automember.ldif", self.sub_dict)
|
|
|
|
|
2012-06-18 14:25:31 -05:00
|
|
|
def __add_range_check_plugin(self):
|
|
|
|
self._ldap_mod("range-check-conf.ldif", self.sub_dict)
|
|
|
|
|
2015-05-12 07:31:46 -05:00
|
|
|
def _add_sidgen_plugin(self):
|
|
|
|
"""
|
|
|
|
Add sidgen directory server plugin configuration if it does not already exist.
|
|
|
|
"""
|
|
|
|
self._ldap_mod('ipa-sidgen-conf.ldif', self.sub_dict)
|
|
|
|
|
2015-08-10 03:53:28 -05:00
|
|
|
def add_sidgen_plugin(self):
|
|
|
|
"""
|
|
|
|
Add sidgen plugin configuration only if it does not already exist.
|
|
|
|
"""
|
|
|
|
dn = DN('cn=IPA SIDGEN,cn=plugins,cn=config')
|
|
|
|
try:
|
|
|
|
self.admin_conn.get_entry(dn)
|
|
|
|
except errors.NotFound:
|
|
|
|
self._add_sidgen_plugin()
|
|
|
|
else:
|
|
|
|
root_logger.debug("sidgen plugin is already configured")
|
|
|
|
|
2015-05-12 07:31:46 -05:00
|
|
|
def _add_extdom_plugin(self):
|
|
|
|
"""
|
2015-08-10 03:53:28 -05:00
|
|
|
Add directory server configuration for the extdom extended operation.
|
2015-05-12 07:31:46 -05:00
|
|
|
"""
|
|
|
|
self._ldap_mod('ipa-extdom-extop-conf.ldif', self.sub_dict)
|
|
|
|
|
2015-08-10 03:53:28 -05:00
|
|
|
def add_extdom_plugin(self):
|
|
|
|
"""
|
|
|
|
Add extdom configuration if it does not already exist.
|
|
|
|
"""
|
|
|
|
dn = DN('cn=ipa_extdom_extop,cn=plugins,cn=config')
|
|
|
|
try:
|
|
|
|
self.admin_conn.get_entry(dn)
|
|
|
|
except errors.NotFound:
|
|
|
|
self._add_extdom_plugin()
|
|
|
|
else:
|
|
|
|
root_logger.debug("extdom plugin is already configured")
|
|
|
|
|
2011-01-21 13:32:55 -06:00
|
|
|
def replica_populate(self):
|
|
|
|
self.ldap_connect()
|
|
|
|
|
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
|
|
|
dn = DN(('cn', 'default'), ('ou', 'profile'), self.suffix)
|
2011-01-21 13:32:55 -06:00
|
|
|
try:
|
2013-01-23 09:05:21 -06:00
|
|
|
entry = self.admin_conn.get_entry(dn)
|
2013-09-10 05:20:24 -05:00
|
|
|
srvlist = entry.single_value.get('defaultServerList', '')
|
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
|
|
|
srvlist = srvlist.split()
|
2011-01-21 13:32:55 -06:00
|
|
|
if not self.fqdn in srvlist:
|
|
|
|
srvlist.append(self.fqdn)
|
|
|
|
attr = ' '.join(srvlist)
|
|
|
|
mod = [(ldap.MOD_REPLACE, 'defaultServerList', attr)]
|
|
|
|
self.admin_conn.modify_s(dn, mod)
|
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
|
|
|
except errors.NotFound:
|
2011-01-21 13:32:55 -06:00
|
|
|
pass
|
|
|
|
except ldap.TYPE_OR_VALUE_EXISTS:
|
|
|
|
pass
|
|
|
|
|
|
|
|
self.ldap_disconnect()
|
2014-03-18 10:23:30 -05:00
|
|
|
|
|
|
|
def find_subject_base(self):
|
|
|
|
"""
|
|
|
|
Try to find the current value of certificate subject base.
|
|
|
|
1) Look in sysupgrade first
|
|
|
|
2) If no value is found there, look in DS (start DS if necessary)
|
|
|
|
3) Last resort, look in the certmap.conf itself
|
|
|
|
4) If all fails, log loudly and return None
|
|
|
|
|
|
|
|
Note that this method can only be executed AFTER the ipa server
|
|
|
|
is configured, the api is initialized elsewhere and
|
|
|
|
that a ticket already have been acquired.
|
|
|
|
"""
|
|
|
|
root_logger.debug(
|
|
|
|
'Trying to find certificate subject base in sysupgrade')
|
|
|
|
subject_base = sysupgrade.get_upgrade_state(
|
|
|
|
'certmap.conf', 'subject_base')
|
|
|
|
|
|
|
|
if subject_base:
|
|
|
|
root_logger.debug(
|
|
|
|
'Found certificate subject base in sysupgrade: %s',
|
|
|
|
subject_base)
|
|
|
|
return subject_base
|
|
|
|
|
|
|
|
root_logger.debug(
|
|
|
|
'Unable to find certificate subject base in sysupgrade')
|
|
|
|
root_logger.debug(
|
|
|
|
'Trying to find certificate subject base in DS')
|
|
|
|
|
|
|
|
ds_is_running = is_ds_running()
|
|
|
|
if not ds_is_running:
|
|
|
|
try:
|
|
|
|
self.start()
|
|
|
|
ds_is_running = True
|
|
|
|
except ipautil.CalledProcessError as e:
|
|
|
|
root_logger.error('Cannot start DS to find certificate '
|
|
|
|
'subject base: %s', e)
|
|
|
|
|
|
|
|
if ds_is_running:
|
|
|
|
try:
|
|
|
|
api.Backend.ldap2.connect(autobind=True)
|
|
|
|
ret = api.Command['config_show']()
|
|
|
|
subject_base = str(
|
|
|
|
ret['result']['ipacertificatesubjectbase'][0])
|
|
|
|
root_logger.debug(
|
|
|
|
'Found certificate subject base in DS: %s', subject_base)
|
2015-07-30 09:49:29 -05:00
|
|
|
except errors.PublicError as e:
|
2014-03-18 10:23:30 -05:00
|
|
|
root_logger.error('Cannot connect to DS to find certificate '
|
|
|
|
'subject base: %s', e)
|
|
|
|
finally:
|
|
|
|
try:
|
|
|
|
api.Backend.ldap2.disconnect()
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if not subject_base:
|
|
|
|
root_logger.debug('Unable to find certificate subject base in DS')
|
|
|
|
root_logger.debug('Trying to find certificate subject base in '
|
|
|
|
'certmap.conf')
|
|
|
|
|
|
|
|
certmap_dir = config_dirname(
|
2015-04-27 07:42:31 -05:00
|
|
|
installutils.realm_to_serverid(api.env.realm)
|
2014-03-18 10:23:30 -05:00
|
|
|
)
|
|
|
|
try:
|
|
|
|
with open(os.path.join(certmap_dir, 'certmap.conf')) as f:
|
|
|
|
for line in f:
|
|
|
|
if line.startswith('certmap ipaca'):
|
|
|
|
subject_base = line.strip().split(',')[-1]
|
|
|
|
root_logger.debug(
|
|
|
|
'Found certificate subject base in certmap.conf: '
|
|
|
|
'%s', subject_base)
|
|
|
|
|
|
|
|
except IOError as e:
|
|
|
|
root_logger.error('Cannot open certmap.conf to find certificate '
|
|
|
|
'subject base: %s', e.strerror)
|
|
|
|
|
|
|
|
if subject_base:
|
|
|
|
return subject_base
|
|
|
|
|
|
|
|
root_logger.debug('Unable to find certificate subject base in '
|
|
|
|
'certmap.conf')
|
|
|
|
return None
|
2015-05-14 03:49:55 -05:00
|
|
|
|
|
|
|
def __set_domain_level(self):
|
|
|
|
# Create global domain level entry and set the domain level
|
|
|
|
if self.domainlevel is not None:
|
|
|
|
self._ldap_mod("domainlevel.ldif", self.sub_dict)
|