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/>.
|
|
|
|
#
|
|
|
|
|
2015-08-12 06:44:11 -05:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2011-09-07 03:17:12 -05:00
|
|
|
import os
|
|
|
|
import errno
|
|
|
|
import ldap
|
|
|
|
import tempfile
|
2011-11-07 05:48:10 -06:00
|
|
|
import uuid
|
2013-01-21 05:05:07 -06:00
|
|
|
import string
|
|
|
|
import struct
|
|
|
|
import re
|
|
|
|
|
2015-09-11 06:43:28 -05:00
|
|
|
import six
|
|
|
|
|
2011-11-07 05:59:20 -06:00
|
|
|
from ipaserver.install import service
|
2013-10-09 06:20:13 -05:00
|
|
|
from ipaserver.install import installutils
|
2011-10-13 05:01:57 -05:00
|
|
|
from ipaserver.install.bindinstance import get_rr, add_rr, del_rr, \
|
|
|
|
dns_zone_exists
|
2015-10-27 10:05:03 -05:00
|
|
|
from ipaserver.install.replication import wait_for_task
|
2011-10-13 05:01:57 -05:00
|
|
|
from ipalib import errors, api
|
2013-10-03 02:43:08 -05:00
|
|
|
from ipalib.util import normalize_zone
|
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
|
2014-08-14 10:14:07 -05:00
|
|
|
from ipapython.ipa_log_manager import root_logger
|
|
|
|
import ipapython.errors
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2012-09-07 05:40:58 -05:00
|
|
|
import ipaclient.ipachangeconf
|
2014-05-29 03:37:18 -05:00
|
|
|
from ipaplatform import services
|
2014-05-29 07:47:17 -05:00
|
|
|
from ipaplatform.paths import paths
|
2014-08-14 10:14:07 -05:00
|
|
|
from ipaplatform.tasks import tasks
|
2012-09-07 05:40:58 -05:00
|
|
|
|
2015-09-11 06:43:28 -05:00
|
|
|
if six.PY3:
|
|
|
|
unicode = str
|
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-10-08 05:27:16 -05:00
|
|
|
UPGRADE_ERROR = """
|
|
|
|
Entry %(dn)s does not exist.
|
|
|
|
This means upgrade from IPA 2.x to 3.x did not went well and required S4U2Proxy
|
|
|
|
configuration was not set up properly. Please run ipa-ldap-updater manually
|
|
|
|
and re-run ipa-adtrust-instal again afterwards.
|
|
|
|
"""
|
|
|
|
|
2014-08-14 10:14:07 -05:00
|
|
|
SELINUX_BOOLEAN_SETTINGS = {'samba_portmapper': 'on'}
|
|
|
|
|
|
|
|
|
2011-11-07 05:59:20 -06:00
|
|
|
def check_inst():
|
2014-05-29 07:47:17 -05:00
|
|
|
for smbfile in [paths.SMBD, paths.NET]:
|
2011-11-07 05:59:20 -06:00
|
|
|
if not os.path.exists(smbfile):
|
2015-08-12 06:44:11 -05:00
|
|
|
print("%s was not found on this system" % smbfile)
|
|
|
|
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:
|
2014-05-29 07:47:17 -05:00
|
|
|
conf_fd = open(paths.SMB_CONF, 'r')
|
2015-07-30 09:49:29 -05:00
|
|
|
except IOError as err:
|
2011-11-07 05:59:20 -06:00
|
|
|
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"
|
2012-09-18 04:32:10 -05:00
|
|
|
ATTR_FALLBACK_GROUP = "ipaNTFallbackPrimaryGroup"
|
2011-11-07 05:48:10 -06:00
|
|
|
OBJC_USER = "ipaNTUserAttrs"
|
|
|
|
OBJC_GROUP = "ipaNTGroupAttrs"
|
|
|
|
OBJC_DOMAIN = "ipaNTDomainAttrs"
|
2012-10-08 03:44:07 -05:00
|
|
|
FALLBACK_GROUP_NAME = u'Default SMB Group'
|
2011-11-07 05:48:10 -06:00
|
|
|
|
2012-07-13 10:12:48 -05:00
|
|
|
def __init__(self, fstore=None):
|
2011-11-07 05:59:20 -06:00
|
|
|
self.netbios_name = None
|
2012-10-29 15:43:56 -05:00
|
|
|
self.reset_netbios_name = None
|
2011-11-07 05:59:20 -06:00
|
|
|
self.no_msdcs = None
|
2012-10-02 15:11:17 -05:00
|
|
|
self.add_sids = None
|
2011-11-07 05:59:20 -06:00
|
|
|
self.smbd_user = None
|
|
|
|
self.smb_dn_pwd = None
|
|
|
|
self.trust_dn = None
|
|
|
|
self.smb_dom_dn = None
|
|
|
|
self.sub_dict = 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
|
|
|
|
2013-10-09 08:45:49 -05:00
|
|
|
self.fqdn = None
|
2014-01-17 06:09:34 -06:00
|
|
|
self.host_netbios_name = None
|
2013-10-09 08:45:49 -05:00
|
|
|
self.realm = None
|
|
|
|
self.domain_name = None
|
|
|
|
|
|
|
|
service.Service.__init__(self, "smb", service_desc="CIFS",
|
|
|
|
dm_password=None, ldapi=True)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
|
|
|
if fstore:
|
|
|
|
self.fstore = fstore
|
|
|
|
else:
|
2014-05-29 07:47:17 -05:00
|
|
|
self.fstore = sysrestore.FileStore(paths.SYSRESTORE)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2013-10-09 08:45:49 -05:00
|
|
|
self.__setup_default_attributes()
|
|
|
|
|
|
|
|
def __setup_default_attributes(self):
|
|
|
|
"""
|
|
|
|
This method setups default attributes that are either constants, or
|
|
|
|
based on api.env attributes, such as realm, hostname or domain name.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Constants
|
2014-05-29 07:47:17 -05:00
|
|
|
self.smb_conf = paths.SMB_CONF
|
|
|
|
self.samba_keytab = paths.SAMBA_KEYTAB
|
2013-10-09 08:45:49 -05:00
|
|
|
self.cifs_hosts = []
|
|
|
|
|
|
|
|
# Values obtained from API.env
|
|
|
|
self.fqdn = self.fqdn or api.env.host
|
2014-01-17 06:09:34 -06:00
|
|
|
self.host_netbios_name = make_netbios_name(self.fqdn)
|
2013-10-09 08:45:49 -05:00
|
|
|
self.realm = self.realm or api.env.realm
|
|
|
|
self.domain_name = self.domain_name or api.env.domain
|
|
|
|
|
|
|
|
self.cifs_principal = "cifs/" + self.fqdn + "@" + self.realm
|
|
|
|
self.suffix = ipautil.realm_to_suffix(self.realm)
|
|
|
|
self.ldapi_socket = "%%2fvar%%2frun%%2fslapd-%s.socket" % \
|
2015-04-27 07:42:31 -05:00
|
|
|
installutils.realm_to_serverid(self.realm)
|
2013-10-09 08:45:49 -05:00
|
|
|
|
|
|
|
# DN definitions
|
|
|
|
self.trust_dn = DN(api.env.container_trusts, self.suffix)
|
|
|
|
|
|
|
|
self.smb_dn = DN(('cn', 'adtrust agents'),
|
|
|
|
('cn', 'sysaccounts'),
|
|
|
|
('cn', 'etc'),
|
|
|
|
self.suffix)
|
|
|
|
|
|
|
|
self.smb_dom_dn = DN(('cn', self.domain_name),
|
|
|
|
api.env.container_cifsdomains,
|
|
|
|
self.suffix)
|
|
|
|
|
|
|
|
self.cifs_agent = DN(('krbprincipalname', self.cifs_principal.lower()),
|
|
|
|
api.env.container_service,
|
|
|
|
self.suffix)
|
2015-05-12 07:31:46 -05:00
|
|
|
self.host_princ = DN(('fqdn', self.fqdn),
|
|
|
|
api.env.container_host,
|
|
|
|
self.suffix)
|
2013-10-09 08:45:49 -05:00
|
|
|
|
|
|
|
|
2011-09-07 03:17:12 -05:00
|
|
|
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):
|
2012-09-18 04:32:10 -05:00
|
|
|
"""
|
|
|
|
The IPA admin and the IPA admins group with get the well knows SIDs
|
|
|
|
used by AD for the administrator and the administrator group.
|
|
|
|
|
|
|
|
By default new users belong only to a user private group (UPG) and no
|
|
|
|
other Posix group since ipausers is not a Posix group anymore. To be
|
|
|
|
able to add a RID to the primary RID attribute in a PAC a fallback
|
|
|
|
group is added.
|
|
|
|
"""
|
|
|
|
|
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:
|
2013-01-23 09:05:21 -06:00
|
|
|
dom_entry = self.admin_conn.get_entry(self.smb_dom_dn)
|
2011-09-23 08:11:23 -05:00
|
|
|
except errors.NotFound:
|
2012-09-18 04:35:57 -05:00
|
|
|
self.print_msg("Samba domain object not found")
|
2011-09-23 08:11:23 -05:00
|
|
|
return
|
|
|
|
|
2013-09-10 05:20:24 -05:00
|
|
|
dom_sid = dom_entry.single_value.get(self.ATTR_SID)
|
2011-09-23 08:11:23 -05:00
|
|
|
if not dom_sid:
|
2012-09-18 04:35:57 -05:00
|
|
|
self.print_msg("Samba domain object does not have a SID")
|
2011-09-23 08:11:23 -05:00
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
2013-01-23 09:05:21 -06:00
|
|
|
admin_entry = self.admin_conn.get_entry(admin_dn)
|
2015-10-27 10:08:10 -05:00
|
|
|
except errors.NotFound:
|
2012-09-18 04:35:57 -05:00
|
|
|
self.print_msg("IPA admin object not found")
|
2011-09-23 08:11:23 -05:00
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
2013-01-23 09:05:21 -06:00
|
|
|
admin_group_entry = self.admin_conn.get_entry(admin_group_dn)
|
2015-10-27 10:08:10 -05:00
|
|
|
except errors.NotFound:
|
2012-09-18 04:35:57 -05:00
|
|
|
self.print_msg("IPA admin group object not found")
|
2011-09-23 08:11:23 -05:00
|
|
|
return
|
|
|
|
|
2013-09-10 05:20:24 -05:00
|
|
|
if admin_entry.single_value.get(self.ATTR_SID):
|
2012-09-18 04:32:10 -05:00
|
|
|
self.print_msg("Admin SID already set, nothing to do")
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
self.admin_conn.modify_s(admin_dn, \
|
|
|
|
[(ldap.MOD_ADD, "objectclass", self.OBJC_USER), \
|
|
|
|
(ldap.MOD_ADD, self.ATTR_SID, dom_sid + "-500")])
|
2015-10-27 10:08:10 -05:00
|
|
|
except Exception:
|
2012-09-18 04:32:10 -05:00
|
|
|
self.print_msg("Failed to modify IPA admin object")
|
|
|
|
|
2013-09-10 05:20:24 -05:00
|
|
|
if admin_group_entry.single_value.get(self.ATTR_SID):
|
2012-09-18 04:32:10 -05:00
|
|
|
self.print_msg("Admin group SID already set, nothing to do")
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
self.admin_conn.modify_s(admin_group_dn, \
|
|
|
|
[(ldap.MOD_ADD, "objectclass", self.OBJC_GROUP), \
|
|
|
|
(ldap.MOD_ADD, self.ATTR_SID, dom_sid + "-512")])
|
2015-10-27 10:08:10 -05:00
|
|
|
except Exception:
|
2012-09-18 04:32:10 -05:00
|
|
|
self.print_msg("Failed to modify IPA admin group object")
|
|
|
|
|
2014-09-22 05:19:26 -05:00
|
|
|
def __add_default_trust_view(self):
|
|
|
|
default_view_dn = DN(('cn', 'Default Trust View'),
|
|
|
|
api.env.container_views, self.suffix)
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.admin_conn.get_entry(default_view_dn)
|
|
|
|
except errors.NotFound:
|
|
|
|
try:
|
|
|
|
self._ldap_mod('default-trust-view.ldif', self.sub_dict)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2014-09-22 05:19:26 -05:00
|
|
|
self.print_msg("Failed to add default trust view.")
|
|
|
|
raise e
|
|
|
|
else:
|
|
|
|
self.print_msg("Default Trust View already exists.")
|
|
|
|
|
|
|
|
# _ldap_mod does not return useful error codes, so we must check again
|
|
|
|
# if the default trust view was created properly.
|
|
|
|
try:
|
|
|
|
self.admin_conn.get_entry(default_view_dn)
|
|
|
|
except errors.NotFound:
|
|
|
|
self.print_msg("Failed to add Default Trust View.")
|
2012-09-18 04:32:10 -05:00
|
|
|
|
|
|
|
def __add_fallback_group(self):
|
|
|
|
"""
|
|
|
|
By default new users belong only to a user private group (UPG) and no
|
|
|
|
other Posix group since ipausers is not a Posix group anymore. To be
|
|
|
|
able to add a RID to the primary RID attribute in a PAC a fallback
|
|
|
|
group is added.
|
|
|
|
|
|
|
|
Since this method must be run after a restart of the directory server
|
|
|
|
to enable the sidgen plugin we have to reconnect to the directory
|
|
|
|
server.
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.ldap_connect()
|
|
|
|
|
|
|
|
try:
|
2013-01-23 09:05:21 -06:00
|
|
|
dom_entry = self.admin_conn.get_entry(self.smb_dom_dn)
|
2012-09-18 04:32:10 -05:00
|
|
|
except errors.NotFound:
|
|
|
|
self.print_msg("Samba domain object not found")
|
|
|
|
return
|
|
|
|
|
2013-09-10 05:20:24 -05:00
|
|
|
if dom_entry.single_value.get(self.ATTR_FALLBACK_GROUP):
|
2012-09-18 04:32:10 -05:00
|
|
|
self.print_msg("Fallback group already set, nothing to do")
|
|
|
|
return
|
|
|
|
|
|
|
|
fb_group_dn = DN(('cn', self.FALLBACK_GROUP_NAME),
|
|
|
|
api.env.container_group, self.suffix)
|
|
|
|
try:
|
2013-01-23 09:05:21 -06:00
|
|
|
self.admin_conn.get_entry(fb_group_dn)
|
2012-09-18 04:32:10 -05:00
|
|
|
except errors.NotFound:
|
|
|
|
try:
|
2012-10-08 03:44:07 -05:00
|
|
|
self._ldap_mod('default-smb-group.ldif', self.sub_dict)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2012-09-18 04:32:10 -05:00
|
|
|
self.print_msg("Failed to add fallback group.")
|
|
|
|
raise e
|
2011-09-23 08:11:23 -05:00
|
|
|
|
2012-10-08 03:44:07 -05:00
|
|
|
# _ldap_mod does not return useful error codes, so we must check again
|
|
|
|
# if the fallback group was created properly.
|
|
|
|
try:
|
2013-01-23 09:05:21 -06:00
|
|
|
self.admin_conn.get_entry(fb_group_dn)
|
2012-10-08 03:44:07 -05:00
|
|
|
except errors.NotFound:
|
2012-10-09 04:03:00 -05:00
|
|
|
self.print_msg("Failed to add fallback group.")
|
|
|
|
return
|
2012-10-08 03:44:07 -05:00
|
|
|
|
2011-09-23 08:11:23 -05:00
|
|
|
try:
|
2012-10-08 03:44:07 -05:00
|
|
|
mod = [(ldap.MOD_ADD, self.ATTR_FALLBACK_GROUP, fb_group_dn)]
|
2012-09-18 04:32:10 -05:00
|
|
|
self.admin_conn.modify_s(self.smb_dom_dn, mod)
|
2015-10-27 10:08:10 -05:00
|
|
|
except Exception:
|
2012-09-18 04:32:10 -05:00
|
|
|
self.print_msg("Failed to add fallback group to domain object")
|
2011-09-23 08:11:23 -05:00
|
|
|
|
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:
|
2013-05-13 06:19:12 -05:00
|
|
|
# Get the ranges
|
|
|
|
ranges = self.admin_conn.get_entries(
|
2013-01-21 07:39:09 -06:00
|
|
|
DN(api.env.container_ranges, self.suffix),
|
|
|
|
ldap.SCOPE_ONELEVEL, "(objectclass=ipaDomainIDRange)")
|
2012-06-12 10:53:36 -05:00
|
|
|
|
2013-05-13 06:19:12 -05:00
|
|
|
# Filter out ranges where RID base is already set
|
|
|
|
no_rid_base_set = lambda r: not any((
|
2013-09-10 05:20:24 -05:00
|
|
|
r.single_value.get('ipaBaseRID'),
|
|
|
|
r.single_value.get('ipaSecondaryBaseRID')))
|
2013-05-13 06:19:12 -05:00
|
|
|
|
2015-08-11 09:42:28 -05:00
|
|
|
ranges_with_no_rid_base = [r for r in ranges if no_rid_base_set(r)]
|
2013-05-13 06:19:12 -05:00
|
|
|
|
|
|
|
# Return if no range is without RID base
|
|
|
|
if len(ranges_with_no_rid_base) == 0:
|
2012-09-18 04:35:57 -05:00
|
|
|
self.print_msg("RID bases already set, nothing to do")
|
2012-06-12 10:53:36 -05:00
|
|
|
return
|
|
|
|
|
2013-05-13 06:19:12 -05:00
|
|
|
# Abort if RID base needs to be added to more than one range
|
|
|
|
if len(ranges_with_no_rid_base) != 1:
|
|
|
|
root_logger.critical("Found more than one local domain ID "
|
|
|
|
"range with no RID base set.")
|
|
|
|
raise RuntimeError("Too many ID ranges\n")
|
|
|
|
|
|
|
|
# Abort if RID bases are too close
|
|
|
|
local_range = ranges_with_no_rid_base[0]
|
2013-09-10 05:20:24 -05:00
|
|
|
size = local_range.single_value.get('ipaIDRangeSize')
|
2013-05-13 06:19:12 -05:00
|
|
|
|
2012-06-12 10:53:36 -05:00
|
|
|
if abs(self.rid_base - self.secondary_rid_base) > size:
|
2013-05-13 06:19:12 -05:00
|
|
|
self.print_msg("Primary and secondary RID base are too close. "
|
2012-09-18 04:35:57 -05:00
|
|
|
"They have to differ at least by %d." % size)
|
2012-06-12 10:53:36 -05:00
|
|
|
raise RuntimeError("RID bases too close.\n")
|
|
|
|
|
2013-05-13 06:19:12 -05:00
|
|
|
# Modify the range
|
|
|
|
# If the RID bases would cause overlap with some other range,
|
|
|
|
# this will be detected by ipa-range-check DS plugin
|
2012-06-12 10:53:36 -05:00
|
|
|
try:
|
2013-05-13 06:19:12 -05:00
|
|
|
self.admin_conn.modify_s(local_range.dn,
|
|
|
|
[(ldap.MOD_ADD, "ipaBaseRID",
|
|
|
|
str(self.rid_base)),
|
|
|
|
(ldap.MOD_ADD, "ipaSecondaryBaseRID",
|
2012-06-12 10:53:36 -05:00
|
|
|
str(self.secondary_rid_base))])
|
2015-07-30 09:49:29 -05:00
|
|
|
except ldap.CONSTRAINT_VIOLATION as e:
|
2013-05-13 06:19:12 -05:00
|
|
|
self.print_msg("Failed to add RID bases to the local range "
|
|
|
|
"object:\n %s" % e[0]['info'])
|
|
|
|
raise RuntimeError("Constraint violation.\n")
|
2012-06-12 10:53:36 -05:00
|
|
|
|
|
|
|
except errors.NotFound as e:
|
2013-05-13 06:19:12 -05:00
|
|
|
root_logger.critical("ID range of the local domain not found, "
|
2012-06-12 10:53:36 -05:00
|
|
|
"define it and run again.")
|
|
|
|
raise e
|
|
|
|
|
2012-10-29 15:43:56 -05:00
|
|
|
def __reset_netbios_name(self):
|
|
|
|
"""
|
|
|
|
Set the NetBIOS domain name to a new value.
|
|
|
|
"""
|
|
|
|
self.print_msg("Reset NetBIOS domain name")
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.admin_conn.modify_s(self.smb_dom_dn,
|
|
|
|
[(ldap.MOD_REPLACE, self.ATTR_FLAT_NAME,
|
|
|
|
self.netbios_name)])
|
|
|
|
except ldap.LDAPError:
|
|
|
|
self.print_msg("Failed to reset the NetBIOS domain name")
|
|
|
|
|
2011-09-07 03:17:12 -05:00
|
|
|
def __create_samba_domain_object(self):
|
|
|
|
|
|
|
|
try:
|
2013-01-23 09:05:21 -06:00
|
|
|
self.admin_conn.get_entry(self.smb_dom_dn)
|
2012-10-29 15:43:56 -05:00
|
|
|
if self.reset_netbios_name:
|
|
|
|
self.__reset_netbios_name()
|
|
|
|
else :
|
|
|
|
self.print_msg("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:
|
2013-01-23 09:05:21 -06:00
|
|
|
self.admin_conn.get_entry(new_dn)
|
2011-11-07 04:56:57 -06:00
|
|
|
except errors.NotFound:
|
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
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2012-09-18 04:35:57 -05:00
|
|
|
self.print_msg('Cannot extract RDN attribute value from "%s": %s' % \
|
|
|
|
(new_dn, e))
|
2011-11-07 04:56:57 -06:00
|
|
|
return
|
2013-01-18 08:24:35 -06:00
|
|
|
entry = self.admin_conn.make_entry(
|
|
|
|
new_dn, objectclass=['nsContainer'], cn=[name])
|
2013-01-23 08:27:05 -06:00
|
|
|
self.admin_conn.add_entry(entry)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2013-01-18 08:24:35 -06:00
|
|
|
entry = self.admin_conn.make_entry(
|
|
|
|
self.smb_dom_dn,
|
|
|
|
{
|
|
|
|
'objectclass': [self.OBJC_DOMAIN, "nsContainer"],
|
|
|
|
'cn': [self.domain_name],
|
|
|
|
self.ATTR_FLAT_NAME: [self.netbios_name],
|
|
|
|
self.ATTR_SID: [self.__gen_sid_string()],
|
|
|
|
self.ATTR_GUID: [str(uuid.uuid4())],
|
|
|
|
}
|
|
|
|
)
|
2011-09-07 03:17:12 -05:00
|
|
|
#TODO: which MAY attributes do we want to set ?
|
2013-01-23 08:27:05 -06:00
|
|
|
self.admin_conn.add_entry(entry)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
|
|
|
def __write_smb_conf(self):
|
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')
|
2014-07-14 17:18:00 -05:00
|
|
|
conf_fd.write('debug pid = yes\n')
|
2011-11-07 05:59:20 -06:00
|
|
|
conf_fd.write('config backend = registry\n')
|
|
|
|
conf_fd.close()
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2012-10-04 03:15:40 -05:00
|
|
|
def __add_plugin_conf(self, name, plugin_cn, ldif_file):
|
|
|
|
"""
|
|
|
|
Add directory server plugin configuration if it not already
|
|
|
|
exists.
|
|
|
|
"""
|
2012-02-28 05:23:51 -06:00
|
|
|
try:
|
2012-10-04 03:15:40 -05:00
|
|
|
plugin_dn = DN(('cn', plugin_cn), ('cn', 'plugins'),
|
|
|
|
('cn', 'config'))
|
2013-01-23 09:05:21 -06:00
|
|
|
self.admin_conn.get_entry(plugin_dn)
|
2012-10-04 03:15:40 -05:00
|
|
|
self.print_msg('%s plugin already configured, nothing to do' % name)
|
|
|
|
except errors.NotFound:
|
|
|
|
try:
|
|
|
|
self._ldap_mod(ldif_file, self.sub_dict)
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def __add_cldap_module(self):
|
|
|
|
"""
|
|
|
|
Add cldap directory server plugin configuration if it not already
|
|
|
|
exists.
|
|
|
|
"""
|
|
|
|
self.__add_plugin_conf('CLDAP', 'ipa_cldap', 'ipa-cldap-conf.ldif')
|
2011-11-18 07:04:09 -06:00
|
|
|
|
2015-05-12 07:31:46 -05:00
|
|
|
def __add_sidgen_task(self):
|
2012-10-04 03:15:40 -05:00
|
|
|
"""
|
|
|
|
Add sidgen directory server plugin configuration and the related task
|
|
|
|
if they not already exist.
|
|
|
|
"""
|
|
|
|
self.__add_plugin_conf('Sidgen task', 'ipa-sidgen-task',
|
|
|
|
'ipa-sidgen-task-conf.ldif')
|
2012-10-02 15:11:17 -05:00
|
|
|
|
|
|
|
def __add_sids(self):
|
|
|
|
"""
|
2015-10-27 10:05:03 -05:00
|
|
|
Add SIDs for existing users and groups. Make sure the task is finished
|
|
|
|
before continuing.
|
2012-10-02 15:11:17 -05:00
|
|
|
"""
|
|
|
|
|
|
|
|
try:
|
2015-10-27 10:05:03 -05:00
|
|
|
# Start the sidgen task
|
2012-10-02 15:11:17 -05:00
|
|
|
self._ldap_mod("ipa-sidgen-task-run.ldif", self.sub_dict)
|
2015-10-27 10:05:03 -05:00
|
|
|
|
|
|
|
# Notify the user about the possible delay
|
|
|
|
self.print_msg("This step may take considerable amount of time, please wait..")
|
|
|
|
|
|
|
|
# Wait for the task to complete
|
|
|
|
task_dn = DN('cn=sidgen,cn=ipa-sidgen-task,cn=tasks,cn=config')
|
|
|
|
wait_for_task(self.admin_conn, task_dn)
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
root_logger.warning("Exception occured during SID generation: {0}"
|
|
|
|
.format(str(e)))
|
2012-06-21 05:54:34 -05:00
|
|
|
|
2012-10-08 05:27:16 -05:00
|
|
|
def __add_s4u2proxy_target(self):
|
|
|
|
"""
|
|
|
|
Add CIFS principal to S4U2Proxy target
|
|
|
|
"""
|
|
|
|
|
|
|
|
targets_dn = DN(('cn', 'ipa-cifs-delegation-targets'), ('cn', 's4u2proxy'),
|
|
|
|
('cn', 'etc'), self.suffix)
|
|
|
|
try:
|
2013-01-18 08:43:53 -06:00
|
|
|
current = self.admin_conn.get_entry(targets_dn)
|
|
|
|
members = current.get('memberPrincipal', [])
|
2012-10-08 05:27:16 -05:00
|
|
|
if not(self.cifs_principal in members):
|
2013-01-18 08:43:53 -06:00
|
|
|
current["memberPrincipal"] = members + [self.cifs_principal]
|
2013-10-31 11:54:49 -05:00
|
|
|
self.admin_conn.update_entry(current)
|
2012-10-08 05:27:16 -05:00
|
|
|
else:
|
|
|
|
self.print_msg('cifs principal already targeted, nothing to do.')
|
|
|
|
except errors.NotFound:
|
|
|
|
self.print_msg(UPGRADE_ERROR % dict(dn=targets_dn))
|
|
|
|
|
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
|
|
|
|
2014-05-29 07:47:17 -05:00
|
|
|
args = [paths.NET, "conf", "import", tmp_name]
|
2011-09-07 03:17:12 -05:00
|
|
|
|
|
|
|
try:
|
|
|
|
ipautil.run(args)
|
|
|
|
finally:
|
|
|
|
os.remove(tmp_name)
|
|
|
|
|
2015-05-12 07:31:46 -05:00
|
|
|
def __setup_group_membership(self):
|
|
|
|
# Add the CIFS and host principals 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
|
|
|
|
service.add_principals_to_group(self.admin_conn, self.smb_dn, "member",
|
|
|
|
[self.cifs_agent, self.host_princ])
|
|
|
|
|
2011-09-07 03:17:12 -05:00
|
|
|
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))
|
2014-08-01 09:34:33 -05:00
|
|
|
except errors.DuplicateEntry:
|
2013-10-09 06:20:13 -05:00
|
|
|
# CIFS principal already exists, it is not the first time
|
|
|
|
# adtrustinstance is managed
|
2012-02-28 05:24:41 -06:00
|
|
|
# That's fine, we we'll re-extract the key again.
|
|
|
|
pass
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2014-08-01 09:34:33 -05:00
|
|
|
self.print_msg("Cannot add CIFS service: %s" % e)
|
|
|
|
|
2013-10-09 06:20:13 -05:00
|
|
|
self.clean_samba_keytab()
|
2015-10-09 11:08:38 -05:00
|
|
|
installutils.remove_ccache(paths.KRB5CC_SAMBA)
|
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,
|
2013-10-09 06:20:13 -05:00
|
|
|
"-k", self.samba_keytab])
|
|
|
|
except ipautil.CalledProcessError:
|
|
|
|
root_logger.critical("Failed to add key for %s"
|
|
|
|
% self.cifs_principal)
|
|
|
|
|
|
|
|
def clean_samba_keytab(self):
|
|
|
|
if os.path.exists(self.samba_keytab):
|
|
|
|
try:
|
|
|
|
ipautil.run(["ipa-rmkeytab", "--principal", self.cifs_principal,
|
|
|
|
"-k", self.samba_keytab])
|
2015-07-30 09:49:29 -05:00
|
|
|
except ipautil.CalledProcessError as e:
|
2013-10-09 06:20:13 -05:00
|
|
|
if e.returncode != 5:
|
|
|
|
root_logger.critical("Failed to remove old key for %s"
|
|
|
|
% self.cifs_principal)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2013-03-06 02:12:40 -06:00
|
|
|
def srv_rec(self, host, port, prio):
|
|
|
|
return "%(prio)d 100 %(port)d %(host)s" % dict(host=host,prio=prio,port=port)
|
|
|
|
|
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
|
2013-10-03 02:43:08 -05:00
|
|
|
host, host_domain = self.fqdn.split(".", 1)
|
|
|
|
|
|
|
|
if normalize_zone(zone) == normalize_zone(host_domain):
|
|
|
|
host_in_rr = host
|
|
|
|
else:
|
|
|
|
host_in_rr = normalize_zone(self.fqdn)
|
|
|
|
|
2013-03-06 02:12:40 -06:00
|
|
|
priority = 0
|
2011-10-13 05:01:57 -05:00
|
|
|
|
|
|
|
ipa_srv_rec = (
|
2013-10-03 02:43:08 -05:00
|
|
|
("_ldap._tcp", [self.srv_rec(host_in_rr, 389, priority)], 389),
|
|
|
|
("_kerberos._tcp", [self.srv_rec(host_in_rr, 88, priority)], 88),
|
|
|
|
("_kerberos._udp", [self.srv_rec(host_in_rr, 88, priority)], 88),
|
2011-10-13 05:01:57 -05:00
|
|
|
)
|
|
|
|
win_srv_suffix = (".Default-First-Site-Name._sites.dc._msdcs",
|
|
|
|
".dc._msdcs")
|
|
|
|
|
|
|
|
err_msg = None
|
2012-10-04 05:40:33 -05:00
|
|
|
|
|
|
|
if self.no_msdcs:
|
|
|
|
err_msg = '--no-msdcs was given, special DNS service records ' \
|
|
|
|
'are not added to local DNS server'
|
2011-10-13 05:01:57 -05:00
|
|
|
else:
|
2012-10-04 05:40:33 -05:00
|
|
|
ret = api.Command['dns_is_enabled']()
|
|
|
|
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
|
2011-10-13 05:01:57 -05:00
|
|
|
|
|
|
|
if err_msg:
|
2012-09-18 04:35:57 -05:00
|
|
|
self.print_msg(err_msg)
|
|
|
|
self.print_msg("Add the following service records to your DNS " \
|
|
|
|
"server for DNS zone %s: " % zone)
|
2015-10-09 07:58:14 -05:00
|
|
|
for suff in win_srv_suffix:
|
|
|
|
for srv in ipa_srv_rec:
|
|
|
|
self.print_msg("%s%s IN SRV %s" % (srv[0], suff, " ".join(srv[1])))
|
|
|
|
self.print_msg("")
|
2011-10-13 05:01:57 -05:00
|
|
|
return
|
|
|
|
|
2013-03-06 02:12:40 -06:00
|
|
|
for (srv, rdata, port) in ipa_srv_rec:
|
|
|
|
cifs_rdata = list()
|
|
|
|
for fqdn in self.cifs_hosts:
|
|
|
|
cifs_srv = self.srv_rec(fqdn, port, priority)
|
|
|
|
cifs_rdata.append(cifs_srv)
|
|
|
|
cifs_rdata.extend(rdata)
|
2011-10-13 05:01:57 -05:00
|
|
|
|
|
|
|
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)
|
2013-03-06 02:12:40 -06:00
|
|
|
for rec in cifs_rdata:
|
2011-10-13 05:01:57 -05:00
|
|
|
add_rr(zone, win_srv, "SRV", rec)
|
|
|
|
|
2012-05-30 04:54:01 -05:00
|
|
|
def __configure_selinux_for_smbd(self):
|
|
|
|
try:
|
2014-08-14 10:14:07 -05:00
|
|
|
tasks.set_selinux_booleans(SELINUX_BOOLEAN_SETTINGS,
|
|
|
|
self.backup_state)
|
|
|
|
except ipapython.errors.SetseboolError as e:
|
|
|
|
self.print_msg(e.format_service_warning('adtrust service'))
|
2012-05-30 04:54:01 -05:00
|
|
|
|
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")
|
2013-02-08 11:37:43 -06:00
|
|
|
krbconf.setOptionAssignment((" = ", " "))
|
2012-09-07 05:40:58 -05:00
|
|
|
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}]
|
|
|
|
|
2014-05-29 07:47:17 -05:00
|
|
|
krbconf.changeConf(paths.KRB5_CONF, opts)
|
2012-09-07 05:40:58 -05:00
|
|
|
|
|
|
|
def __update_krb5_conf(self):
|
|
|
|
"""
|
|
|
|
Update /etc/krb5.conf if needed
|
|
|
|
"""
|
|
|
|
|
|
|
|
try:
|
2014-05-29 07:47:17 -05:00
|
|
|
krb5conf = open(paths.KRB5_CONF, 'r')
|
2015-07-30 09:49:29 -05:00
|
|
|
except IOError as e:
|
2012-09-07 05:40:58 -05:00
|
|
|
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.")
|
|
|
|
|
2013-03-06 02:12:40 -06:00
|
|
|
def __check_replica(self):
|
|
|
|
try:
|
|
|
|
cifs_services = DN(api.env.container_service, self.suffix)
|
|
|
|
# Search for cifs services which also belong to adtrust agents, these are our DCs
|
|
|
|
res = self.admin_conn.get_entries(cifs_services,
|
|
|
|
ldap.SCOPE_ONELEVEL,
|
|
|
|
"(&(krbprincipalname=cifs/*@%s)(memberof=%s))" % (self.realm, str(self.smb_dn)))
|
|
|
|
if len(res) > 1:
|
|
|
|
# there are other CIFS services defined, we are not alone
|
|
|
|
for entry in res:
|
2013-09-10 05:20:24 -05:00
|
|
|
managedBy = entry.single_value.get('managedBy')
|
2013-03-06 02:12:40 -06:00
|
|
|
if managedBy:
|
|
|
|
fqdn = DN(managedBy)['fqdn']
|
|
|
|
if fqdn != unicode(self.fqdn):
|
|
|
|
# this is CIFS service of a different host in our
|
|
|
|
# REALM, we need to remember it to announce via
|
|
|
|
# SRV records for _msdcs
|
|
|
|
self.cifs_hosts.append(fqdn.split(".")[0])
|
2012-09-07 05:40:58 -05:00
|
|
|
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2013-03-06 02:12:40 -06:00
|
|
|
root_logger.critical("Checking replicas for cifs principals failed with error '%s'" % e)
|
2012-09-07 05:40:58 -05:00
|
|
|
|
ipa-adtrust-install: configure compatibility tree to serve trusted domain users
Enables support for trusted domains users for old clients through Schema
Compatibility plugin. SSSD supports trusted domains natively starting with
version 1.9 platform. For platforms that lack SSSD or run older SSSD version
one needs to use this option. When enabled, slapi-nis package needs to
be installed and schema-compat-plugin will be configured to provide lookup of
users and groups from trusted domains via SSSD on IPA server. These users and
groups will be available under cn=users,cn=compat,$SUFFIX and
cn=groups,cn=compat,$SUFFIX trees. SSSD will normalize names of users and
groups to lower case.
In addition to providing these users and groups through the compat tree,
this option enables authentication over LDAP for trusted domain users with DN
under compat tree, i.e. using bind DN uid=administrator@ad.domain,cn=users,cn=compat,$SUFFIX.
This authentication is related to PAM stack using 'system-auth' PAM
service. If you have disabled HBAC rule 'allow_all', then make sure there is
special service called 'system-auth' created and HBAC rule to allow access to
anyone to this rule on IPA masters is added. Please note that system-auth PAM
service is not used directly by any other application, therefore it is safe to
create one specifically to support trusted domain users via compatibility path.
https://fedorahosted.org/freeipa/ticket/3567
2013-07-15 11:13:50 -05:00
|
|
|
def __enable_compat_tree(self):
|
|
|
|
try:
|
|
|
|
compat_plugin_dn = DN("cn=Schema Compatibility,cn=plugins,cn=config")
|
2013-08-05 07:42:29 -05:00
|
|
|
lookup_nsswitch_name = "schema-compat-lookup-nsswitch"
|
ipa-adtrust-install: configure compatibility tree to serve trusted domain users
Enables support for trusted domains users for old clients through Schema
Compatibility plugin. SSSD supports trusted domains natively starting with
version 1.9 platform. For platforms that lack SSSD or run older SSSD version
one needs to use this option. When enabled, slapi-nis package needs to
be installed and schema-compat-plugin will be configured to provide lookup of
users and groups from trusted domains via SSSD on IPA server. These users and
groups will be available under cn=users,cn=compat,$SUFFIX and
cn=groups,cn=compat,$SUFFIX trees. SSSD will normalize names of users and
groups to lower case.
In addition to providing these users and groups through the compat tree,
this option enables authentication over LDAP for trusted domain users with DN
under compat tree, i.e. using bind DN uid=administrator@ad.domain,cn=users,cn=compat,$SUFFIX.
This authentication is related to PAM stack using 'system-auth' PAM
service. If you have disabled HBAC rule 'allow_all', then make sure there is
special service called 'system-auth' created and HBAC rule to allow access to
anyone to this rule on IPA masters is added. Please note that system-auth PAM
service is not used directly by any other application, therefore it is safe to
create one specifically to support trusted domain users via compatibility path.
https://fedorahosted.org/freeipa/ticket/3567
2013-07-15 11:13:50 -05:00
|
|
|
for config in (("cn=users", "user"), ("cn=groups", "group")):
|
|
|
|
entry_dn = DN(config[0], compat_plugin_dn)
|
|
|
|
current = self.admin_conn.get_entry(entry_dn)
|
2013-08-05 07:42:29 -05:00
|
|
|
lookup_nsswitch = current.get(lookup_nsswitch_name, [])
|
|
|
|
if not(config[1] in lookup_nsswitch):
|
|
|
|
current[lookup_nsswitch_name] = [config[1]]
|
2013-10-31 11:54:49 -05:00
|
|
|
self.admin_conn.update_entry(current)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2013-08-05 07:42:29 -05:00
|
|
|
root_logger.critical("Enabling nsswitch support in slapi-nis failed with error '%s'" % e)
|
ipa-adtrust-install: configure compatibility tree to serve trusted domain users
Enables support for trusted domains users for old clients through Schema
Compatibility plugin. SSSD supports trusted domains natively starting with
version 1.9 platform. For platforms that lack SSSD or run older SSSD version
one needs to use this option. When enabled, slapi-nis package needs to
be installed and schema-compat-plugin will be configured to provide lookup of
users and groups from trusted domains via SSSD on IPA server. These users and
groups will be available under cn=users,cn=compat,$SUFFIX and
cn=groups,cn=compat,$SUFFIX trees. SSSD will normalize names of users and
groups to lower case.
In addition to providing these users and groups through the compat tree,
this option enables authentication over LDAP for trusted domain users with DN
under compat tree, i.e. using bind DN uid=administrator@ad.domain,cn=users,cn=compat,$SUFFIX.
This authentication is related to PAM stack using 'system-auth' PAM
service. If you have disabled HBAC rule 'allow_all', then make sure there is
special service called 'system-auth' created and HBAC rule to allow access to
anyone to this rule on IPA masters is added. Please note that system-auth PAM
service is not used directly by any other application, therefore it is safe to
create one specifically to support trusted domain users via compatibility path.
https://fedorahosted.org/freeipa/ticket/3567
2013-07-15 11:13:50 -05:00
|
|
|
|
2011-09-07 03:17:12 -05:00
|
|
|
def __start(self):
|
|
|
|
try:
|
|
|
|
self.start()
|
2014-05-29 03:37:18 -05:00
|
|
|
services.service('winbind').start()
|
2015-10-27 10:08:10 -05:00
|
|
|
except Exception:
|
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:
|
2014-05-29 03:37:18 -05:00
|
|
|
services.service('winbind').stop()
|
2011-09-07 03:17:12 -05:00
|
|
|
self.stop()
|
2015-10-27 10:08:10 -05:00
|
|
|
except Exception:
|
2011-09-07 03:17:12 -05:00
|
|
|
pass
|
|
|
|
|
2012-06-21 08:04:10 -05:00
|
|
|
def __restart_dirsrv(self):
|
2012-03-27 05:06:33 -05:00
|
|
|
try:
|
2014-05-29 03:37:18 -05:00
|
|
|
services.knownservices.dirsrv.restart()
|
2015-10-27 10:08:10 -05:00
|
|
|
except Exception:
|
2012-03-27 05:06:33 -05:00
|
|
|
pass
|
|
|
|
|
2015-10-27 10:05:35 -05:00
|
|
|
def __restart_smb(self):
|
|
|
|
try:
|
|
|
|
services.knownservices.smb.restart()
|
|
|
|
except Exception:
|
|
|
|
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)
|
2015-07-30 09:49:29 -05:00
|
|
|
except (ldap.ALREADY_EXISTS, errors.DuplicateEntry) as 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)
|
2015-07-30 09:49:29 -05:00
|
|
|
except (ldap.ALREADY_EXISTS, errors.DuplicateEntry) as e:
|
2011-11-30 06:29:10 -06:00
|
|
|
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,
|
2014-01-17 06:09:34 -06:00
|
|
|
HOST_NETBIOS_NAME = self.host_netbios_name,
|
2011-09-07 03:17:12 -05:00
|
|
|
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
|
|
|
|
2015-04-28 08:34:07 -05:00
|
|
|
def setup(self, fqdn, realm_name, domain_name, netbios_name,
|
2012-10-29 15:43:56 -05:00
|
|
|
reset_netbios_name, rid_base, secondary_rid_base,
|
ipa-adtrust-install: configure compatibility tree to serve trusted domain users
Enables support for trusted domains users for old clients through Schema
Compatibility plugin. SSSD supports trusted domains natively starting with
version 1.9 platform. For platforms that lack SSSD or run older SSSD version
one needs to use this option. When enabled, slapi-nis package needs to
be installed and schema-compat-plugin will be configured to provide lookup of
users and groups from trusted domains via SSSD on IPA server. These users and
groups will be available under cn=users,cn=compat,$SUFFIX and
cn=groups,cn=compat,$SUFFIX trees. SSSD will normalize names of users and
groups to lower case.
In addition to providing these users and groups through the compat tree,
this option enables authentication over LDAP for trusted domain users with DN
under compat tree, i.e. using bind DN uid=administrator@ad.domain,cn=users,cn=compat,$SUFFIX.
This authentication is related to PAM stack using 'system-auth' PAM
service. If you have disabled HBAC rule 'allow_all', then make sure there is
special service called 'system-auth' created and HBAC rule to allow access to
anyone to this rule on IPA masters is added. Please note that system-auth PAM
service is not used directly by any other application, therefore it is safe to
create one specifically to support trusted domain users via compatibility path.
https://fedorahosted.org/freeipa/ticket/3567
2013-07-15 11:13:50 -05:00
|
|
|
no_msdcs=False, add_sids=False, smbd_user="samba", enable_compat=False):
|
2011-11-07 05:59:20 -06:00
|
|
|
self.fqdn = fqdn
|
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-10-29 15:43:56 -05:00
|
|
|
self.reset_netbios_name = reset_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
|
2012-10-02 15:11:17 -05:00
|
|
|
self.add_sids = add_sids
|
ipa-adtrust-install: configure compatibility tree to serve trusted domain users
Enables support for trusted domains users for old clients through Schema
Compatibility plugin. SSSD supports trusted domains natively starting with
version 1.9 platform. For platforms that lack SSSD or run older SSSD version
one needs to use this option. When enabled, slapi-nis package needs to
be installed and schema-compat-plugin will be configured to provide lookup of
users and groups from trusted domains via SSSD on IPA server. These users and
groups will be available under cn=users,cn=compat,$SUFFIX and
cn=groups,cn=compat,$SUFFIX trees. SSSD will normalize names of users and
groups to lower case.
In addition to providing these users and groups through the compat tree,
this option enables authentication over LDAP for trusted domain users with DN
under compat tree, i.e. using bind DN uid=administrator@ad.domain,cn=users,cn=compat,$SUFFIX.
This authentication is related to PAM stack using 'system-auth' PAM
service. If you have disabled HBAC rule 'allow_all', then make sure there is
special service called 'system-auth' created and HBAC rule to allow access to
anyone to this rule on IPA masters is added. Please note that system-auth PAM
service is not used directly by any other application, therefore it is safe to
create one specifically to support trusted domain users via compatibility path.
https://fedorahosted.org/freeipa/ticket/3567
2013-07-15 11:13:50 -05:00
|
|
|
self.enable_compat = enable_compat
|
2011-09-07 03:17:12 -05:00
|
|
|
self.smbd_user = smbd_user
|
|
|
|
|
2013-10-09 08:45:49 -05:00
|
|
|
# Setup constants and attributes derived from the values above
|
|
|
|
self.__setup_default_attributes()
|
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()
|
|
|
|
|
2013-01-28 11:02:48 -06:00
|
|
|
if self.admin_conn.get_entries(
|
|
|
|
DN(api.env.container_ranges, self.suffix),
|
|
|
|
ldap.SCOPE_ONELEVEL,
|
|
|
|
"(objectclass=ipaDomainIDRange)"):
|
2012-06-12 10:53:36 -05:00
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
2013-01-23 09:05:21 -06:00
|
|
|
entry = self.admin_conn.get_entry(
|
|
|
|
DN(('cn', 'admins'), api.env.container_group, self.suffix))
|
2012-06-12 10:53:36 -05:00
|
|
|
except errors.NotFound:
|
|
|
|
raise ValueError("No local ID range and no admins group found.\n" \
|
|
|
|
"Add local ID range manually and try again!")
|
|
|
|
|
2013-09-10 05:20:24 -05:00
|
|
|
base_id = int(entry.single_value['gidNumber'])
|
2012-06-12 10:53:36 -05:00
|
|
|
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))
|
2013-01-28 11:02:48 -06:00
|
|
|
if self.admin_conn.get_entries(DN(('cn', 'accounts'), self.suffix),
|
|
|
|
ldap.SCOPE_SUBTREE, id_filter):
|
2012-06-12 10:53:36 -05:00
|
|
|
raise ValueError("There are objects with IDs out of the expected" \
|
|
|
|
"range.\nAdd local ID range manually and try " \
|
|
|
|
"again!")
|
|
|
|
|
2013-01-18 08:24:35 -06:00
|
|
|
entry = self.admin_conn.make_entry(
|
|
|
|
DN(
|
|
|
|
('cn', ('%s_id_range' % self.realm)),
|
|
|
|
api.env.container_ranges, self.suffix),
|
|
|
|
objectclass=['ipaDomainIDRange'],
|
|
|
|
cn=['%s_id_range' % self.realm],
|
|
|
|
ipaBaseID=[str(base_id)],
|
|
|
|
ipaIDRangeSize=[str(id_range_size)],
|
|
|
|
)
|
2013-01-23 08:27:05 -06:00
|
|
|
self.admin_conn.add_entry(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)
|
2015-05-12 07:31:46 -05:00
|
|
|
self.step("adding cifs and host Kerberos principals to the adtrust agents group", \
|
|
|
|
self.__setup_group_membership)
|
2013-03-06 02:12:40 -06:00
|
|
|
self.step("check for cifs services defined on other replicas", self.__check_replica)
|
2012-10-08 05:27:16 -05:00
|
|
|
self.step("adding cifs principal to S4U2Proxy targets", self.__add_s4u2proxy_target)
|
2012-03-27 05:06:33 -05:00
|
|
|
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)
|
2015-05-12 07:31:46 -05:00
|
|
|
self.step("activating sidgen task", self.__add_sidgen_task)
|
2011-09-07 03:17:12 -05:00
|
|
|
self.step("configuring smbd to start on boot", self.__enable)
|
2012-10-04 05:40:33 -05:00
|
|
|
self.step("adding special DNS service records", \
|
|
|
|
self.__add_dns_service_records)
|
ipa-adtrust-install: configure compatibility tree to serve trusted domain users
Enables support for trusted domains users for old clients through Schema
Compatibility plugin. SSSD supports trusted domains natively starting with
version 1.9 platform. For platforms that lack SSSD or run older SSSD version
one needs to use this option. When enabled, slapi-nis package needs to
be installed and schema-compat-plugin will be configured to provide lookup of
users and groups from trusted domains via SSSD on IPA server. These users and
groups will be available under cn=users,cn=compat,$SUFFIX and
cn=groups,cn=compat,$SUFFIX trees. SSSD will normalize names of users and
groups to lower case.
In addition to providing these users and groups through the compat tree,
this option enables authentication over LDAP for trusted domain users with DN
under compat tree, i.e. using bind DN uid=administrator@ad.domain,cn=users,cn=compat,$SUFFIX.
This authentication is related to PAM stack using 'system-auth' PAM
service. If you have disabled HBAC rule 'allow_all', then make sure there is
special service called 'system-auth' created and HBAC rule to allow access to
anyone to this rule on IPA masters is added. Please note that system-auth PAM
service is not used directly by any other application, therefore it is safe to
create one specifically to support trusted domain users via compatibility path.
https://fedorahosted.org/freeipa/ticket/3567
2013-07-15 11:13:50 -05:00
|
|
|
|
|
|
|
if self.enable_compat:
|
|
|
|
self.step("enabling trusted domains support for older clients via Schema Compatibility plugin",
|
|
|
|
self.__enable_compat_tree)
|
|
|
|
|
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-09-18 04:32:10 -05:00
|
|
|
self.step("adding fallback group", self.__add_fallback_group)
|
2014-09-22 05:19:26 -05:00
|
|
|
self.step("adding Default Trust View", self.__add_default_trust_view)
|
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
|
|
|
|
2012-10-02 15:11:17 -05:00
|
|
|
if self.add_sids:
|
|
|
|
self.step("adding SIDs to existing users and groups",
|
|
|
|
self.__add_sids)
|
2015-10-27 10:05:35 -05:00
|
|
|
self.step("restarting smbd", self.__restart_smb)
|
2012-10-02 15:11:17 -05:00
|
|
|
|
2012-10-11 02:32:17 -05:00
|
|
|
self.start_creation(show_service_name=False)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
|
|
|
def uninstall(self):
|
|
|
|
if self.is_configured():
|
|
|
|
self.print_msg("Unconfiguring %s" % self.service_name)
|
|
|
|
|
2013-11-21 08:25:27 -06:00
|
|
|
# Call restore_state so that we do not leave mess in the statestore
|
|
|
|
# Otherwise this does nothing
|
|
|
|
self.restore_state("running")
|
|
|
|
self.restore_state("enabled")
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2014-05-29 03:37:18 -05:00
|
|
|
winbind = services.service("winbind")
|
2013-11-21 08:25:27 -06:00
|
|
|
# Always try to stop and disable smb service, since we do not leave
|
|
|
|
# working configuration after uninstall
|
2011-09-07 03:17:12 -05:00
|
|
|
try:
|
|
|
|
self.stop()
|
2013-11-21 08:25:27 -06:00
|
|
|
self.disable()
|
2014-02-25 12:11:50 -06:00
|
|
|
winbind.stop()
|
|
|
|
winbind.disable()
|
|
|
|
except Exception:
|
2011-09-07 03:17:12 -05:00
|
|
|
pass
|
|
|
|
|
2013-10-09 05:23:18 -05:00
|
|
|
# Since we do not guarantee restoring back to working samba state,
|
|
|
|
# we should not restore smb.conf
|
|
|
|
|
|
|
|
# Restore the state of affected selinux booleans
|
2014-08-14 10:14:07 -05:00
|
|
|
boolean_states = {name: self.restore_state(name)
|
|
|
|
for name in SELINUX_BOOLEAN_SETTINGS}
|
|
|
|
try:
|
|
|
|
tasks.set_selinux_booleans(boolean_states)
|
|
|
|
except ipapython.errors.SetseboolError as e:
|
|
|
|
self.print_msg('WARNING: ' + str(e))
|
2012-05-30 04:54:01 -05:00
|
|
|
|
2013-10-09 06:20:13 -05:00
|
|
|
# Remove samba's credentials cache
|
2015-10-09 11:08:38 -05:00
|
|
|
installutils.remove_ccache(ccache_path=paths.KRB5CC_SAMBA)
|
2013-10-09 06:20:13 -05:00
|
|
|
|
|
|
|
# Remove samba's configuration file
|
|
|
|
installutils.remove_file(self.smb_conf)
|
|
|
|
|
|
|
|
# Remove samba's persistent and temporary tdb files
|
2014-05-29 07:47:17 -05:00
|
|
|
tdb_files = [tdb_file for tdb_file in os.listdir(paths.SAMBA_DIR)
|
2013-10-09 06:20:13 -05:00
|
|
|
if tdb_file.endswith(".tdb")]
|
|
|
|
for tdb_file in tdb_files:
|
|
|
|
installutils.remove_file(tdb_file)
|
|
|
|
|
|
|
|
# Remove our keys from samba's keytab
|
|
|
|
self.clean_samba_keytab()
|