0000-12-31 18:09:24 -05:50
|
|
|
# Authors: Karl MacMillan <kmacmillan@mentalrootkit.com>
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007 Red Hat
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
2010-12-09 06:59:11 -06:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
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
|
|
|
#
|
|
|
|
|
2011-11-15 13:39:31 -06:00
|
|
|
import sys
|
2011-01-05 06:46:30 -06:00
|
|
|
import os, socket
|
2009-05-12 08:20:24 -05:00
|
|
|
import tempfile
|
2012-02-15 15:55:59 -06:00
|
|
|
import pwd
|
2013-01-21 05:05:07 -06:00
|
|
|
import time
|
|
|
|
import datetime
|
|
|
|
|
2013-01-31 05:59:35 -06:00
|
|
|
from ipapython import sysrestore, ipautil, dogtag, ipaldap
|
2011-09-12 16:01:23 -05:00
|
|
|
from ipapython import services as ipaservices
|
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
|
2011-11-15 13:39:31 -06:00
|
|
|
from ipapython.ipa_log_manager import *
|
2013-01-21 05:05:07 -06:00
|
|
|
from ipalib import errors
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2012-07-13 10:12:48 -05:00
|
|
|
# Autobind modes
|
|
|
|
AUTO = 1
|
|
|
|
ENABLED = 2
|
|
|
|
DISABLED = 3
|
|
|
|
|
2012-05-24 10:23:36 -05:00
|
|
|
# The service name as stored in cn=masters,cn=ipa,cn=etc. In the tuple
|
|
|
|
# the first value is the *nix service name, the second the start order.
|
2010-12-04 14:42:14 -06:00
|
|
|
SERVICE_LIST = {
|
2013-06-05 08:48:35 -05:00
|
|
|
'KDC': ('krb5kdc', 10),
|
|
|
|
'KPASSWD': ('kadmin', 20),
|
|
|
|
'DNS': ('named', 30),
|
|
|
|
'MEMCACHE': ('ipa_memcached', 39),
|
|
|
|
'HTTP': ('httpd', 40),
|
|
|
|
'CA': ('%sd' % dogtag.configured_constants().PKI_INSTANCE_NAME, 50),
|
|
|
|
'ADTRUST': ('smb', 60),
|
|
|
|
'EXTID': ('winbind', 70),
|
|
|
|
'OTPD': ('ipa-otpd', 80),
|
2010-12-04 14:42:14 -06:00
|
|
|
}
|
0000-12-31 18:09:24 -05:50
|
|
|
|
|
|
|
def print_msg(message, output_fd=sys.stdout):
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.debug(message)
|
0000-12-31 18:09:24 -05:50
|
|
|
output_fd.write(message)
|
|
|
|
output_fd.write("\n")
|
2013-06-10 07:13:35 -05:00
|
|
|
output_fd.flush()
|
2008-03-27 18:01:38 -05:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2014-03-12 06:59:46 -05:00
|
|
|
def format_seconds(seconds):
|
|
|
|
"""Format a number of seconds as an English minutes+seconds message"""
|
|
|
|
parts = []
|
|
|
|
minutes, seconds = divmod(seconds, 60)
|
|
|
|
if minutes:
|
|
|
|
parts.append('%d minute' % minutes)
|
|
|
|
if minutes != 1:
|
|
|
|
parts[-1] += 's'
|
|
|
|
if seconds or not minutes:
|
|
|
|
parts.append('%d second' % seconds)
|
|
|
|
if seconds != 1:
|
|
|
|
parts[-1] += 's'
|
|
|
|
return ' '.join(parts)
|
|
|
|
|
|
|
|
|
2011-04-27 05:37:04 -05:00
|
|
|
class Service(object):
|
2012-10-11 02:32:17 -05:00
|
|
|
def __init__(self, service_name, service_desc=None, sstore=None, dm_password=None, ldapi=True, autobind=AUTO):
|
0000-12-31 18:09:24 -05:50
|
|
|
self.service_name = service_name
|
2012-10-11 02:32:17 -05:00
|
|
|
self.service_desc = service_desc
|
2011-09-12 16:01:23 -05:00
|
|
|
self.service = ipaservices.service(service_name)
|
2007-12-13 03:31:28 -06:00
|
|
|
self.steps = []
|
0000-12-31 18:09:24 -05:50
|
|
|
self.output_fd = sys.stdout
|
2009-05-12 05:51:46 -05:00
|
|
|
self.dm_password = dm_password
|
2012-02-15 15:55:59 -06:00
|
|
|
self.ldapi = ldapi
|
2012-07-13 10:12:48 -05:00
|
|
|
self.autobind = autobind
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2011-01-05 06:46:30 -06:00
|
|
|
self.fqdn = socket.gethostname()
|
|
|
|
self.admin_conn = None
|
|
|
|
|
2008-03-31 16:27:56 -05:00
|
|
|
if sstore:
|
|
|
|
self.sstore = sstore
|
|
|
|
else:
|
|
|
|
self.sstore = sysrestore.StateFile('/var/lib/ipa/sysrestore')
|
|
|
|
|
2011-04-21 03:13:06 -05:00
|
|
|
self.realm = None
|
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()
|
2011-04-21 03:13:06 -05:00
|
|
|
self.principal = None
|
2011-06-08 09:54:41 -05:00
|
|
|
self.dercert = None
|
2011-04-21 03:13:06 -05:00
|
|
|
|
2011-01-05 06:46:30 -06:00
|
|
|
def ldap_connect(self):
|
2012-07-13 10:12:48 -05:00
|
|
|
# If DM password is provided, we use it
|
|
|
|
# If autobind was requested, attempt autobind when root and ldapi
|
|
|
|
# If autobind was disabled or not succeeded, go with GSSAPI
|
|
|
|
# LDAPI can be used with either autobind or GSSAPI
|
|
|
|
# LDAPI requires realm to be set
|
|
|
|
try:
|
|
|
|
if self.ldapi:
|
|
|
|
if not self.realm:
|
|
|
|
raise errors.NotFound(reason="realm is missing for %s" % (self))
|
|
|
|
conn = ipaldap.IPAdmin(ldapi=self.ldapi, realm=self.realm)
|
|
|
|
else:
|
|
|
|
conn = ipaldap.IPAdmin(self.fqdn, port=389)
|
|
|
|
if self.dm_password:
|
|
|
|
conn.do_simple_bind(bindpw=self.dm_password)
|
|
|
|
elif self.autobind in [AUTO, ENABLED]:
|
|
|
|
if os.getegid() == 0 and self.ldapi:
|
|
|
|
try:
|
|
|
|
# autobind
|
|
|
|
pw_name = pwd.getpwuid(os.geteuid()).pw_name
|
|
|
|
conn.do_external_bind(pw_name)
|
|
|
|
except errors.NotFound, e:
|
|
|
|
if self.autobind == AUTO:
|
|
|
|
# Fall back
|
|
|
|
conn.do_sasl_gssapi_bind()
|
|
|
|
else:
|
|
|
|
# autobind was required and failed, raise
|
|
|
|
# exception that it failed
|
|
|
|
raise e
|
|
|
|
else:
|
|
|
|
conn.do_sasl_gssapi_bind()
|
|
|
|
else:
|
|
|
|
conn.do_sasl_gssapi_bind()
|
|
|
|
except Exception, e:
|
|
|
|
root_logger.debug("Could not connect to the Directory Server on %s: %s" % (self.fqdn, str(e)))
|
2013-01-18 08:24:35 -06:00
|
|
|
raise
|
2012-07-13 10:12:48 -05:00
|
|
|
|
|
|
|
self.admin_conn = conn
|
|
|
|
|
2011-01-05 06:46:30 -06:00
|
|
|
def ldap_disconnect(self):
|
|
|
|
self.admin_conn.unbind()
|
|
|
|
self.admin_conn = None
|
|
|
|
|
2013-11-05 11:38:55 -06:00
|
|
|
def _ldap_mod(self, ldif, sub_dict=None):
|
2010-12-20 22:34:00 -06:00
|
|
|
pw_name = None
|
2009-05-12 05:51:46 -05:00
|
|
|
fd = None
|
|
|
|
path = ipautil.SHARE_DIR + ldif
|
2013-11-05 11:38:55 -06:00
|
|
|
nologlist = []
|
2009-05-12 05:51:46 -05:00
|
|
|
|
|
|
|
if sub_dict is not None:
|
|
|
|
txt = ipautil.template_file(path, sub_dict)
|
|
|
|
fd = ipautil.write_tmp_file(txt)
|
|
|
|
path = fd.name
|
|
|
|
|
2011-01-18 05:31:16 -06:00
|
|
|
# do not log passwords
|
2013-11-05 11:38:55 -06:00
|
|
|
if 'PASSWORD' in sub_dict:
|
2011-02-23 13:37:07 -06:00
|
|
|
nologlist.append(sub_dict['PASSWORD'])
|
2013-11-05 11:38:55 -06:00
|
|
|
if 'RANDOM_PASSWORD' in sub_dict:
|
2011-02-23 13:37:07 -06:00
|
|
|
nologlist.append(sub_dict['RANDOM_PASSWORD'])
|
2011-01-18 05:31:16 -06:00
|
|
|
|
2012-07-13 10:12:48 -05:00
|
|
|
args = ["/usr/bin/ldapmodify", "-v", "-f", path]
|
|
|
|
|
|
|
|
# As we always connect to the local host,
|
|
|
|
# use URI of admin connection
|
|
|
|
if not self.admin_conn:
|
|
|
|
self.ldap_connect()
|
2013-01-17 10:25:47 -06:00
|
|
|
args += ["-H", self.admin_conn.ldap_uri]
|
2012-07-13 10:12:48 -05:00
|
|
|
|
2013-11-05 11:38:55 -06:00
|
|
|
# If DM password is available, use it
|
2010-12-20 22:34:00 -06:00
|
|
|
if self.dm_password:
|
|
|
|
[pw_fd, pw_name] = tempfile.mkstemp()
|
|
|
|
os.write(pw_fd, self.dm_password)
|
|
|
|
os.close(pw_fd)
|
|
|
|
auth_parms = ["-x", "-D", "cn=Directory Manager", "-y", pw_name]
|
2013-11-05 11:38:55 -06:00
|
|
|
# Use GSSAPI auth when not using DM password or not being root
|
|
|
|
elif os.getegid() != 0:
|
|
|
|
auth_parms = ["-Y", "GSSAPI"]
|
|
|
|
# Default to EXTERNAL auth mechanism
|
2010-12-20 22:34:00 -06:00
|
|
|
else:
|
2013-11-05 11:38:55 -06:00
|
|
|
auth_parms = ["-Y", "EXTERNAL"]
|
2009-05-12 05:51:46 -05:00
|
|
|
|
2010-12-20 22:34:00 -06:00
|
|
|
args += auth_parms
|
2009-05-12 05:51:46 -05:00
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
2011-01-18 05:31:16 -06:00
|
|
|
ipautil.run(args, nolog=nologlist)
|
2009-05-12 05:51:46 -05:00
|
|
|
except ipautil.CalledProcessError, e:
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.critical("Failed to load %s: %s" % (ldif, str(e)))
|
2009-05-12 05:51:46 -05:00
|
|
|
finally:
|
2010-12-20 22:34:00 -06:00
|
|
|
if pw_name:
|
|
|
|
os.remove(pw_name)
|
2009-05-12 05:51:46 -05:00
|
|
|
|
|
|
|
if fd is not None:
|
|
|
|
fd.close()
|
|
|
|
|
2009-12-07 22:17:00 -06:00
|
|
|
def move_service(self, principal):
|
|
|
|
"""
|
|
|
|
Used to move a principal entry created by kadmin.local from
|
|
|
|
cn=kerberos to cn=services
|
|
|
|
"""
|
2011-01-05 06:46:30 -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
|
|
|
dn = DN(('krbprincipalname', principal), ('cn', self.realm), ('cn', 'kerberos'), self.suffix)
|
2009-12-07 22:17:00 -06:00
|
|
|
try:
|
2013-01-23 09:05:21 -06:00
|
|
|
entry = self.admin_conn.get_entry(dn)
|
2009-12-07 22:17:00 -06:00
|
|
|
except errors.NotFound:
|
|
|
|
# There is no service in the wrong location, nothing to do.
|
|
|
|
# This can happen when installing a replica
|
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
|
|
|
return None
|
|
|
|
newdn = DN(('krbprincipalname', principal), ('cn', 'services'), ('cn', 'accounts'), self.suffix)
|
|
|
|
hostdn = DN(('fqdn', self.fqdn), ('cn', 'computers'), ('cn', 'accounts'), self.suffix)
|
2013-01-23 08:35:55 -06:00
|
|
|
self.admin_conn.delete_entry(entry)
|
2009-12-07 22:17:00 -06:00
|
|
|
entry.dn = newdn
|
2013-01-21 03:34:44 -06:00
|
|
|
classes = entry.get("objectclass")
|
2009-12-07 22:17:00 -06:00
|
|
|
classes = classes + ["ipaobject", "ipaservice", "pkiuser"]
|
2013-01-21 03:42:16 -06:00
|
|
|
entry["objectclass"] = list(set(classes))
|
|
|
|
entry["ipauniqueid"] = ['autogenerate']
|
|
|
|
entry["managedby"] = [hostdn]
|
2013-01-23 08:27:05 -06:00
|
|
|
self.admin_conn.add_entry(entry)
|
2009-12-07 22:17:00 -06:00
|
|
|
return newdn
|
|
|
|
|
2011-03-14 15:27:19 -05:00
|
|
|
def add_simple_service(self, principal):
|
|
|
|
"""
|
|
|
|
Add a very basic IPA service.
|
|
|
|
|
|
|
|
The principal needs to be fully-formed: service/host@REALM
|
|
|
|
"""
|
|
|
|
if not self.admin_conn:
|
|
|
|
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(('krbprincipalname', principal), ('cn', 'services'), ('cn', 'accounts'), self.suffix)
|
|
|
|
hostdn = DN(('fqdn', self.fqdn), ('cn', 'computers'), ('cn', 'accounts'), self.suffix)
|
2013-01-18 08:24:35 -06:00
|
|
|
entry = self.admin_conn.make_entry(
|
|
|
|
dn,
|
|
|
|
objectclass=[
|
|
|
|
"krbprincipal", "krbprincipalaux", "krbticketpolicyaux",
|
|
|
|
"ipaobject", "ipaservice", "pkiuser"],
|
|
|
|
krbprincipalname=[principal],
|
|
|
|
ipauniqueid=['autogenerate'],
|
|
|
|
managedby=[hostdn],
|
|
|
|
)
|
2013-01-23 08:27:05 -06:00
|
|
|
self.admin_conn.add_entry(entry)
|
2011-03-14 15:27:19 -05:00
|
|
|
return dn
|
|
|
|
|
2009-12-07 22:17:00 -06:00
|
|
|
def add_cert_to_service(self):
|
|
|
|
"""
|
|
|
|
Add a certificate to a service
|
|
|
|
|
2011-06-08 09:54:41 -05:00
|
|
|
This server cert should be in DER format.
|
2009-12-07 22:17:00 -06:00
|
|
|
"""
|
2011-01-05 06:46:30 -06:00
|
|
|
|
2012-07-13 10:12:48 -05:00
|
|
|
# add_cert_to_service() is relatively rare operation
|
|
|
|
# we actually call it twice during ipa-server-install, for different
|
|
|
|
# instances: ds and cs. Unfortunately, it may happen that admin
|
|
|
|
# connection was created well before add_cert_to_service() is called
|
|
|
|
# If there are other operations in between, it will become stale and
|
|
|
|
# since we are using SimpleLDAPObject, not ReconnectLDAPObject, the
|
|
|
|
# action will fail. Thus, explicitly disconnect and connect again.
|
|
|
|
# Using ReconnectLDAPObject instead of SimpleLDAPObject was considered
|
|
|
|
# but consequences for other parts of the framework are largely
|
|
|
|
# unknown.
|
|
|
|
if self.admin_conn:
|
|
|
|
self.ldap_disconnect()
|
|
|
|
self.ldap_connect()
|
2011-01-05 06:46:30 -06:00
|
|
|
|
2013-01-30 08:51:08 -06:00
|
|
|
dn = DN(('krbprincipalname', self.principal), ('cn', 'services'),
|
|
|
|
('cn', 'accounts'), self.suffix)
|
|
|
|
entry = self.admin_conn.get_entry(dn)
|
|
|
|
entry.setdefault('userCertificate', []).append(self.dercert)
|
2009-12-07 22:17:00 -06:00
|
|
|
try:
|
2013-01-30 08:51:08 -06:00
|
|
|
self.admin_conn.update_entry(entry)
|
2009-12-07 22:17:00 -06:00
|
|
|
except Exception, e:
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.critical("Could not add certificate to service %s entry: %s" % (self.principal, str(e)))
|
2009-12-07 22:17:00 -06:00
|
|
|
|
2010-05-03 14:21:51 -05:00
|
|
|
def is_configured(self):
|
|
|
|
return self.sstore.has_state(self.service_name)
|
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
def set_output(self, fd):
|
|
|
|
self.output_fd = fd
|
2008-03-27 18:01:38 -05:00
|
|
|
|
2011-01-17 08:17:08 -06:00
|
|
|
def stop(self, instance_name="", capture_output=True):
|
2011-09-12 16:01:23 -05:00
|
|
|
self.service.stop(instance_name, capture_output=capture_output)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2012-05-24 10:23:36 -05:00
|
|
|
def start(self, instance_name="", capture_output=True, wait=True):
|
|
|
|
self.service.start(instance_name, capture_output=capture_output, wait=wait)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2012-05-24 10:23:36 -05:00
|
|
|
def restart(self, instance_name="", capture_output=True, wait=True):
|
|
|
|
self.service.restart(instance_name, capture_output=capture_output, wait=wait)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2008-01-11 04:36:25 -06:00
|
|
|
def is_running(self):
|
2011-09-12 16:01:23 -05:00
|
|
|
return self.service.is_running()
|
2008-01-11 04:36:25 -06:00
|
|
|
|
2011-09-12 16:01:23 -05:00
|
|
|
def install(self):
|
|
|
|
self.service.install()
|
2008-02-08 14:17:20 -06:00
|
|
|
|
2011-09-12 16:01:23 -05:00
|
|
|
def remove(self):
|
|
|
|
self.service.remove()
|
2008-02-08 14:17:20 -06:00
|
|
|
|
2011-09-12 16:01:23 -05:00
|
|
|
def enable(self):
|
|
|
|
self.service.enable()
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2011-09-12 16:01:23 -05:00
|
|
|
def disable(self):
|
|
|
|
self.service.disable()
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2008-01-11 04:36:25 -06:00
|
|
|
def is_enabled(self):
|
2011-09-12 16:01:23 -05:00
|
|
|
return self.service.is_enabled()
|
2008-01-11 04:36:25 -06:00
|
|
|
|
2008-01-14 11:43:26 -06:00
|
|
|
def backup_state(self, key, value):
|
2008-03-31 16:27:56 -05:00
|
|
|
self.sstore.backup_state(self.service_name, key, value)
|
2008-01-14 11:43:26 -06:00
|
|
|
|
2008-01-11 05:57:36 -06:00
|
|
|
def restore_state(self, key):
|
2008-03-31 16:27:56 -05:00
|
|
|
return self.sstore.restore_state(self.service_name, key)
|
2013-03-26 12:06:50 -05:00
|
|
|
|
|
|
|
def get_state(self, key):
|
|
|
|
return self.sstore.get_state(self.service_name, key)
|
2008-01-11 05:57:36 -06:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
def print_msg(self, message):
|
|
|
|
print_msg(message, self.output_fd)
|
|
|
|
|
2007-12-13 03:31:28 -06:00
|
|
|
def step(self, message, method):
|
|
|
|
self.steps.append((message, method))
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2012-10-11 02:32:17 -05:00
|
|
|
def start_creation(self, start_message=None, end_message=None,
|
|
|
|
show_service_name=True, runtime=-1):
|
|
|
|
"""
|
|
|
|
Starts creation of the service.
|
|
|
|
|
|
|
|
Use start_message and end_message for explicit messages
|
|
|
|
at the beggining / end of the process. Otherwise they are generated
|
|
|
|
using the service description (or service name, if the description has
|
|
|
|
not been provided).
|
|
|
|
|
|
|
|
Use show_service_name to include service name in generated descriptions.
|
|
|
|
"""
|
|
|
|
|
|
|
|
if start_message is None:
|
|
|
|
# no other info than mandatory service_name provided, use that
|
|
|
|
if self.service_desc is None:
|
|
|
|
start_message = "Configuring %s" % self.service_name
|
|
|
|
|
|
|
|
# description should be more accurate than service name
|
|
|
|
else:
|
|
|
|
start_message = "Configuring %s" % self.service_desc
|
|
|
|
if show_service_name:
|
|
|
|
start_message = "%s (%s)" % (start_message, self.service_name)
|
|
|
|
|
|
|
|
if end_message is None:
|
|
|
|
if self.service_desc is None:
|
|
|
|
if show_service_name:
|
|
|
|
end_message = "Done configuring %s." % self.service_name
|
|
|
|
else:
|
|
|
|
end_message = "Done."
|
|
|
|
else:
|
|
|
|
if show_service_name:
|
|
|
|
end_message = "Done configuring %s (%s)." % (
|
|
|
|
self.service_desc, self.service_name)
|
|
|
|
else:
|
|
|
|
end_message = "Done configuring %s." % self.service_desc
|
|
|
|
|
2010-09-29 12:55:54 -05:00
|
|
|
if runtime > 0:
|
2014-03-12 06:59:46 -05:00
|
|
|
self.print_msg('%s: Estimated time %s' % (start_message,
|
|
|
|
format_seconds(runtime)))
|
2010-09-29 12:55:54 -05:00
|
|
|
else:
|
2012-10-11 02:32:17 -05:00
|
|
|
self.print_msg(start_message)
|
2007-12-13 03:31:28 -06:00
|
|
|
|
|
|
|
step = 0
|
|
|
|
for (message, method) in self.steps:
|
2008-02-28 20:57:52 -06:00
|
|
|
self.print_msg(" [%d/%d]: %s" % (step+1, len(self.steps), message))
|
2010-09-29 12:55:54 -05:00
|
|
|
s = datetime.datetime.now()
|
2007-12-13 03:31:28 -06:00
|
|
|
method()
|
2010-09-29 12:55:54 -05:00
|
|
|
e = datetime.datetime.now()
|
|
|
|
d = e - s
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.debug(" duration: %d seconds" % d.seconds)
|
2007-12-13 03:31:28 -06:00
|
|
|
step += 1
|
2008-03-27 18:01:38 -05:00
|
|
|
|
2012-10-11 02:32:17 -05:00
|
|
|
self.print_msg(end_message)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2007-12-13 03:31:28 -06:00
|
|
|
self.steps = []
|
2008-01-22 05:58:06 -06:00
|
|
|
|
2010-12-04 14:42:14 -06:00
|
|
|
def ldap_enable(self, name, fqdn, dm_password, ldap_suffix):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(ldap_suffix, DN)
|
2011-09-12 16:01:23 -05:00
|
|
|
self.disable()
|
2012-02-15 15:55:59 -06:00
|
|
|
if not self.admin_conn:
|
|
|
|
self.ldap_connect()
|
2010-12-04 14:42:14 -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
|
|
|
entry_name = DN(('cn', name), ('cn', fqdn), ('cn', 'masters'), ('cn', 'ipa'), ('cn', 'etc'), ldap_suffix)
|
2010-12-04 14:42:14 -06:00
|
|
|
order = SERVICE_LIST[name][1]
|
2013-01-18 08:24:35 -06:00
|
|
|
entry = self.admin_conn.make_entry(
|
|
|
|
entry_name,
|
|
|
|
objectclass=["nsContainer", "ipaConfigObject"],
|
|
|
|
cn=[name],
|
|
|
|
ipaconfigstring=[
|
|
|
|
"enabledService", "startOrder " + str(order)],
|
|
|
|
)
|
2010-12-04 14:42:14 -06:00
|
|
|
|
|
|
|
try:
|
2013-01-23 08:27:05 -06:00
|
|
|
self.admin_conn.add_entry(entry)
|
2013-01-30 08:51:08 -06:00
|
|
|
except (errors.DuplicateEntry), e:
|
2012-02-15 15:55:59 -06:00
|
|
|
root_logger.debug("failed to add %s Service startup entry" % name)
|
2010-12-04 14:42:14 -06:00
|
|
|
raise e
|
|
|
|
|
2008-01-22 05:58:06 -06:00
|
|
|
class SimpleServiceInstance(Service):
|
2012-07-13 10:12:48 -05:00
|
|
|
def create_instance(self, gensvc_name=None, fqdn=None, dm_password=None, ldap_suffix=None, realm=None):
|
2010-12-04 14:42:14 -06:00
|
|
|
self.gensvc_name = gensvc_name
|
|
|
|
self.fqdn = fqdn
|
|
|
|
self.dm_password = dm_password
|
|
|
|
self.suffix = ldap_suffix
|
2012-07-13 10:12:48 -05:00
|
|
|
self.realm = realm
|
|
|
|
if not realm:
|
|
|
|
self.ldapi = False
|
2010-12-04 14:42:14 -06:00
|
|
|
|
2008-01-22 05:58:06 -06:00
|
|
|
self.step("starting %s " % self.service_name, self.__start)
|
|
|
|
self.step("configuring %s to start on boot" % self.service_name, self.__enable)
|
|
|
|
self.start_creation("Configuring %s" % self.service_name)
|
|
|
|
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
suffix = ipautil.dn_attribute_property('_ldap_suffix')
|
|
|
|
|
2008-01-22 05:58:06 -06:00
|
|
|
def __start(self):
|
|
|
|
self.backup_state("running", self.is_running())
|
|
|
|
self.restart()
|
|
|
|
|
|
|
|
def __enable(self):
|
2011-09-12 16:01:23 -05:00
|
|
|
self.enable()
|
2008-01-22 05:58:06 -06:00
|
|
|
self.backup_state("enabled", self.is_enabled())
|
2010-12-04 14:42:14 -06:00
|
|
|
if self.gensvc_name == None:
|
2011-09-12 16:01:23 -05:00
|
|
|
self.enable()
|
2010-12-04 14:42:14 -06:00
|
|
|
else:
|
|
|
|
self.ldap_enable(self.gensvc_name, self.fqdn,
|
|
|
|
self.dm_password, self.suffix)
|
2008-01-22 05:58:06 -06:00
|
|
|
|
|
|
|
def uninstall(self):
|
2010-05-03 14:21:51 -05:00
|
|
|
if self.is_configured():
|
|
|
|
self.print_msg("Unconfiguring %s" % self.service_name)
|
|
|
|
|
2008-01-22 05:58:06 -06:00
|
|
|
running = self.restore_state("running")
|
|
|
|
enabled = not self.restore_state("enabled")
|
|
|
|
|
|
|
|
if not running is None and not running:
|
|
|
|
self.stop()
|
|
|
|
if not enabled is None and not enabled:
|
2011-09-12 16:01:23 -05:00
|
|
|
self.disable()
|
|
|
|
self.remove()
|