2011-11-23 15:59:21 -06:00
|
|
|
# Authors:
|
|
|
|
# Rob Crittenden <rcritten@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/>.
|
|
|
|
|
|
|
|
from ipalib import api, errors
|
2012-05-21 04:03:21 -05:00
|
|
|
from ipalib import Str, StrEnum, Bool
|
2011-11-23 15:59:21 -06:00
|
|
|
from ipalib.plugins.baseldap import *
|
|
|
|
from ipalib import _, ngettext
|
|
|
|
from ipalib.plugins.hbacrule import is_all
|
|
|
|
|
|
|
|
__doc__ = _("""
|
|
|
|
SELinux User Mapping
|
|
|
|
|
|
|
|
Map IPA users to SELinux users by host.
|
|
|
|
|
|
|
|
Hosts, hostgroups, users and groups can be either defined within
|
2012-01-17 16:54:00 -06:00
|
|
|
the rule or it may point to an existing HBAC rule. When using
|
|
|
|
--hbacrule option to selinuxusermap-find an exact match is made on the
|
|
|
|
HBAC rule name, so only one or zero entries will be returned.
|
2011-11-23 15:59:21 -06:00
|
|
|
|
|
|
|
EXAMPLES:
|
|
|
|
|
|
|
|
Create a rule, "test1", that sets all users to xguest_u:s0 on the host "server":
|
|
|
|
ipa selinuxusermap-add --usercat=all --selinuxuser=xguest_u:s0 test1
|
|
|
|
ipa selinuxusermap-add-host --hosts=server.example.com test1
|
|
|
|
|
|
|
|
Create a rule, "test2", that sets all users to guest_u:s0 and uses an existing HBAC rule for users and hosts:
|
2012-08-09 10:54:33 -05:00
|
|
|
ipa selinuxusermap-add --usercat=all --hbacrule=webserver --selinuxuser=guest_u:s0 test2
|
2011-11-23 15:59:21 -06:00
|
|
|
|
2012-08-09 10:54:33 -05:00
|
|
|
Display the properties of a rule:
|
|
|
|
ipa selinuxusermap-show test2
|
2011-11-23 15:59:21 -06:00
|
|
|
|
|
|
|
Create a rule for a specific user. This sets the SELinux context for
|
|
|
|
user john to unconfined_u:s0-s0:c0.c1023 on any machine:
|
|
|
|
ipa selinuxusermap-add --hostcat=all --selinuxuser=unconfined_u:s0-s0:c0.c1023 john_unconfined
|
|
|
|
ipa selinuxusermap-add-user --users=john john_unconfined
|
|
|
|
|
2012-08-09 10:54:33 -05:00
|
|
|
Disable a rule:
|
2011-11-23 15:59:21 -06:00
|
|
|
ipa selinuxusermap-disable test1
|
|
|
|
|
2012-08-09 10:54:33 -05:00
|
|
|
Enable a rule:
|
2011-11-23 15:59:21 -06:00
|
|
|
ipa selinuxusermap-enable test1
|
|
|
|
|
2012-01-17 16:54:00 -06:00
|
|
|
Find a rule referencing a specific HBAC rule:
|
|
|
|
ipa selinuxusermap-find --hbacrule=allow_some
|
|
|
|
|
2012-08-09 10:54:33 -05:00
|
|
|
Remove a rule:
|
2011-11-23 15:59:21 -06:00
|
|
|
ipa selinuxusermap-del john_unconfined
|
|
|
|
|
|
|
|
SEEALSO:
|
|
|
|
|
|
|
|
The list controlling the order in which the SELinux user map is applied
|
2012-03-14 07:16:29 -05:00
|
|
|
and the default SELinux user are available in the config-show command.
|
2011-11-23 15:59:21 -06:00
|
|
|
""")
|
|
|
|
|
|
|
|
notboth_err = _('HBAC rule and local members cannot both be set')
|
|
|
|
|
2012-09-06 06:03:42 -05:00
|
|
|
|
2011-11-23 15:59:21 -06:00
|
|
|
def validate_selinuxuser(ugettext, user):
|
|
|
|
"""
|
2012-08-15 16:21:19 -05:00
|
|
|
An SELinux user has 3 components: user:MLS:MCS. user and MLS are required.
|
|
|
|
user traditionally ends with _u but this is not mandatory.
|
|
|
|
The regex is ^[a-zA-Z][a-zA-Z_]*
|
|
|
|
|
|
|
|
The MLS part can only be:
|
|
|
|
Level: s[0-15](-s[0-15])
|
|
|
|
|
2011-11-23 15:59:21 -06:00
|
|
|
Then MCS could be c[0-1023].c[0-1023] and/or c[0-1023]-c[0-c0123]
|
|
|
|
Meaning
|
|
|
|
s0 s0-s1 s0-s15:c0.c1023 s0-s1:c0,c2,c15.c26 s0-s0:c0.c1023
|
|
|
|
|
|
|
|
Returns a message on invalid, returns nothing on valid.
|
|
|
|
"""
|
|
|
|
regex_name = re.compile(r'^[a-zA-Z][a-zA-Z_]*$')
|
|
|
|
regex_mls = re.compile(r'^s[0-9][1-5]{0,1}(-s[0-9][1-5]{0,1}){0,1}$')
|
|
|
|
regex_mcs = re.compile(r'^c(\d+)([.,-]c(\d+))*?$')
|
|
|
|
|
|
|
|
# If we add in ::: we don't have to check to see if some values are
|
|
|
|
# empty
|
2012-09-06 06:03:42 -05:00
|
|
|
(name, mls, mcs, ignore) = (user + ':::').split(':', 3)
|
2011-11-23 15:59:21 -06:00
|
|
|
|
|
|
|
if not regex_name.match(name):
|
|
|
|
return _('Invalid SELinux user name, only a-Z and _ are allowed')
|
2012-08-15 16:21:19 -05:00
|
|
|
if not mls or not regex_mls.match(mls):
|
2011-11-23 15:59:21 -06:00
|
|
|
return _('Invalid MLS value, must match s[0-15](-s[0-15])')
|
2012-08-28 16:14:28 -05:00
|
|
|
m = regex_mcs.match(mcs)
|
|
|
|
if mcs and (not m or (m.group(3) and (int(m.group(3)) > 1023))):
|
2012-09-06 06:03:42 -05:00
|
|
|
return _('Invalid MCS value, must match c[0-1023].c[0-1023] '
|
|
|
|
'and/or c[0-1023]-c[0-c0123]')
|
2011-11-23 15:59:21 -06:00
|
|
|
|
|
|
|
return None
|
|
|
|
|
2012-09-06 06:03:42 -05:00
|
|
|
|
2011-11-23 15:59:21 -06:00
|
|
|
def validate_selinuxuser_inlist(ldap, user):
|
|
|
|
"""
|
|
|
|
Ensure the user is in the list of allowed SELinux users.
|
|
|
|
|
|
|
|
Returns nothing if the user is found, raises an exception otherwise.
|
|
|
|
"""
|
|
|
|
config = ldap.get_ipa_config()[1]
|
|
|
|
item = config.get('ipaselinuxusermaporder', [])
|
|
|
|
if len(item) != 1:
|
2012-09-06 06:03:42 -05:00
|
|
|
raise errors.NotFound(reason=_('SELinux user map list not '
|
|
|
|
'found in configuration'))
|
2011-11-23 15:59:21 -06:00
|
|
|
userlist = item[0].split('$')
|
|
|
|
if user not in userlist:
|
2012-09-06 06:03:42 -05:00
|
|
|
raise errors.NotFound(
|
|
|
|
reason=_('SELinux user %(user)s not found in '
|
|
|
|
'ordering list (in config)') % dict(user=user))
|
2011-11-23 15:59:21 -06:00
|
|
|
|
|
|
|
return
|
|
|
|
|
2012-09-06 06:03:42 -05:00
|
|
|
|
2011-11-23 15:59:21 -06:00
|
|
|
class selinuxusermap(LDAPObject):
|
|
|
|
"""
|
|
|
|
SELinux User Map object.
|
|
|
|
"""
|
|
|
|
container_dn = api.env.container_selinux
|
|
|
|
object_name = _('SELinux User Map rule')
|
|
|
|
object_name_plural = _('SELinux User Map rules')
|
|
|
|
object_class = ['ipaassociation', 'ipaselinuxusermap']
|
|
|
|
default_attributes = [
|
|
|
|
'cn', 'ipaenabledflag',
|
|
|
|
'description', 'usercategory', 'hostcategory',
|
|
|
|
'ipaenabledflag', 'memberuser', 'memberhost',
|
|
|
|
'memberhostgroup', 'seealso', 'ipaselinuxuser',
|
|
|
|
]
|
|
|
|
uuid_attribute = 'ipauniqueid'
|
|
|
|
rdn_attribute = 'ipauniqueid'
|
|
|
|
attribute_members = {
|
|
|
|
'memberuser': ['user', 'group'],
|
|
|
|
'memberhost': ['host', 'hostgroup'],
|
|
|
|
}
|
|
|
|
|
|
|
|
# These maps will not show as members of other entries
|
|
|
|
|
|
|
|
label = _('SELinux User Maps')
|
|
|
|
label_singular = _('SELinux User Map')
|
|
|
|
|
|
|
|
takes_params = (
|
|
|
|
Str('cn',
|
|
|
|
cli_name='name',
|
|
|
|
label=_('Rule name'),
|
|
|
|
primary_key=True,
|
|
|
|
),
|
|
|
|
Str('ipaselinuxuser', validate_selinuxuser,
|
|
|
|
cli_name='selinuxuser',
|
|
|
|
label=_('SELinux User'),
|
|
|
|
),
|
|
|
|
Str('seealso?',
|
|
|
|
cli_name='hbacrule',
|
|
|
|
label=_('HBAC Rule'),
|
|
|
|
doc=_('HBAC Rule that defines the users, groups and hostgroups'),
|
|
|
|
),
|
|
|
|
StrEnum('usercategory?',
|
|
|
|
cli_name='usercat',
|
|
|
|
label=_('User category'),
|
|
|
|
doc=_('User category the rule applies to'),
|
|
|
|
values=(u'all', ),
|
|
|
|
),
|
|
|
|
StrEnum('hostcategory?',
|
|
|
|
cli_name='hostcat',
|
|
|
|
label=_('Host category'),
|
|
|
|
doc=_('Host category the rule applies to'),
|
|
|
|
values=(u'all', ),
|
|
|
|
),
|
|
|
|
Str('description?',
|
|
|
|
cli_name='desc',
|
|
|
|
label=_('Description'),
|
|
|
|
),
|
2012-05-21 04:03:21 -05:00
|
|
|
Bool('ipaenabledflag?',
|
2011-11-23 15:59:21 -06:00
|
|
|
label=_('Enabled'),
|
2012-05-21 04:03:21 -05:00
|
|
|
flags=['no_option'],
|
2011-11-23 15:59:21 -06:00
|
|
|
),
|
|
|
|
Str('memberuser_user?',
|
|
|
|
label=_('Users'),
|
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
|
|
|
Str('memberuser_group?',
|
|
|
|
label=_('User Groups'),
|
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
|
|
|
Str('memberhost_host?',
|
|
|
|
label=_('Hosts'),
|
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
|
|
|
Str('memberhost_hostgroup?',
|
|
|
|
label=_('Host Groups'),
|
|
|
|
flags=['no_create', 'no_update', 'no_search'],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
def _normalize_seealso(self, seealso):
|
|
|
|
"""
|
|
|
|
Given a HBAC rule name verify its existence and return the dn.
|
|
|
|
"""
|
|
|
|
if not seealso:
|
|
|
|
return None
|
|
|
|
|
|
|
|
try:
|
|
|
|
dn = DN(seealso)
|
|
|
|
return str(dn)
|
|
|
|
except ValueError:
|
|
|
|
try:
|
|
|
|
(dn, entry_attrs) = self.backend.find_entry_by_attr(
|
2012-09-06 06:03:42 -05:00
|
|
|
self.api.Object['hbacrule'].primary_key.name,
|
|
|
|
seealso,
|
|
|
|
self.api.Object['hbacrule'].object_class,
|
|
|
|
[''],
|
|
|
|
self.api.Object['hbacrule'].container_dn)
|
2011-11-23 15:59:21 -06:00
|
|
|
seealso = dn
|
|
|
|
except errors.NotFound:
|
|
|
|
raise errors.NotFound(reason=_('HBAC rule %(rule)s not found') % dict(rule=seealso))
|
|
|
|
|
|
|
|
return seealso
|
|
|
|
|
|
|
|
def _convert_seealso(self, ldap, entry_attrs, **options):
|
|
|
|
"""
|
|
|
|
Convert an HBAC rule dn into a name
|
|
|
|
"""
|
|
|
|
if options.get('raw', False):
|
2012-09-06 06:03:42 -05:00
|
|
|
return
|
2011-11-23 15:59:21 -06:00
|
|
|
|
|
|
|
if 'seealso' in entry_attrs:
|
|
|
|
(hbac_dn, hbac_attrs) = ldap.get_entry(entry_attrs['seealso'][0], ['cn'])
|
|
|
|
entry_attrs['seealso'] = hbac_attrs['cn'][0]
|
|
|
|
|
|
|
|
api.register(selinuxusermap)
|
|
|
|
|
|
|
|
|
|
|
|
class selinuxusermap_add(LDAPCreate):
|
|
|
|
__doc__ = _('Create a new SELinux User Map.')
|
|
|
|
|
|
|
|
msg_summary = _('Added SELinux User Map "%(value)s"')
|
|
|
|
|
|
|
|
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)
|
2011-11-23 15:59:21 -06:00
|
|
|
# rules are enabled by default
|
|
|
|
entry_attrs['ipaenabledflag'] = 'TRUE'
|
|
|
|
validate_selinuxuser_inlist(ldap, entry_attrs['ipaselinuxuser'])
|
2012-09-06 06:03:42 -05:00
|
|
|
|
|
|
|
# hbacrule is not allowed when usercat or hostcat is set
|
|
|
|
is_to_be_set = lambda x: x in entry_attrs and entry_attrs[x] != None
|
|
|
|
|
|
|
|
are_local_members_to_be_set = any(is_to_be_set(attr)
|
|
|
|
for attr in ('usercategory',
|
|
|
|
'hostcategory'))
|
|
|
|
|
|
|
|
is_hbacrule_to_be_set = is_to_be_set('seealso')
|
|
|
|
|
|
|
|
if is_hbacrule_to_be_set and are_local_members_to_be_set:
|
|
|
|
raise errors.MutuallyExclusiveError(reason=notboth_err)
|
|
|
|
|
|
|
|
if is_hbacrule_to_be_set:
|
|
|
|
entry_attrs['seealso'] = self.obj._normalize_seealso(entry_attrs['seealso'])
|
2011-11-23 15:59:21 -06:00
|
|
|
|
|
|
|
return dn
|
|
|
|
|
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *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)
|
2011-11-23 15:59:21 -06:00
|
|
|
self.obj._convert_seealso(ldap, entry_attrs, **options)
|
|
|
|
|
|
|
|
return dn
|
|
|
|
|
|
|
|
api.register(selinuxusermap_add)
|
|
|
|
|
|
|
|
|
|
|
|
class selinuxusermap_del(LDAPDelete):
|
|
|
|
__doc__ = _('Delete a SELinux User Map.')
|
|
|
|
|
|
|
|
msg_summary = _('Deleted SELinux User Map "%(value)s"')
|
|
|
|
|
|
|
|
api.register(selinuxusermap_del)
|
|
|
|
|
|
|
|
|
|
|
|
class selinuxusermap_mod(LDAPUpdate):
|
|
|
|
__doc__ = _('Modify a SELinux User Map.')
|
|
|
|
|
|
|
|
msg_summary = _('Modified SELinux User Map "%(value)s"')
|
|
|
|
|
|
|
|
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)
|
2011-11-23 15:59:21 -06:00
|
|
|
try:
|
|
|
|
(_dn, _entry_attrs) = ldap.get_entry(dn, attrs_list)
|
|
|
|
except errors.NotFound:
|
|
|
|
self.obj.handle_not_found(*keys)
|
|
|
|
|
2012-09-06 06:03:42 -05:00
|
|
|
is_to_be_deleted = lambda x: (x in _entry_attrs and x in entry_attrs) and \
|
|
|
|
entry_attrs[x] == None
|
|
|
|
|
|
|
|
# makes sure the local members and hbacrule is not set at the same time
|
|
|
|
# memberuser or memberhost could have been set using --setattr
|
|
|
|
is_to_be_set = lambda x: ((x in _entry_attrs and _entry_attrs[x] != None) or \
|
|
|
|
(x in entry_attrs and entry_attrs[x] != None)) and \
|
|
|
|
not is_to_be_deleted(x)
|
|
|
|
|
|
|
|
are_local_members_to_be_set = any(is_to_be_set(attr)
|
|
|
|
for attr in ('usercategory',
|
|
|
|
'hostcategory',
|
|
|
|
'memberuser',
|
|
|
|
'memberhost'))
|
|
|
|
|
|
|
|
is_hbacrule_to_be_set = is_to_be_set('seealso')
|
|
|
|
|
|
|
|
# this can disable all modifications if hbacrule and local members were
|
|
|
|
# set at the same time bypassing this commad, e.g. using ldapmodify
|
|
|
|
if are_local_members_to_be_set and is_hbacrule_to_be_set:
|
2011-11-23 15:59:21 -06:00
|
|
|
raise errors.MutuallyExclusiveError(reason=notboth_err)
|
|
|
|
|
2012-09-06 06:03:42 -05:00
|
|
|
if is_all(entry_attrs, 'usercategory') and 'memberuser' in entry_attrs:
|
|
|
|
raise errors.MutuallyExclusiveError(reason="user category "
|
|
|
|
"cannot be set to 'all' while there are allowed users")
|
|
|
|
if is_all(entry_attrs, 'hostcategory') and 'memberhost' in entry_attrs:
|
|
|
|
raise errors.MutuallyExclusiveError(reason="host category "
|
|
|
|
"cannot be set to 'all' while there are allowed hosts")
|
2011-11-23 15:59:21 -06:00
|
|
|
|
2012-08-15 16:21:19 -05:00
|
|
|
if 'ipaselinuxuser' in entry_attrs:
|
|
|
|
validate_selinuxuser_inlist(ldap, entry_attrs['ipaselinuxuser'])
|
2011-11-23 15:59:21 -06:00
|
|
|
|
2012-08-15 16:21:19 -05:00
|
|
|
if 'seealso' in entry_attrs:
|
|
|
|
entry_attrs['seealso'] = self.obj._normalize_seealso(entry_attrs['seealso'])
|
2011-11-23 15:59:21 -06:00
|
|
|
return dn
|
|
|
|
|
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *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)
|
2011-11-23 15:59:21 -06:00
|
|
|
self.obj._convert_seealso(ldap, entry_attrs, **options)
|
|
|
|
return dn
|
|
|
|
|
|
|
|
api.register(selinuxusermap_mod)
|
|
|
|
|
|
|
|
|
|
|
|
class selinuxusermap_find(LDAPSearch):
|
|
|
|
__doc__ = _('Search for SELinux User Maps.')
|
|
|
|
|
|
|
|
msg_summary = ngettext(
|
|
|
|
'%(count)d SELinux User Map matched', '%(count)d SELinux User Maps matched', 0
|
|
|
|
)
|
|
|
|
|
|
|
|
def execute(self, *args, **options):
|
|
|
|
# If searching on hbacrule we need to find the uuid to search on
|
2012-01-17 16:54:00 -06:00
|
|
|
if options.get('seealso'):
|
|
|
|
hbacrule = options['seealso']
|
|
|
|
|
|
|
|
try:
|
|
|
|
hbac = api.Command['hbacrule_show'](hbacrule,
|
|
|
|
all=True)['result']
|
|
|
|
dn = hbac['dn']
|
|
|
|
except errors.NotFound:
|
|
|
|
return dict(count=0, result=[], truncated=False)
|
|
|
|
options['seealso'] = dn
|
2011-11-23 15:59:21 -06:00
|
|
|
|
|
|
|
return super(selinuxusermap_find, self).execute(*args, **options)
|
|
|
|
|
|
|
|
def post_callback(self, ldap, entries, truncated, *args, **options):
|
|
|
|
if options.get('pkey_only', False):
|
2012-05-23 10:00:24 -05:00
|
|
|
return truncated
|
2011-11-23 15:59:21 -06:00
|
|
|
for entry in entries:
|
|
|
|
(dn, attrs) = entry
|
|
|
|
self.obj._convert_seealso(ldap, attrs, **options)
|
2012-05-23 10:00:24 -05:00
|
|
|
return truncated
|
2011-11-23 15:59:21 -06:00
|
|
|
|
|
|
|
api.register(selinuxusermap_find)
|
|
|
|
|
|
|
|
|
|
|
|
class selinuxusermap_show(LDAPRetrieve):
|
|
|
|
__doc__ = _('Display the properties of a SELinux User Map rule.')
|
|
|
|
|
|
|
|
def post_callback(self, ldap, dn, entry_attrs, *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)
|
2011-11-23 15:59:21 -06:00
|
|
|
self.obj._convert_seealso(ldap, entry_attrs, **options)
|
|
|
|
return dn
|
|
|
|
|
|
|
|
api.register(selinuxusermap_show)
|
|
|
|
|
|
|
|
|
|
|
|
class selinuxusermap_enable(LDAPQuery):
|
|
|
|
__doc__ = _('Enable an SELinux User Map rule.')
|
|
|
|
|
|
|
|
msg_summary = _('Enabled SELinux User Map "%(value)s"')
|
|
|
|
has_output = output.standard_value
|
|
|
|
|
|
|
|
def execute(self, cn):
|
|
|
|
ldap = self.obj.backend
|
|
|
|
|
|
|
|
dn = self.obj.get_dn(cn)
|
|
|
|
entry_attrs = {'ipaenabledflag': 'TRUE'}
|
|
|
|
|
|
|
|
try:
|
|
|
|
ldap.update_entry(dn, entry_attrs)
|
|
|
|
except errors.EmptyModlist:
|
|
|
|
raise errors.AlreadyActive()
|
|
|
|
except errors.NotFound:
|
|
|
|
self.obj.handle_not_found(cn)
|
|
|
|
|
|
|
|
return dict(
|
|
|
|
result=True,
|
|
|
|
value=cn,
|
|
|
|
)
|
|
|
|
|
|
|
|
api.register(selinuxusermap_enable)
|
|
|
|
|
|
|
|
|
|
|
|
class selinuxusermap_disable(LDAPQuery):
|
|
|
|
__doc__ = _('Disable an SELinux User Map rule.')
|
|
|
|
|
|
|
|
msg_summary = _('Disabled SELinux User Map "%(value)s"')
|
|
|
|
has_output = output.standard_value
|
|
|
|
|
|
|
|
def execute(self, cn):
|
|
|
|
ldap = self.obj.backend
|
|
|
|
|
|
|
|
dn = self.obj.get_dn(cn)
|
|
|
|
entry_attrs = {'ipaenabledflag': 'FALSE'}
|
|
|
|
|
|
|
|
try:
|
|
|
|
ldap.update_entry(dn, entry_attrs)
|
|
|
|
except errors.EmptyModlist:
|
|
|
|
raise errors.AlreadyInactive()
|
|
|
|
except errors.NotFound:
|
|
|
|
self.obj.handle_not_found(cn)
|
|
|
|
|
|
|
|
return dict(
|
|
|
|
result=True,
|
|
|
|
value=cn,
|
|
|
|
)
|
|
|
|
|
|
|
|
api.register(selinuxusermap_disable)
|
|
|
|
|
|
|
|
|
|
|
|
class selinuxusermap_add_user(LDAPAddMember):
|
|
|
|
__doc__ = _('Add users and groups to an SELinux User Map rule.')
|
|
|
|
|
|
|
|
member_attributes = ['memberuser']
|
|
|
|
member_count_out = ('%i object added.', '%i objects added.')
|
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, found, not_found, *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)
|
2011-11-23 15:59:21 -06:00
|
|
|
try:
|
|
|
|
(dn, entry_attrs) = ldap.get_entry(dn, self.obj.default_attributes)
|
|
|
|
except errors.NotFound:
|
|
|
|
self.obj.handle_not_found(*keys)
|
|
|
|
if 'usercategory' in entry_attrs and \
|
|
|
|
entry_attrs['usercategory'][0].lower() == 'all':
|
2012-07-04 07:52:47 -05:00
|
|
|
raise errors.MutuallyExclusiveError(
|
|
|
|
reason=_("users cannot be added when user category='all'"))
|
2011-11-23 15:59:21 -06:00
|
|
|
if 'seealso' in entry_attrs:
|
|
|
|
raise errors.MutuallyExclusiveError(reason=notboth_err)
|
|
|
|
return dn
|
|
|
|
|
|
|
|
api.register(selinuxusermap_add_user)
|
|
|
|
|
|
|
|
|
|
|
|
class selinuxusermap_remove_user(LDAPRemoveMember):
|
|
|
|
__doc__ = _('Remove users and groups from an SELinux User Map rule.')
|
|
|
|
|
|
|
|
member_attributes = ['memberuser']
|
|
|
|
member_count_out = ('%i object removed.', '%i objects removed.')
|
|
|
|
|
|
|
|
api.register(selinuxusermap_remove_user)
|
|
|
|
|
|
|
|
|
|
|
|
class selinuxusermap_add_host(LDAPAddMember):
|
|
|
|
__doc__ = _('Add target hosts and hostgroups to an SELinux User Map rule.')
|
|
|
|
|
|
|
|
member_attributes = ['memberhost']
|
|
|
|
member_count_out = ('%i object added.', '%i objects added.')
|
|
|
|
|
|
|
|
def pre_callback(self, ldap, dn, found, not_found, *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)
|
2011-11-23 15:59:21 -06:00
|
|
|
try:
|
|
|
|
(dn, entry_attrs) = ldap.get_entry(dn, self.obj.default_attributes)
|
|
|
|
except errors.NotFound:
|
|
|
|
self.obj.handle_not_found(*keys)
|
|
|
|
if 'hostcategory' in entry_attrs and \
|
|
|
|
entry_attrs['hostcategory'][0].lower() == 'all':
|
2012-07-04 07:52:47 -05:00
|
|
|
raise errors.MutuallyExclusiveError(
|
|
|
|
reason=_("hosts cannot be added when host category='all'"))
|
2011-11-23 15:59:21 -06:00
|
|
|
if 'seealso' in entry_attrs:
|
|
|
|
raise errors.MutuallyExclusiveError(reason=notboth_err)
|
|
|
|
return dn
|
|
|
|
|
|
|
|
api.register(selinuxusermap_add_host)
|
|
|
|
|
|
|
|
|
|
|
|
class selinuxusermap_remove_host(LDAPRemoveMember):
|
|
|
|
__doc__ = _('Remove target hosts and hostgroups from an SELinux User Map rule.')
|
|
|
|
|
|
|
|
member_attributes = ['memberhost']
|
|
|
|
member_count_out = ('%i object removed.', '%i objects removed.')
|
|
|
|
|
|
|
|
api.register(selinuxusermap_remove_host)
|