2009-05-13 07:21:30 -05:00
|
|
|
# Authors:
|
|
|
|
# Rob Crittenden <rcritten@redhat.com>
|
|
|
|
# Pavel Zuna <pzuna@redhat.com>
|
|
|
|
#
|
|
|
|
# Copyright (C) 2008 Red Hat
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
2010-12-09 06:59:11 -06:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
2009-05-13 07:21:30 -05:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2010-12-09 06:59:11 -06:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-08-24 21:48:30 -05:00
|
|
|
|
|
|
|
from ipalib import 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 ipalib import Bool, Int, Str, IA5Str, StrEnum, DNParam
|
2015-12-16 12:04:20 -06:00
|
|
|
from ipalib import errors
|
2019-05-01 09:15:37 -05:00
|
|
|
from ipalib.constants import MAXHOSTNAMELEN
|
2014-06-10 10:27:51 -05:00
|
|
|
from ipalib.plugable import Registry
|
2017-03-09 11:14:52 -06:00
|
|
|
from ipalib.util import validate_domain_name
|
2016-04-20 08:41:34 -05:00
|
|
|
from .baseldap import (
|
2015-12-16 12:04:20 -06:00
|
|
|
LDAPObject,
|
|
|
|
LDAPUpdate,
|
|
|
|
LDAPRetrieve)
|
2016-04-20 08:41:34 -05:00
|
|
|
from .selinuxusermap import validate_selinuxuser
|
2011-08-24 21:48:30 -05:00
|
|
|
from ipalib import _
|
2015-12-16 12:04:20 -06:00
|
|
|
from ipapython.dn import DN
|
2011-08-24 21:48:30 -05:00
|
|
|
|
2011-10-11 03:26:21 -05:00
|
|
|
# 389-ds attributes that should be skipped in attribute checks
|
|
|
|
OPERATIONAL_ATTRIBUTES = ('nsaccountlock', 'member', 'memberof',
|
|
|
|
'memberindirect', 'memberofindirect',)
|
|
|
|
|
2017-03-09 11:14:52 -06:00
|
|
|
DOMAIN_RESOLUTION_ORDER_SEPARATOR = u':'
|
|
|
|
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _("""
|
2011-11-10 05:06:49 -06:00
|
|
|
Server configuration
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2011-03-04 10:08:54 -06:00
|
|
|
Manage the default values that IPA uses and some of its tuning parameters.
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2011-11-10 05:06:49 -06:00
|
|
|
NOTES:
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2011-11-10 05:06:49 -06:00
|
|
|
The password notification value (--pwdexpnotify) is stored here so it will
|
|
|
|
be replicated. It is not currently used to notify users in advance of an
|
|
|
|
expiring password.
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2011-11-10 05:06:49 -06:00
|
|
|
Some attributes are read-only, provided only for information purposes. These
|
|
|
|
include:
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2011-11-10 05:06:49 -06:00
|
|
|
Certificate Subject base: the configured certificate subject base,
|
|
|
|
e.g. O=EXAMPLE.COM. This is configurable only at install time.
|
|
|
|
Password plug-in features: currently defines additional hashes that the
|
|
|
|
password will generate (there may be other conditions).
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2011-11-23 15:59:21 -06:00
|
|
|
When setting the order list for mapping SELinux users you may need to
|
|
|
|
quote the value so it isn't interpreted by the shell.
|
|
|
|
|
2019-05-01 09:15:37 -05:00
|
|
|
The maximum length of a hostname in Linux is controlled by
|
|
|
|
MAXHOSTNAMELEN in the kernel and defaults to 64. Some other operating
|
|
|
|
systems, Solaris for example, allows hostnames up to 255 characters.
|
|
|
|
This option will allow flexibility in length but by default limiting
|
|
|
|
to the Linux maximum length.
|
|
|
|
|
2011-11-10 05:06:49 -06:00
|
|
|
EXAMPLES:
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2011-11-10 05:06:49 -06:00
|
|
|
Show basic server configuration:
|
|
|
|
ipa config-show
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2011-11-10 05:06:49 -06:00
|
|
|
Show all configuration options:
|
|
|
|
ipa config-show --all
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2011-11-10 05:06:49 -06:00
|
|
|
Change maximum username length to 99 characters:
|
|
|
|
ipa config-mod --maxusername=99
|
2010-06-02 13:08:50 -05:00
|
|
|
|
2019-05-01 09:15:37 -05:00
|
|
|
Change maximum host name length to 255 characters:
|
|
|
|
ipa config-mod --maxhostname=255
|
|
|
|
|
2011-11-10 05:06:49 -06:00
|
|
|
Increase default time and size limits for maximum IPA server search:
|
|
|
|
ipa config-mod --searchtimelimit=10 --searchrecordslimit=2000
|
2010-12-01 16:48:41 -06:00
|
|
|
|
2011-11-10 05:06:49 -06:00
|
|
|
Set default user e-mail domain:
|
|
|
|
ipa config-mod --emaildomain=example.com
|
2010-12-01 16:48:41 -06:00
|
|
|
|
2011-11-10 05:06:49 -06:00
|
|
|
Enable migration mode to make "ipa migrate-ds" command operational:
|
|
|
|
ipa config-mod --enable-migration=TRUE
|
2011-11-23 15:59:21 -06:00
|
|
|
|
|
|
|
Define SELinux user map order:
|
|
|
|
ipa config-mod --ipaselinuxusermaporder='guest_u:s0$xguest_u:s0$user_u:s0-s0:c0.c1023$staff_u:s0-s0:c0.c1023$unconfined_u:s0-s0:c0.c1023'
|
2011-08-24 21:48:30 -05:00
|
|
|
""")
|
2009-05-13 07:21:30 -05:00
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
register = Registry()
|
|
|
|
|
2018-06-18 16:26:01 -05:00
|
|
|
|
|
|
|
def validate_search_records_limit(ugettext, value):
|
|
|
|
"""Check if value is greater than a realistic minimum.
|
|
|
|
|
|
|
|
Values 0 and -1 are valid, as they represent unlimited.
|
|
|
|
"""
|
|
|
|
if value in {-1, 0}:
|
2018-07-10 15:14:04 -05:00
|
|
|
return None
|
2018-06-18 16:26:01 -05:00
|
|
|
if value < 10:
|
|
|
|
return _('must be at least 10')
|
2018-07-10 15:14:04 -05:00
|
|
|
return None
|
2018-06-18 16:26:01 -05:00
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2009-08-27 08:49:58 -05:00
|
|
|
class config(LDAPObject):
|
2009-05-13 07:21:30 -05:00
|
|
|
"""
|
2009-08-27 08:49:58 -05:00
|
|
|
IPA configuration object
|
2009-05-13 07:21:30 -05:00
|
|
|
"""
|
2011-07-12 11:01:25 -05:00
|
|
|
object_name = _('configuration options')
|
2009-08-27 08:49:58 -05:00
|
|
|
default_attributes = [
|
|
|
|
'ipamaxusernamelength', 'ipahomesrootdir', 'ipadefaultloginshell',
|
2010-12-05 02:26:52 -06:00
|
|
|
'ipadefaultprimarygroup', 'ipadefaultemaildomain', 'ipasearchtimelimit',
|
2009-08-27 08:49:58 -05:00
|
|
|
'ipasearchrecordslimit', 'ipausersearchfields', 'ipagroupsearchfields',
|
2010-01-20 10:26:20 -06:00
|
|
|
'ipamigrationenabled', 'ipacertificatesubjectbase',
|
2012-01-19 16:42:26 -06:00
|
|
|
'ipapwdexpadvnotify', 'ipaselinuxusermaporder',
|
2012-08-01 09:14:11 -05:00
|
|
|
'ipaselinuxusermapdefault', 'ipaconfigstring', 'ipakrbauthzdata',
|
2019-05-01 09:15:37 -05:00
|
|
|
'ipauserauthtype', 'ipadomainresolutionorder', 'ipamaxhostnamelength',
|
2009-08-27 08:49:58 -05:00
|
|
|
]
|
2014-03-26 08:56:30 -05:00
|
|
|
container_dn = DN(('cn', 'ipaconfig'), ('cn', 'etc'))
|
|
|
|
permission_filter_objectclasses = ['ipaguiconfig']
|
|
|
|
managed_permissions = {
|
|
|
|
'System: Read Global Configuration': {
|
|
|
|
'replaces_global_anonymous_aci': True,
|
|
|
|
'ipapermbindruletype': 'all',
|
|
|
|
'ipapermright': {'read', 'search', 'compare'},
|
|
|
|
'ipapermdefaultattr': {
|
|
|
|
'cn', 'objectclass',
|
|
|
|
'ipacertificatesubjectbase', 'ipaconfigstring',
|
|
|
|
'ipadefaultemaildomain', 'ipadefaultloginshell',
|
2017-03-09 11:14:52 -06:00
|
|
|
'ipadefaultprimarygroup', 'ipadomainresolutionorder',
|
|
|
|
'ipagroupobjectclasses',
|
2014-03-26 08:56:30 -05:00
|
|
|
'ipagroupsearchfields', 'ipahomesrootdir',
|
|
|
|
'ipakrbauthzdata', 'ipamaxusernamelength',
|
|
|
|
'ipamigrationenabled', 'ipapwdexpadvnotify',
|
|
|
|
'ipaselinuxusermapdefault', 'ipaselinuxusermaporder',
|
|
|
|
'ipasearchrecordslimit', 'ipasearchtimelimit',
|
|
|
|
'ipauserauthtype', 'ipauserobjectclasses',
|
|
|
|
'ipausersearchfields', 'ipacustomfields',
|
2019-05-01 09:15:37 -05:00
|
|
|
'ipamaxhostnamelength',
|
2014-03-26 08:56:30 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2009-08-27 08:49:58 -05:00
|
|
|
|
2010-09-24 19:48:23 -05:00
|
|
|
label = _('Configuration')
|
2011-07-13 21:10:47 -05:00
|
|
|
label_singular = _('Configuration')
|
2010-09-24 19:48:23 -05:00
|
|
|
|
2009-08-27 08:49:58 -05:00
|
|
|
takes_params = (
|
2012-02-20 03:03:27 -06:00
|
|
|
Int('ipamaxusernamelength',
|
2009-05-13 07:21:30 -05:00
|
|
|
cli_name='maxusername',
|
2011-11-10 05:06:49 -06:00
|
|
|
label=_('Maximum username length'),
|
2009-05-13 07:21:30 -05:00
|
|
|
minvalue=1,
|
2016-04-14 10:03:51 -05:00
|
|
|
maxvalue=255,
|
2009-05-13 07:21:30 -05:00
|
|
|
),
|
2019-05-01 09:15:37 -05:00
|
|
|
Int('ipamaxhostnamelength',
|
|
|
|
cli_name='maxhostname',
|
|
|
|
label=_('Maximum hostname length'),
|
|
|
|
minvalue=MAXHOSTNAMELEN,
|
|
|
|
maxvalue=255,),
|
2012-02-20 03:03:27 -06:00
|
|
|
IA5Str('ipahomesrootdir',
|
2009-05-13 07:21:30 -05:00
|
|
|
cli_name='homedirectory',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Home directory base'),
|
2011-11-10 05:06:49 -06:00
|
|
|
doc=_('Default location of home directories'),
|
2009-05-13 07:21:30 -05:00
|
|
|
),
|
2012-02-20 03:03:27 -06:00
|
|
|
Str('ipadefaultloginshell',
|
2009-05-13 07:21:30 -05:00
|
|
|
cli_name='defaultshell',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Default shell'),
|
2011-11-10 05:06:49 -06:00
|
|
|
doc=_('Default shell for new users'),
|
2009-05-13 07:21:30 -05:00
|
|
|
),
|
2012-02-20 03:03:27 -06:00
|
|
|
Str('ipadefaultprimarygroup',
|
2009-05-13 07:21:30 -05:00
|
|
|
cli_name='defaultgroup',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Default users group'),
|
2011-11-10 05:06:49 -06:00
|
|
|
doc=_('Default group for new users'),
|
2009-05-13 07:21:30 -05:00
|
|
|
),
|
|
|
|
Str('ipadefaultemaildomain?',
|
|
|
|
cli_name='emaildomain',
|
2011-11-10 05:06:49 -06:00
|
|
|
label=_('Default e-mail domain'),
|
|
|
|
doc=_('Default e-mail domain'),
|
2009-05-13 07:21:30 -05:00
|
|
|
),
|
2015-09-21 07:55:17 -05:00
|
|
|
Int('ipasearchtimelimit',
|
2009-05-13 07:21:30 -05:00
|
|
|
cli_name='searchtimelimit',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Search time limit'),
|
2015-09-21 07:55:17 -05:00
|
|
|
doc=_('Maximum amount of time (seconds) for a search (-1 or 0 is unlimited)'),
|
2009-05-13 07:21:30 -05:00
|
|
|
minvalue=-1,
|
|
|
|
),
|
2012-02-20 03:03:27 -06:00
|
|
|
Int('ipasearchrecordslimit',
|
2018-06-18 16:26:01 -05:00
|
|
|
validate_search_records_limit,
|
2009-05-13 07:21:30 -05:00
|
|
|
cli_name='searchrecordslimit',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Search size limit'),
|
2015-09-21 07:55:17 -05:00
|
|
|
doc=_('Maximum number of records to search (-1 or 0 is unlimited)'),
|
2009-05-13 07:21:30 -05:00
|
|
|
),
|
2012-02-20 03:03:27 -06:00
|
|
|
IA5Str('ipausersearchfields',
|
2009-05-13 07:21:30 -05:00
|
|
|
cli_name='usersearch',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('User search fields'),
|
2011-11-10 05:06:49 -06:00
|
|
|
doc=_('A comma-separated list of fields to search in when searching for users'),
|
2009-05-13 07:21:30 -05:00
|
|
|
),
|
2012-02-20 03:03:27 -06:00
|
|
|
IA5Str('ipagroupsearchfields',
|
2009-05-13 07:21:30 -05:00
|
|
|
cli_name='groupsearch',
|
2016-11-30 03:51:04 -06:00
|
|
|
label=_('Group search fields'),
|
2011-11-10 05:06:49 -06:00
|
|
|
doc=_('A comma-separated list of fields to search in when searching for groups'),
|
2009-05-13 07:21:30 -05:00
|
|
|
),
|
2012-02-20 03:03:27 -06:00
|
|
|
Bool('ipamigrationenabled',
|
2009-11-30 05:10:06 -06:00
|
|
|
cli_name='enable_migration',
|
2011-06-30 12:45:35 -05:00
|
|
|
label=_('Enable migration mode'),
|
2011-11-10 05:06:49 -06:00
|
|
|
doc=_('Enable migration mode'),
|
2009-11-30 05:10:06 -06:00
|
|
|
),
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
DNParam('ipacertificatesubjectbase',
|
2010-01-20 10:26:20 -06:00
|
|
|
cli_name='subject',
|
2010-02-19 10:08:16 -06:00
|
|
|
label=_('Certificate Subject base'),
|
2011-11-10 05:06:49 -06:00
|
|
|
doc=_('Base for certificate subjects (OU=Test,O=Example)'),
|
2010-12-01 16:48:41 -06:00
|
|
|
flags=['no_update'],
|
|
|
|
),
|
2012-02-20 03:03:27 -06:00
|
|
|
Str('ipagroupobjectclasses+',
|
2010-12-01 16:48:41 -06:00
|
|
|
cli_name='groupobjectclasses',
|
|
|
|
label=_('Default group objectclasses'),
|
2011-11-10 05:06:49 -06:00
|
|
|
doc=_('Default group objectclasses (comma-separated list)'),
|
2010-12-01 16:48:41 -06:00
|
|
|
),
|
2012-02-20 03:03:27 -06:00
|
|
|
Str('ipauserobjectclasses+',
|
2010-12-01 16:48:41 -06:00
|
|
|
cli_name='userobjectclasses',
|
|
|
|
label=_('Default user objectclasses'),
|
2011-11-10 05:06:49 -06:00
|
|
|
doc=_('Default user objectclasses (comma-separated list)'),
|
2010-12-01 16:48:41 -06:00
|
|
|
),
|
2012-02-20 03:03:27 -06:00
|
|
|
Int('ipapwdexpadvnotify',
|
2010-12-01 16:48:41 -06:00
|
|
|
cli_name='pwdexpnotify',
|
2011-07-05 13:55:03 -05:00
|
|
|
label=_('Password Expiration Notification (days)'),
|
2011-11-10 05:06:49 -06:00
|
|
|
doc=_('Number of days\'s notice of impending password expiration'),
|
2010-12-01 16:48:41 -06:00
|
|
|
minvalue=0,
|
|
|
|
),
|
2012-01-19 16:42:26 -06:00
|
|
|
StrEnum('ipaconfigstring*',
|
2010-12-01 16:48:41 -06:00
|
|
|
cli_name='ipaconfigstring',
|
|
|
|
label=_('Password plugin features'),
|
2011-11-10 05:06:49 -06:00
|
|
|
doc=_('Extra hashes to generate in password plug-in'),
|
2013-10-29 05:37:03 -05:00
|
|
|
values=(u'AllowNThash',
|
2015-11-24 14:39:08 -06:00
|
|
|
u'KDC:Disable Last Success', u'KDC:Disable Lockout',
|
|
|
|
u'KDC:Disable Default Preauth for SPNs'),
|
2010-01-20 10:26:20 -06:00
|
|
|
),
|
2012-02-20 03:03:27 -06:00
|
|
|
Str('ipaselinuxusermaporder',
|
2011-11-23 15:59:21 -06:00
|
|
|
label=_('SELinux user map order'),
|
|
|
|
doc=_('Order in increasing priority of SELinux users, delimited by $'),
|
|
|
|
),
|
2012-09-10 16:07:54 -05:00
|
|
|
Str('ipaselinuxusermapdefault?',
|
2011-11-23 15:59:21 -06:00
|
|
|
label=_('Default SELinux user'),
|
|
|
|
doc=_('Default SELinux user when no match is found in SELinux map rule'),
|
|
|
|
),
|
2012-08-01 09:14:11 -05:00
|
|
|
StrEnum('ipakrbauthzdata*',
|
|
|
|
cli_name='pac_type',
|
2012-10-02 10:06:10 -05:00
|
|
|
label=_('Default PAC types'),
|
|
|
|
doc=_('Default types of PAC supported for services'),
|
2013-03-04 07:52:10 -06:00
|
|
|
values=(u'MS-PAC', u'PAD', u'nfs:NONE'),
|
2012-08-01 09:14:11 -05:00
|
|
|
),
|
2019-07-29 10:00:35 -05:00
|
|
|
StrEnum(
|
|
|
|
'ipauserauthtype*',
|
2013-09-18 14:48:23 -05:00
|
|
|
cli_name='user_auth_type',
|
|
|
|
label=_('Default user authentication types'),
|
|
|
|
doc=_('Default types of supported user authentication'),
|
2019-07-29 10:00:35 -05:00
|
|
|
values=(u'password', u'radius', u'otp',
|
|
|
|
u'pkinit', u'hardened', u'disabled'),
|
2013-09-18 14:48:23 -05:00
|
|
|
),
|
2016-05-30 11:42:01 -05:00
|
|
|
Str(
|
|
|
|
'ipa_master_server*',
|
|
|
|
label=_('IPA masters'),
|
|
|
|
doc=_('List of all IPA masters'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update'}
|
|
|
|
),
|
2019-03-25 09:59:51 -05:00
|
|
|
Str(
|
|
|
|
'ipa_master_hidden_server*',
|
|
|
|
label=_('Hidden IPA masters'),
|
|
|
|
doc=_('List of all hidden IPA masters'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update'}
|
|
|
|
),
|
|
|
|
Str(
|
|
|
|
'pkinit_server_server*',
|
|
|
|
label=_('IPA master capable of PKINIT'),
|
|
|
|
doc=_('IPA master which can process PKINIT requests'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update'}
|
|
|
|
),
|
2016-05-30 11:42:01 -05:00
|
|
|
Str(
|
|
|
|
'ca_server_server*',
|
|
|
|
label=_('IPA CA servers'),
|
|
|
|
doc=_('IPA servers configured as certificate authority'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update'}
|
|
|
|
),
|
2019-03-25 09:59:51 -05:00
|
|
|
Str(
|
|
|
|
'ca_server_hidden_server*',
|
|
|
|
label=_('Hidden IPA CA servers'),
|
|
|
|
doc=_('Hidden IPA servers configured as certificate authority'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update'}
|
|
|
|
),
|
2016-05-30 11:42:01 -05:00
|
|
|
Str(
|
|
|
|
'ca_renewal_master_server?',
|
|
|
|
label=_('IPA CA renewal master'),
|
|
|
|
doc=_('Renewal master for IPA certificate authority'),
|
2016-05-30 11:51:48 -05:00
|
|
|
flags={'virtual_attribute', 'no_create'}
|
2017-03-09 11:14:52 -06:00
|
|
|
),
|
2017-05-12 08:27:36 -05:00
|
|
|
Str(
|
2019-03-25 09:59:51 -05:00
|
|
|
'kra_server_server*',
|
|
|
|
label=_('IPA KRA servers'),
|
|
|
|
doc=_('IPA servers configured as key recovery agent'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update'}
|
|
|
|
),
|
|
|
|
Str(
|
|
|
|
'kra_server_hidden_server*',
|
|
|
|
label=_('Hidden IPA KRA servers'),
|
|
|
|
doc=_('Hidden IPA servers configured as key recovery agent'),
|
2017-05-12 08:27:36 -05:00
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update'}
|
|
|
|
),
|
2017-03-09 11:14:52 -06:00
|
|
|
Str(
|
|
|
|
'ipadomainresolutionorder?',
|
|
|
|
cli_name='domain_resolution_order',
|
|
|
|
label=_('Domain resolution order'),
|
|
|
|
doc=_('colon-separated list of domains used for short name'
|
|
|
|
' qualification')
|
2019-03-25 09:59:51 -05:00
|
|
|
),
|
|
|
|
Str(
|
|
|
|
'dns_server_server*',
|
|
|
|
label=_('IPA DNS servers'),
|
|
|
|
doc=_('IPA servers configured as domain name server'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update'}
|
|
|
|
),
|
|
|
|
Str(
|
|
|
|
'dns_server_hidden_server*',
|
|
|
|
label=_('Hidden IPA DNS servers'),
|
|
|
|
doc=_('Hidden IPA servers configured as domain name server'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update'}
|
|
|
|
),
|
|
|
|
Str(
|
|
|
|
'dnssec_key_master_server?',
|
|
|
|
label=_('IPA DNSSec key master'),
|
|
|
|
doc=_('DNSec key master'),
|
|
|
|
flags={'virtual_attribute', 'no_create', 'no_update'}
|
|
|
|
),
|
2009-05-13 07:21:30 -05:00
|
|
|
)
|
|
|
|
|
2009-08-27 08:49:58 -05:00
|
|
|
def get_dn(self, *keys, **kwargs):
|
2013-02-04 02:47:00 -06:00
|
|
|
return DN(('cn', 'ipaconfig'), ('cn', 'etc'), api.env.basedn)
|
2009-05-13 07:21:30 -05:00
|
|
|
|
2017-05-16 10:29:39 -05:00
|
|
|
def update_entry_with_role_config(self, role_name, entry_attrs):
|
|
|
|
backend = self.api.Backend.serverroles
|
|
|
|
|
2018-03-19 14:48:04 -05:00
|
|
|
try:
|
|
|
|
role_config = backend.config_retrieve(role_name)
|
|
|
|
except errors.EmptyResult:
|
|
|
|
# No role config means current user identity
|
|
|
|
# has no rights to see it, return with no action
|
|
|
|
return
|
|
|
|
|
2017-05-16 10:29:39 -05:00
|
|
|
for key, value in role_config.items():
|
2018-03-19 14:48:04 -05:00
|
|
|
try:
|
|
|
|
entry_attrs.update({key: value})
|
|
|
|
except errors.EmptyResult:
|
|
|
|
# An update that doesn't change an entry is fine here
|
|
|
|
# Just ignore and move to the next key pair
|
|
|
|
pass
|
2017-05-16 10:29:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
def show_servroles_attributes(self, entry_attrs, *roles, **options):
|
2016-05-30 11:42:01 -05:00
|
|
|
if options.get('raw', False):
|
|
|
|
return
|
|
|
|
|
2017-05-16 10:29:39 -05:00
|
|
|
for role in roles:
|
|
|
|
self.update_entry_with_role_config(role, entry_attrs)
|
2009-05-13 07:21:30 -05:00
|
|
|
|
2017-03-09 11:14:52 -06:00
|
|
|
def gather_trusted_domains(self):
|
|
|
|
"""
|
|
|
|
Aggregate all trusted domains into a dict keyed by domain names with
|
|
|
|
values corresponding to domain status (enabled/disabled)
|
|
|
|
"""
|
|
|
|
command = self.api.Command
|
|
|
|
try:
|
|
|
|
ad_forests = command.trust_find(sizelimit=0)['result']
|
|
|
|
except errors.NotFound:
|
|
|
|
return {}
|
|
|
|
|
|
|
|
trusted_domains = {}
|
|
|
|
for forest_name in [a['cn'][0] for a in ad_forests]:
|
|
|
|
forest_domains = command.trustdomain_find(
|
|
|
|
forest_name, sizelimit=0)['result']
|
|
|
|
|
|
|
|
trusted_domains.update(
|
|
|
|
{
|
|
|
|
dom['cn'][0]: dom['domain_enabled'][0]
|
|
|
|
for dom in forest_domains if 'domain_enabled' in dom
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
return trusted_domains
|
|
|
|
|
|
|
|
def _validate_single_domain(self, attr_name, domain, known_domains):
|
|
|
|
"""
|
|
|
|
Validate a single domain from domain resolution order
|
|
|
|
|
|
|
|
:param attr_name: name of attribute that holds domain resolution order
|
|
|
|
:param domain: domain name
|
|
|
|
:param known_domains: dict of domains known to IPA keyed by domain name
|
|
|
|
and valued by boolean value corresponding to domain status
|
|
|
|
(enabled/disabled)
|
|
|
|
|
|
|
|
:raises: ValidationError if the domain name is empty, syntactically
|
|
|
|
invalid or corresponds to a disable domain
|
|
|
|
NotFound if a syntactically correct domain name unknown to IPA
|
|
|
|
is supplied (not IPA domain and not any of trusted domains)
|
|
|
|
"""
|
|
|
|
if not domain:
|
|
|
|
raise errors.ValidationError(
|
|
|
|
name=attr_name,
|
|
|
|
error=_("Empty domain is not allowed")
|
|
|
|
)
|
|
|
|
|
|
|
|
try:
|
|
|
|
validate_domain_name(domain)
|
|
|
|
except ValueError as e:
|
|
|
|
raise errors.ValidationError(
|
|
|
|
name=attr_name,
|
|
|
|
error=_("Invalid domain name '%(domain)s': %(e)s")
|
|
|
|
% dict(domain=domain, e=e))
|
|
|
|
|
|
|
|
if domain not in known_domains:
|
|
|
|
raise errors.NotFound(
|
|
|
|
reason=_("Server has no information about domain '%(domain)s'")
|
|
|
|
% dict(domain=domain)
|
|
|
|
)
|
|
|
|
|
|
|
|
if not known_domains[domain]:
|
|
|
|
raise errors.ValidationError(
|
|
|
|
name=attr_name,
|
|
|
|
error=_("Disabled domain '%(domain)s' is not allowed")
|
|
|
|
% dict(domain=domain)
|
|
|
|
)
|
|
|
|
|
|
|
|
def validate_domain_resolution_order(self, entry_attrs):
|
|
|
|
"""
|
|
|
|
Validate domain resolution order, e.g. split by the delimiter (colon)
|
|
|
|
and check each domain name for non-emptiness, syntactic correctness,
|
|
|
|
and status (enabled/disabled).
|
|
|
|
|
|
|
|
supplying empty order (':') bypasses validations and allows to specify
|
|
|
|
empty attribute value.
|
|
|
|
"""
|
|
|
|
attr_name = 'ipadomainresolutionorder'
|
|
|
|
if attr_name not in entry_attrs:
|
|
|
|
return
|
|
|
|
|
|
|
|
domain_resolution_order = entry_attrs[attr_name]
|
|
|
|
|
2017-03-28 09:15:21 -05:00
|
|
|
# setting up an empty string means that the previous configuration has
|
|
|
|
# to be cleaned up/removed. So, do nothing and let it pass
|
|
|
|
if not domain_resolution_order:
|
|
|
|
return
|
|
|
|
|
2017-03-09 11:14:52 -06:00
|
|
|
# empty resolution order is signalized by single separator, do nothing
|
|
|
|
# and let it pass
|
|
|
|
if domain_resolution_order == DOMAIN_RESOLUTION_ORDER_SEPARATOR:
|
|
|
|
return
|
|
|
|
|
|
|
|
submitted_domains = domain_resolution_order.split(
|
|
|
|
DOMAIN_RESOLUTION_ORDER_SEPARATOR)
|
|
|
|
|
|
|
|
known_domains = self.gather_trusted_domains()
|
|
|
|
|
|
|
|
# add FreeIPA domain to the list of domains. This one is always enabled
|
|
|
|
known_domains.update({self.api.env.domain: True})
|
|
|
|
|
|
|
|
for domain in submitted_domains:
|
|
|
|
self._validate_single_domain(attr_name, domain, known_domains)
|
|
|
|
|
2009-05-13 07:21:30 -05:00
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2009-08-27 08:49:58 -05:00
|
|
|
class config_mod(LDAPUpdate):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Modify configuration options.')
|
|
|
|
|
2009-11-30 05:10:06 -06:00
|
|
|
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
Use DN objects instead of strings
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
2012-05-13 06:36:35 -05:00
|
|
|
assert isinstance(dn, DN)
|
2010-12-06 10:08:10 -06:00
|
|
|
if 'ipadefaultprimarygroup' in entry_attrs:
|
|
|
|
group=entry_attrs['ipadefaultprimarygroup']
|
|
|
|
try:
|
2013-06-25 07:58:37 -05:00
|
|
|
api.Object['group'].get_dn_if_exists(group)
|
2010-12-06 10:08:10 -06:00
|
|
|
except errors.NotFound:
|
2011-10-11 04:30:48 -05:00
|
|
|
raise errors.NotFound(message=_("The group doesn't exist"))
|
2011-01-25 14:25:52 -06:00
|
|
|
kw = {}
|
|
|
|
if 'ipausersearchfields' in entry_attrs:
|
|
|
|
kw['ipausersearchfields'] = 'ipauserobjectclasses'
|
|
|
|
if 'ipagroupsearchfields' in entry_attrs:
|
|
|
|
kw['ipagroupsearchfields'] = 'ipagroupobjectclasses'
|
|
|
|
if kw:
|
Use Python3-compatible dict method names
Python 2 has keys()/values()/items(), which return lists,
iterkeys()/itervalues()/iteritems(), which return iterators,
and viewkeys()/viewvalues()/viewitems() which return views.
Python 3 has only keys()/values()/items(), which return views.
To get iterators, one can use iter() or a for loop/comprehension;
for lists there's the list() constructor.
When iterating through the entire dict, without modifying the dict,
the difference between Python 2's items() and iteritems() is
negligible, especially on small dicts (the main overhead is
extra memory, not CPU time). In the interest of simpler code,
this patch changes many instances of iteritems() to items(),
iterkeys() to keys() etc.
In other cases, helpers like six.itervalues are used.
Reviewed-By: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
2015-08-11 06:51:14 -05:00
|
|
|
config = ldap.get_ipa_config(list(kw.values()))
|
|
|
|
for (k, v) in kw.items():
|
2013-10-31 11:54:21 -05:00
|
|
|
allowed_attrs = ldap.get_allowed_attributes(config[v])
|
2016-08-22 03:14:20 -05:00
|
|
|
# normalize attribute names
|
|
|
|
attributes = [field.strip().lower()
|
|
|
|
for field in entry_attrs[k].split(',')]
|
|
|
|
# test if all base types (without sub-types) are allowed
|
|
|
|
for a in attributes:
|
2019-10-18 14:56:47 -05:00
|
|
|
a, _unused1, _unused2 = a.partition(';')
|
2011-01-25 14:25:52 -06:00
|
|
|
if a not in allowed_attrs:
|
|
|
|
raise errors.ValidationError(
|
2011-10-11 04:30:48 -05:00
|
|
|
name=k, error=_('attribute "%s" not allowed') % a
|
2011-01-25 14:25:52 -06:00
|
|
|
)
|
2016-08-22 03:14:20 -05:00
|
|
|
# write normalized form to LDAP
|
|
|
|
entry_attrs[k] = ','.join(attributes)
|
2011-10-11 03:26:21 -05:00
|
|
|
|
2015-09-21 07:55:17 -05:00
|
|
|
# Set ipasearchrecordslimit to -1 if 0 is used
|
|
|
|
if 'ipasearchrecordslimit' in entry_attrs:
|
2019-09-03 04:48:50 -05:00
|
|
|
if entry_attrs['ipasearchrecordslimit'] == 0:
|
2015-09-21 07:55:17 -05:00
|
|
|
entry_attrs['ipasearchrecordslimit'] = -1
|
|
|
|
|
|
|
|
# Set ipasearchtimelimit to -1 if 0 is used
|
|
|
|
if 'ipasearchtimelimit' in entry_attrs:
|
2019-09-03 04:48:50 -05:00
|
|
|
if entry_attrs['ipasearchtimelimit'] == 0:
|
2015-09-21 07:55:17 -05:00
|
|
|
entry_attrs['ipasearchtimelimit'] = -1
|
|
|
|
|
2011-10-11 03:26:21 -05:00
|
|
|
for (attr, obj) in (('ipauserobjectclasses', 'user'),
|
|
|
|
('ipagroupobjectclasses', 'group')):
|
|
|
|
if attr in entry_attrs:
|
2011-11-08 16:04:26 -06:00
|
|
|
if not entry_attrs[attr]:
|
|
|
|
raise errors.ValidationError(name=attr,
|
|
|
|
error=_('May not be empty'))
|
2012-05-02 11:36:15 -05:00
|
|
|
objectclasses = list(set(entry_attrs[attr]).union(
|
|
|
|
self.api.Object[obj].possible_objectclasses))
|
2011-10-11 03:26:21 -05:00
|
|
|
new_allowed_attrs = ldap.get_allowed_attributes(objectclasses,
|
|
|
|
raise_on_unknown=True)
|
|
|
|
checked_attrs = self.api.Object[obj].default_attributes
|
|
|
|
if self.api.Object[obj].uuid_attribute:
|
|
|
|
checked_attrs = checked_attrs + [self.api.Object[obj].uuid_attribute]
|
|
|
|
for obj_attr in checked_attrs:
|
2019-10-18 14:56:47 -05:00
|
|
|
obj_attr, _unused1, _unused2 = obj_attr.partition(';')
|
2011-10-11 03:26:21 -05:00
|
|
|
if obj_attr in OPERATIONAL_ATTRIBUTES:
|
|
|
|
continue
|
2012-02-25 18:02:04 -06:00
|
|
|
if obj_attr in self.api.Object[obj].params and \
|
|
|
|
'virtual_attribute' in \
|
|
|
|
self.api.Object[obj].params[obj_attr].flags:
|
|
|
|
# skip virtual attributes
|
|
|
|
continue
|
2011-10-11 03:26:21 -05:00
|
|
|
if obj_attr not in new_allowed_attrs:
|
|
|
|
raise errors.ValidationError(name=attr,
|
2012-02-10 03:27:53 -06:00
|
|
|
error=_('%(obj)s default attribute %(attr)s would not be allowed!') \
|
|
|
|
% dict(obj=obj, attr=obj_attr))
|
2011-10-11 03:26:21 -05:00
|
|
|
|
2012-09-25 06:46:56 -05:00
|
|
|
if ('ipaselinuxusermapdefault' in entry_attrs or
|
|
|
|
'ipaselinuxusermaporder' in entry_attrs):
|
2011-11-23 15:59:21 -06:00
|
|
|
config = None
|
2012-07-24 21:55:27 -05:00
|
|
|
failedattr = 'ipaselinuxusermaporder'
|
2012-09-25 06:46:56 -05:00
|
|
|
|
|
|
|
if 'ipaselinuxusermapdefault' in entry_attrs:
|
|
|
|
defaultuser = entry_attrs['ipaselinuxusermapdefault']
|
2012-07-24 21:55:27 -05:00
|
|
|
failedattr = 'ipaselinuxusermapdefault'
|
2012-09-25 06:46:56 -05:00
|
|
|
|
|
|
|
# validate the new default user first
|
|
|
|
if defaultuser is not None:
|
|
|
|
error_message = validate_selinuxuser(_, defaultuser)
|
|
|
|
|
|
|
|
if error_message:
|
|
|
|
raise errors.ValidationError(name='ipaselinuxusermapdefault',
|
|
|
|
error=error_message)
|
|
|
|
|
2011-11-23 15:59:21 -06:00
|
|
|
else:
|
2013-10-31 11:54:21 -05:00
|
|
|
config = ldap.get_ipa_config()
|
2012-09-25 06:46:56 -05:00
|
|
|
defaultuser = config.get('ipaselinuxusermapdefault', [None])[0]
|
2011-11-23 15:59:21 -06:00
|
|
|
|
2012-09-25 06:46:56 -05:00
|
|
|
if 'ipaselinuxusermaporder' in entry_attrs:
|
|
|
|
order = entry_attrs['ipaselinuxusermaporder']
|
2012-07-24 21:55:27 -05:00
|
|
|
userlist = order.split('$')
|
2012-09-25 06:46:56 -05:00
|
|
|
|
|
|
|
# validate the new user order first
|
|
|
|
for user in userlist:
|
|
|
|
if not user:
|
|
|
|
raise errors.ValidationError(name='ipaselinuxusermaporder',
|
|
|
|
error=_('A list of SELinux users delimited by $ expected'))
|
|
|
|
|
|
|
|
error_message = validate_selinuxuser(_, user)
|
|
|
|
if error_message:
|
|
|
|
error_message = _("SELinux user '%(user)s' is not "
|
|
|
|
"valid: %(error)s") % dict(user=user,
|
|
|
|
error=error_message)
|
|
|
|
raise errors.ValidationError(name='ipaselinuxusermaporder',
|
|
|
|
error=error_message)
|
2011-11-23 15:59:21 -06:00
|
|
|
else:
|
|
|
|
if not config:
|
2013-10-31 11:54:21 -05:00
|
|
|
config = ldap.get_ipa_config()
|
2011-11-23 15:59:21 -06:00
|
|
|
order = config['ipaselinuxusermaporder']
|
2012-07-24 21:55:27 -05:00
|
|
|
userlist = order[0].split('$')
|
2012-09-10 16:07:54 -05:00
|
|
|
if defaultuser and defaultuser not in userlist:
|
2012-07-24 21:55:27 -05:00
|
|
|
raise errors.ValidationError(name=failedattr,
|
|
|
|
error=_('SELinux user map default user not in order list'))
|
2011-11-23 15:59:21 -06:00
|
|
|
|
2016-05-30 11:51:48 -05:00
|
|
|
if 'ca_renewal_master_server' in options:
|
|
|
|
new_master = options['ca_renewal_master_server']
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.api.Object.server.get_dn_if_exists(new_master)
|
|
|
|
except errors.NotFound:
|
2018-01-03 05:11:15 -06:00
|
|
|
raise self.api.Object.server.handle_not_found(new_master)
|
2016-05-30 11:51:48 -05:00
|
|
|
|
|
|
|
backend = self.api.Backend.serverroles
|
|
|
|
backend.config_update(ca_renewal_master_server=new_master)
|
|
|
|
|
2017-03-09 11:14:52 -06:00
|
|
|
self.obj.validate_domain_resolution_order(entry_attrs)
|
|
|
|
|
2009-11-30 05:10:06 -06:00
|
|
|
return dn
|
2009-05-13 07:21:30 -05:00
|
|
|
|
2016-05-30 11:51:48 -05:00
|
|
|
def exc_callback(self, keys, options, exc, call_func,
|
|
|
|
*call_args, **call_kwargs):
|
|
|
|
if (isinstance(exc, errors.EmptyModlist) and
|
|
|
|
call_func.__name__ == 'update_entry' and
|
|
|
|
'ca_renewal_master_server' in options):
|
|
|
|
return
|
|
|
|
|
|
|
|
super(config_mod, self).exc_callback(
|
|
|
|
keys, options, exc, call_func, *call_args, **call_kwargs)
|
|
|
|
|
2016-05-30 11:42:01 -05:00
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
2017-05-16 10:29:39 -05:00
|
|
|
self.obj.show_servroles_attributes(
|
2019-03-25 09:59:51 -05:00
|
|
|
entry_attrs, "CA server", "KRA server", "IPA master",
|
|
|
|
"DNS server", **options)
|
2016-05-30 11:42:01 -05:00
|
|
|
return dn
|
2009-05-13 07:21:30 -05:00
|
|
|
|
|
|
|
|
2014-06-10 10:27:51 -05:00
|
|
|
@register()
|
2009-08-27 08:49:58 -05:00
|
|
|
class config_show(LDAPRetrieve):
|
2011-08-24 21:48:30 -05:00
|
|
|
__doc__ = _('Show the current configuration.')
|
2009-05-13 07:21:30 -05:00
|
|
|
|
2016-05-30 11:42:01 -05:00
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
|
2017-05-16 10:29:39 -05:00
|
|
|
self.obj.show_servroles_attributes(
|
2019-03-25 09:59:51 -05:00
|
|
|
entry_attrs, "CA server", "KRA server", "IPA master",
|
|
|
|
"DNS server", **options)
|
2016-05-30 11:42:01 -05:00
|
|
|
return dn
|