2011-09-07 03:17:12 -05:00
|
|
|
# Authors: Sumit Bose <sbose@redhat.com>
|
|
|
|
#
|
|
|
|
# Copyright (C) 2011 Red Hat
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
|
|
|
import errno
|
|
|
|
import ldap
|
|
|
|
import tempfile
|
2011-11-07 05:48:10 -06:00
|
|
|
import uuid
|
2011-09-07 03:17:12 -05:00
|
|
|
from ipaserver import ipaldap
|
2011-11-07 05:59:20 -06:00
|
|
|
from ipaserver.install import installutils
|
|
|
|
from ipaserver.install import service
|
2011-09-07 03:17:12 -05:00
|
|
|
from ipaserver.install.dsinstance import realm_to_serverid
|
2011-10-13 05:01:57 -05:00
|
|
|
from ipaserver.install.bindinstance import get_rr, add_rr, del_rr, \
|
|
|
|
dns_zone_exists
|
|
|
|
from ipalib import errors, api
|
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-09-07 03:17:12 -05:00
|
|
|
from ipapython import sysrestore
|
|
|
|
from ipapython import ipautil
|
2011-11-15 13:39:31 -06:00
|
|
|
from ipapython.ipa_log_manager import *
|
2012-03-27 05:06:33 -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-09-07 03:17:12 -05:00
|
|
|
|
2012-09-07 05:40:58 -05:00
|
|
|
import ipaclient.ipachangeconf
|
|
|
|
|
2011-09-07 03:17:12 -05:00
|
|
|
import string
|
|
|
|
import struct
|
2012-09-07 05:40:58 -05:00
|
|
|
import re
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2011-11-07 05:59:20 -06:00
|
|
|
ALLOWED_NETBIOS_CHARS = string.ascii_uppercase + string.digits
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2012-05-30 04:54:01 -05:00
|
|
|
SELINUX_WARNING = """
|
|
|
|
WARNING: could not set selinux boolean(s) %(var)s to true. The adtrust
|
|
|
|
service may not function correctly until this boolean is successfully
|
|
|
|
change with the command:
|
|
|
|
/usr/sbin/setsebool -P %(var)s true
|
|
|
|
Try updating the policycoreutils and selinux-policy packages.
|
|
|
|
"""
|
|
|
|
|
2011-11-07 05:59:20 -06:00
|
|
|
def check_inst():
|
|
|
|
for smbfile in ['/usr/sbin/smbd', '/usr/bin/net', '/usr/bin/smbpasswd']:
|
|
|
|
if not os.path.exists(smbfile):
|
|
|
|
print "%s was not found on this system" % file
|
|
|
|
print "Please install the 'samba' packages and " \
|
|
|
|
"start the installation again"
|
2011-09-07 03:17:12 -05:00
|
|
|
return False
|
|
|
|
|
|
|
|
#TODO: Add check for needed samba4 libraries
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
def ipa_smb_conf_exists():
|
|
|
|
try:
|
2011-11-07 05:59:20 -06:00
|
|
|
conf_fd = open('/etc/samba/smb.conf', 'r')
|
|
|
|
except IOError, err:
|
|
|
|
if err.errno == errno.ENOENT:
|
2011-09-07 03:17:12 -05:00
|
|
|
return False
|
|
|
|
|
2011-11-07 05:59:20 -06:00
|
|
|
lines = conf_fd.readlines()
|
|
|
|
conf_fd.close()
|
2011-09-07 03:17:12 -05:00
|
|
|
for line in lines:
|
|
|
|
if line.startswith('### Added by IPA Installer ###'):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def check_netbios_name(s):
|
|
|
|
# NetBIOS names may not be longer than 15 allowed characters
|
2011-11-07 05:59:20 -06:00
|
|
|
if not s or len(s) > 15 or \
|
|
|
|
''.join([c for c in s if c not in ALLOWED_NETBIOS_CHARS]):
|
2011-09-07 03:17:12 -05:00
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
def make_netbios_name(s):
|
2011-11-07 05:59:20 -06:00
|
|
|
return ''.join([c for c in s.split('.')[0].upper() \
|
|
|
|
if c in ALLOWED_NETBIOS_CHARS])[:15]
|
2011-09-07 03:17:12 -05:00
|
|
|
|
|
|
|
class ADTRUSTInstance(service.Service):
|
2011-11-07 05:48:10 -06:00
|
|
|
|
|
|
|
ATTR_SID = "ipaNTSecurityIdentifier"
|
|
|
|
ATTR_FLAT_NAME = "ipaNTFlatName"
|
|
|
|
ATTR_GUID = "ipaNTDomainGUID"
|
|
|
|
OBJC_USER = "ipaNTUserAttrs"
|
|
|
|
OBJC_GROUP = "ipaNTGroupAttrs"
|
|
|
|
OBJC_DOMAIN = "ipaNTDomainAttrs"
|
|
|
|
|
2012-07-13 10:12:48 -05:00
|
|
|
def __init__(self, fstore=None):
|
2011-11-07 05:59:20 -06:00
|
|
|
self.fqdn = None
|
|
|
|
self.ip_address = None
|
2012-09-07 05:40:58 -05:00
|
|
|
self.realm = None
|
2011-11-07 05:59:20 -06:00
|
|
|
self.domain_name = None
|
|
|
|
self.netbios_name = None
|
|
|
|
self.no_msdcs = None
|
|
|
|
self.smbd_user = 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-11-07 05:59:20 -06:00
|
|
|
self.ldapi_socket = None
|
|
|
|
self.smb_conf = None
|
|
|
|
self.smb_dn = None
|
|
|
|
self.smb_dn_pwd = None
|
|
|
|
self.trust_dn = None
|
|
|
|
self.smb_dom_dn = None
|
|
|
|
self.sub_dict = None
|
2012-05-15 12:03:16 -05:00
|
|
|
self.cifs_principal = None
|
|
|
|
self.cifs_agent = None
|
2012-05-30 04:54:01 -05:00
|
|
|
self.selinux_booleans = None
|
2012-06-12 10:53:36 -05:00
|
|
|
self.rid_base = None
|
|
|
|
self.secondary_rid_base = None
|
2011-11-07 05:59:20 -06:00
|
|
|
|
2012-07-13 10:12:48 -05:00
|
|
|
service.Service.__init__(self, "smb", dm_password=None, ldapi=True)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
|
|
|
if fstore:
|
|
|
|
self.fstore = fstore
|
|
|
|
else:
|
|
|
|
self.fstore = sysrestore.FileStore('/var/lib/ipa/sysrestore')
|
|
|
|
|
|
|
|
def __gen_sid_string(self):
|
|
|
|
sub_ids = struct.unpack("<LLL", os.urandom(12))
|
|
|
|
return "S-1-5-21-%d-%d-%d" % (sub_ids[0], sub_ids[1], sub_ids[2])
|
|
|
|
|
2011-09-23 08:11:23 -05:00
|
|
|
def __add_admin_sids(self):
|
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
|
|
|
admin_dn = DN(('uid', 'admin'), api.env.container_user,
|
|
|
|
self.suffix)
|
|
|
|
admin_group_dn = DN(('cn', 'admins'), api.env.container_group,
|
|
|
|
self.suffix)
|
2011-09-23 08:11:23 -05:00
|
|
|
try:
|
|
|
|
dom_entry = self.admin_conn.getEntry(self.smb_dom_dn, \
|
|
|
|
ldap.SCOPE_BASE)
|
|
|
|
except errors.NotFound:
|
|
|
|
print "Samba domain object not found"
|
|
|
|
return
|
|
|
|
|
2011-11-07 05:48:10 -06:00
|
|
|
dom_sid = dom_entry.getValue(self.ATTR_SID)
|
2011-09-23 08:11:23 -05:00
|
|
|
if not dom_sid:
|
|
|
|
print "Samba domain object does not have a SID"
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
admin_entry = self.admin_conn.getEntry(admin_dn, ldap.SCOPE_BASE)
|
|
|
|
except:
|
|
|
|
print "IPA admin object not found"
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
admin_group_entry = self.admin_conn.getEntry(admin_group_dn, \
|
|
|
|
ldap.SCOPE_BASE)
|
|
|
|
except:
|
|
|
|
print "IPA admin group object not found"
|
|
|
|
return
|
|
|
|
|
2011-11-07 05:48:10 -06:00
|
|
|
if admin_entry.getValue(self.ATTR_SID) or \
|
|
|
|
admin_group_entry.getValue(self.ATTR_SID):
|
2011-09-23 08:11:23 -05:00
|
|
|
print "Admin SID already set, nothing to do"
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.admin_conn.modify_s(admin_dn, \
|
2011-11-07 05:48:10 -06:00
|
|
|
[(ldap.MOD_ADD, "objectclass", self.OBJC_USER), \
|
|
|
|
(ldap.MOD_ADD, self.ATTR_SID, dom_sid + "-500")])
|
2011-09-23 08:11:23 -05:00
|
|
|
except:
|
|
|
|
print "Failed to modify IPA admin object"
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.admin_conn.modify_s(admin_group_dn, \
|
2011-11-07 05:48:10 -06:00
|
|
|
[(ldap.MOD_ADD, "objectclass", self.OBJC_GROUP), \
|
|
|
|
(ldap.MOD_ADD, self.ATTR_SID, dom_sid + "-512")])
|
2011-09-23 08:11:23 -05:00
|
|
|
except:
|
|
|
|
print "Failed to modify IPA admin group object"
|
|
|
|
|
2012-06-12 10:53:36 -05:00
|
|
|
def __add_rid_bases(self):
|
|
|
|
"""
|
|
|
|
Add RID bases to the range object for the local ID range.
|
|
|
|
|
|
|
|
TODO: handle missing or multiple ranges more gracefully.
|
|
|
|
"""
|
|
|
|
|
|
|
|
try:
|
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
|
|
|
res = self.admin_conn.getList(DN(api.env.container_ranges, self.suffix),
|
|
|
|
ldap.SCOPE_ONELEVEL,
|
|
|
|
"(objectclass=ipaDomainIDRange)")
|
2012-06-12 10:53:36 -05:00
|
|
|
if len(res) != 1:
|
|
|
|
root_logger.critical("Found more than one ID range for the " \
|
|
|
|
"local domain.")
|
|
|
|
raise RuntimeError("Too many ID ranges\n")
|
|
|
|
|
|
|
|
if res[0].getValue('ipaBaseRID') or \
|
|
|
|
res[0].getValue('ipaSecondaryBaseRID'):
|
|
|
|
print "RID bases already set, nothing to do"
|
|
|
|
return
|
|
|
|
|
|
|
|
size = res[0].getValue('ipaIDRangeSize')
|
|
|
|
if abs(self.rid_base - self.secondary_rid_base) > size:
|
|
|
|
print "Primary and secondary RID base are too close. " \
|
|
|
|
"They have to differ at least by %d." % size
|
|
|
|
raise RuntimeError("RID bases too close.\n")
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.admin_conn.modify_s(res[0].dn,
|
|
|
|
[(ldap.MOD_ADD, "ipaBaseRID", \
|
|
|
|
str(self.rid_base)), \
|
|
|
|
(ldap.MOD_ADD, "ipaSecondaryBaseRID", \
|
|
|
|
str(self.secondary_rid_base))])
|
|
|
|
except:
|
|
|
|
print "Failed to add RID bases to the local range object"
|
|
|
|
|
|
|
|
except errors.NotFound as e:
|
|
|
|
root_logger.critical("ID range of the local domain not found, " \
|
|
|
|
"define it and run again.")
|
|
|
|
raise e
|
|
|
|
|
2011-09-07 03:17:12 -05:00
|
|
|
def __create_samba_domain_object(self):
|
|
|
|
|
|
|
|
try:
|
2011-09-23 08:11:23 -05:00
|
|
|
self.admin_conn.getEntry(self.smb_dom_dn, ldap.SCOPE_BASE)
|
2012-02-28 05:24:41 -06:00
|
|
|
root_logger.info("Samba domain object already exists")
|
2011-09-07 03:17:12 -05:00
|
|
|
return
|
|
|
|
except errors.NotFound:
|
|
|
|
pass
|
|
|
|
|
2011-11-07 04:56:57 -06:00
|
|
|
for new_dn in (self.trust_dn, \
|
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(('cn', 'ad'), self.trust_dn), \
|
|
|
|
DN(api.env.container_cifsdomains, self.suffix)):
|
2011-11-07 04:56:57 -06:00
|
|
|
try:
|
2011-11-07 05:59:20 -06:00
|
|
|
self.admin_conn.getEntry(new_dn, ldap.SCOPE_BASE)
|
2011-11-07 04:56:57 -06:00
|
|
|
except errors.NotFound:
|
2011-11-07 05:59:20 -06:00
|
|
|
entry = ipaldap.Entry(new_dn)
|
2011-11-07 04:56:57 -06:00
|
|
|
entry.setValues("objectclass", ["nsContainer"])
|
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
|
|
|
try:
|
|
|
|
name = new_dn[1].attr
|
|
|
|
except Exception, e:
|
|
|
|
print 'Cannot extract RDN attribute value from "%s": %s' % \
|
|
|
|
(new_dn, e)
|
2011-11-07 04:56:57 -06:00
|
|
|
return
|
|
|
|
entry.setValues("cn", name)
|
|
|
|
self.admin_conn.addEntry(entry)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2011-09-23 08:11:23 -05:00
|
|
|
entry = ipaldap.Entry(self.smb_dom_dn)
|
2011-11-07 05:48:10 -06:00
|
|
|
entry.setValues("objectclass", [self.OBJC_DOMAIN, "nsContainer"])
|
2011-11-07 04:56:57 -06:00
|
|
|
entry.setValues("cn", self.domain_name)
|
2011-11-07 05:48:10 -06:00
|
|
|
entry.setValues(self.ATTR_FLAT_NAME, self.netbios_name)
|
|
|
|
entry.setValues(self.ATTR_SID, self.__gen_sid_string())
|
|
|
|
entry.setValues(self.ATTR_GUID, str(uuid.uuid4()))
|
2011-09-07 03:17:12 -05:00
|
|
|
#TODO: which MAY attributes do we want to set ?
|
2011-11-07 05:59:20 -06:00
|
|
|
self.admin_conn.addEntry(entry)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
|
|
|
def __write_smb_conf(self):
|
|
|
|
self.fstore.backup_file(self.smb_conf)
|
|
|
|
|
2011-11-07 05:59:20 -06:00
|
|
|
conf_fd = open(self.smb_conf, "w")
|
|
|
|
conf_fd.write('### Added by IPA Installer ###\n')
|
|
|
|
conf_fd.write('[global]\n')
|
|
|
|
conf_fd.write('config backend = registry\n')
|
|
|
|
conf_fd.close()
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2011-11-18 07:04:09 -06:00
|
|
|
def __add_cldap_module(self):
|
2012-02-28 05:23:51 -06:00
|
|
|
try:
|
|
|
|
self._ldap_mod("ipa-cldap-conf.ldif", self.sub_dict)
|
|
|
|
except:
|
|
|
|
pass
|
2011-11-18 07:04:09 -06:00
|
|
|
|
2012-06-21 05:54:34 -05:00
|
|
|
def __add_sidgen_module(self):
|
|
|
|
try:
|
|
|
|
self._ldap_mod("ipa-sidgen-conf.ldif", self.sub_dict)
|
|
|
|
self._ldap_mod("ipa-sidgen-task-conf.ldif", self.sub_dict)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2011-11-30 06:29:10 -06:00
|
|
|
def __add_extdom_module(self):
|
|
|
|
try:
|
|
|
|
self._ldap_mod("ipa-extdom-extop-conf.ldif", self.sub_dict)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2011-09-07 03:17:12 -05:00
|
|
|
def __write_smb_registry(self):
|
|
|
|
template = os.path.join(ipautil.SHARE_DIR, "smb.conf.template")
|
|
|
|
conf = ipautil.template_file(template, self.sub_dict)
|
2011-11-07 05:59:20 -06:00
|
|
|
[tmp_fd, tmp_name] = tempfile.mkstemp()
|
|
|
|
os.write(tmp_fd, conf)
|
|
|
|
os.close(tmp_fd)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
|
|
|
args = ["/usr/bin/net", "conf", "import", tmp_name]
|
|
|
|
|
|
|
|
try:
|
|
|
|
ipautil.run(args)
|
|
|
|
finally:
|
|
|
|
os.remove(tmp_name)
|
|
|
|
|
|
|
|
def __setup_principal(self):
|
2012-02-28 05:24:41 -06:00
|
|
|
try:
|
2012-05-15 12:03:16 -05:00
|
|
|
api.Command.service_add(unicode(self.cifs_principal))
|
|
|
|
# Add the principal to the 'adtrust agents' group
|
|
|
|
# as 389-ds only operates with GroupOfNames, we have to use
|
|
|
|
# the principal's proper dn as defined in self.cifs_agent
|
|
|
|
entry = self.admin_conn.getEntry(self.smb_dn, ldap.SCOPE_BASE)
|
|
|
|
current = ipaldap.Entry(self.smb_dn, entry.toDict())
|
|
|
|
if not('member' in current):
|
|
|
|
current['member'] = []
|
|
|
|
entry.setValues("member", current['member'] + [self.cifs_agent])
|
|
|
|
self.admin_conn.updateEntry(self.smb_dn, current, entry)
|
2012-03-27 05:06:33 -05:00
|
|
|
except Exception, e:
|
2012-02-28 05:24:41 -06:00
|
|
|
# CIFS principal already exists, it is not the first time adtrustinstance is managed
|
|
|
|
# That's fine, we we'll re-extract the key again.
|
|
|
|
pass
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2012-02-28 05:23:51 -06:00
|
|
|
samba_keytab = "/etc/samba/samba.keytab"
|
|
|
|
if os.path.exists(samba_keytab):
|
|
|
|
try:
|
2012-05-15 12:03:16 -05:00
|
|
|
ipautil.run(["ipa-rmkeytab", "--principal", self.cifs_principal,
|
2012-02-28 05:23:51 -06:00
|
|
|
"-k", samba_keytab])
|
|
|
|
except ipautil.CalledProcessError, e:
|
|
|
|
if e.returncode != 5:
|
2012-05-15 12:03:16 -05:00
|
|
|
root_logger.critical("Failed to remove old key for %s" % self.cifs_principal)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
|
|
|
try:
|
|
|
|
ipautil.run(["ipa-getkeytab", "--server", self.fqdn,
|
2012-05-15 12:03:16 -05:00
|
|
|
"--principal", self.cifs_principal,
|
2012-02-28 05:23:51 -06:00
|
|
|
"-k", samba_keytab])
|
2011-09-07 03:17:12 -05:00
|
|
|
except ipautil.CalledProcessError, e:
|
2012-05-15 12:03:16 -05:00
|
|
|
root_logger.critical("Failed to add key for %s" % self.cifs_principal)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2011-10-13 05:01:57 -05:00
|
|
|
def __add_dns_service_records(self):
|
|
|
|
"""
|
|
|
|
Add DNS service records for Windows if DNS is enabled and the DNS zone
|
|
|
|
is managed. If there are already service records for LDAP and Kerberos
|
|
|
|
their values are used. Otherwise default values are used.
|
|
|
|
"""
|
|
|
|
|
|
|
|
zone = self.domain_name
|
|
|
|
host = self.fqdn.split(".")[0]
|
|
|
|
|
|
|
|
ipa_srv_rec = (
|
|
|
|
("_ldap._tcp", ["0 100 389 %s" % host]),
|
|
|
|
("_kerberos._tcp", ["0 100 88 %s" % host]),
|
|
|
|
("_kerberos._udp", ["0 100 88 %s" % host])
|
|
|
|
)
|
|
|
|
win_srv_suffix = (".Default-First-Site-Name._sites.dc._msdcs",
|
|
|
|
".dc._msdcs")
|
|
|
|
|
|
|
|
err_msg = None
|
2011-11-07 05:59:20 -06:00
|
|
|
ret = api.Command['dns_is_enabled']()
|
2011-10-13 05:01:57 -05:00
|
|
|
if not ret['result']:
|
|
|
|
err_msg = "DNS management was not enabled at install time."
|
|
|
|
else:
|
|
|
|
if not dns_zone_exists(zone):
|
|
|
|
err_msg = "DNS zone %s cannot be managed " \
|
|
|
|
"as it is not defined in IPA" % zone
|
|
|
|
|
|
|
|
if err_msg:
|
|
|
|
print err_msg
|
|
|
|
print "Add the following service records to your DNS server " \
|
|
|
|
"for DNS zone %s: " % zone
|
|
|
|
for (srv, rdata) in ipa_srv_rec:
|
|
|
|
for suff in win_srv_suffix:
|
|
|
|
print " - %s%s" % (srv, suff)
|
|
|
|
return
|
|
|
|
|
|
|
|
for (srv, rdata) in ipa_srv_rec:
|
|
|
|
ipa_rdata = get_rr(zone, srv, "SRV")
|
|
|
|
if not ipa_rdata:
|
|
|
|
ipa_rdata = rdata
|
|
|
|
|
|
|
|
for suff in win_srv_suffix:
|
|
|
|
win_srv = srv+suff
|
|
|
|
win_rdata = get_rr(zone, win_srv, "SRV")
|
|
|
|
if win_rdata:
|
|
|
|
for rec in win_rdata:
|
|
|
|
del_rr(zone, win_srv, "SRV", rec)
|
|
|
|
for rec in ipa_rdata:
|
|
|
|
add_rr(zone, win_srv, "SRV", rec)
|
|
|
|
|
2012-05-30 04:54:01 -05:00
|
|
|
def __configure_selinux_for_smbd(self):
|
|
|
|
selinux = False
|
|
|
|
try:
|
|
|
|
if (os.path.exists('/usr/sbin/selinuxenabled')):
|
|
|
|
ipautil.run(["/usr/sbin/selinuxenabled"])
|
|
|
|
selinux = True
|
|
|
|
except ipautil.CalledProcessError:
|
|
|
|
# selinuxenabled returns 1 if not enabled
|
|
|
|
pass
|
|
|
|
|
|
|
|
if selinux:
|
|
|
|
# Don't assume all booleans are available
|
|
|
|
sebools = []
|
|
|
|
for var in self.selinux_booleans:
|
|
|
|
try:
|
|
|
|
(stdout, stderr, returncode) = ipautil.run(["/usr/sbin/getsebool", var])
|
|
|
|
if stdout and not stderr and returncode == 0:
|
|
|
|
self.backup_state(var, stdout.split()[2])
|
|
|
|
sebools.append(var)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if sebools:
|
|
|
|
bools = [var + "=true" for var in sebools]
|
|
|
|
args = ["/usr/sbin/setsebool", "-P"]
|
|
|
|
args.extend(bools);
|
|
|
|
try:
|
|
|
|
ipautil.run(args)
|
|
|
|
except:
|
|
|
|
self.print_msg(SELINUX_WARNING % dict(var=','.join(sebools)))
|
|
|
|
|
2012-09-07 05:40:58 -05:00
|
|
|
def __mod_krb5_conf(self):
|
|
|
|
"""
|
|
|
|
Set dns_lookup_kdc to true and master_kdc in /etc/krb5.conf
|
|
|
|
"""
|
|
|
|
|
|
|
|
if not self.fqdn or not self.realm:
|
|
|
|
self.print_msg("Cannot modify /etc/krb5.conf")
|
|
|
|
|
|
|
|
krbconf = ipaclient.ipachangeconf.IPAChangeConf("IPA Installer")
|
|
|
|
krbconf.setOptionAssignment(" = ")
|
|
|
|
krbconf.setSectionNameDelimiters(("[", "]"))
|
|
|
|
krbconf.setSubSectionDelimiters(("{", "}"))
|
|
|
|
krbconf.setIndent(("", " ", " "))
|
|
|
|
|
|
|
|
libopts = [{'name':'dns_lookup_kdc', 'type':'option', 'action':'set',
|
|
|
|
'value':'true'}]
|
|
|
|
|
|
|
|
master_kdc = self.fqdn + ":88"
|
|
|
|
kropts = [{'name':'master_kdc', 'type':'option', 'action':'set',
|
|
|
|
'value':master_kdc}]
|
|
|
|
|
|
|
|
ropts = [{'name':self.realm, 'type':'subsection', 'action':'set',
|
|
|
|
'value':kropts}]
|
|
|
|
|
|
|
|
opts = [{'name':'libdefaults', 'type':'section', 'action':'set',
|
|
|
|
'value':libopts},
|
|
|
|
{'name':'realms', 'type':'section', 'action':'set',
|
|
|
|
'value':ropts}]
|
|
|
|
|
|
|
|
krbconf.changeConf("/etc/krb5.conf", opts)
|
|
|
|
|
|
|
|
def __update_krb5_conf(self):
|
|
|
|
"""
|
|
|
|
Update /etc/krb5.conf if needed
|
|
|
|
"""
|
|
|
|
|
|
|
|
try:
|
|
|
|
krb5conf = open("/etc/krb5.conf", 'r')
|
|
|
|
except IOError, e:
|
|
|
|
self.print_msg("Cannot open /etc/krb5.conf (%s)\n" % str(e))
|
|
|
|
return
|
|
|
|
|
|
|
|
has_dns_lookup_kdc_true = False
|
|
|
|
for line in krb5conf:
|
|
|
|
if re.match("^\s*dns_lookup_kdc\s*=\s*[Tt][Rr][Uu][Ee]\s*$", line):
|
|
|
|
has_dns_lookup_kdc_true = True
|
|
|
|
break
|
|
|
|
krb5conf.close()
|
|
|
|
|
|
|
|
if not has_dns_lookup_kdc_true:
|
|
|
|
self.__mod_krb5_conf()
|
|
|
|
else:
|
|
|
|
self.print_msg("'dns_lookup_kdc' already set to 'true', "
|
|
|
|
"nothing to do.")
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-09-07 03:17:12 -05:00
|
|
|
def __start(self):
|
|
|
|
try:
|
|
|
|
self.start()
|
2011-11-30 06:29:10 -06:00
|
|
|
ipaservices.service('winbind').start()
|
2011-09-07 03:17:12 -05:00
|
|
|
except:
|
2011-11-30 06:29:10 -06:00
|
|
|
root_logger.critical("CIFS services failed to start")
|
2011-09-07 03:17:12 -05:00
|
|
|
|
|
|
|
def __stop(self):
|
|
|
|
self.backup_state("running", self.is_running())
|
|
|
|
try:
|
|
|
|
self.stop()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2012-06-21 08:04:10 -05:00
|
|
|
def __restart_dirsrv(self):
|
2012-03-27 05:06:33 -05:00
|
|
|
try:
|
2012-06-21 08:04:10 -05:00
|
|
|
ipaservices.knownservices.dirsrv.restart()
|
2012-03-27 05:06:33 -05:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2011-09-07 03:17:12 -05:00
|
|
|
def __enable(self):
|
|
|
|
self.backup_state("enabled", self.is_enabled())
|
|
|
|
# We do not let the system start IPA components on its own,
|
|
|
|
# Instead we reply on the IPA init script to start only enabled
|
|
|
|
# components as found in our LDAP configuration tree
|
2012-07-13 10:12:48 -05:00
|
|
|
# Note that self.dm_password is None for ADTrustInstance because
|
|
|
|
# we ensure to be called as root and using ldapi to use autobind
|
2011-09-07 03:17:12 -05:00
|
|
|
try:
|
2011-11-07 05:59:20 -06:00
|
|
|
self.ldap_enable('ADTRUST', self.fqdn, self.dm_password, \
|
|
|
|
self.suffix)
|
2012-02-28 05:23:51 -06:00
|
|
|
except (ldap.ALREADY_EXISTS, errors.DuplicateEntry), e:
|
2012-02-28 05:24:41 -06:00
|
|
|
root_logger.info("ADTRUST Service startup entry already exists.")
|
2011-11-30 06:29:10 -06:00
|
|
|
|
|
|
|
try:
|
|
|
|
self.ldap_enable('EXTID', self.fqdn, self.dm_password, \
|
|
|
|
self.suffix)
|
|
|
|
except (ldap.ALREADY_EXISTS, errors.DuplicateEntry), e:
|
|
|
|
root_logger.info("EXTID Service startup entry already exists.")
|
2011-09-07 03:17:12 -05:00
|
|
|
|
|
|
|
def __setup_sub_dict(self):
|
2012-07-13 10:12:48 -05:00
|
|
|
self.sub_dict = dict(REALM = self.realm,
|
2011-09-07 03:17:12 -05:00
|
|
|
SUFFIX = self.suffix,
|
|
|
|
NETBIOS_NAME = self.netbios_name,
|
|
|
|
SMB_DN = self.smb_dn,
|
2012-05-15 12:03:16 -05:00
|
|
|
LDAPI_SOCKET = self.ldapi_socket,
|
|
|
|
FQDN = self.fqdn)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
|
|
|
def setup(self, fqdn, ip_address, realm_name, domain_name, netbios_name,
|
2012-06-12 10:53:36 -05:00
|
|
|
rid_base, secondary_rid_base, no_msdcs=False, smbd_user="samba"):
|
2011-11-07 05:59:20 -06:00
|
|
|
self.fqdn = fqdn
|
2011-09-07 03:17:12 -05:00
|
|
|
self.ip_address = ip_address
|
2012-07-13 10:12:48 -05:00
|
|
|
self.realm = realm_name
|
2011-09-07 03:17:12 -05:00
|
|
|
self.domain_name = domain_name
|
|
|
|
self.netbios_name = netbios_name
|
2012-06-12 10:53:36 -05:00
|
|
|
self.rid_base = rid_base
|
|
|
|
self.secondary_rid_base = secondary_rid_base
|
2011-10-13 05:01:57 -05:00
|
|
|
self.no_msdcs = no_msdcs
|
2011-09-07 03:17:12 -05:00
|
|
|
self.smbd_user = smbd_user
|
2012-07-13 10:12:48 -05:00
|
|
|
self.suffix = ipautil.realm_to_suffix(self.realm)
|
2011-11-07 05:59:20 -06:00
|
|
|
self.ldapi_socket = "%%2fvar%%2frun%%2fslapd-%s.socket" % \
|
2012-07-13 10:12:48 -05:00
|
|
|
realm_to_serverid(self.realm)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
|
|
|
self.smb_conf = "/etc/samba/smb.conf"
|
|
|
|
|
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.smb_dn = DN(('cn', 'adtrust agents'), ('cn', 'sysaccounts'),
|
|
|
|
('cn', 'etc'), self.suffix)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
self.trust_dn = DN(api.env.container_trusts, self.suffix)
|
|
|
|
self.smb_dom_dn = DN(('cn', self.domain_name),
|
|
|
|
api.env.container_cifsdomains, self.suffix)
|
2012-07-13 10:12:48 -05:00
|
|
|
self.cifs_principal = "cifs/" + self.fqdn + "@" + self.realm
|
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.cifs_agent = DN(('krbprincipalname', self.cifs_principal.lower()),
|
|
|
|
api.env.container_service,
|
|
|
|
self.suffix)
|
2012-05-30 04:54:01 -05:00
|
|
|
self.selinux_booleans = ["samba_portmapper"]
|
2011-09-23 08:11:23 -05:00
|
|
|
|
2011-09-07 03:17:12 -05:00
|
|
|
self.__setup_sub_dict()
|
|
|
|
|
2012-06-12 10:53:36 -05:00
|
|
|
def find_local_id_range(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
|
|
|
if self.admin_conn.search_s(DN(api.env.container_ranges, self.suffix),
|
2012-06-12 10:53:36 -05:00
|
|
|
ldap.SCOPE_ONELEVEL,
|
|
|
|
"objectclass=ipaDomainIDRange"):
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
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 = self.admin_conn.getEntry(DN(('cn', 'admins'), api.env.container_group, self.suffix),
|
2012-06-12 10:53:36 -05:00
|
|
|
ldap.SCOPE_BASE)
|
|
|
|
except errors.NotFound:
|
|
|
|
raise ValueError("No local ID range and no admins group found.\n" \
|
|
|
|
"Add local ID range manually and try again!")
|
|
|
|
|
|
|
|
base_id = int(entry.getValue('gidNumber'))
|
|
|
|
id_range_size = 200000
|
|
|
|
|
|
|
|
id_filter = "(&" \
|
|
|
|
"(|(objectclass=posixAccount)" \
|
|
|
|
"(objectclass=posixGroup)" \
|
|
|
|
"(objectclass=ipaIDObject))" \
|
|
|
|
"(|(uidNumber<=%d)(uidNumber>=%d)" \
|
|
|
|
"(gidNumber<=%d)(gidNumner>=%d)))" % \
|
|
|
|
((base_id - 1), (base_id + id_range_size),
|
|
|
|
(base_id - 1), (base_id + id_range_size))
|
|
|
|
if self.admin_conn.search_s("cn=accounts," + self.suffix,
|
|
|
|
ldap.SCOPE_SUBTREE, id_filter):
|
|
|
|
raise ValueError("There are objects with IDs out of the expected" \
|
|
|
|
"range.\nAdd local ID range manually and try " \
|
|
|
|
"again!")
|
|
|
|
|
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 = ipaldap.Entry(DN(('cn', ('%s_id_range' % self.realm)),
|
|
|
|
api.env.container_ranges,
|
|
|
|
self.suffix))
|
2012-06-12 10:53:36 -05:00
|
|
|
entry.setValue('objectclass', 'ipaDomainIDRange')
|
2012-07-13 10:12:48 -05:00
|
|
|
entry.setValue('cn', ('%s_id_range' % self.realm))
|
2012-06-12 10:53:36 -05:00
|
|
|
entry.setValue('ipaBaseID', str(base_id))
|
|
|
|
entry.setValue('ipaIDRangeSize', str(id_range_size))
|
|
|
|
self.admin_conn.addEntry(entry)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
|
|
|
def create_instance(self):
|
|
|
|
|
|
|
|
self.ldap_connect()
|
|
|
|
|
|
|
|
self.step("stopping smbd", self.__stop)
|
2012-03-27 05:06:33 -05:00
|
|
|
self.step("creating samba domain object", \
|
2011-11-07 05:59:20 -06:00
|
|
|
self.__create_samba_domain_object)
|
2012-03-27 05:06:33 -05:00
|
|
|
self.step("creating samba config registry", self.__write_smb_registry)
|
2011-09-07 03:17:12 -05:00
|
|
|
self.step("writing samba config file", self.__write_smb_conf)
|
2012-03-27 05:06:33 -05:00
|
|
|
self.step("adding cifs Kerberos principal", self.__setup_principal)
|
|
|
|
self.step("adding admin(group) SIDs", self.__add_admin_sids)
|
2012-06-12 10:53:36 -05:00
|
|
|
self.step("adding RID bases", self.__add_rid_bases)
|
2012-09-07 05:40:58 -05:00
|
|
|
self.step("updating Kerberos config", self.__update_krb5_conf)
|
2012-03-27 05:06:33 -05:00
|
|
|
self.step("activating CLDAP plugin", self.__add_cldap_module)
|
2012-06-21 05:54:34 -05:00
|
|
|
self.step("activating sidgen plugin and task", self.__add_sidgen_module)
|
2011-11-30 06:29:10 -06:00
|
|
|
self.step("activating extdom plugin", self.__add_extdom_module)
|
2011-09-07 03:17:12 -05:00
|
|
|
self.step("configuring smbd to start on boot", self.__enable)
|
2011-10-13 05:01:57 -05:00
|
|
|
if not self.no_msdcs:
|
2011-11-07 05:59:20 -06:00
|
|
|
self.step("adding special DNS service records", \
|
|
|
|
self.__add_dns_service_records)
|
2011-11-30 06:29:10 -06:00
|
|
|
self.step("restarting Directory Server to take MS PAC and LDAP plugins changes into account", \
|
2012-06-21 08:04:10 -05:00
|
|
|
self.__restart_dirsrv)
|
2012-05-30 04:54:01 -05:00
|
|
|
self.step("setting SELinux booleans", \
|
|
|
|
self.__configure_selinux_for_smbd)
|
2011-11-30 06:29:10 -06:00
|
|
|
self.step("starting CIFS services", self.__start)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2011-11-30 06:29:10 -06:00
|
|
|
self.start_creation("Configuring CIFS:")
|
2011-09-07 03:17:12 -05:00
|
|
|
|
|
|
|
def uninstall(self):
|
|
|
|
if self.is_configured():
|
|
|
|
self.print_msg("Unconfiguring %s" % self.service_name)
|
|
|
|
|
|
|
|
running = self.restore_state("running")
|
|
|
|
enabled = self.restore_state("enabled")
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.stop()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2011-11-07 05:59:20 -06:00
|
|
|
for r_file in [self.smb_conf]:
|
2011-09-07 03:17:12 -05:00
|
|
|
try:
|
2011-11-07 05:59:20 -06:00
|
|
|
self.fstore.restore_file(r_file)
|
2011-09-07 03:17:12 -05:00
|
|
|
except ValueError, error:
|
2011-11-15 13:39:31 -06:00
|
|
|
root_logger.debug(error)
|
2011-09-07 03:17:12 -05:00
|
|
|
pass
|
|
|
|
|
2012-05-30 04:54:01 -05:00
|
|
|
for var in self.selinux_booleans:
|
|
|
|
sebool_state = self.restore_state(var)
|
|
|
|
if not sebool_state is None:
|
|
|
|
try:
|
|
|
|
ipautil.run(["/usr/sbin/setsebool", "-P", var, sebool_state])
|
|
|
|
except:
|
|
|
|
self.print_msg(SELINUX_WARNING % dict(var=var))
|
|
|
|
|
2011-09-07 03:17:12 -05:00
|
|
|
if not enabled is None and not enabled:
|
|
|
|
self.disable()
|
|
|
|
|
|
|
|
if not running is None and running:
|
|
|
|
self.start()
|