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-01-31 05:59:35 -06:00
|
|
|
import base64
|
2013-05-14 11:36:50 -05:00
|
|
|
import stat
|
2013-09-02 03:56:19 -05:00
|
|
|
import grp
|
0000-12-31 18:09:24 -05:50
|
|
|
|
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
|
2011-09-13 02:47:13 -05:00
|
|
|
from ipapython import services as ipaservices
|
0000-12-31 18:09:24 -05:50
|
|
|
import service
|
0000-12-31 18:09:24 -05:50
|
|
|
import installutils
|
0000-12-31 18:09:24 -05:50
|
|
|
import certs
|
2009-02-04 09:53:34 -06:00
|
|
|
import ldap
|
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
|
2013-03-27 08:25:18 -05:00
|
|
|
from ipalib import errors
|
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
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2007-08-15 18:45:18 -05:00
|
|
|
SERVER_ROOT_64 = "/usr/lib64/dirsrv"
|
|
|
|
SERVER_ROOT_32 = "/usr/lib/dirsrv"
|
2010-12-10 13:53:06 -06:00
|
|
|
CACERT="/etc/ipa/ca.crt"
|
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",
|
|
|
|
"60ipadns.ldif",
|
|
|
|
"61kerberos-ipav3.ldif",
|
|
|
|
"65ipasudo.ldif",
|
2013-04-29 11:09:45 -05:00
|
|
|
"70ipaotp.ldif",
|
|
|
|
"15rfc2307bis.ldif",
|
|
|
|
"15rfc4876.ldif")
|
2013-04-26 05:55:56 -05:00
|
|
|
|
|
|
|
ALL_SCHEMA_FILES = IPA_SCHEMA_FILES + ("05rfc2247.ldif", )
|
|
|
|
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
def find_server_root():
|
0000-12-31 18:09:24 -05:50
|
|
|
if ipautil.dir_exists(SERVER_ROOT_64):
|
0000-12-31 18:09:24 -05:50
|
|
|
return SERVER_ROOT_64
|
|
|
|
else:
|
0000-12-31 18:09:24 -05:50
|
|
|
return SERVER_ROOT_32
|
0000-12-31 18:09:24 -05:50
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
def realm_to_serverid(realm_name):
|
|
|
|
return "-".join(realm_name.split("."))
|
|
|
|
|
2008-01-22 05:57:59 -06:00
|
|
|
def config_dirname(serverid):
|
|
|
|
return "/etc/dirsrv/slapd-" + 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
|
|
|
|
|
|
|
def erase_ds_instance_data(serverid):
|
2011-08-29 10:16:52 -05:00
|
|
|
installutils.rmtree("/etc/dirsrv/slapd-%s" % serverid)
|
|
|
|
|
|
|
|
installutils.rmtree("/usr/lib/dirsrv/slapd-%s" % serverid)
|
|
|
|
|
|
|
|
installutils.rmtree("/usr/lib64/dirsrv/slapd-%s" % serverid)
|
|
|
|
|
|
|
|
installutils.rmtree("/var/lib/dirsrv/slapd-%s" % serverid)
|
|
|
|
|
|
|
|
installutils.rmtree("/var/lock/dirsrv/slapd-%s" % serverid)
|
|
|
|
|
|
|
|
installutils.remove_file("/var/run/slapd-%s.socket" % serverid)
|
|
|
|
|
|
|
|
installutils.rmtree("/var/lib/dirsrv/scripts-%s" % serverid)
|
|
|
|
|
|
|
|
installutils.remove_file("/etc/dirsrv/ds.keytab")
|
|
|
|
|
|
|
|
installutils.remove_file("/etc/sysconfig/dirsrv-%s" % serverid)
|
|
|
|
|
2008-09-11 11:56:55 -05:00
|
|
|
# try:
|
|
|
|
# shutil.rmtree("/var/log/dirsrv/slapd-%s" % serverid)
|
|
|
|
# except:
|
|
|
|
# pass
|
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.
|
|
|
|
'''
|
|
|
|
|
|
|
|
dirsrv_instance_dir='/etc/dirsrv'
|
|
|
|
instance_prefix = 'slapd-'
|
|
|
|
|
|
|
|
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
|
|
|
|
if basename.startswith(instance_prefix) and not basename.endswith('.removed'):
|
|
|
|
# Strip off prefix
|
|
|
|
instance = basename[len(instance_prefix):]
|
|
|
|
# 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=''):
|
|
|
|
return ipaservices.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():
|
|
|
|
"""
|
|
|
|
Create DS user if it doesn't exist yet.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
pwd.getpwnam(DS_USER)
|
|
|
|
root_logger.debug('DS user %s exists', DS_USER)
|
|
|
|
except KeyError:
|
|
|
|
root_logger.debug('Adding DS user %s', DS_USER)
|
|
|
|
args = [
|
|
|
|
'/usr/sbin/useradd',
|
|
|
|
'-g', DS_GROUP,
|
|
|
|
'-c', 'DS System User',
|
|
|
|
'-d', '/var/lib/dirsrv',
|
|
|
|
'-s', '/sbin/nologin',
|
|
|
|
'-M', '-r', DS_USER
|
|
|
|
]
|
|
|
|
try:
|
|
|
|
ipautil.run(args)
|
|
|
|
root_logger.debug('Done adding DS user')
|
|
|
|
except ipautil.CalledProcessError, e:
|
|
|
|
root_logger.critical('Failed to add DS user: %s', e)
|
|
|
|
|
|
|
|
|
|
|
|
def create_ds_group():
|
|
|
|
"""
|
|
|
|
Create DS group if it doesn't exist yet.
|
|
|
|
Returns True if the group already exists.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
grp.getgrnam(DS_GROUP)
|
|
|
|
root_logger.debug('DS group %s exists', DS_GROUP)
|
|
|
|
group_exists = True
|
|
|
|
except KeyError:
|
|
|
|
group_exists = False
|
|
|
|
root_logger.debug('Adding DS group %s', DS_GROUP)
|
|
|
|
args = ['/usr/sbin/groupadd', '-r', DS_GROUP]
|
|
|
|
try:
|
|
|
|
ipautil.run(args)
|
|
|
|
root_logger.debug('Done adding DS group')
|
|
|
|
except ipautil.CalledProcessError, e:
|
|
|
|
root_logger.critical('Failed to add DS group: %s', e)
|
|
|
|
|
|
|
|
return group_exists
|
|
|
|
|
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,
|
|
|
|
fstore=None, cert_nickname='Server-Cert'):
|
2012-10-11 02:32:17 -05:00
|
|
|
service.Service.__init__(self, "dirsrv",
|
|
|
|
service_desc="directory server",
|
|
|
|
dm_password=dm_password,
|
|
|
|
ldapi=False,
|
|
|
|
autobind=service.DISABLED
|
|
|
|
)
|
2013-03-15 04:09:58 -05:00
|
|
|
self.nickname = cert_nickname
|
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
|
2008-01-22 05:58:06 -06:00
|
|
|
self.pkcs12_info = 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
|
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:
|
|
|
|
self.fstore = sysrestore.FileStore('/var/lib/ipa/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)
|
2013-12-16 15:19:08 -06:00
|
|
|
self.step("configuring OTP last token plugin", self.__config_otp_lasttoken_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:
|
2012-09-19 22:35:42 -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)
|
|
|
|
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)
|
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()
|
|
|
|
self.serverid = realm_to_serverid(self.realm)
|
|
|
|
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)
|
|
|
|
|
|
|
|
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
|
|
|
|
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)
|
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,
|
2012-08-13 02:38:24 -05:00
|
|
|
IDRANGE_SIZE=idrange_size
|
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)
|
2010-11-17 11:25:01 -06:00
|
|
|
self.fstore.backup_file("/etc/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
|
|
|
|
|
|
|
target_fname = '/var/lib/dirsrv/boot.ldif'
|
|
|
|
base_fd = open(target_fname, "w")
|
|
|
|
base_fd.write(base_txt)
|
|
|
|
base_fd.close()
|
|
|
|
|
|
|
|
# Must be readable for dirsrv
|
|
|
|
os.chmod(target_fname, 0440)
|
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)
|
0000-12-31 18:09:24 -05:50
|
|
|
if ipautil.file_exists("/usr/sbin/setup-ds.pl"):
|
0000-12-31 18:09:24 -05:50
|
|
|
args = ["/usr/sbin/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:
|
2007-08-06 09:05:53 -05:00
|
|
|
args = ["/usr/bin/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")
|
2007-11-30 14:53:02 -06:00
|
|
|
except ipautil.CalledProcessError, 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")
|
2007-11-30 14:53:02 -06:00
|
|
|
except ipautil.CalledProcessError, 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()
|
|
|
|
os.remove("/var/lib/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)
|
|
|
|
os.chmod(target_fname, 0440) # read access for dirsrv user/group
|
|
|
|
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)
|
|
|
|
os.chmod(target_fname, 0440)
|
|
|
|
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)
|
|
|
|
except SystemExit, e:
|
|
|
|
raise e
|
|
|
|
except Exception, 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):
|
2011-11-23 15:52:40 -06:00
|
|
|
ld = ldapupdate.LDAPUpdate(dm_password=self.dm_password, sub_dict=self.sub_dict, plugins=True)
|
2008-09-15 19:51:01 -05:00
|
|
|
files = ld.get_all_files(ldapupdate.UPDATES_DIR)
|
2013-04-10 11:05:29 -05:00
|
|
|
ld.update(files, ordered=True)
|
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
|
|
|
|
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)
|
|
|
|
rv = ld.update(['/usr/share/ipa/schema_compat.uldif'])
|
|
|
|
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")
|
|
|
|
self._ldap_mod("uuid-ipauniqueid.ldif", self.sub_dict)
|
|
|
|
|
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")
|
|
|
|
|
2013-12-16 15:19:08 -06:00
|
|
|
def __config_otp_lasttoken_module(self):
|
|
|
|
self._ldap_mod("otp-lasttoken-conf.ldif")
|
|
|
|
|
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")
|
|
|
|
ccache = '/tmp/krb5cc_%d' % pent.pw_uid
|
|
|
|
filepath = '/etc/sysconfig/dirsrv'
|
|
|
|
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)
|
|
|
|
ipaservices.restore_context(filepath)
|
|
|
|
|
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()
|
|
|
|
|
2012-09-19 22:35:42 -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:
|
2013-03-26 09:31:07 -05:00
|
|
|
dsdb.create_from_pkcs12(self.pkcs12_info[0], self.pkcs12_info[1],
|
|
|
|
ca_file=self.ca_file)
|
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
|
|
|
|
nickname = server_certs[0][0]
|
2011-06-08 09:54:41 -05:00
|
|
|
self.dercert = dsdb.get_cert_from_db(nickname, pem=False)
|
0000-12-31 18:09:24 -05:50
|
|
|
else:
|
2013-03-15 04:09:58 -05:00
|
|
|
nickname = self.nickname
|
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(
|
|
|
|
nickname, self.fqdn, cadb)
|
2013-10-17 07:52:07 -05:00
|
|
|
dsdb.create_pin_file()
|
|
|
|
|
|
|
|
if self.ca_is_configured:
|
2013-03-27 08:25:18 -05:00
|
|
|
dsdb.track_server_cert(
|
|
|
|
nickname, self.principal, dsdb.passwd_fname,
|
|
|
|
'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"),
|
|
|
|
(ldap.MOD_REPLACE, "nsSSL3Ciphers",
|
|
|
|
"-rsa_null_md5,+rsa_rc4_128_md5,+rsa_rc4_40_md5,+rsa_rc2_40_md5,\
|
|
|
|
+rsa_des_sha,+rsa_fips_des_sha,+rsa_3des_sha,+rsa_fips_3des_sha,+fortezza,\
|
|
|
|
+fortezza_rc4_128_sha,+fortezza_null,+tls_rsa_export1024_with_rc4_56_sha,\
|
|
|
|
+tls_rsa_export1024_with_des_cbc_sha")]
|
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"],
|
|
|
|
nsSSLPersonalitySSL=[nickname],
|
|
|
|
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-03-14 07:58:27 -05:00
|
|
|
def export_ca_cert(self, nickname, location):
|
|
|
|
dirname = config_dirname(self.serverid)
|
|
|
|
dsdb = certs.NSSDatabase(nssdir=dirname)
|
|
|
|
dsdb.export_pem_cert(nickname, location)
|
|
|
|
|
|
|
|
def upload_ca_cert(self, cacert_name=None):
|
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)
|
2013-10-11 02:38:10 -05:00
|
|
|
certdb = certs.CertDB(self.realm, nssdir=dirname, subject_base=self.subject_base)
|
2012-11-12 16:43:05 -06:00
|
|
|
|
2013-03-14 07:58:27 -05:00
|
|
|
if cacert_name is None:
|
|
|
|
cacert_name = certdb.cacert_name
|
|
|
|
dercert = certdb.get_cert_from_db(cacert_name, pem=False)
|
|
|
|
self.upload_ca_dercert(dercert)
|
|
|
|
|
|
|
|
def upload_ca_dercert(self, dercert):
|
|
|
|
"""Upload the CA DER certificate to the LDAP directory
|
|
|
|
"""
|
|
|
|
# Note: Don't try to optimize if base64 data is already available.
|
|
|
|
# We want to re-encode using Python's b64encode to ensure the
|
|
|
|
# data is normalized (no extra newlines in the ldif)
|
2012-11-12 16:43:05 -06:00
|
|
|
self.sub_dict['CADERCERT'] = base64.b64encode(dercert)
|
|
|
|
|
|
|
|
self._ldap_mod('upload-cacert.ldif', self.sub_dict)
|
|
|
|
|
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)
|
|
|
|
|
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:
|
2010-10-13 11:21:48 -05:00
|
|
|
(dmpwdfd, dmpwdfile) = tempfile.mkstemp(dir='/var/lib/ipa')
|
|
|
|
os.write(dmpwdfd, self.dm_password)
|
|
|
|
os.close(dmpwdfd)
|
|
|
|
|
|
|
|
(admpwdfd, admpwdfile) = tempfile.mkstemp(dir='/var/lib/ipa')
|
|
|
|
os.write(admpwdfd, password)
|
|
|
|
os.close(admpwdfd)
|
|
|
|
|
2010-10-18 10:23:44 -05:00
|
|
|
args = ["/usr/bin/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")
|
2010-10-13 11:21:48 -05:00
|
|
|
except ipautil.CalledProcessError, e:
|
|
|
|
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:
|
2010-11-16 11:45:21 -06:00
|
|
|
self.fstore.restore_file("/etc/security/limits.conf")
|
2010-11-17 11:25:01 -06:00
|
|
|
self.fstore.restore_file("/etc/sysconfig/dirsrv")
|
|
|
|
except ValueError, error:
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.debug(error)
|
2010-11-17 11:25:01 -06:00
|
|
|
pass
|
|
|
|
|
2008-01-11 05:57:36 -06:00
|
|
|
if not enabled is None and not enabled:
|
2011-09-13 02:47:13 -05:00
|
|
|
self.disable()
|
2008-01-11 05:57:36 -06:00
|
|
|
|
|
|
|
serverid = self.restore_state("serverid")
|
|
|
|
if not serverid is None:
|
2013-03-26 12:06:50 -05:00
|
|
|
self.stop_tracking_certificates(serverid)
|
2008-01-11 05:57:36 -06:00
|
|
|
erase_ds_instance_data(serverid)
|
|
|
|
|
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:
|
2012-05-24 10:23:36 -05:00
|
|
|
ipaservices.knownservices.dirsrv.restart(ds_instance, wait=False)
|
2012-04-04 14:19:29 -05:00
|
|
|
except Exception, e:
|
|
|
|
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
|
|
|
|
except OSError, 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
|
|
|
|
2013-10-11 02:38:10 -05:00
|
|
|
dirname = config_dirname(realm_to_serverid(self.realm))
|
|
|
|
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:
|
|
|
|
certdb.load_cacert(cacert_fname)
|
2009-08-13 08:27:13 -05:00
|
|
|
except ipautil.CalledProcessError, 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
|
|
|
|
proceed = ipaservices.knownservices.dirsrv.tune_nofile_platform(
|
|
|
|
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)
|
|
|
|
|
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()
|